/* ============================================================
   Momentum — mobile-first styles
   Base rules target phones; @media (min-width:820px) enhances
   for tablet/desktop.
   ============================================================ */
:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1f232c;
  --border: #272c37;
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --muted-2: #6b7280;
  --accent: #6ea8fe;
  --accent-2: #7c5cff;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --nav-h: 64px;
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: radial-gradient(1000px 500px at 80% -10%, #1a1f2b 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: calc(10px + var(--sa-top));
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  background: rgba(15, 17, 21, 0.8);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 16px rgba(124, 92, 255, 0.5);
  flex: none;
}
.brand-name { letter-spacing: 0.3px; font-size: 17px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.iconbtn {
  position: relative;
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 0 12px; height: 40px; min-width: 40px;
  justify-content: center; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
}
.iconbtn .ic { font-size: 17px; line-height: 1; }
.iconbtn:active { transform: scale(0.96); }
#accountBtn.synced { border-color: rgba(52, 211, 153, 0.5); }
#accountBtn.synced::before {
  content: ''; position: absolute; top: 7px; right: 7px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 2px var(--bg-elev-2);
}
#notifBtn.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0b0d12; border-color: transparent; }

/* ---------- Bottom navigation (mobile) ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  background: rgba(20, 23, 28, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 6px 4px;
  padding-bottom: calc(6px + var(--sa-bottom));
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; color: var(--muted-2);
  font: inherit; font-size: 11px; font-weight: 600;
  padding: 6px 2px; border-radius: 12px; cursor: pointer;
}
.tab .tab-ic { font-size: 21px; line-height: 1; transition: transform 0.12s; }
.tab.active { color: var(--accent); }
.tab.active .tab-ic { transform: translateY(-1px) scale(1.08); }

/* ---------- Floating action button ---------- */
.fab {
  position: fixed; right: 16px; z-index: 35;
  bottom: calc(var(--nav-h) + 14px + var(--sa-bottom));
  width: 58px; height: 58px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0d12; font-size: 32px; font-weight: 300; line-height: 1;
  border: none; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 8px 22px rgba(124, 92, 255, 0.55);
}
.fab:active { transform: scale(0.93); }

