/* =========================================================
   CalorieLab — Calorie & Macro Calculator
   Plain CSS · no frameworks
   ========================================================= */

:root {
  --bg-1: #070812;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-solid: #12152a;
  --border: rgba(255, 255, 255, 0.09);
  --text: #eef0ff;
  --muted: #9aa1c0;
  --accent: #34d399;
  --accent-2: #fbbf24;
  --accent-3: #22d3ee;
  --danger: #f43f5e;
  --grad: linear-gradient(135deg, #34d399, #fbbf24);
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.5);
}

html[data-theme="light"] {
  --bg-1: #e9edf9;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --border: rgba(23, 24, 60, 0.1);
  --text: #16182e;
  --muted: #62678a;
  --shadow: 0 18px 50px rgba(70, 80, 150, 0.16);
}

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

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg-1);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

/* ---------- Background ---------- */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.5; animation: float 20s ease-in-out infinite; }
.orb-1 { width: 440px; height: 440px; background: #34d399; top: -130px; left: -90px; }
.orb-2 { width: 400px; height: 400px; background: #fbbf24; bottom: -150px; right: -70px; animation-delay: -7s; }
.orb-3 { width: 320px; height: 320px; background: #22d3ee; top: 42%; left: 56%; animation-delay: -13s; opacity: 0.34; }
html[data-theme="light"] .orb { opacity: 0.3; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -42px) scale(1.06); }
  66% { transform: translate(-32px, 30px) scale(0.96); }
}

.grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.22;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
}

/* ---------- App layout ---------- */
.app {
  height: 100dvh;
  display: flex; flex-direction: column;
  gap: 16px; padding: 0 22px 22px;
  width: 100%; max-width: 1320px; margin: 0 auto;
  position: relative; z-index: 1;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 16px 4px 2px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 13px;
  background: var(--grad); display: grid; place-items: center; color: #fff;
  box-shadow: 0 10px 26px rgba(52, 211, 153, 0.4);
}
.brand-mark svg { width: 23px; height: 23px; }
.brand-text h1 { font-family: 'Space Grotesk', sans-serif; font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.brand-text p { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.unit-toggle { display: flex; background: var(--surface-solid); border: 1px solid var(--border); border-radius: 12px; padding: 3px; height: 42px; }
.unit-btn {
  border: none; background: transparent; color: var(--muted);
  font-size: 0.82rem; font-weight: 600; padding: 0 14px;
  border-radius: 9px; cursor: pointer; transition: 0.2s; font-family: inherit;
}
.unit-btn.active { background: var(--grad); color: #fff; box-shadow: 0 6px 16px rgba(52, 211, 153, 0.35); }

.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-solid); color: var(--text); cursor: pointer; transition: 0.2s;
}
.icon-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Workspace ---------- */
.workspace { flex: 1; display: flex; gap: 16px; min-height: 0; }
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow); animation: rise 0.5s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Input panel ---------- */
.input-panel {
  width: 340px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 2px;
  padding: 18px; overflow-y: auto;
}
.panel-head { padding-bottom: 12px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-family: 'Space Grotesk', sans-serif; font-size: 1.05rem; }

.field { display: grid; gap: 7px; padding: 8px 0; }
.field label { font-size: 0.82rem; color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; }
.field-val { font-size: 0.72rem; color: var(--muted); font-weight: 400; }

.seg { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.seg-btn {
  flex: 1; border: none; background: transparent; color: var(--muted);
  font-size: 0.85rem; font-weight: 600; padding: 9px; border-radius: 9px;
  cursor: pointer; transition: 0.2s; font-family: inherit;
}
.seg-btn.active { background: var(--grad); color: #fff; }

.unit-input, .select-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: 12px; padding: 0 13px; min-height: 46px;
}
.unit-input:focus-within, .select-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15); }
.unit-input input {
  flex: 1; background: transparent; border: none; color: var(--text); outline: none;
  font-size: 1rem; font-weight: 600; font-family: inherit; min-width: 0; padding: 12px 0;
  -moz-appearance: textfield;
}
.unit-input input::-webkit-outer-spin-button, .unit-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.unit-input .unit { font-size: 0.82rem; color: var(--muted); flex-shrink: 0; }
.unit-input.imperial input { max-width: 72px; }

