/* KeepTrack — iOS-inspired light theme */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --line: rgba(60, 60, 67, 0.12);
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --radius: 14px;
  --radius-lg: 18px;
  --tab-h: 64px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  font-size: 17px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 19px; font-weight: 600; margin: 0 0 8px 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* Layout */
.page, .auth { max-width: 640px; margin: 0 auto; padding: 16px 16px 0; }
.auth { padding-top: 48px; }
.page-hdr { padding: 8px 4px 16px; }
.section-hdr { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 4px 8px; }
.section-hdr h2 { font-size: 15px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.04em; font-weight: 600; margin: 0; }

/* Card */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

/* Auth */
.auth-hdr { text-align: center; margin-bottom: 24px; }
.auth-hdr h1 { font-size: 34px; letter-spacing: -0.025em; }

/* Form */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 500; }
.form input, .form select, .form textarea {
  font: inherit; color: var(--text);
  background: #f2f2f7;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 12px 14px;
  min-height: 44px;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .15s, background .15s;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none;
  background: #fff;
  border-color: var(--accent);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { flex-direction: row !important; align-items: center; gap: 8px; color: var(--text) !important; }
.check input { min-height: 0; }
.more summary { cursor: pointer; color: var(--accent); padding: 4px 0; font-weight: 500; }
.more[open] { padding-bottom: 8px; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600;
  border: none; border-radius: 12px;
  padding: 12px 16px;
  min-height: 48px;
  cursor: pointer;
  transition: opacity .15s, transform .05s;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.985); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--accent-soft); color: var(--accent); }
.btn-danger { background: var(--red); color: #fff; }
.btn[disabled] { opacity: 0.5; cursor: progress; }
.btn-mini { background: var(--accent-soft); color: var(--accent); padding: 6px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.iconbtn {
  background: transparent; border: none; cursor: pointer;
  font-size: 20px; padding: 8px 10px; border-radius: 10px; color: var(--accent);
  min-width: 40px; min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
}
.iconbtn:hover { background: var(--accent-soft); }
.iconbtn.danger { color: var(--red); }
.iconbtn.danger:hover { background: rgba(255, 59, 48, 0.1); }
.btnrow { display: flex; gap: 12px; flex-wrap: wrap; }

/* Banner */
.banner { padding: 12px 16px; border-radius: 12px; margin-bottom: 12px; font-size: 14px; }
.banner-error { background: rgba(255, 59, 48, 0.1); color: var(--red); }
.banner-ok    { background: rgba(52, 199, 89, 0.12); color: var(--green); }

/* Today / Stats */
.date-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.date-title { text-align: center; flex: 1; }
.date-title h1 { font-size: 22px; }
.date-title .small { display: block; margin-top: 2px; }
.stats .stat { padding: 4px 0; }
.stats .stat + .stat { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 16px; }
.stat-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.stat-label { font-weight: 600; }
.stat-value { font-size: 17px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 13px; margin-top: 4px; }
.bar { height: 8px; background: #e5e5ea; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); transition: width .25s ease-out; }
.bar-fill.protein { background: var(--green); }
.macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; }
.macros > div { display: flex; flex-direction: column; gap: 2px; }

/* Lists */
.list { list-style: none; padding: 0; margin: 0; background: var(--card); border-radius: var(--radius-lg); overflow: hidden; }
.row { display: flex; align-items: center; padding: 12px 14px; gap: 12px; min-height: 56px; }
.row + .row { border-top: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 500; }
.row-sub { font-size: 13px; margin-top: 2px; }
.pickable { cursor: pointer; }
.pickable:hover { background: rgba(0,0,0,0.02); }
.pill { display: inline-block; background: var(--accent-soft); color: var(--accent); font-size: 11px; padding: 2px 6px; border-radius: 6px; margin-left: 4px; font-weight: 600; vertical-align: middle; }
.pill.green { background: rgba(52,199,89,0.15); color: var(--green); }

/* Empty state */
.empty { text-align: center; padding: 32px 16px; }
.empty-emoji { font-size: 48px; margin-bottom: 8px; }
.empty p { color: var(--muted); margin: 4px 0 16px; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(1.8) blur(20px);
  -webkit-backdrop-filter: saturate(1.8) blur(20px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  flex: 1; min-height: var(--tab-h);
  color: var(--muted);
  font-size: 11px; font-weight: 500;
  text-decoration: none;
}
.tab .tab-ico { font-size: 22px; line-height: 1; }
.tab.active { color: var(--accent); }
.tab:hover { text-decoration: none; }

/* Tabs in Add */
.tabs-inline { display: flex; gap: 6px; padding: 6px; }
.seg {
  flex: 1; background: transparent; border: none; padding: 10px;
  border-radius: 9px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg.active { background: var(--accent-soft); color: var(--accent); }
.tab-pane { animation: fadeIn .15s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* Scanner */
.scan-card { display: flex; flex-direction: column; gap: 12px; }
#scan-video { width: 100%; max-height: 320px; background: #000; border-radius: 12px; object-fit: cover; }
.scan-actions { display: flex; gap: 12px; justify-content: center; }
#scan-found { margin-top: 12px; }

/* Search */
.search-input { width: 100%; padding: 12px 14px; border: none; background: #f2f2f7; border-radius: 11px; font: inherit; min-height: 44px; }
.search-input:focus { outline: none; background: #fff; box-shadow: 0 0 0 2px var(--accent-soft); }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 8px 8px; font-weight: 600; letter-spacing: 0.04em; }
.table td { padding: 12px 8px; border-top: 1px solid var(--line); }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Danger zone */
.danger-zone { border: 1px solid rgba(255,59,48,0.2); }

/* Language switcher (auth pages) */
.lang-switch { display: flex; gap: 8px; justify-content: center; margin-top: 16px; padding: 0; }
.lang-btn { background: transparent; border: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; }
.lang-btn.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Desktop tweaks */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .tabbar {
    position: sticky; top: 0; bottom: auto;
    border-top: none; border-bottom: 1px solid var(--line);
    max-width: 100%;
  }
  .tab { flex-direction: row; gap: 6px; min-height: 56px; font-size: 14px; }
  .tab .tab-ico { font-size: 18px; }
  .page, .auth { padding-top: 24px; }
}
