@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #7C9070;
  --primary-light: #9AAD8E;
  --primary-dark: #5A7A4E;
  --accent: #D4A5A5;
  --accent-warm: #C9B8A8;
  --bg: #FAF8F5;
  --bg-primary: #F7F6F3;
  --card: rgba(255,255,255,0.90);
  --text: #1A1A1A;
  --text-muted: #6B6B6B;
  --text-light: #999999;
  --border: #E8E6E1;
  --border-subtle: #F0EFEC;
  --green: #7C9070;
  --blue: #8BA4B8;
  --yellow: #C9A96E;
  --orange: #C47D4E;
  --red: #C26B6B;
  --max-w: 480px;
  --nav-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { height: 100%; }

body {
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(160deg, #FAF8F5 0%, #F7F6F3 40%, #F0EFEC 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ── App Shell ── */
.app {
  max-width: var(--max-w);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* On desktop, add subtle phone frame feel */
@media (min-width: 520px) {
  .app {
    border-left: 1px solid rgba(0,0,0,0.04);
    border-right: 1px solid rgba(0,0,0,0.04);
    box-shadow: 0 0 40px rgba(0,0,0,0.04);
  }
}

/* ── Top Bar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(255,255,255,0.78);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--nav-h);
  min-height: var(--nav-h);
  padding: 0 16px;
  flex-shrink: 0;
}
.topbar-title {
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.topbar-back {
  position: absolute;
  left: 12px;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--primary);
  display: none;
  padding: 4px 8px;
}

/* ── Views ── */
.view {
  display: none;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  flex: 1;
  overflow-y: auto;
}
.view.active { display: block; animation: fadeUp .35s ease; }

/* Chat view: lock to viewport, no page scroll */
#view-chat { padding: 0; overflow: hidden; }
#view-chat.active { display: flex; }

/* When chat is active, lock body and app to exact viewport */
body.chat-active { overflow: hidden; height: 100vh; height: 100dvh; }
body.chat-active .app { height: 100vh; height: 100dvh; min-height: 0; max-height: 100vh; max-height: 100dvh; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Cards ── */
.card {
  background: var(--card);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.04);
  border: 1px solid var(--border-subtle);
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Upload View ── */
.upload-hero {
  text-align: center;
  padding: 40px 0 24px;
}
.upload-hero h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}
.upload-hero p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
}

.upload-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
/* Desktop: hide camera button, show drag zone */
@media (hover: hover) and (pointer: fine) {
  .upload-buttons { display: none; }
}
/* Mobile: hide drag zone, show buttons */
@media (hover: none) and (pointer: coarse) {
  .upload-zone { display: none !important; }
  .upload-buttons { display: flex; }
}

.upload-zone {
  border: 2px dashed var(--primary-light);
  border-radius: 20px;
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  background: rgba(124,144,112,0.04);
  position: relative;
  overflow: hidden;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(124,144,112,0.08);
  transform: scale(1.01);
}
.upload-zone-text { font-size: 15px; font-weight: 500; color: var(--text-muted); }
.upload-zone-sub { font-size: 12px; color: var(--text-light); margin-top: 8px; }
.upload-zone input { display: none; }

.upload-preview {
  display: none;
  text-align: center;
}
.upload-preview img {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 20px;
  border: 3px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  margin-bottom: 16px;
}
.upload-preview-name {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 32px;
  border-radius: 16px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 4px 16px rgba(124,144,112,0.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(124,144,112,0.35); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary {
  background: var(--bg-primary);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border-subtle); }
.btn-block { width: 100%; }

.validation-error {
  background: #FDF0E8;
  border: 1px solid #E8C8B8;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  text-align: center;
  animation: fadeUp .35s ease;
}
.upload-notice {
  text-align: center;
  padding: 8px 0;
}
.upload-notice p {
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.8;
}

.validation-error-icon { display: none; }
.validation-error-reason { font-size: 14px; font-weight: 600; color: var(--red); line-height: 1.5; margin-bottom: 8px; }
.validation-error-tip { font-size: 13px; color: #8B6914; line-height: 1.5; background: #FAF5EF; padding: 10px 14px; border-radius: 10px; }

.upload-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}

/* ── Loading View ── */
#view-loading {
  display: none;
  text-align: center;
  padding-top: 120px;
}
#view-loading.active { display: block; }

.loading-spinner {
  width: 72px;
  height: 72px;
  margin: 0 auto 24px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}
.loading-sub {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}
.loading-steps {
  margin-top: 32px;
  text-align: left;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}
.loading-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  font-size: 14px;
  color: var(--text-light);
  transition: color .3s;
}
.loading-step.active { color: var(--primary); font-weight: 600; }
.loading-step.done { color: var(--green); }
.loading-step-icon {
  font-size: 12px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-light);
  font-weight: 600;
  flex-shrink: 0;
  transition: all .3s;
}
.loading-step.active .loading-step-icon {
  background: var(--primary);
  color: #fff;
}
.loading-step.done .loading-step-icon {
  background: var(--green);
  color: #fff;
}

