:root {
  color-scheme: dark;
  --bg: #080a0f;
  --panel: #111620;
  --panel-2: #171d29;
  --text: #f6f7fb;
  --muted: #97a1b5;
  --line: rgba(255,255,255,.1);
  --accent: #58d6b4;
  --accent-2: #f5c76b;
  --danger: #ff6b7a;
  --shadow: 0 24px 80px rgba(0,0,0,.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.light {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef2f7;
  --text: #111722;
  --muted: #607086;
  --line: rgba(20,28,40,.12);
  --shadow: 0 18px 60px rgba(27,38,58,.12);
}

* { box-sizing: border-box; }
html { width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(88,214,180,.14), transparent 34%), var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
button, input, select { font: inherit; min-width: 0; }
button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 16px;
  background: var(--accent);
  color: #07110e;
  font-weight: 800;
  cursor: pointer;
}
button.ghost, .icon-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}
.compact { min-height: 44px; padding: 0 12px; }
.hidden { display: none !important; }
.muted, small { color: var(--muted); }
.error { min-height: 22px; color: var(--danger); margin: 0; }
.status-text { min-height: 22px; color: var(--muted); margin: 0; font-size: 13px; font-weight: 700; }
.status-text.success { color: var(--accent); }
.status-text.danger { color: var(--danger); }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: 0; font-size: 12px; font-weight: 900; margin: 0 0 8px; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-panel {
  width: min(940px, 100%);
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 28px;
  align-items: center;
  background: linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.02));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(24px, 5vw, 58px);
  box-shadow: var(--shadow);
}
.login-panel h1 { font-size: clamp(38px, 7vw, 86px); line-height: .92; margin: 0 0 18px; letter-spacing: 0; max-width: 650px; }
.stack { display: grid; gap: 14px; }
.auth-step { display: none; }
.auth-step.active { display: grid; }
.pattern-step {
  justify-items: center;
}
.pattern-lock {
  width: min(100%, 390px);
  display: grid;
  gap: 13px;
  justify-items: center;
  text-align: center;
}
.pattern-brand {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .2em;
  font-size: 12px;
}
.pattern-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 2px solid var(--text);
  color: var(--text);
  font-size: 25px;
  font-weight: 950;
  letter-spacing: 0;
}
.pattern-mark span { color: var(--muted); }
.pattern-lock h2 {
  margin: 0;
  font-size: clamp(30px, 6vw, 46px);
  letter-spacing: 0;
}
.pattern-lock p {
  margin: 0;
  color: var(--muted);
}
.pattern-board {
  position: relative;
  width: min(76vw, 340px);
  aspect-ratio: 1;
  margin: 12px auto 0;
  user-select: none;
  touch-action: none;
}
#patternCanvas,
.pattern-grid {
  position: absolute;
  inset: 0;
}
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  align-items: center;
  justify-items: center;
  padding: 9%;
}
.pattern-dot {
  width: clamp(22px, 5vw, 34px);
  height: clamp(22px, 5vw, 34px);
  border: 0;
  border-radius: 999px;
  background: var(--text);
  padding: 0;
  min-height: 0;
  transform: scale(1);
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.pattern-dot.active {
  transform: scale(1.2);
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 25%, transparent);
}
.pattern-message {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.pattern-message.error { color: var(--danger); }
.pattern-message.ok { color: var(--accent); }
.pattern-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  width: 100%;
}
.pattern-actions button { min-width: 116px; text-transform: uppercase; letter-spacing: .08em; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(8,10,15,.76);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 24px;
}
body.light .sidebar { background: rgba(255,255,255,.74); }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #06100d;
  font-weight: 950;
}
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
nav { display: grid; gap: 8px; }
nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 800;
}
nav a.active, nav a:hover { background: var(--panel-2); color: var(--text); }
.sidebar .ghost { margin-top: auto; }