.select-wrap { padding: 0; }
.select-wrap select {
  width: 100%; background: transparent; border: none; color: var(--text);
  outline: none; font-size: 0.9rem; padding: 12px 13px; cursor: pointer; font-family: inherit;
  appearance: none; -webkit-appearance: none;
}
.select-wrap::after { content: '▾'; color: var(--muted); padding-right: 13px; pointer-events: none; }
.select-wrap option { background: var(--surface-solid); color: var(--text); }

/* Macro sliders */
.macros-field { padding-top: 4px; }
.macro { padding: 7px 0; }
.macro-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
.macro-name { display: flex; align-items: center; gap: 7px; font-size: 0.84rem; color: var(--text); }
.macro-val { font-size: 0.84rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.mdot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.mdot-p { background: #34d399; }
.mdot-c { background: #fbbf24; }
.mdot-f { background: #f43f5e; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 999px; background: var(--border); outline: none; cursor: pointer; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: pointer; box-shadow: 0 3px 10px rgba(0,0,0,0.3); transition: 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); cursor: pointer; }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--border); }

/* ---------- Results panel ---------- */
.results-panel {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 16px;
  padding: 18px; overflow-y: auto;
}
.results-top { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.bigcard {
  padding: 18px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; display: grid; gap: 3px; align-content: center;
}
.target-card { background: linear-gradient(135deg, rgba(52,211,153,0.14), rgba(251,191,36,0.14)); }
.eyebrow { font-size: 0.7rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.big-number {
  font-family: 'Space Grotesk', sans-serif; font-size: clamp(1.5rem, 2.6vw, 2.2rem);
  font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1.1;
}
.sub { font-size: 0.8rem; color: var(--muted); }

.results-body { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 14px;
}
.card h3 { font-family: 'Space Grotesk', sans-serif; font-size: 1rem; }
.card h4 { font-family: 'Space Grotesk', sans-serif; font-size: 0.88rem; margin-bottom: 8px; }

.macro-donut-row { display: flex; align-items: center; gap: 22px; }
.donut { width: 140px; height: 140px; border-radius: 50%; position: relative; flex-shrink: 0; transition: background 0.4s; }
.donut-hole {
  position: absolute; inset: 20px; border-radius: 50%;
  background: var(--surface-solid); border: 1px solid var(--border);
  display: grid; place-items: center; text-align: center;
}
.donut-hole span { font-family: 'Space Grotesk', sans-serif; font-size: 1.2rem; font-weight: 700; }
.donut-hole small { font-size: 0.6rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.legend { display: grid; gap: 10px; flex: 1; }
.legend-row { display: flex; align-items: center; gap: 9px; font-size: 0.83rem; }
.legend-row .lg-dot { width: 11px; height: 11px; border-radius: 4px; flex-shrink: 0; }
.legend-row .lg-label { color: var(--muted); }
.legend-row .lg-val { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }

.meal-box { border-top: 1px solid var(--border); padding-top: 14px; }
.meal-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.86rem; }
.meal-row span:first-child { color: var(--muted); }
.meal-row .val { font-weight: 600; font-variant-numeric: tabular-nums; }

.bmi-scale {
  position: relative; height: 16px; border-radius: 999px; margin-top: 4px;
  background: linear-gradient(90deg, #38bdf8 0% 17.3%, #34d399 17.3% 42.3%, #fbbf24 42.3% 61.5%, #f43f5e 61.5% 100%);
}
.bmi-marker {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 3px solid var(--text); box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  left: 50%; transition: left 0.4s ease;
}
.bmi-labels { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--muted); }
.bmi-cats { display: flex; justify-content: space-between; font-size: 0.68rem; color: var(--muted); margin-top: 2px; }

.info-box {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 13px;
}
.info-ico { font-size: 1.3rem; }
.info-box strong { font-size: 0.86rem; }
.info-box p { font-size: 0.84rem; color: var(--muted); margin-top: 3px; line-height: 1.5; }

.disclaimer { font-size: 0.74rem; color: var(--muted); line-height: 1.55; border-top: 1px solid var(--border); padding-top: 12px; }

/* Snapshots */
.snapshots h3 { font-family: 'Space Grotesk', sans-serif; font-size: 0.95rem; display: flex; align-items: center; justify-content: space-between; }
.snap-count { font-size: 0.72rem; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 1px 9px; color: var(--muted); }
.snap-list { list-style: none; display: grid; gap: 10px; margin-top: 10px; }
.snap { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.snap-meta { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--muted); margin-bottom: 6px; }
.snap-text { font-size: 0.82rem; color: var(--text); line-height: 1.5; margin-bottom: 10px; white-space: pre-wrap; word-break: break-word; }
.snap-actions { display: flex; gap: 8px; }
.snap-actions button {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 5px 11px; font-size: 0.76rem; cursor: pointer; transition: 0.15s; font-family: inherit;
}
.snap-actions button:hover { color: var(--text); border-color: var(--accent); }
.snap-empty { color: var(--muted); font-size: 0.84rem; text-align: center; padding: 14px; }

/* ---------- Controls ---------- */
.controls { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 20px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-solid);
  color: var(--text); font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: 0.2s; font-family: inherit;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.btn:active { transform: translateY(0); }
.btn svg { width: 17px; height: 17px; }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--grad); color: #fff; border: none; box-shadow: 0 10px 26px rgba(52, 211, 153, 0.32); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 6, 15, 0.6);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: grid; place-items: center; z-index: 40; padding: 20px;
}
.modal {
  width: min(560px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: 22px; padding: 28px; box-shadow: var(--shadow); position: relative;
}
.modal h2 { font-family: 'Space Grotesk', sans-serif; font-size: 1.4rem; margin-bottom: 6px; }
.modal h3 { font-family: 'Space Grotesk', sans-serif; font-size: 1rem; margin: 22px 0 10px; }
.modal-intro { color: var(--muted); font-size: 0.92rem; margin-bottom: 14px; }
.modal-close { position: absolute; top: 14px; right: 16px; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text); font-size: 1.2rem; cursor: pointer; line-height: 1; }
.help-steps { padding-left: 20px; display: grid; gap: 10px; font-size: 0.92rem; }
.kbd-grid { display: grid; gap: 8px; }
.kbd-grid > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 0.88rem; color: var(--muted); }
.help-notes { padding-left: 18px; display: grid; gap: 8px; font-size: 0.9rem; color: var(--muted); }
kbd {
  background: var(--surface); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 6px; padding: 2px 7px;
  font-family: 'Space Grotesk', monospace; font-size: 0.78rem; color: var(--text);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-solid); border: 1px solid var(--border);
  color: var(--text); padding: 13px 20px; border-radius: 12px;
  box-shadow: var(--shadow); font-size: 0.88rem;
  opacity: 0; pointer-events: none; transition: 0.3s; z-index: 60; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: rgba(52, 211, 153, 0.55); }
.toast.error { border-color: rgba(244, 63, 94, 0.65); }
.toast.warn { border-color: rgba(251, 191, 36, 0.65); }

/* ---------- Scrollbars ---------- */
.input-panel, .results-panel, .modal { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.input-panel::-webkit-scrollbar, .results-panel::-webkit-scrollbar, .modal::-webkit-scrollbar { width: 8px; }
.input-panel::-webkit-scrollbar-thumb, .results-panel::-webkit-scrollbar-thumb, .modal::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

::selection { background: rgba(52, 211, 153, 0.32); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .workspace { flex-direction: column; }
  .input-panel { width: 100%; flex-shrink: 1; }
  .results-top { grid-template-columns: repeat(2, 1fr); }
  .results-body { grid-template-columns: 1fr; }
  .results-panel { overflow: visible; }
}

@media (max-width: 560px) {
  .topbar-actions { width: 100%; justify-content: space-between; }
  .results-top { grid-template-columns: 1fr; }
  .btn { padding: 11px 16px; }
}
