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

:root {
  --accent:    #34C759;
  --accent-dk: #248A3D;
  --bg:        #F2F2F7;
  --card:      #FFFFFF;
  --sep:       #E5E5EA;
  --text:      #000000;
  --text2:     rgba(60,60,67,0.6);
  --text3:     rgba(60,60,67,0.3);
  --red:       #FF3B30;
  --blue:      #007AFF;
  --nav-h:     60px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 430px;
  margin: 0 auto;
  padding-bottom: calc(var(--nav-h) + 24px);
}

/* ── Header ── */
.header {
  padding: 20px 20px 8px;
}
.header h1 {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.header p {
  font-size: 13px;
  color: var(--text2);
  margin-top: 2px;
}

/* ── PWA install banner ── */
.install-banner {
  display: flex; align-items: center; gap: 12px;
  margin: 0 20px 12px; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--sep); border-radius: 14px;
  position: relative;
}
.install-banner-icon { font-size: 24px; flex-shrink: 0; }
.install-banner-text { flex: 1; min-width: 0; }
.install-banner-text strong { display: block; font-size: 14px; font-weight: 600; }
.install-banner-text p { font-size: 12px; color: var(--text2); margin-top: 2px; line-height: 1.4; }
.install-banner-btn {
  flex-shrink: 0; padding: 8px 14px; background: var(--accent); color: #fff;
  border: none; border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.install-banner-close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; color: var(--text2); font-size: 13px; cursor: pointer;
  padding: 4px;
}

/* ── Main ── */
.main { padding: 0 16px; }

/* ── Tabs ── */
.tab-content { display: none; padding-top: 16px; }
.tab-content.active { display: block; }