.content { padding: 24px; max-width: 1440px; width: 100%; min-width: 0; margin: 0 auto; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
}
.topbar h2 { margin: 0; font-size: clamp(26px, 4vw, 44px); letter-spacing: 0; }
.top-controls { display: flex; gap: 12px; align-items: stretch; }
.profile-date-card {
  display: grid;
  grid-template-columns: 170px 160px;
  gap: 10px;
}
.control-field {
  gap: 5px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.control-field span {
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
  color: var(--muted);
}
.control-field input,
.control-field select {
  min-height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
}
.quick-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.icon-btn { width: 44px; padding: 0; }
.view { display: none; }
.view.active { display: grid; gap: 18px; }

.metric-grid {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: 14px;
}
.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric { padding: 18px; min-height: 132px; display: grid; align-content: space-between; }
.metric span { color: var(--muted); font-weight: 800; }
.metric strong { font-size: clamp(28px, 4vw, 48px); letter-spacing: 0; }
.hero-metric { background: linear-gradient(135deg, rgba(88,214,180,.18), var(--panel)); }
.progress { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress i { display: block; width: 0; height: 100%; background: var(--accent); border-radius: inherit; }
.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.summary-strip article {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}
.summary-strip strong {
  font-size: 22px;
}
.day-activity-panel {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 320px) auto;
  gap: 14px;
  align-items: end;
}
.day-activity-panel h3 {
  margin: 0 0 5px;
  font-size: 17px;
}
.day-activity-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.analytics-grid, .split-grid, .form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.panel { padding: 18px; min-width: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel h3 { margin: 0; font-size: 17px; letter-spacing: 0; }
.panel-head span { color: var(--muted); font-weight: 800; font-size: 13px; }
canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  contain: layout paint size;
}
.list { display: grid; gap: 10px; }
.food-results {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
  padding-right: 2px;
}
.food-results button {
  min-height: 0;
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 11px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.food-results span {
  color: var(--muted);
  font-size: 12px;
}
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-2);
}
.item strong { display: block; }
.item span { color: var(--muted); font-size: 12px; font-weight: 700; }
.item button { min-height: 34px; padding: 0 10px; background: transparent; color: var(--danger); border: 1px solid rgba(255,107,122,.35); }
.item-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.item-actions button:first-child {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.form-panel { display: grid; gap: 13px; align-content: start; }
.wide { max-width: 860px; }
.form-actions { display: grid; gap: 8px; }
.inline-actions { grid-template-columns: 1fr auto; }
.triple { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.formula-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.formula-strip span {
  padding: 12px;
  background: var(--panel-2);
  border-radius: 8px;
  color: var(--text);
  font-weight: 900;
  text-align: center;
}
.info-strip {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}
.info-strip p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.info-strip strong { color: var(--text); }

@media (max-width: 900px) {
  .login-panel { grid-template-columns: 1fr; }
  .app-shell { grid-template-columns: minmax(0, 1fr); padding-bottom: calc(98px + env(safe-area-inset-bottom)); }
  .sidebar {
    position: fixed;
    z-index: 10;
    inset: auto 0 0 0;
    min-height: 84px;
    height: auto;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -18px 46px rgba(0,0,0,.28);
    flex-direction: row;
    align-items: center;
  }
  .brand, .sidebar .ghost { display: none; }
  nav { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; gap: 7px; }
  nav a {
    min-height: 54px;
    display: grid;
    place-items: center;
    padding: 8px 4px;
    text-align: center;
    font-size: 12px;
    line-height: 1.05;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line);
  }
  nav a.active {
    background: color-mix(in srgb, var(--accent) 22%, var(--panel-2));
    border-color: color-mix(in srgb, var(--accent) 65%, var(--line));
    color: var(--text);
    box-shadow: inset 0 3px 0 var(--accent);
  }
  .content { padding: 16px; }
  .topbar, .view, .panel, .metric, .day-activity-panel { min-width: 0; }
  .topbar { align-items: start; flex-direction: column; gap: 18px; }
  .top-controls {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr auto;
    gap: 10px;
  }
  .profile-date-card {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
  }
  .quick-actions {
    display: grid;
    grid-template-columns: 44px 44px;
    gap: 8px;
  }
  .quick-actions .logoutBtn {
    grid-column: 1 / -1;
    min-height: 36px;
    font-size: 12px;
    padding: 0 8px;
  }
  .metric-grid, .analytics-grid, .split-grid, .form-grid, .day-activity-panel, .summary-strip { grid-template-columns: 1fr; }
  .day-activity-panel { align-items: stretch; }
}

@media (max-width: 520px) {
  body { min-height: 100svh; }
  .login-shell { padding: 14px; }
  .login-panel { padding: 22px; }
  .login-panel h1 { font-size: clamp(32px, 9vw, 42px); line-height: 1; }
  .pattern-board { width: min(74vw, 300px); }
  .top-controls {
    width: 100%;
    grid-template-columns: 1fr;
    align-items: stretch;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: color-mix(in srgb, var(--panel) 88%, transparent);
  }
  .profile-date-card {
    grid-template-columns: 1fr;
    width: 100%;
  }
  .quick-actions {
    grid-template-columns: 44px 44px minmax(86px, 1fr);
  }
  .quick-actions .logoutBtn {
    grid-column: auto;
    min-height: 44px;
    width: 100%;
    font-size: 13px;
  }
  .sidebar {
    min-height: 88px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }
  nav { gap: 5px; }
  nav a {
    min-height: 58px;
    padding: 7px 2px;
    font-size: 10.5px;
    border-radius: 7px;
    overflow-wrap: anywhere;
  }
  .formula-strip, .triple { grid-template-columns: 1fr; }
  .form-actions {
    position: sticky;
    bottom: calc(94px + env(safe-area-inset-bottom));
    padding-top: 8px;
    background: linear-gradient(180deg, transparent, var(--bg) 24%);
  }
}
