/* Jarvis Command Center — OKLCH Design System (Dark-first + Light toggle) */

:root {
  color-scheme: dark;
  /* Pure near-black obsidian neutral ramp (C=0.000) */
  --bg: oklch(0.11 0 0);
  --surface: oklch(0.165 0 0);
  --surface-2: oklch(0.215 0 0);
  --surface-hover: oklch(0.245 0 0);
  --border: oklch(0.275 0 0);
  --border-subtle: oklch(0.205 0 0);

  /* Ink */
  --ink: oklch(0.955 0 0);
  --muted: oklch(0.68 0 0);
  --on-fill: oklch(0.985 0 0);

  /* Brand & semantic (OKLCH only; anchor hue ~110° olive + ~40° terracotta) */
  --primary: oklch(0.49 0.115 110);
  --primary-hover: oklch(0.54 0.125 110);
  --primary-ink: oklch(0.79 0.14 112);
  --primary-tint: oklch(0.22 0.04 110);

  --accent: oklch(0.60 0.16 40);
  --accent-ink: oklch(0.78 0.14 44);
  --accent-tint: oklch(0.22 0.05 40);

  --ok: oklch(0.67 0.15 152);
  --ok-tint: oklch(0.21 0.045 152);
  --warn: oklch(0.76 0.14 76);
  --warn-tint: oklch(0.23 0.05 76);
  --danger: oklch(0.58 0.19 25);
  --danger-tint: oklch(0.22 0.065 25);
  --info: oklch(0.67 0.13 240);
  --info-tint: oklch(0.21 0.045 240);

  /* Typography */
  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Radii & rhythm */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  /* Semantic z-index scale */
  --z-sticky: 10;
  --z-nav: 20;
  --z-dialog: 30;
  --z-toast: 40;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 160ms;
  --t-mid: 220ms;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: oklch(1.000 0 0);
  --surface: oklch(0.965 0 0);
  --surface-2: oklch(0.925 0 0);
  --surface-hover: oklch(0.89 0 0);
  --border: oklch(0.84 0 0);
  --border-subtle: oklch(0.90 0 0);

  --ink: oklch(0.16 0 0);
  --muted: oklch(0.45 0 0);
  --on-fill: oklch(0.99 0 0);

  --primary: oklch(0.45 0.11 110);
  --primary-hover: oklch(0.40 0.11 110);
  --primary-ink: oklch(0.39 0.105 110);
  --primary-tint: oklch(0.93 0.035 110);

  --accent: oklch(0.55 0.16 38);
  --accent-ink: oklch(0.47 0.15 38);
  --accent-tint: oklch(0.94 0.04 40);

  --ok: oklch(0.48 0.14 152);
  --ok-tint: oklch(0.93 0.04 152);
  --warn: oklch(0.55 0.14 74);
  --warn-tint: oklch(0.94 0.045 78);
  --danger: oklch(0.52 0.19 25);
  --danger-tint: oklch(0.94 0.045 25);
  --info: oklch(0.49 0.14 240);
  --info-tint: oklch(0.93 0.04 240);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.app-shell {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar-title-wrap {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.topbar-title {
  margin: 0;
  font-size: 1.1875rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-stamp {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.icon-btn:active { transform: scale(0.93); }
.icon-btn:focus-visible { outline: 2px solid var(--primary-ink); outline-offset: 2px; }
.icon-btn.spinning svg { animation: spin 750ms linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Main view ---------- */
.main {
  flex: 1;
  padding: 14px 16px calc(88px + env(safe-area-inset-bottom, 0px));
}

/* ---------- Section headers (clean sentence-case, no uppercase eyebrows) ---------- */
.sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 20px 0 8px;
}

.sec-head:first-child { margin-top: 2px; }

.sec-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-pill {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface-2);
  padding: 1px 7px;
  border-radius: var(--r-pill);
}

.text-action {
  background: none;
  border: none;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  color: var(--primary-ink);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--t-fast) var(--ease);
}

.text-action:hover { background: var(--primary-tint); }

/* ---------- Structural surfaces & divided rows ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--t-fast) var(--ease);
}

.row:last-child { border-bottom: none; }

.row-body {
  flex: 1;
  min-width: 0;
}

.row-title {
  font-size: 0.9375rem;
  font-weight: 450;
  color: var(--ink);
  word-break: break-word;
  transition: color var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
}

.row-meta {
  margin-top: 3px;
  font-size: 0.8125rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- Tactile checkboxes (Tasks & Events) ---------- */
.check-btn {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border-radius: 6px;
  border: 1.75px solid var(--border);
  background: transparent;
  color: var(--on-fill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

.check-btn:hover { border-color: var(--primary-ink); }
.check-btn:active { transform: scale(0.88); }
.check-btn[aria-checked="true"] {
  background: var(--primary);
  border-color: var(--primary);
}

.row.is-done .row-title {
  color: var(--muted);
  text-decoration: line-through;
  opacity: 0.72;
}

/* ---------- Status badges & pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
}

.pill.neutral { background: var(--surface-2); color: var(--muted); }
.pill.primary { background: var(--primary-tint); color: var(--primary-ink); }
.pill.accent { background: var(--accent-tint); color: var(--accent-ink); }
.pill.ok { background: var(--ok-tint); color: var(--ok); }
.pill.warn { background: var(--warn-tint); color: var(--warn); }
.pill.danger { background: var(--danger-tint); color: var(--danger); }
.pill.info { background: var(--info-tint); color: var(--info); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.danger { background: var(--danger); }
.dot.muted { background: var(--muted); }

/* ---------- Alert strip (full border + subtle tint, NO side-stripe) ---------- */
.alert-strip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 10px;
  font-size: 0.875rem;
}

.alert-strip.warn {
  background: var(--warn-tint);
  border-color: var(--warn);
}

.alert-strip.danger {
  background: var(--danger-tint);
  border-color: var(--danger);
}

/* ---------- Metric strip (compact precision telemetry) ---------- */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--border-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: 12px;
}

.metric-cell {
  background: var(--surface);
  padding: 10px 12px;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 1.0625rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.metric-lbl {
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ---------- Segmented sub-tabs ---------- */
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }

.seg button {
  flex: 1 0 auto;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.seg button.active {
  background: var(--surface-2);
  color: var(--ink);
}

/* ---------- Forms & buttons ---------- */
.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.field, select.field, textarea.field {
  width: 100%;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  outline: none;
  transition: border-color var(--t-fast) var(--ease);
}

.field::placeholder { color: var(--muted); opacity: 0.9; }
.field:focus { border-color: var(--primary-ink); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-fill);
}
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-fill);
}

.btn.sm { padding: 5px 10px; font-size: 0.8125rem; border-radius: var(--r-sm); }

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }

.row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.del-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  border: none;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.del-btn:hover { background: var(--danger-tint); color: var(--danger); }

.day-label {
  font-size: 0.8125rem;
  font-weight: 650;
  color: var(--muted);
  margin: 14px 2px 6px;
}
.day-label:first-of-type { margin-top: 4px; }

.inline-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px;
  margin-bottom: 12px;
}