/* ---------- Layout ---------- */
.container {
  max-width: 980px; margin: 0 auto;
  padding: 14px 14px;
  padding-bottom: calc(var(--nav-h) + 90px + var(--sa-bottom));
}
.view { display: none; animation: fade 0.2s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.muted-2 { color: var(--muted-2); }
.small { font-size: 12px; }
.hide-mobile { display: none; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; border-radius: 12px;
  padding: 11px 16px; border: 1px solid transparent; cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease, border 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0b0d12; }
.btn-primary:active { filter: brightness(1.05); }
.btn-ghost { background: var(--bg-elev-2); color: var(--text); border-color: var(--border); }
.btn-ghost.small { padding: 8px 12px; font-size: 13px; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 8px; border-radius: 10px; line-height: 1; }
.icon-btn:active { background: var(--bg-elev-2); }

/* ---------- Metrics ---------- */
.metrics-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.metric { margin: 0; padding: 14px; }
.metric-label { color: var(--muted); font-size: 11.5px; font-weight: 600; }
.metric-value { font-size: 28px; font-weight: 800; margin: 6px 0 3px; line-height: 1; }
.metric-unit { font-size: 13px; font-weight: 600; color: var(--muted); }
.metric-sub { color: var(--muted-2); font-size: 11.5px; line-height: 1.4; }

/* ---------- Chart ---------- */
.chart { width: 100%; min-height: 150px; }
.chart svg { width: 100%; height: 170px; display: block; }
.chart .bar { fill: url(#barGrad); }
.chart .axis-label { fill: var(--muted-2); font-size: 10px; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }

/* ---------- Lists ---------- */
.inline-add { display: flex; gap: 8px; margin-bottom: 14px; }
.inline-add input {
  flex: 1; min-width: 0; background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); padding: 12px; border-radius: 12px; font: inherit; font-size: 16px;
}
.inline-add input:focus { outline: none; border-color: var(--accent); }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px;
}
.list-item.done .item-text { color: var(--muted-2); text-decoration: line-through; }
.item-text { flex: 1; min-width: 0; word-break: break-word; }
.item-text[contenteditable="true"] { outline: 1px solid var(--accent); border-radius: 6px; padding: 2px 4px; }
.chk {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--muted-2);
  background: transparent; cursor: pointer; flex: none; display: grid; place-items: center; color: transparent;
}
.chk.on { background: var(--green); border-color: var(--green); color: #06281c; }
.item-actions { display: flex; gap: 2px; flex: none; }
.empty { color: var(--muted-2); text-align: center; padding: 20px; font-size: 14px; line-height: 1.6; }
.tag { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); flex: none; }
.tag.done { color: var(--green); border-color: rgba(52,211,153,0.4); }
.archive { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.archived-list { margin-top: 10px; opacity: 0.85; }

/* due-date chip */
.due-wrap { display: inline-flex; align-items: center; gap: 2px; position: relative; flex: none; }
.due-input { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.due-chip {
  font: inherit; font-size: 12px; font-weight: 600;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
.due-chip.has-due { color: var(--accent); border-color: rgba(110, 168, 254, 0.4); }

/* ---------- Calendar ---------- */
.calendar-head { justify-content: space-between; flex-wrap: nowrap; }
.calendar-head h2 { flex: 1; text-align: center; font-size: 16px; }
.calendar-head .btn-ghost { padding: 8px 14px; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 6px; }
.weekdays span { text-align: center; color: var(--muted-2); font-size: 11px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cell {
  min-height: 52px; background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 4px; cursor: pointer; display: flex; flex-direction: column; gap: 3px;
}
.cell.empty-cell { background: transparent; border: none; cursor: default; }
.cell.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cell .date-num { font-size: 12px; color: var(--muted); font-weight: 600; }
.cell.today .date-num { color: var(--accent); }
.cell-tasks { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.pill {
  font-size: 9.5px; padding: 1px 4px; border-radius: 5px; background: var(--bg);
  border: 1px solid var(--border); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pill.done { color: var(--muted-2); text-decoration: line-through; }
.more { font-size: 9.5px; color: var(--muted-2); }

/* ---------- Modals (bottom sheet on mobile) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  backdrop-filter: blur(3px); animation: fade 0.15s ease;
}
.modal-backdrop[hidden], .toast[hidden] { display: none; }
.modal {
  width: 100%; max-width: 540px; background: var(--bg-elev);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  animation: sheetUp 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 92vh; display: flex; flex-direction: column;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); flex: none; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px; padding-bottom: calc(20px + var(--sa-bottom)); display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input[type="text"], .field input[type="password"], .field textarea, .field input[type="date"] {
  width: 100%; background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); padding: 13px 12px; border-radius: 12px; font: inherit; font-size: 16px; resize: vertical;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }

/* Auth gate */
.seg { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
.seg-btn { flex: 1; background: transparent; border: none; color: var(--muted); font: inherit; font-weight: 700; padding: 11px; border-radius: 9px; cursor: pointer; }
.seg-btn.active { background: var(--bg-elev-2); color: var(--text); box-shadow: var(--shadow); }
.auth-error { color: var(--red); font-size: 13px; margin: 0; line-height: 1.5; }
.ios-steps { margin: 14px 0; padding-left: 20px; line-height: 1.9; color: var(--muted); }
.ios-steps li { margin-bottom: 6px; }
.ios-steps b { color: var(--text); }

/* Energy slider */
.energy-row { display: flex; align-items: center; gap: 12px; }
.energy-row input[type="range"] { flex: 1; accent-color: var(--accent); height: 28px; }
.energy-val {
  min-width: 44px; text-align: center; font-weight: 800; font-size: 19px;
  padding: 6px; border-radius: 10px; background: var(--bg-elev-2); border: 1px solid var(--border);
}

/* ---------- Toast + sync pill ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 20px + var(--sa-bottom));
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow); z-index: 60; font-size: 14px;
  max-width: calc(100vw - 32px); text-align: center;
  animation: fade 0.18s ease;
}
.sync-pill {
  position: fixed; left: 14px; z-index: 40;
  bottom: calc(var(--nav-h) + 16px + var(--sa-bottom));
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--muted);
  font-size: 12px; padding: 6px 12px; border-radius: 999px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 6px; opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
.sync-pill.show { opacity: 1; }
.sync-pill.ok { color: var(--green); }
.sync-pill.err { color: var(--red); }

/* ============================================================
   Tablet / desktop
   ============================================================ */
@media (min-width: 820px) {
  .topbar { padding: 14px 22px; }
  .hide-mobile { display: inline; }
  .iconbtn { padding: 0 14px; }
  #accountBtn.synced::before { display: none; }
  #accountBtn.synced { color: var(--green); }

  /* nav moves to the top as a horizontal bar */
  .tabs {
    position: sticky; top: calc(57px + var(--sa-top)); bottom: auto;
    max-width: 980px; margin: 0 auto; gap: 4px;
    justify-content: flex-start; background: transparent; backdrop-filter: none;
    border-top: none; padding: 10px 16px 0;
  }
  .tab { flex: 0 0 auto; flex-direction: row; gap: 7px; font-size: 15px; padding: 10px 16px; border-radius: 10px 10px 0 0; }
  .tab .tab-ic { font-size: 16px; }
  .tab.active { background: var(--bg-elev); box-shadow: inset 0 -2px 0 var(--accent); color: var(--text); }
  .tab.active .tab-ic { transform: none; }

  .container { padding: 16px; padding-bottom: 40px; }
  .metrics-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .metric { padding: 18px; }
  .metric-value { font-size: 30px; }
  .card { padding: 18px; }
  .card-head h2 { font-size: 16px; }
  .chart svg { height: 180px; }
  .cell { min-height: 76px; padding: 6px; border-radius: 10px; }
  .pill { font-size: 10px; padding: 2px 6px; }

  /* centered dialog instead of bottom sheet */
  .modal-backdrop { align-items: center; padding: 16px; }
  .modal { border: 1px solid var(--border); border-radius: 16px; max-height: 86vh; animation: pop 0.18s ease; }
  @keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
  .modal-body { padding-bottom: 18px; }

  /* FAB sits above the sync pill area, no bottom nav to clear */
  .fab { bottom: 24px; right: 24px; }
  .toast { bottom: 24px; }
  .sync-pill { bottom: 24px; left: 24px; }
}
