:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #131a2a;
  --muted: #68718a;
  --primary: #4f7cff;
  --primary-dark: #3a62d8;
  --accent: #17c3b2;
  --danger: #e5484d;
  --warning: #f5a524;
  --success: #30a46c;
  --border: #e3e7f0;
  --shadow: 0 8px 30px rgba(19, 26, 42, 0.08);
  --radius: 18px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 520px;
  min-height: 100dvh;
  position: relative;
}

.view {
  display: none;
  min-height: 100dvh;
  padding-bottom: 40px;
  animation: fadeIn 0.25s ease;
}

.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  background: rgba(244, 246, 251, 0.9);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.logo {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(19, 26, 42, 0.06);
  transition: transform 0.15s;
}

.icon-btn:active { transform: scale(0.94); }

.page-title {
  font-weight: 700;
  font-size: 17px;
}

.home-hero {
  padding: 28px 24px 20px;
  text-align: center;
}

.home-hero h1 {
  font-size: 27px;
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.home-hero p {
  margin: 12px auto 24px;
  color: var(--muted);
  line-height: 1.55;
  max-width: 380px;
}

.drop-hint {
  font-size: 13px;
  color: var(--muted);
  margin: -4px 0 6px;
  text-align: center;
}

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
  font-family: inherit;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 10px 24px rgba(79, 124, 255, 0.3);
}

.btn-primary:hover { box-shadow: 0 12px 28px rgba(79, 124, 255, 0.4); }

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-big {
  padding: 18px;
  font-size: 18px;
  border-radius: 18px;
  margin-bottom: 12px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 10px;
}

.recent {
  padding: 10px 20px 30px;
}

.section-title {
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 14px;
}

.recent-list {
  display: grid;
  gap: 12px;
}

.recent-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 14px;
  align-items: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.12s;
}

.recent-card:active { transform: scale(0.985); }

