/* Marco Health Dashboard */
*{margin:0;padding:0;box-sizing:border-box}

:root{
  --bg:#f4f5f9;
  --surface:#fff;
  --surface-alt:#f0f1f6;
  --border:#e4e6ee;
  --text:#1c1e2a;
  --text-secondary:#5f6380;
  --text-muted:#9498b3;

  --green:#22c55e;
  --green-soft:#dcfce7;
  --yellow:#eab308;
  --yellow-soft:#fef9c3;
  --red:#ef4444;
  --red-soft:#fee2e2;
  --blue:#3b82f6;
  --blue-soft:#dbeafe;
  --purple:#8b5cf6;
  --purple-soft:#ede9fe;
  --orange:#f59e0b;

  --accent:#6366f1;
  --accent-hover:#4f46e5;
  --accent-soft:#eef2ff;

  --hero-bg:linear-gradient(135deg,#1a1d2e 0%,#252840 50%,#1e2235 100%);
  --hero-text:#e8e9f0;
  --hero-muted:#8b8fa8;

  --radius:12px;
  --radius-lg:16px;
  --shadow-sm:0 1px 2px rgba(0,0,0,.04);
  --shadow:0 2px 8px rgba(0,0,0,.06);
  --shadow-lg:0 8px 24px rgba(0,0,0,.08);

  --font:-apple-system,BlinkMacSystemFont,'Segoe UI','Helvetica Neue',sans-serif;
  --font-mono:'SF Mono','Cascadia Code','Fira Code',monospace;
  --sidebar-w:72px;
  --bottom-h:64px;
}

body{font-family:var(--font);background:var(--bg);color:var(--text);font-size:14px;line-height:1.6;-webkit-font-smoothing:antialiased}

/* ── Login ─────────────────────────────── */
#login-screen{display:flex;align-items:center;justify-content:center;min-height:100vh;position:fixed;inset:0;z-index:300;overflow:hidden}
.login-bg{position:absolute;inset:0;background:var(--hero-bg)}
.login-card{position:relative;background:var(--surface);border-radius:var(--radius-lg);padding:3rem 2.5rem;width:360px;text-align:center;box-shadow:var(--shadow-lg);animation:fadeUp .5s ease}
.login-icon{width:56px;height:56px;border-radius:14px;background:var(--accent);color:#fff;font-size:24px;font-weight:700;display:flex;align-items:center;justify-content:center;margin:0 auto 1.25rem}
.login-card h1{font-size:1.5rem;font-weight:700;margin-bottom:.25rem}
.login-card p{color:var(--text-secondary);margin-bottom:1.5rem;font-size:14px}
.login-card input{width:100%;padding:.75rem 1rem;background:var(--surface-alt);border:1px solid var(--border);border-radius:var(--radius);color:var(--text);font-family:var(--font-mono);font-size:13px;margin-bottom:1rem;transition:border-color .2s,box-shadow .2s}
.login-card input:focus{outline:none;border-color:var(--accent);box-shadow:0 0 0 3px rgba(99,102,241,.12)}
.login-card button{width:100%;padding:.8rem;font-weight:600;font-size:14px}
.error{color:var(--red);font-size:13px;margin-top:.5rem}

/* ── Dashboard layout ──────────────────── */
#dashboard{display:flex;min-height:100vh}
#dashboard[hidden]{display:none}

/* Sidebar */
#sidebar{width:var(--sidebar-w);background:var(--surface);border-right:1px solid var(--border);display:flex;flex-direction:column;align-items:center;padding:1rem 0;position:fixed;top:0;bottom:0;left:0;z-index:60}
.sidebar-brand{width:40px;height:40px;border-radius:10px;background:var(--accent);color:#fff;font-size:18px;font-weight:700;display:flex;align-items:center;justify-content:center;margin-bottom:2rem}
.sidebar-nav{display:flex;flex-direction:column;gap:.5rem;flex:1}
.nav-item{background:none;border:none;color:var(--text-muted);cursor:pointer;display:flex;flex-direction:column;align-items:center;gap:4px;padding:.75rem .5rem;border-radius:var(--radius);transition:all .15s;font-family:var(--font);width:56px}
.nav-item svg{width:20px;height:20px;flex-shrink:0}
.nav-item span{font-size:10px;font-weight:500;letter-spacing:.02em}
.nav-item:hover{color:var(--text-secondary);background:var(--surface-alt)}
.nav-item.active{color:var(--accent);background:var(--accent-soft)}
.nav-settings{margin-top:auto;margin-bottom:.5rem}

/* Main */
#main{flex:1;margin-left:var(--sidebar-w);min-height:100vh;display:flex;flex-direction:column}

/* Header */
header{display:flex;justify-content:space-between;align-items:center;padding:.75rem 1.5rem;background:var(--surface);border-bottom:1px solid var(--border);position:sticky;top:0;z-index:50;gap:.5rem}
.header-left{display:flex;align-items:baseline;gap:.75rem;min-width:0}
.header-left h1{font-size:1.1rem;font-weight:700;white-space:nowrap}
#header-date{color:var(--text-muted);font-size:13px;white-space:nowrap}
.header-right{display:flex;align-items:center;gap:.5rem;color:var(--text-muted);font-size:13px;font-family:var(--font-mono);white-space:nowrap;flex-shrink:0}
.header-refresh-btn{background:none;border:none;color:var(--text-muted);cursor:pointer;padding:4px;border-radius:var(--radius);transition:color .15s,transform .3s}
.header-refresh-btn:hover{color:var(--accent);background:var(--accent-soft)}
.header-refresh-btn.spinning svg{animation:spin .8s linear infinite}
@keyframes spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}
.header-settings-btn{display:none;background:none;border:none;color:var(--text-muted);cursor:pointer;padding:4px;border-radius:var(--radius);transition:color .15s}
.header-settings-btn:hover{color:var(--text);background:var(--surface-alt)}
.status-dot{width:8px;height:8px;border-radius:50%;display:inline-block}
.status-dot.connected{background:var(--green);box-shadow:0 0 6px rgba(34,197,94,.4)}
.status-dot.disconnected{background:var(--red)}

/* Bottom nav */
#bottom-nav{display:none}

/* ── Tab content ───────────────────────── */
.tab-content{padding:1.5rem;max-width:900px;width:100%}
.tab-content[hidden]{display:none}

/* ── Hero ──────────────────────────────── */
.hero-card{background:var(--hero-bg);border-radius:var(--radius-lg);padding:2rem;display:flex;align-items:center;gap:2.5rem;margin-bottom:1.5rem;position:relative;overflow:hidden}
.hero-card::after{content:'';position:absolute;top:-50%;right:-20%;width:300px;height:300px;background:radial-gradient(circle,rgba(99,102,241,.08) 0%,transparent 70%);pointer-events:none}
.hero-ring-wrap{position:relative;width:200px;height:200px;flex-shrink:0}
.hero-ring-label{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;pointer-events:none}
.ring-pct{font-size:3rem;font-weight:200;color:#fff;letter-spacing:-.02em;line-height:1}
.ring-sub{font-size:12px;color:var(--hero-muted);text-transform:uppercase;letter-spacing:.08em;margin-top:4px}
.hero-metrics{display:grid;grid-template-columns:1fr 1fr;gap:1.5rem 2rem;flex:1}
.hero-metric{text-align:center}
.hero-metric-val{display:block;font-size:1.75rem;font-weight:300;color:#fff;letter-spacing:-.01em;font-variant-numeric:tabular-nums}
.hero-metric-label{font-size:11px;color:var(--hero-muted);text-transform:uppercase;letter-spacing:.06em}

/* ── Data Freshness ───────────────────── */
.data-freshness{display:flex;align-items:center;gap:1.25rem;margin-bottom:1rem;font-size:12px;color:var(--text-muted);flex-wrap:wrap}
.freshness-item{display:flex;align-items:center;gap:5px}
.freshness-dot{width:6px;height:6px;border-radius:50%;flex-shrink:0}
.freshness-dot.fresh{background:var(--green)}
.freshness-dot.stale{background:var(--yellow)}
.freshness-dot.old{background:var(--red)}
.freshness-dot.none{background:var(--text-muted);opacity:.4}
.sync-btn{background:none;border:1px solid var(--border);color:var(--text-muted);font-size:11px;font-family:var(--font);padding:2px 8px;border-radius:6px;cursor:pointer;transition:all .15s;white-space:nowrap}
.sync-btn:hover{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}
.sync-btn:disabled{opacity:.5;cursor:not-allowed}

/* ── Cards ─────────────────────────────── */
.cards-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:1rem}
.card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.25rem;box-shadow:var(--shadow-sm);transition:box-shadow .15s}
.card:hover{box-shadow:var(--shadow)}
.card-wide{grid-column:1/-1}
.card-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem}
.card-header h3{font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:var(--text-secondary)}
.card-meta{font-size:12px;color:var(--text-muted)}
.card-body{min-height:60px}

/* Skeleton */
.skeleton-block{height:40px;background:linear-gradient(90deg,var(--surface-alt) 25%,#e8e9f0 50%,var(--surface-alt) 75%);background-size:200% 100%;border-radius:8px;animation:shimmer 1.5s infinite}
@keyframes shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}

/* ── Mood & Energy ─────────────────────── */
.mood-bar-group{display:flex;flex-direction:column;gap:.75rem}
.mood-bar-row{display:flex;align-items:center;gap:.75rem}
.mood-bar-label{font-size:13px;font-weight:500;color:var(--text);width:50px;flex-shrink:0}
.mood-bar-track{flex:1;height:8px;background:var(--surface-alt);border-radius:4px;overflow:hidden}
.mood-bar-fill{height:100%;border-radius:4px;transition:width .6s ease}
.mood-bar-fill.mood{background:var(--purple)}
.mood-bar-fill.energy{background:var(--orange)}
.mood-bar-val{font-size:15px;font-weight:600;color:var(--text);font-variant-numeric:tabular-nums;width:32px;text-align:right}
.checkin-latest{margin-top:.75rem;font-size:12px;color:var(--text-muted);line-height:1.5}

/* ── Marco's Take ──────────────────────── */
.marco-bubble{background:var(--accent-soft);border-radius:var(--radius) var(--radius) var(--radius) 4px;padding:1rem 1.25rem;font-size:13px;line-height:1.7;color:var(--text);white-space:pre-wrap;position:relative}
.marco-bubble::before{content:'';position:absolute;bottom:0;left:-6px;width:12px;height:12px;background:var(--accent-soft);clip-path:polygon(100% 0,100% 100%,0 100%)}
.marco-empty{color:var(--text-muted);font-size:13px;font-style:italic}

/* ── Food summary ──────────────────────── */
.food-summary-grid{display:flex;gap:1.5rem;align-items:flex-start}
.food-donut-wrap{position:relative;width:160px;height:160px;flex-shrink:0}
.donut-center{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;pointer-events:none}
.donut-center span:first-child{font-size:1.5rem;font-weight:600;color:var(--text);line-height:1}
.donut-center span:last-child{font-size:11px;color:var(--text-muted);text-transform:uppercase;letter-spacing:.04em}
.donut-center.lg span:first-child{font-size:2rem}
.food-list{flex:1;min-width:0}
.food-item{padding:.5rem 0;border-bottom:1px solid var(--border);font-size:13px}
.food-item:last-child{border-bottom:none}
.food-item-desc{color:var(--text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.food-item-meta{color:var(--text-muted);font-size:12px;margin-top:2px}
.food-item-more{color:var(--text-muted);font-size:12px;padding:.5rem 0;text-align:center}
.empty-state{color:var(--text-muted);font-size:13px;text-align:center;padding:1.5rem 0}
.meta{color:var(--text-muted);font-size:12px}

/* ── Location Timeline ─────────────────── */
.loc-timeline{display:flex;flex-direction:column}
.loc-item{display:flex;gap:.75rem;padding:.5rem 0;position:relative}
.loc-dot{width:8px;height:8px;border-radius:50%;background:var(--accent);margin-top:6px;flex-shrink:0;position:relative}
.loc-dot::after{content:'';position:absolute;top:12px;left:3px;width:2px;height:calc(100% + 8px);background:var(--border)}
.loc-item:last-child .loc-dot::after{display:none}
.loc-info{display:flex;flex-direction:column;gap:1px}
.loc-label{font-size:13px;color:var(--text);font-weight:500}
.loc-time{font-size:12px;color:var(--text-muted)}

/* ── Trends ────────────────────────────── */
.comparison-row{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:.75rem;margin-bottom:1.5rem}
.comparison-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1rem 1.25rem;box-shadow:var(--shadow-sm)}
.comparison-label{font-size:11px;text-transform:uppercase;letter-spacing:.04em;color:var(--text-muted);margin-bottom:4px}
.comparison-val{font-size:1.5rem;font-weight:600;color:var(--text);font-variant-numeric:tabular-nums}
.comparison-delta{font-size:12px;font-weight:500;margin-top:2px}
.comparison-delta.up{color:var(--green)}
.comparison-delta.down{color:var(--red)}

.chart-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.25rem;margin-bottom:1rem;box-shadow:var(--shadow-sm)}
.chart-card h3{font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:var(--text-secondary);margin-bottom:1rem}
.chart-wrap{position:relative;height:240px}
.chart-wrap canvas{width:100%!important;height:100%!important}

/* ── Nutrition ─────────────────────────── */
.date-nav{display:flex;align-items:center;justify-content:center;gap:1rem;margin-bottom:1.5rem}
.date-btn{background:var(--surface);border:1px solid var(--border);color:var(--text);width:36px;height:36px;border-radius:var(--radius);cursor:pointer;font-size:16px;display:flex;align-items:center;justify-content:center;transition:all .15s;padding:0}
.date-btn:hover:not(:disabled){background:var(--accent-soft);border-color:var(--accent);color:var(--accent)}
.date-btn:disabled{opacity:.3;cursor:not-allowed}
#date-display{font-size:15px;font-weight:600;color:var(--text);min-width:140px;text-align:center}
.nutrition-grid{display:grid;grid-template-columns:280px 1fr;gap:1rem}
.card-grow{min-width:0}
.macro-donut-wrap{position:relative;width:200px;height:200px;margin:0 auto 1.25rem}
.calorie-bar-wrap{margin-bottom:1rem}
.calorie-bar-label{display:flex;justify-content:space-between;font-size:12px;color:var(--text-muted);margin-bottom:6px}
.calorie-bar{height:8px;background:var(--surface-alt);border-radius:4px;overflow:hidden}
.calorie-fill{height:100%;border-radius:4px;background:var(--green);transition:width .6s ease}
.macro-legend{display:flex;flex-direction:column;gap:.5rem}
.macro-legend-item{display:flex;align-items:center;gap:.5rem;font-size:13px}
.macro-dot{width:10px;height:10px;border-radius:3px;flex-shrink:0}
.macro-val{margin-left:auto;font-weight:600;font-variant-numeric:tabular-nums;color:var(--text)}

/* Food table */
.food-table{width:100%;border-collapse:collapse;font-size:13px}
.food-table th,.food-table td{padding:.6rem .75rem;text-align:left;border-bottom:1px solid var(--border)}
.food-table th{color:var(--text-muted);font-weight:500;font-size:11px;text-transform:uppercase;letter-spacing:.04em}
.food-table td{color:var(--text);font-variant-numeric:tabular-nums}
.food-table tfoot td{border-top:2px solid var(--border);font-weight:600;border-bottom:none}
.food-table td:first-child{max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

/* ── Insights ──────────────────────────── */
.insights-grid{display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin-top:1rem}
.insight-item{padding:.75rem 0;border-bottom:1px solid var(--border);font-size:13px;color:var(--text);line-height:1.6}
.insight-item:last-child{border-bottom:none}
.insight-text{color:var(--text)}
.insight-meta{font-size:11px;color:var(--text-muted);margin-top:4px}
.narrative-text{font-size:14px;line-height:1.8;color:var(--text);white-space:pre-wrap}

/* ── Settings ──────────────────────────── */
.settings-overlay{position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:200;display:flex;justify-content:flex-end;backdrop-filter:blur(2px)}
.settings-overlay[hidden]{display:none}
.settings-panel{background:var(--surface);width:360px;max-width:100%;height:100%;box-shadow:var(--shadow-lg);animation:slideIn .2s ease}
.settings-header{display:flex;justify-content:space-between;align-items:center;padding:1.25rem 1.5rem;border-bottom:1px solid var(--border)}
.settings-header h2{font-size:1.1rem;font-weight:700}
.settings-close{background:none;border:none;color:var(--text-muted);font-size:24px;cursor:pointer;padding:0;width:32px;height:32px;display:flex;align-items:center;justify-content:center;border-radius:var(--radius)}
.settings-close:hover{background:var(--surface-alt);color:var(--text)}
.settings-body{padding:1.5rem}
.settings-body h4{font-size:12px;text-transform:uppercase;letter-spacing:.04em;color:var(--text-muted);margin-bottom:.75rem;margin-top:1.5rem}
.settings-body h4:first-child{margin-top:0}
.connection-cards{display:flex;flex-direction:column;gap:.5rem}
.connection-card{display:flex;align-items:center;gap:.75rem;padding:.75rem 1rem;background:var(--surface-alt);border-radius:var(--radius);font-size:13px}
.connection-card.connected{background:var(--green-soft)}
.conn-icon{font-size:20px;flex-shrink:0}
.conn-info{flex:1;display:flex;flex-direction:column;gap:1px}
.conn-name{font-weight:500;font-size:13px}
.conn-status{font-size:11px;color:var(--text-muted)}
.connection-card.connected .conn-status{color:var(--green)}
.conn-link{color:var(--accent);font-size:12px;font-weight:500;text-decoration:none}
.conn-link:hover{text-decoration:underline}
.conn-check{color:var(--green);font-size:16px;font-weight:700}
.connection-card.conn-warning{background:var(--red-soft);border:1px solid var(--red)}
.connection-card.conn-warning .conn-status{color:var(--red)}
.conn-link-warn{color:var(--red)!important;font-weight:600}
.conn-disconnect{background:none;border:none;color:var(--text-muted);font-size:18px;cursor:pointer;padding:2px 6px;border-radius:4px;line-height:1}
.conn-disconnect:hover{color:var(--red);background:var(--red-soft)}
.action-btn{display:flex;align-items:center;gap:.5rem;width:100%;padding:.75rem 1rem;background:var(--surface-alt);border:1px solid var(--border);border-radius:var(--radius);color:var(--text);font-size:13px;font-weight:500;cursor:pointer;font-family:var(--font);margin-bottom:.5rem;transition:all .15s}
.action-btn:hover{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}
.action-hint{font-size:11px;color:var(--text-muted);margin:-2px 0 .75rem .25rem;line-height:1.4}
.action-btn.logout{color:var(--red)}
.action-btn.logout:hover{border-color:var(--red);background:var(--red-soft)}

/* ── Live bar ──────────────────────────── */
.live-bar{position:fixed;bottom:var(--bottom-h);left:var(--sidebar-w);right:0;background:var(--surface);border-top:1px solid var(--border);padding:.5rem 1.5rem;display:flex;align-items:center;gap:.5rem;font-size:13px;z-index:100;box-shadow:0 -2px 8px rgba(0,0,0,.05)}
.live-bar[hidden]{display:none}
.live-dot{width:6px;height:6px;border-radius:50%;background:var(--blue);animation:pulse 1.5s infinite}

/* ── Buttons ───────────────────────────── */
button{background:var(--accent);border:none;color:#fff;padding:.5rem 1rem;border-radius:var(--radius);cursor:pointer;font-family:var(--font);font-size:13px;font-weight:500;transition:background .15s}
button:hover{background:var(--accent-hover)}

/* ── Animations ────────────────────────── */
@keyframes fadeUp{from{opacity:0;transform:translateY(12px)}to{opacity:1;transform:none}}
@keyframes slideIn{from{transform:translateX(100%)}to{transform:none}}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.3}}

/* ── Scrollbar ─────────────────────────── */
::-webkit-scrollbar{width:6px}
::-webkit-scrollbar-track{background:var(--bg)}
::-webkit-scrollbar-thumb{background:#c4c8d4;border-radius:3px}
::-webkit-scrollbar-thumb:hover{background:#9ca3af}

/* ── Mobile ────────────────────────────── */
@media(max-width:768px){
  #sidebar{display:none}
  #main{margin-left:0}
  #bottom-nav{display:flex;position:fixed;bottom:0;left:0;right:0;background:var(--surface);border-top:1px solid var(--border);height:var(--bottom-h);align-items:center;justify-content:space-around;z-index:60;padding:0 .5rem}
  .bnav-item{background:none;border:none;color:var(--text-muted);display:flex;flex-direction:column;align-items:center;gap:2px;padding:.5rem;cursor:pointer;font-family:var(--font);border-radius:var(--radius);transition:all .15s;flex:1}
  .bnav-item svg{width:20px;height:20px}
  .bnav-item span{font-size:10px;font-weight:500}
  .bnav-item.active{color:var(--accent);background:var(--accent-soft);border-radius:var(--radius)}
  .tab-content{padding:1rem;padding-bottom:calc(var(--bottom-h) + 1rem)}
  .hero-card{flex-direction:column;gap:1.5rem;padding:1.5rem}
  .hero-ring-wrap{width:160px;height:160px;margin:0 auto}
  .hero-metrics{width:100%}
  .ring-pct{font-size:2.5rem}
  .cards-grid{grid-template-columns:1fr}
  .food-summary-grid{flex-direction:column;align-items:center}
  .food-donut-wrap{margin-bottom:1rem}
  .nutrition-grid{grid-template-columns:1fr}
  .insights-grid{grid-template-columns:1fr}
  .comparison-row{grid-template-columns:1fr 1fr}
  .live-bar{left:0;bottom:var(--bottom-h)}
  .settings-panel{width:100%}
  header{padding:.75rem 1rem}
  header h1{font-size:1rem}
  #header-date{display:none}
  .header-settings-btn{display:flex;align-items:center;justify-content:center}
  #clock{font-size:11px}
}
@media(min-width:769px){
  #bottom-nav{display:none}
}