/* ── Report View ── */
.profile {
  display: flex;
  gap: 16px;
  align-items: center;
}
.profile-img {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  flex-shrink: 0;
}
.profile-info { flex: 1; min-width: 0; }
.profile-type {
  display: inline-block;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 3px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}
.profile-summary {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 4px;
}

/* Score ring */
.score-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 4px 0;
}
.score-ring { position: relative; width: 120px; height: 120px; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring-bg { fill: none; stroke: var(--border-subtle); stroke-width: 8; }
.score-ring-fill { fill: none; stroke-width: 8; stroke-linecap: round; transition: stroke-dasharray 1s ease; }
.score-ring-text { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
.score-ring-num { font-size: 32px; font-weight: 700; line-height: 1; }
.score-ring-label { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.score-meta { display: flex; flex-direction: column; gap: 10px; }
.score-meta-item { text-align: center; background: var(--bg); border-radius: 12px; padding: 10px 18px; }
.score-meta-val { font-size: 20px; font-weight: 700; color: var(--text); }
.score-meta-label { font-size: 11px; color: var(--text-light); margin-top: 2px; }

/* Radar */
.radar-wrap { display: flex; justify-content: center; padding: 4px 0; }

/* Metrics */
.metrics-grid { display: flex; flex-direction: column; gap: 12px; }
.metric-card { background: var(--bg); border-radius: 14px; padding: 16px; border: 1px solid var(--border-subtle); }
.metric-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.metric-icon { display: none; }
.metric-name { font-size: 14px; font-weight: 600; flex: 1; }
.metric-badge {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.score-bar-wrap { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.score-bar { height: 100%; border-radius: 3px; transition: width .8s ease; }
.score-num { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.score-num small { font-size: 12px; color: var(--text-light); font-weight: 400; }
.metric-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-bottom: 6px; }
.metric-advice { font-size: 12px; color: var(--primary-dark); line-height: 1.5; background: rgba(124,144,112,0.06); padding: 8px 12px; border-radius: 8px; }

/* Zones */
.zone-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-subtle); align-items: baseline; }
.zone-item:last-child { border-bottom: none; }
.zone-label { font-size: 13px; font-weight: 600; color: var(--primary-dark); min-width: 60px; }
.zone-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* Concerns */
.concerns-list { list-style: none; counter-reset: concern; }
.concerns-list li {
  counter-increment: concern;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.concerns-list li:last-child { border-bottom: none; }
.concerns-list li::before {
  content: counter(concern);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  background: linear-gradient(135deg, var(--accent), var(--red));
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.ingredients-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.ingredient-tag {
  background: rgba(124,144,112,0.10);
  color: var(--primary-dark);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid rgba(124,144,112,0.15);
}

.daily-tip {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-muted);
  background: linear-gradient(135deg, #FAF5EF, #F0E6D6);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(201,184,168,0.2);
}

/* Chat CTA in report */
.chat-cta {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  color: #fff;
  margin-bottom: 16px;
}
.chat-cta h3 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.chat-cta p { font-size: 13px; opacity: 0.9; margin-bottom: 16px; line-height: 1.5; }
.btn-chat {
  background: rgba(255,255,255,0.95);
  color: var(--primary-dark);
  border: none;
  padding: 12px 28px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .2s;
}
.btn-chat:hover { background: #fff; transform: translateY(-1px); }

.report-footer {
  text-align: center;
  padding: 12px 0 24px;
  font-size: 11px;
  color: var(--text-light);
  line-height: 1.6;
}

/* ── Chat View ── */
.chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.chat-msg {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.6;
  animation: fadeUp .25s ease;
  word-break: break-word;
}
.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-bottom-right-radius: 6px;
}
.chat-msg.bot {
  align-self: flex-start;
  background: var(--card);
  color: var(--text);
  border-bottom-left-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border: 1px solid var(--border-subtle);
}
.chat-msg.bot .msg-label {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 4px;
}
/* Markdown in chat */
.chat-msg.bot .md-h2,
.chat-msg.bot .md-h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 8px 0 4px;
  color: var(--text);
}
.chat-msg.bot .md-list {
  margin: 4px 0 4px 8px;
  padding-left: 14px;
  list-style: disc;
}
.chat-msg.bot .md-list li {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 2px;
}
.chat-msg.typing .dots {
  display: inline-flex;
  gap: 4px;
}
.chat-msg.typing .dots span {
  width: 7px; height: 7px;
  background: var(--text-light);
  border-radius: 50%;
  animation: bounce .6s infinite alternate;
}
.chat-msg.typing .dots span:nth-child(2) { animation-delay: .15s; }
.chat-msg.typing .dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  to { transform: translateY(-6px); opacity: .4; }
}

.chat-input-area {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 8px;
  align-items: end;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  transition: border-color .2s;
  background: #fff;
}
.chat-input:focus { border-color: var(--primary-light); }
.chat-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s;
}
.chat-send:hover { transform: scale(1.05); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 8px;
  flex-shrink: 0;
}
.chat-suggestion {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.chat-suggestion:hover { background: var(--border-subtle); color: var(--text); }

/* ── New analysis btn ── */
.new-analysis-bar {
  padding: 12px 16px;
  text-align: center;
}