.recent-thumb {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  object-fit: cover;
  background: linear-gradient(135deg, #dfe7ff, #e5faf7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.recent-info { flex: 1; min-width: 0; }

.recent-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-verdict {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-score {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
  flex-shrink: 0;
}

.empty-state {
  background: var(--card);
  border: 1px dashed #c9d2e4;
  border-radius: var(--radius);
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.content {
  padding: 8px 20px 40px;
}

.content.center {
  text-align: center;
  padding-top: 40px;
}

.ocr-photo {
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
  background: #dfe7ff;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ocr-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ocr-photo .placeholder {
  font-size: 42px;
  opacity: 0.6;
}

.confidence {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.confidence .good { color: var(--success); font-weight: 700; }
.confidence .bad { color: var(--danger); font-weight: 700; }

.ocr-textarea {
  width: 100%;
  min-height: 180px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  font-size: 15px;
  line-height: 1.5;
  resize: vertical;
  background: var(--card);
  font-family: inherit;
  color: var(--text);
  outline: none;
}

.ocr-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.15);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.actions .btn:only-child {
  grid-column: 1 / -1;
}

.nutrition-icon {
  font-size: 60px;
  margin-bottom: 14px;
}

.content.center h2 {
  font-size: 23px;
  font-weight: 800;
  margin-bottom: 10px;
}

.content.center p {
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 24px;
  padding: 0 10px;
}

.processing-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 30px;
}

.spinner {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 5px solid #dfe7ff;
  border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.processing-title {
  font-size: 20px;
  font-weight: 800;
}

.processing-note {
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Результат ---------- */

.result-header {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
}

.result-photo {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  object-fit: cover;
  background: linear-gradient(135deg, #dfe7ff, #e5faf7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.result-name {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.25;
}

.result-brand {
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  background: #eef1fb;
  color: var(--primary-dark);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 6px;
}

.score-card {
  background: linear-gradient(150deg, #1f2b4d, #2c3e6b 55%, #3b4f80);
  color: #fff;
  border-radius: 22px;
  padding: 26px 20px;
  text-align: center;
  margin-bottom: 16px;
  box-shadow: 0 16px 36px rgba(31, 43, 77, 0.25);
}

.score-ring {
  width: 150px;
  height: 150px;
  margin: 0 auto 12px;
  position: relative;
}

.score-ring svg {
  transform: rotate(-90deg);
}

.score-ring .track {
  stroke: rgba(255, 255, 255, 0.14);
}

.score-ring .bar {
  stroke: url(#scoreGradient);
  stroke-linecap: round;
  transition: stroke-dashoffset 1s ease;
}

.score-number {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-number b {
  font-size: 42px;
  line-height: 1;
}

.score-number span {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}

.score-verdict {
  font-size: 17px;
  font-weight: 700;
}

.summary {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 15px;
  line-height: 1.55;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.card h3 {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 10px;
}

.main-issue {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 15px;
  line-height: 1.45;
}

.main-issue .emoji {
  font-size: 24px;
  line-height: 1.2;
}

.positives-list {
  list-style: none;
  display: grid;
  gap: 8px;
}

.positives-list li {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 14.5px;
}

.positives-list .check {
  color: var(--success);
  font-weight: 800;
}

.breakdown {
  display: grid;
  gap: 12px;
}

.breakdown-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
}

.breakdown-row .label {
  font-size: 14px;
  font-weight: 600;
}

.breakdown-row .value {
  font-size: 14px;
  font-weight: 800;
  color: var(--primary);
}

.bar {
  grid-column: 1 / -1;
  height: 8px;
  border-radius: 10px;
  background: #eef1f8;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.8s ease;
}

.adjust-row {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  color: var(--muted);
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.adjust-row b {
  color: var(--text);
}

.ingredient-list {
  display: grid;
  gap: 10px;
}

.ingredient-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 14px;
  cursor: pointer;
  background: #fbfcff;
  transition: transform 0.12s, border-color 0.15s;
}

.ingredient-card:active { transform: scale(0.99); }
.ingredient-card:hover { border-color: var(--primary); }

.ingredient-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ingredient-name {
  font-weight: 700;
  font-size: 14.5px;
}

.ingredient-e {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-dark);
  background: #eaf0ff;
  border-radius: 12px;
  padding: 2px 8px;
}

.status-badge {
  font-size: 11px;
  font-weight: 700;
  border-radius: 12px;
  padding: 2px 8px;
}

.status-matched { background: #e4f8ef; color: #1f7a52; }
.status-probable { background: #fff3dd; color: #a4650a; }
.status-unknown { background: #ffe9e9; color: #b03030; }

.ingredient-desc {
  font-size: 13.5px;
  color: var(--muted);
  margin-top: 7px;
  line-height: 1.45;
}

.warnings {
  display: grid;
  gap: 10px;
}

.warning {
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  border: 1px solid;
}

.warning-important {
  background: #fff1f1;
  border-color: #f5c6c7;
  color: #9d2c2c;
}

.warning-caution {
  background: #fff8e8;
  border-color: #f0d9a8;
  color: #8a5a10;
}

.warning-info {
  background: #eef4ff;
  border-color: #c9d9f5;
  color: #2d4f9e;
}

.warning .w-title {
  font-weight: 800;
}

.warning .w-desc {
  margin-top: 3px;
  opacity: 0.9;
}

.plain-text {
  font-size: 15px;
  line-height: 1.6;
  color: #24304a;
}

.reliability {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding: 12px 14px;
  background: #f1f4fb;
  border-radius: 14px;
  margin-bottom: 16px;
}

.reliability b {
  text-transform: capitalize;
}

.research-note {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 10px;
}

.research-sources {
  display: grid;
  gap: 10px;
}

.research-source {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fbfcff;
}

.research-source a {
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
}

.research-source a:hover {
  text-decoration: underline;
}

.source-type {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-dark);
  background: #eaf0ff;
  border-radius: 12px;
  padding: 2px 8px;
  margin-left: 6px;
  vertical-align: middle;
}

.research-snippet {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.45;
}

.result-actions {
  display: grid;
  gap: 10px;
}

.result-actions .btn {
  grid-column: 1 / -1;
}

.result-actions .btn-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  grid-column: 1 / -1;
}

.meta-note {
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

/* ---------- Модалки ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 16, 32, 0.5);
  animation: fadeIn 0.2s;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 85dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 24px 22px 30px;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.modal-card h2 {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
}

.modal-card h3 {
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 8px;
}

.modal-card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 10px;
}

.modal-card textarea {
  width: 100%;
  min-height: 110px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 4px;
}

.detail-row {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f2f8;
  font-size: 14px;
}

.detail-row:last-child { border-bottom: none; }

.detail-row .d-label {
  flex: 0 0 120px;
  color: var(--muted);
  font-weight: 600;
}

.detail-row .d-value {
  flex: 1;
  line-height: 1.45;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #17203a;
  color: #fff;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
  max-width: 90vw;
  text-align: center;
  animation: slideUp 0.25s ease;
}

.toast.hidden { display: none; }

/* ---------- Drag & drop overlay ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(79, 124, 255, 0.18);
  backdrop-filter: blur(3px);
}

.drop-overlay.hidden { display: none; }

.drop-overlay-card {
  background: var(--card);
  border: 2px dashed var(--primary);
  border-radius: 22px;
  padding: 30px 38px;
  font-size: 18px;
  font-weight: 800;
  box-shadow: var(--shadow);
  animation: fadeIn 0.15s ease;
}

@media (min-width: 560px) {
  .modal {
    align-items: center;
    padding: 20px;
  }

  .modal-card {
    border-radius: 22px;
  }
}