.chk-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.875rem;
  color: var(--ink);
  cursor: pointer;
}
.chk-inline input { accent-color: var(--primary); width: 16px; height: 16px; }

/* ---------- Progress bar ---------- */
.bar-track {
  height: 5px;
  background: var(--surface-2);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin-top: 6px;
}

.bar-fill {
  width: 100%;
  height: 100%;
  background: var(--primary-ink);
  border-radius: var(--r-pill);
  transform-origin: left center;
  transition: transform var(--t-mid) var(--ease);
}

.bar-fill.warn { background: var(--warn); }
.bar-fill.danger { background: var(--danger); }

/* ---------- Empty states & Skeletons ---------- */
.empty-state {
  padding: 22px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}

.skeleton-stack { display: flex; flex-direction: column; gap: 10px; }
.skeleton {
  height: 54px;
  border-radius: var(--r-lg);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Bottom Navigation ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-nav);
  background: var(--bg);
  border-top: 1px solid var(--border-subtle);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
}

.bottom-nav-inner {
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  border-radius: var(--r-md);
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.nav-item:hover { color: var(--ink); }
.nav-item.active {
  color: var(--primary-ink);
  background: var(--primary-tint);
}

.nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- Native <dialog> sheet ---------- */
dialog.sheet {
  width: min(94vw, 480px);
  max-height: 86dvh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  z-index: var(--z-dialog);
}

dialog.sheet::backdrop {
  background: oklch(0 0 0 / 0.62);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.sheet-title { margin: 0; font-size: 1rem; font-weight: 650; }
.sheet-body { padding: 14px 16px; overflow-y: auto; max-height: 66dvh; }
.sheet-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 0.75rem; font-weight: 600; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(14px);
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 9px 15px;
  border-radius: var(--r-pill);
  font-size: 0.8125rem;
  font-weight: 550;
  opacity: 0;
  pointer-events: none;
  z-index: var(--z-toast);
  max-width: 90vw;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger-tint); border-color: var(--danger); color: var(--ink); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