/* ── Card ── */
.card {
  background: var(--card);
  border-radius: 16px;
  border: 1px solid var(--sep);
  overflow: hidden;
  margin-bottom: 12px;
}
.card h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--sep);
}

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--sep);
  display: flex; justify-content: space-around; align-items: center;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  padding: 8px 20px;
  color: var(--text3);
  font-size: 10px;
  font-weight: 500;
  transition: color 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn svg {
  width: 24px; height: 24px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.nav-btn.active { color: var(--accent); }

/* ── Quick actions ── */
.quick-actions { display: flex; justify-content: center; gap: 20px; margin-bottom: 12px; padding: 4px 0; }
.btn-quick {
  padding: 0;
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  color: var(--accent);
  -webkit-tap-highlight-color: transparent;
}
.btn-quick:active { opacity: 0.6; }

/* ── Drop zone ── */
.drop-zone {
  background: var(--card);
  border-radius: 16px;
  border: 1px solid var(--sep);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.drop-zone.drag-over { background: #F0FDF4; }
.drop-zone-content {
  display: flex; flex-direction: column; align-items: center;
  padding: 44px 24px 36px; gap: 8px; text-align: center;
}
.drop-icon {
  width: 64px; height: 64px;
  background: var(--bg);
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 6px;
}
.drop-icon svg {
  width: 30px; height: 30px;
  stroke: var(--text2); fill: none;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.drop-zone-content h2 { font-size: 17px; font-weight: 600; }
.drop-zone-content p  { color: var(--text2); font-size: 14px; line-height: 1.4; }
.drop-zone-cta {
  margin-top: 12px; padding: 13px 36px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 99px;
  font-size: 16px; font-weight: 600;
  pointer-events: none;
}
.drop-zone:active .drop-zone-cta { opacity: 0.8; }

/* ── Preview ── */
.preview-area { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.preview-wrapper {
  position: relative; border-radius: 16px; overflow: hidden;
  border: 1px solid var(--sep);
}
.preview-wrapper img { width: 100%; max-height: 300px; object-fit: cover; display: block; }
.btn-remove {
  position: absolute; top: 10px; right: 10px;
  width: 30px; height: 30px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(8px);
  color: #fff; border: none; border-radius: 50%;
  font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.btn-analyze {
  width: 100%; padding: 16px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 14px;
  font-size: 17px; font-weight: 600; cursor: pointer;
  letter-spacing: -0.2px;
}
.btn-analyze:active { opacity: 0.85; }
.btn-analyze:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Results ── */
.results-section { margin-bottom: 12px; }
.loading-card {
  background: var(--card); border-radius: 16px; border: 1px solid var(--sep);
  padding: 48px 24px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.loading-card p { font-size: 15px; font-weight: 500; }
.loading-card small { color: var(--text2); font-size: 13px; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--sep); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-card { background: var(--card); border-radius: 16px; border: 1px solid var(--sep); overflow: hidden; }
.result-header { display: none; }

.total-calories {
  padding: 28px 20px 20px;
  border-bottom: 1px solid var(--sep);
  text-align: center;
}
.calories-number { font-size: 72px; font-weight: 700; color: var(--text); line-height: 1; letter-spacing: -2px; }
.calories-label { font-size: 17px; color: var(--text2); margin-top: 4px; }

.macros-grid { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--sep); }
.macro-card {
  padding: 16px 8px; text-align: center;
  border-right: 1px solid var(--sep);
}
.macro-card:last-child { border-right: none; }
.macro-icon { display: none; }
.macro-value { font-size: 22px; font-weight: 700; color: var(--text); display: flex; align-items: baseline; justify-content: center; gap: 2px; }
.macro-unit { font-size: 13px; font-weight: 400; color: var(--text2); }
.macro-label { font-size: 11px; color: var(--text2); margin-top: 3px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }

.dishes-section { }
.dishes-section h3 {
  font-size: 12px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 12px 16px 8px; border-bottom: 1px solid var(--sep);
}
.dishes-list { list-style: none; }
.dish-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--sep); font-size: 15px;
}
.dish-item:last-child { border-bottom: none; }
.dish-name { font-weight: 400; }
.dish-calories { color: var(--text2); font-size: 14px; }

.description-section { padding: 12px 16px; }
.description-section h3 {
  font-size: 12px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px;
}
#result-description { font-size: 14px; color: var(--text2); line-height: 1.5; }

.error-card {
  background: var(--card); border-radius: 16px; border: 1px solid var(--sep);
  padding: 36px 24px; text-align: center; border-top: 3px solid var(--red);
}
.error-icon { font-size: 40px; margin-bottom: 10px; }
.error-card h3 { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.error-card p { color: var(--text2); font-size: 14px; margin-bottom: 20px; line-height: 1.5; }

.btn-new {
  display: block; width: 100%; padding: 14px 16px;
  background: none; color: var(--accent);
  border: none; border-top: 1px solid var(--sep);
  font-size: 17px; font-weight: 400; cursor: pointer; text-align: center;
}
.btn-new:active { background: var(--bg); }

/* ── Progress ── */
.progress-item { padding: 12px 16px; border-bottom: 1px solid var(--sep); }
.progress-item:last-child { border-bottom: none; }
.progress-label {
  display: flex; justify-content: space-between;
  font-size: 14px; font-weight: 500; margin-bottom: 7px;
}
.progress-label span:last-child { color: var(--text2); font-weight: 400; font-size: 13px; }
.progress-bar-track { height: 5px; background: var(--sep); border-radius: 99px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.5s ease; }
.progress-bar-fill.protein { background: var(--blue); }
.progress-bar-fill.fat     { background: #FF9500; }
.progress-bar-fill.carbs   { background: #5AC8FA; }

/* ── Water ── */
.water-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 10px; }
.water-header h2 { font-size: 17px; font-weight: 600; padding: 0; border: none; }
.water-header span { font-size: 14px; color: var(--text2); }
.water-progress-track { height: 5px; background: var(--sep); border-radius: 99px; overflow: hidden; margin: 0 16px 14px; }
.water-progress-fill { height: 100%; background: #5AC8FA; border-radius: 99px; transition: width 0.4s ease; }
.water-buttons { display: flex; gap: 8px; padding: 0 16px 16px; flex-wrap: wrap; }
.btn-water {
  padding: 7px 14px; background: rgba(90,200,250,0.12); color: #0095CE;
  border: none; border-radius: 99px; font-size: 14px; font-weight: 500; cursor: pointer;
}
.btn-water:active { background: rgba(90,200,250,0.25); }
.btn-water-reset { background: var(--bg); color: var(--text2); margin-left: auto; }

/* ── Weight ── */
.weight-input-row {
  display: flex; align-items: center; gap: 8px; padding: 14px 16px;
  border-bottom: 1px solid var(--sep);
}
.weight-input-row input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--sep);
  border-radius: 10px; font-size: 20px; font-weight: 600;
  outline: none; background: var(--bg); transition: border-color 0.15s;
}
.weight-input-row input:focus { border-color: var(--accent); }
.weight-unit { font-size: 15px; color: var(--text2); }
.btn-save-weight {
  padding: 10px 18px; background: var(--accent); color: #fff;
  border: none; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.weight-empty { text-align: center; color: var(--text2); font-size: 14px; padding: 24px 16px; }
#weight-chart { width: 100%; display: block; padding: 8px 0; }
.weight-log-list { list-style: none; }
.weight-log-item {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--sep);
}
.weight-log-date { color: var(--text2); font-size: 14px; flex: 1; }
.weight-log-kg { font-weight: 600; font-size: 17px; }

/* ── Goals ── */
.goal-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--sep);
}
.goal-row:last-of-type { border-bottom: none; }
.goal-row label { font-size: 15px; }
.goal-row input {
  width: 90px; padding: 7px 10px; text-align: right;
  border: 1px solid var(--sep); border-radius: 8px;
  font-size: 15px; font-weight: 600; background: var(--bg); outline: none;
  transition: border-color 0.15s;
}
.goal-row input:focus { border-color: var(--accent); }
.btn-save-goals {
  display: block; width: 100%; padding: 14px;
  background: var(--accent); color: #fff;
  border: none; border-top: 1px solid var(--sep);
  font-size: 17px; font-weight: 600; cursor: pointer; text-align: center;
}
.goals-saved { text-align: center; color: var(--accent); font-size: 14px; padding: 12px; }

/* ── History ── */
.history-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--sep);
}
.history-header h2 { font-size: 17px; font-weight: 600; padding: 0; border: none; }
.btn-clear-history { font-size: 15px; color: var(--red); background: none; border: none; cursor: pointer; }
.history-empty { text-align: center; color: var(--text2); font-size: 14px; padding: 28px; }
.history-list { list-style: none; }
.history-item { padding: 12px 16px; border-top: 1px solid var(--sep); }
.history-item-header { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.history-time { font-size: 13px; color: var(--text2); }
.history-cal { font-size: 16px; font-weight: 600; flex: 1; }
.history-macros { font-size: 12px; color: var(--text2); margin-bottom: 2px; }
.btn-delete-meal { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 16px; padding: 0 2px; }
.btn-delete-meal:hover { color: var(--red); }
.history-desc { font-size: 13px; color: var(--text2); line-height: 1.4; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200; display: flex; align-items: flex-end;
}
.modal {
  background: var(--bg); border-radius: 20px 20px 0 0;
  width: 100%; max-height: 92vh; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.modal::before {
  content: ''; display: block; width: 36px; height: 4px;
  background: var(--sep); border-radius: 99px; margin: 10px auto 0;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 6px; }
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-close {
  background: var(--sep); border: none; border-radius: 50%;
  width: 28px; height: 28px; font-size: 12px; cursor: pointer;
  color: var(--text2); display: flex; align-items: center; justify-content: center;
}
.modal-body { padding: 0 0 16px; }

.form-section {
  background: var(--card); border-radius: 12px;
  margin: 0 16px 12px; overflow: hidden; border: 1px solid var(--sep);
}
.form-row { border-bottom: 1px solid var(--sep); }
.form-row:last-child { border-bottom: none; }
.form-row label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 14px 0;
}
.form-row input {
  display: block; width: 100%; padding: 6px 14px 10px;
  border: none; background: none; font-size: 16px; color: var(--text); outline: none;
}

.btn-modal-calc {
  display: block; width: calc(100% - 32px); margin: 0 16px;
  padding: 14px; background: var(--accent); color: #fff;
  border: none; border-radius: 12px;
  font-size: 17px; font-weight: 600; cursor: pointer;
}
.btn-modal-calc:active { opacity: 0.85; }
.btn-modal-calc:disabled { opacity: 0.45; cursor: not-allowed; }

.manual-loading {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; color: var(--text2); font-size: 14px;
}
.spinner-small {
  width: 18px; height: 18px;
  border: 2.5px solid var(--sep); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite; flex-shrink: 0;
}
.manual-error { color: var(--red); font-size: 13px; text-align: center; padding: 10px 16px; }

.manual-result {
  background: var(--card); border-radius: 12px;
  margin: 12px 16px 0; border: 1px solid var(--sep); overflow: hidden;
}
.manual-result-calories {
  font-size: 52px; font-weight: 700; letter-spacing: -1.5px;
  text-align: center; padding: 20px 16px 2px;
}
.manual-result-macros { text-align: center; font-size: 14px; color: var(--text2); padding: 2px 16px 10px; }
.manual-result-note {
  text-align: center; font-size: 12px; color: var(--text2);
  padding: 0 16px 12px; line-height: 1.4;
  border-bottom: 1px solid var(--sep);
}
.btn-modal-save {
  display: block; width: 100%; padding: 14px;
  background: none; color: var(--accent);
  border: none; font-size: 17px; font-weight: 400; cursor: pointer; text-align: center;
}
.btn-modal-save:active { background: var(--bg); }

/* ── Barcode ── */
#barcode-reader { overflow: hidden; margin-bottom: 0; }
.barcode-hint { text-align: center; color: var(--text2); font-size: 14px; padding: 12px 16px; }
.barcode-product-name { font-size: 16px; font-weight: 600; padding: 12px 16px 2px; }
.barcode-per100 { font-size: 12px; color: var(--text2); padding: 0 16px 8px; }
.barcode-macros { display: flex; gap: 6px; padding: 0 16px 12px; flex-wrap: wrap; }
.barcode-macros span {
  background: var(--bg); color: var(--text2);
  padding: 4px 10px; border-radius: 99px; font-size: 13px; border: 1px solid var(--sep);
}
.barcode-inputs { display: grid; grid-template-columns: 1fr 1fr; }
.barcode-inputs .form-row { border-bottom: 1px solid var(--sep); border-right: 1px solid var(--sep); }
.barcode-inputs .form-row:last-child { border-right: none; }
.barcode-total {
  background: var(--bg); padding: 12px 16px;
  font-size: 15px; font-weight: 600;
  border-top: 1px solid var(--sep); border-bottom: 1px solid var(--sep);
}
.barcode-error { color: var(--red); font-size: 13px; text-align: center; padding: 12px 16px; }

/* ── Footer ── */
.footer { padding: 16px 20px; text-align: center; color: var(--text3); font-size: 11px; line-height: 1.5; }

/* ── Paywall ── */
.paywall-card {
  background: var(--card); border-radius: 16px; border: 1px solid var(--sep);
  padding: 32px 24px; text-align: center;
}
.paywall-icon { font-size: 40px; margin-bottom: 10px; }
.paywall-card h3 { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.paywall-card p { color: var(--text2); font-size: 14px; line-height: 1.5; }

.promo-row {
  display: flex; gap: 8px; margin: 20px 0 6px;
}
.promo-row input {
  flex: 1; padding: 12px 14px; border: 1px solid var(--sep); border-radius: 12px;
  font-size: 15px; color: var(--text); background: var(--bg); outline: none;
}
.promo-row input:focus { border-color: var(--accent); }
.promo-row .btn-quick {
  padding: 0 14px; font-weight: 600;
}
.promo-message { font-size: 13px; color: var(--accent); margin-bottom: 6px; }
.promo-message-error { color: var(--red); }

.paywall-price {
  font-size: 22px; font-weight: 700; color: var(--text);
  margin: 20px 0 12px;
}
#paywall-email {
  width: 100%; padding: 12px 14px; border: 1px solid var(--sep); border-radius: 12px;
  font-size: 15px; color: var(--text); background: var(--bg); outline: none;
  margin-bottom: 10px; box-sizing: border-box;
}
#paywall-email:focus { border-color: var(--accent); }
.paywall-email-error { font-size: 13px; color: var(--red); margin-bottom: 10px; }

.paywall-card-number {
  margin-top: 14px; padding: 14px; background: var(--bg); border-radius: 12px;
}
.paywall-card-number-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.paywall-card-number-row code {
  font-size: 17px; font-weight: 600; letter-spacing: 0.5px;
}
.paywall-card-number-row .btn-quick { padding: 0 10px; font-weight: 600; }
.paywall-copy-message { font-size: 12px; color: var(--accent); margin-top: 6px; }

.paywall-id-hint {
  font-size: 12px; color: var(--text2); margin-top: 14px;
}
.paywall-id-hint code {
  background: var(--bg); border-radius: 6px; padding: 2px 6px; font-size: 12px;
}
.paywall-contact { font-size: 12px; margin-top: 8px; }
.paywall-contact a { color: var(--accent); }

.paywall-closed-message {
  font-size: 14px; color: var(--text2); margin-top: 20px; line-height: 1.5;
}

.hidden { display: none !important; }

/* ── Mobile ── */
@media (max-width: 390px) {
  .header { padding: 16px 16px 8px; }
  .header h1 { font-size: 28px; }
  .calories-number { font-size: 58px; }
  .nav-btn { padding: 8px 12px; }
  .macro-value { font-size: 18px; }
}
