/* ============================================================
   MyDashboard — warm, rounded reinterpretation
   Foundation: U-NEXT Design System type stack + spacing rhythm.
   Palette: warm cream + walnut sidebar + soft peach accent.
   ============================================================ */

:root {
  /* Type stack from U-NEXT (Japanese-first) */
  --font-sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN",
               "Noto Sans JP", "Noto Sans CJK JP", "BIZ UDPGothic",
               Meiryo, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "SF Mono", "SF Pro Text", "Helvetica Neue", "Segoe UI",
               "Arial", monospace;

  /* Default — these get overwritten by JS via tweaks */

  /* Warm cream content surface */
  --bg-app:       #f6f1e8;       /* outer canvas */
  --bg-content:   #fbf7f0;       /* slightly lighter content area */
  --bg-card:      #ffffff;       /* card surface */
  --bg-card-soft: #f4ede1;       /* nested / inset surface */
  --bg-hover:     rgba(120, 88, 60, 0.06);

  /* Walnut sidebar (warm dark) */
  --bg-sidebar:        #2a231d;
  --bg-sidebar-active: #3d342c;
  --fg-sidebar:        #f1e6d4;
  --fg-sidebar-muted:  rgba(241, 230, 212, 0.55);
  --fg-sidebar-faded:  rgba(241, 230, 212, 0.35);

  /* Foreground text on cream */
  --fg:        #2b2419;          /* near-walnut */
  --fg-muted:  #6b5c48;          /* warm gray */
  --fg-faded:  #9a8a72;          /* paler */
  --fg-subtle: #c4b69c;

  /* Accent — soft peach/terracotta */
  --accent:        #d97757;
  --accent-hover:  #e08a6e;
  --accent-soft:   #f6e3d8;       /* tinted bg for accent backgrounds */
  --accent-fg:     #ffffff;

  /* Status */
  --success: #7ba05b;             /* sage green */
  --success-soft: #e2ebd5;
  --warning: #d9a85a;             /* amber */
  --danger:  #c75a4a;

  /* Borders & dividers */
  --border-soft:   rgba(120, 88, 60, 0.08);
  --border:        rgba(120, 88, 60, 0.14);
  --border-strong: rgba(120, 88, 60, 0.22);

  /* Radius — rounded vibe */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* Shadow — warm + soft */
  --shadow-card: 0 1px 2px rgba(80, 50, 20, 0.04),
                 0 4px 14px rgba(80, 50, 20, 0.06);
  --shadow-pop:  0 8px 28px rgba(80, 50, 20, 0.14);

  /* Density (tweakable) */
  --pad-card: 22px;
  --gap: 16px;

  --sidebar-w: 232px;

  /* Type tokens (lifted from U-NEXT system) */
  --weight-light: 300;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semi: 600;
  --weight-bold: 700;
}

/* ── reset ──────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-sans);
  font-weight: var(--weight-light);
  line-height: 1.45;
  color: var(--fg);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ── app shell ──────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  background: var(--bg-app);
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-sidebar);
  color: var(--fg-sidebar);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 14px;
  border-bottom: 1px solid rgba(241, 230, 212, 0.08);
  margin-bottom: 14px;
}
.sb-brand-mark {
  width: 30px; height: 30px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--accent), #b85a3f);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
  letter-spacing: -0.02em;
}
.sb-brand-name {
  font-size: 16px; font-weight: 600; letter-spacing: -0.01em;
  flex: 1;
}
.sb-brand-chev {
  opacity: 0.4; width: 14px; height: 14px;
}

.sb-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sb-nav-section {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-sidebar-faded);
  padding: 14px 10px 6px;
}
.sb-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px;
  border-radius: var(--r-md);
  color: var(--fg-sidebar-muted);
  font-size: 13.5px; font-weight: 400;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
  border: none; background: transparent; text-align: left;
  width: 100%;
}
.sb-item:hover { color: var(--fg-sidebar); background: rgba(241, 230, 212, 0.05); }
.sb-item.is-active {
  background: var(--bg-sidebar-active);
  color: var(--fg-sidebar);
  font-weight: 500;
}
.sb-item .ico {
  width: 18px; height: 18px;
  filter: invert(1) brightness(0.95);
  opacity: 0.75;
}
.sb-item.is-active .ico { opacity: 1; }
.sb-item .badge {
  margin-left: auto;
  font-size: 11px; font-weight: 500;
  padding: 1px 7px; border-radius: var(--r-pill);
  background: rgba(241, 230, 212, 0.1);
  color: var(--fg-sidebar-muted);
}

.sb-quick-capture {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: rgba(241, 230, 212, 0.06);
  border: 1px solid rgba(241, 230, 212, 0.08);
  font-size: 12.5px;
  color: var(--fg-sidebar-muted);
  margin-top: 14px;
  cursor: pointer;
}
.sb-quick-capture:hover { background: rgba(241, 230, 212, 0.1); }
.sb-quick-capture .kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 2px 6px;
  background: rgba(241, 230, 212, 0.08);
  border-radius: 4px;
}

.sb-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px 4px;
  margin-top: 12px;
  border-top: 1px solid rgba(241, 230, 212, 0.08);
  padding-top: 14px;
}
.sb-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, #d4a574, #b88958);
  display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 13px;
  flex-shrink: 0;
}
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-name { font-size: 13.5px; font-weight: 500; color: var(--fg-sidebar); }
.sb-user-plan { font-size: 11.5px; color: var(--fg-sidebar-faded); margin-top: 1px; }
.sb-user-chev { width: 14px; height: 14px; opacity: 0.4; }

/* ── Main area ──────────────────────────────────────────────── */
.main {
  background: var(--bg-content);
  border-top-left-radius: var(--r-xl);
  border-bottom-left-radius: var(--r-xl);
  margin: 12px 12px 12px 0;
  display: flex; flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border-soft);
}
.search {
  flex: 1; max-width: 360px;
  margin-left: auto;
  position: relative;
}
.search input {
  width: 100%;
  padding: 9px 12px 9px 38px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--bg-card);
  font: inherit; font-size: 13px;
  color: var(--fg);
  outline: none;
  transition: border-color 150ms ease;
}
.search input:focus { border-color: var(--accent); }
.search input::placeholder { color: var(--fg-faded); }
.search-ico {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; opacity: 0.45;
}
.search-kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-faded);
  background: var(--bg-card-soft);
  padding: 2px 7px;
  border-radius: 5px;
}

.icon-btn {
  width: 38px; height: 38px;
  border-radius: var(--r-pill);
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
  position: relative;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-card-soft); }
.icon-btn img { width: 16px; height: 16px; opacity: 0.6; }
.icon-btn .dot {
  position: absolute; top: 9px; right: 11px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  border: 1.5px solid var(--bg-card);
}

.avatar-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, #e8c195, #c79768);
  display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 13px;
  cursor: pointer;
  border: 2px solid var(--bg-card);
  box-shadow: var(--shadow-card);
}

/* Content scroll area */
.content {
  flex: 1; overflow-y: auto;
  padding: 28px 28px 20px;
}

/* Page header */
.page-head {
  display: flex; align-items: flex-start; gap: 24px;
  margin-bottom: 22px;
}
.page-head h1 {
  font-size: 30px; font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  line-height: 1.15;
}
.page-head .greet {
  font-size: 14px;
  color: var(--fg-muted);
  font-weight: 300;
}
.page-head .date {
  margin-left: auto;
  text-align: right;
  flex-shrink: 0;
}
.page-head .date-d { font-size: 14px; font-weight: 500; }
.page-head .date-w { font-size: 13px; color: var(--fg-faded); margin-top: 2px; }

/* ── Stat strip (5 cards) ──────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--gap);
  margin-bottom: var(--gap);
}
.stat {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  padding: var(--pad-card);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; gap: 12px;
  min-width: 0;
}
.stat-head {
  display: flex; align-items: center; gap: 10px;
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 500;
}
.stat-icon {
  width: 30px; height: 30px;
  border-radius: var(--r-sm);
  background: var(--bg-card-soft);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.stat-icon img { width: 15px; height: 15px; opacity: 0.7; }
.stat-icon.accent { background: var(--accent-soft); }
.stat-icon.accent img { filter: invert(48%) sepia(35%) saturate(700%) hue-rotate(330deg); opacity: 0.95; }
.stat-value {
  font-size: 28px; font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}
.stat-sub {
  font-size: 12px;
  color: var(--fg-faded);
}
.stat-bar {
  height: 4px;
  background: var(--bg-card-soft);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin-top: 2px;
}
.stat-bar-fill {
  height: 100%;
  background: var(--fg);
  border-radius: var(--r-pill);
}
.stat-bar-fill.accent { background: var(--accent); }

/* ── Grid: real w×h cells ────────────────────────────────────────────
   3 equal columns, fixed row height, dense packing so smaller items
   backfill earlier holes left by widgets that wrapped. layout.yml sets
   `w: 1..3` and `h: 1..3` per widget; Panel applies grid-column /
   grid-row spans. Result: rows always align, mixed sizes pack cleanly. */
:root { --row-h: 200px; }
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: var(--row-h);
  grid-auto-flow: dense;
  gap: var(--gap);
}
.grid-row { display: contents; }

/* Panel card. min-height: 0 + overflow: hidden are critical so the cell
   bounds the panel; without them the inner content can push the grid
   row taller than --row-h and break alignment. */
.panel {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  padding: var(--pad-card);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  overflow: hidden;
}
.panel-body {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
  overflow-y: auto;
  /* hide scrollbar visually but keep it scrollable */
}
.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
/* Compact panels (1×1 cell) get a denser title to claw back vertical space. */
.panel[data-size="compact"] { padding: 14px 18px; }
.panel[data-size="compact"] .panel-head { margin-bottom: 8px; }
.panel[data-size="compact"] .panel-title { font-size: 13px; }
.panel-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
  min-width: 0;                /* let children shrink past content size */
}
.panel-title {
  font-size: 15px; font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.panel-title .muted { color: var(--fg-faded); font-weight: 400; margin-left: 4px; font-size: 13px; }
.panel-action {
  margin-left: auto;
  font-size: 12.5px; color: var(--fg-muted);
  background: transparent; border: none; cursor: pointer;
  padding: 4px 8px; border-radius: var(--r-sm);
  font-weight: 500;
  flex-shrink: 0;              /* don't get squeezed by a long title */
}
.panel-action:hover { background: var(--bg-hover); color: var(--fg); }
.panel-select {
  margin-left: auto;
  font-size: 12.5px; color: var(--fg-muted);
  background: var(--bg-card-soft);
  border: none; padding: 5px 10px;
  border-radius: var(--r-pill);
  display: flex; align-items: center; gap: 4px;
  cursor: pointer; font-family: inherit;
  font-weight: 500;
}

/* ── Agenda list ──────────────────────────────────────────── */
.agenda { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.agenda-item {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 9px 4px;
  position: relative;
  min-width: 0;
}
.agenda-time {
  width: 56px; flex-shrink: 0;
  font-size: 12.5px; color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
  font-weight: 500;
}
.agenda-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 7px; flex-shrink: 0;
  background: var(--accent);
}
.agenda-dot.work { background: var(--accent); }
.agenda-dot.focus { background: var(--success); }
.agenda-dot.personal { background: var(--warning); }
.agenda-content { flex: 1 1 auto; min-width: 0; }
.agenda-title {
  font-size: 13.5px; font-weight: 500; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.agenda-meta {
  font-size: 12px; color: var(--fg-faded); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.panel-foot {
  margin-top: auto; padding-top: 12px;
  border-top: 1px dashed var(--border);
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--fg-muted);
  cursor: pointer;
  font-weight: 500;
}
.panel-foot:hover { color: var(--fg); }
.panel-foot .arr { width: 12px; height: 12px; opacity: 0.6; }

/* ── Task list ────────────────────────────────────────────── */
.task-list { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.task {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-soft);
  min-width: 0;
}
.task:last-of-type { border-bottom: none; }
.task-check {
  width: 18px; height: 18px; border-radius: 6px;
  border: 1.5px solid var(--border-strong);
  display: grid; place-items: center;
  background: var(--bg-card);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 150ms ease;
}
.task-check.done {
  background: var(--accent);
  border-color: var(--accent);
}
.task-check.done::after {
  content: ""; width: 10px; height: 6px;
  border-left: 2px solid #fff; border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}
.task-text {
  flex: 1 1 auto; min-width: 0;
  font-size: 13.5px;
  color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.task.done .task-text {
  text-decoration: line-through;
  color: var(--fg-faded);
}
.task-tag {
  font-size: 11px; font-weight: 500;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  background: var(--bg-card-soft);
  color: var(--fg-muted);
  letter-spacing: 0.01em;
  flex-shrink: 0;
}
.task-tag.work { background: var(--accent-soft); color: var(--accent); }
.task-tag.personal { background: var(--bg-card-soft); color: var(--fg-muted); }
.task-add {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 0 0;
  margin-top: auto;
  font-size: 13px; color: var(--fg-muted);
  cursor: pointer;
  font-weight: 500;
}
.task-add:hover { color: var(--fg); }
.task-add .plus {
  width: 16px; height: 16px;
  border-radius: 5px;
  display: grid; place-items: center;
  font-size: 13px; line-height: 1;
}

/* ── Focus chart ──────────────────────────────────────────── */
.focus-summary {
  display: flex; align-items: baseline; gap: 12px;
  margin-bottom: 14px;
}
.focus-total {
  font-size: 32px; font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}
.focus-delta {
  font-size: 13px;
  color: var(--success);
  font-weight: 500;
}
.focus-chart {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  padding: 12px 0 0;
  position: relative;
}
.focus-chart-grid {
  position: absolute; left: 0; right: 0;
  border-top: 1px dashed var(--border);
  font-size: 10.5px; color: var(--fg-faded);
  text-align: right;
  padding-right: 4px;
}
.focus-chart-grid::before {
  content: attr(data-label);
  position: absolute;
  right: 0; top: -8px;
  background: var(--bg-card);
  padding: 0 6px;
  color: var(--fg-faded);
}
.focus-bar {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center;
  gap: 8px;
}
.focus-bar-fill {
  width: 100%;
  max-width: 14px;
  background: var(--fg);
  border-radius: var(--r-pill);
  min-height: 6px;
}
.focus-bar-fill.muted { background: var(--bg-card-soft); }
.focus-bar-fill.accent { background: var(--accent); }
.focus-bar-label {
  font-size: 11.5px;
  color: var(--fg-faded);
  font-weight: 500;
}
.focus-bar-label.today { color: var(--fg); font-weight: 600; }

/* ── Notes ────────────────────────────────────────────────── */
.note { display: flex; align-items: flex-start; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border-soft); }
.note:last-of-type { border-bottom: none; }
.note-icon {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  background: var(--bg-card-soft);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.note-icon img { width: 14px; height: 14px; opacity: 0.6; }
.note-body { flex: 1; min-width: 0; }
.note-title-row { display: flex; align-items: baseline; gap: 8px; }
.note-title { font-size: 13.5px; font-weight: 500; color: var(--fg); flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-time { font-size: 11.5px; color: var(--fg-faded); flex-shrink: 0; font-weight: 400; }
.note-snippet {
  font-size: 12.5px; color: var(--fg-muted);
  margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Habits ───────────────────────────────────────────────── */
.habit { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border-soft); }
.habit:last-of-type { border-bottom: none; }
.habit-icon {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.habit-icon img { width: 14px; height: 14px; filter: invert(48%) sepia(35%) saturate(700%) hue-rotate(330deg); opacity: 0.95; }
.habit-body { flex: 1; min-width: 0; }
.habit-name { font-size: 13.5px; font-weight: 500; color: var(--fg); }
.habit-streak { font-size: 11.5px; color: var(--fg-muted); margin-top: 1px; }
.habit-dots { display: flex; gap: 5px; flex-shrink: 0; }
.habit-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--bg-card-soft);
}
.habit-dot.on { background: var(--fg); }
.habit-dot.today { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── Bookmarks ────────────────────────────────────────────── */
.bookmark { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border-soft); cursor: pointer; min-width: 0; }
.bookmark:last-of-type { border-bottom: none; }
.bookmark:hover { background: var(--bg-hover); margin: 0 -8px; padding: 11px 8px; border-radius: var(--r-sm); border-bottom-color: transparent; }
.bookmark-favicon {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}
.bookmark-body { flex: 1 1 auto; min-width: 0; }
.bookmark-name {
  font-size: 13.5px; font-weight: 500; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bookmark-url {
  font-size: 11.5px; color: var(--fg-faded); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Footer quote ─────────────────────────────────────────── */
.footer {
  display: flex; align-items: center; gap: 8px;
  padding: 18px 28px;
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
  color: var(--fg-muted);
  font-style: italic;
}
.footer .att {
  margin-left: auto;
  font-style: normal;
  color: var(--fg-faded);
  font-size: 12.5px;
}

/* ── theme: cool variant (toggleable) ─────────────────────── */
body[data-tone="cool"] {
  --bg-app: #eef0f3;
  --bg-content: #f6f7f9;
  --bg-card: #ffffff;
  --bg-card-soft: #eaecf0;
  --bg-sidebar: #1c2028;
  --bg-sidebar-active: #2a2f38;
  --fg-sidebar: #e6e9ee;
  --fg-sidebar-muted: rgba(230, 233, 238, 0.55);
  --fg-sidebar-faded: rgba(230, 233, 238, 0.35);
  --fg: #1f242c;
  --fg-muted: #5a6473;
  --fg-faded: #8b94a3;
  --fg-subtle: #c3cad5;
  --accent: #5b6cff;
  --accent-hover: #6d7cff;
  --accent-soft: #e2e6ff;
  --border-soft: rgba(60, 80, 110, 0.06);
  --border: rgba(60, 80, 110, 0.12);
  --border-strong: rgba(60, 80, 110, 0.2);
  --bg-hover: rgba(60, 80, 110, 0.05);
}
body[data-tone="sage"] {
  --bg-app: #eef1ec;
  --bg-content: #f4f6f1;
  --bg-card: #ffffff;
  --bg-card-soft: #e8ece2;
  --bg-sidebar: #1f2620;
  --bg-sidebar-active: #2d352b;
  --fg-sidebar: #e7ecdf;
  --fg-sidebar-muted: rgba(231, 236, 223, 0.55);
  --fg-sidebar-faded: rgba(231, 236, 223, 0.35);
  --fg: #232a23;
  --fg-muted: #5e6a5c;
  --fg-faded: #8c9789;
  --fg-subtle: #c0c9b9;
  --accent: #6f8e5a;
  --accent-hover: #7d9c68;
  --accent-soft: #e0e8d4;
  --border-soft: rgba(60, 80, 60, 0.07);
  --border: rgba(60, 80, 60, 0.14);
  --border-strong: rgba(60, 80, 60, 0.22);
  --bg-hover: rgba(60, 80, 60, 0.05);
}
body[data-tone="lavender"] {
  --bg-app: #f1eef4;
  --bg-content: #f7f4fa;
  --bg-card: #ffffff;
  --bg-card-soft: #ece6f2;
  --bg-sidebar: #2a2333;
  --bg-sidebar-active: #3a3045;
  --fg-sidebar: #ece6f3;
  --fg-sidebar-muted: rgba(236, 230, 243, 0.55);
  --fg-sidebar-faded: rgba(236, 230, 243, 0.35);
  --fg: #2b2434;
  --fg-muted: #645871;
  --fg-faded: #918699;
  --fg-subtle: #c8bfd0;
  --accent: #9a72c4;
  --accent-hover: #a886cf;
  --accent-soft: #ebe1f2;
  --border-soft: rgba(80, 60, 100, 0.07);
  --border: rgba(80, 60, 100, 0.14);
  --border-strong: rgba(80, 60, 100, 0.22);
  --bg-hover: rgba(80, 60, 100, 0.05);
}

/* ── Density variants ─────────────────────────────────────── */
body[data-density="compact"] {
  --pad-card: 16px;
  --gap: 12px;
}
body[data-density="comfy"] {
  --pad-card: 28px;
  --gap: 20px;
}

/* ── Sidebar light variant ────────────────────────────────── */
body[data-sidebar="light"] {
  --bg-sidebar: var(--bg-card);
  --bg-sidebar-active: var(--accent-soft);
  --fg-sidebar: var(--fg);
  --fg-sidebar-muted: var(--fg-muted);
  --fg-sidebar-faded: var(--fg-faded);
}
body[data-sidebar="light"] .sb-item .ico { filter: none; }
body[data-sidebar="light"] .sb-item.is-active { color: var(--accent); }
body[data-sidebar="light"] .sb-item.is-active .ico {
  filter: invert(48%) sepia(35%) saturate(700%) hue-rotate(330deg); opacity: 1;
}
body[data-sidebar="light"] .sidebar { border-right: 1px solid var(--border-soft); }
body[data-sidebar="light"] .sb-brand { border-bottom-color: var(--border-soft); }
body[data-sidebar="light"] .sb-user { border-top-color: var(--border-soft); }
body[data-sidebar="light"] .sb-quick-capture {
  background: var(--bg-app);
  border-color: var(--border);
  color: var(--fg-muted);
}
body[data-sidebar="light"] .sb-quick-capture .kbd {
  background: var(--bg-card-soft);
  color: var(--fg-muted);
}

/* ── Dark mode (warm dim) ─────────────────────────────────── */
body[data-mode="dark"] {
  --bg-app:       #18130d;
  --bg-content:   #1f1812;
  --bg-card:      #26201a;
  --bg-card-soft: #2e2720;
  --bg-hover:     rgba(255, 240, 220, 0.04);
  --fg:           #f0e6d4;
  --fg-muted:     #b3a48d;
  --fg-faded:     #8a7d68;
  --fg-subtle:    #5e5444;
  --border-soft:  rgba(255, 230, 200, 0.05);
  --border:       rgba(255, 230, 200, 0.09);
  --border-strong:rgba(255, 230, 200, 0.16);
  --shadow-card:  0 1px 2px rgba(0, 0, 0, 0.3),
                  0 6px 18px rgba(0, 0, 0, 0.25);
  --bg-sidebar: #14100b;
  --bg-sidebar-active: #2a221a;
}
body[data-mode="dark"][data-tone="cool"] {
  --bg-app: #131620; --bg-content: #1a1d28; --bg-card: #222633; --bg-card-soft: #2a2f3d;
  --fg: #e8ecf4; --fg-muted: #98a2b8; --fg-faded: #6c7689;
  --border-soft: rgba(180,200,230,0.06); --border: rgba(180,200,230,0.10); --border-strong: rgba(180,200,230,0.18);
  --bg-sidebar: #0e1018; --bg-sidebar-active: #1f2330;
}
body[data-mode="dark"][data-tone="sage"] {
  --bg-app: #141a14; --bg-content: #1a211a; --bg-card: #232a23; --bg-card-soft: #2c342c;
  --fg: #e6efde; --fg-muted: #a3b39a; --fg-faded: #768174;
  --border-soft: rgba(200,220,180,0.06); --border: rgba(200,220,180,0.10); --border-strong: rgba(200,220,180,0.18);
  --bg-sidebar: #0f130e; --bg-sidebar-active: #1f2820;
}
body[data-mode="dark"][data-tone="lavender"] {
  --bg-app: #1a1620; --bg-content: #211c2a; --bg-card: #2a2434; --bg-card-soft: #332c3f;
  --fg: #ece5f2; --fg-muted: #a99cb8; --fg-faded: #7d7289;
  --border-soft: rgba(220,200,240,0.06); --border: rgba(220,200,240,0.10); --border-strong: rgba(220,200,240,0.18);
  --bg-sidebar: #140f1a; --bg-sidebar-active: #281f33;
}
/* In dark mode, monochrome icons need to flip to light */
body[data-mode="dark"] .stat-icon img,
body[data-mode="dark"] .note-icon img,
body[data-mode="dark"] .icon-btn img,
body[data-mode="dark"] .agenda-content img,
body[data-mode="dark"] .panel-foot .arr,
body[data-mode="dark"] .search-ico {
  filter: invert(1) brightness(0.92);
}
body[data-mode="dark"] .task-tag.work {
  background: rgba(217, 119, 87, 0.18);
  color: var(--accent);
}
body[data-mode="dark"] .task-tag.personal {
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg-muted);
}

/* ── Radius scale (tweak) ─────────────────────────────────── */
body[data-radius="square"] { --r-md: 8px; --r-lg: 10px; --r-xl: 12px; --r-sm: 6px; }
body[data-radius="round"]  { --r-md: 14px; --r-lg: 18px; --r-xl: 22px; --r-sm: 10px; }
body[data-radius="extra"]  { --r-md: 18px; --r-lg: 24px; --r-xl: 30px; --r-sm: 14px; }

/* ── Panel hint (mock/error label) ─────────────────────────── */
.panel-hint {
  font-size: 10px;
  color: var(--fg-faded);
  font-weight: 400;
  margin-left: 6px;
  letter-spacing: 0.01em;
}

/* ── Boot screens (layout.yml load gate) ─────────────────────── */
.boot {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  font: 14px/1.5 var(--font-sans);
  color: var(--fg-muted); background: var(--bg-app);
}
.boot-err { color: var(--danger); white-space: pre-wrap; }

/* ── Markets widget ──────────────────────────────────────────── */
.markets { display: flex; flex-direction: column; gap: 2px; }
.market-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid var(--border-soft);
  min-width: 0;
}
.market-row:last-child { border-bottom: none; }
.market-meta {
  display: flex; flex-direction: column; gap: 2px;
  flex: 1 1 auto; min-width: 0;
}
.market-name {
  font-size: 13px; font-weight: 500; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.market-symbol {
  font-size: 11px; color: var(--fg-faded);
  font-family: var(--font-mono); letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.market-vals {
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
  flex-shrink: 0;
}
.market-price {
  font-size: 13px; font-weight: 500; color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.market-change {
  font-size: 11px; font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}
.market-change.up   { color: var(--success); }
.market-change.down { color: var(--danger); }

/* ── Feed widget (RSS + YouTube) ─────────────────────────────── */
/* Height/scroll handled by .panel-body; .feed just lays out the items. */
.feed { display: flex; flex-direction: column; gap: 2px; }
.feed-item {
  display: flex; gap: 10px; padding: 10px 4px;
  border-bottom: 1px solid var(--border-soft);
  text-decoration: none; color: inherit;
  transition: background 120ms ease;
  min-width: 0;
}
.feed-item:hover { background: var(--bg-hover); }
.feed-item:last-child { border-bottom: none; }
.feed-kind {
  flex-shrink: 0; width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-xs);
  font-size: 11px; font-weight: 600;
  margin-top: 2px;
}
.feed-kind.feed-rss     { background: var(--accent-soft); color: var(--accent); }
.feed-kind.feed-youtube { background: rgba(255, 0, 0, 0.1); color: #cc0000; }
.feed-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.feed-title {
  font-size: 13px; font-weight: 500; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  word-break: break-word;
}
.feed-meta {
  display: flex; gap: 6px; align-items: center;
  font-size: 11px; color: var(--fg-faded);
  min-width: 0;
}
.feed-meta > span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.feed-dot { opacity: 0.5; flex-shrink: 0; }
.feed-meta > span:last-child { flex-shrink: 0; }

/* Markets — compact (top mover only) */
.markets-compact { display: flex; flex-direction: column; gap: 6px; }
.mc-top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.mc-name {
  font-size: 14px; font-weight: 500; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.mc-meta { font-size: 11px; color: var(--fg-faded); }

/* Bookmarks — compact strip of favicon chips */
.bookmark-strip {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 2px 0;
}
.bookmark-chip {
  display: block;
  transition: transform 120ms ease;
}
.bookmark-chip:hover { transform: translateY(-1px); }
.bookmark-chip .bookmark-favicon {
  width: 30px; height: 30px;
  border-radius: var(--r-sm);
  font-size: 13px;
}

/* ── Edit mode (drag-edit UI) ──────────────────────────────────────────
   Active when TopBar's pencil button is on. Adds a toolbar, wraps each
   grid item in chrome (drag handle, size/span selects, remove), and
   appends an "+ Add widget" tile. Save/Reset call /api/layout. */
.icon-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.icon-btn.is-active svg { stroke: var(--accent); opacity: 1; }

.edit-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  margin-bottom: var(--gap);
  background: var(--bg-card-soft);
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  font-size: 12.5px;
}
.edit-toolbar strong { font-weight: 600; color: var(--fg); }
.edit-dirty { color: var(--accent); font-size: 11.5px; font-weight: 500; }
.edit-save {
  background: var(--accent) !important;
  color: var(--accent-fg) !important;
  font-weight: 500;
}
.edit-save:disabled { opacity: 0.45; cursor: not-allowed; }
.edit-save:not(:disabled):hover { background: var(--accent-hover) !important; }

.edit-panel-wrap {
  display: flex; flex-direction: column;
  border: 1px dashed var(--border);
  border-radius: var(--r-lg);
  padding: 8px;
  background: var(--bg-card-soft);
  transition: opacity 120ms ease, border-color 120ms ease, background 120ms ease;
  min-width: 0;
}
.edit-panel-wrap.is-dragging { opacity: 0.4; }
.edit-panel-wrap.is-drop {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-soft);
}

.edit-panel-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 6px 8px;
  font-size: 11.5px;
  color: var(--fg-muted);
}
.edit-grip {
  cursor: grab;
  font-size: 16px; line-height: 1;
  color: var(--fg-faded);
  padding: 0 2px;
  user-select: none;
}
.edit-grip:active { cursor: grabbing; }
.edit-type {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-card);
  padding: 2px 7px;
  border-radius: var(--r-pill);
  color: var(--fg);
}
/* edit-size-btn extends .panel-action with a monospace label so the size
   word visually settles next to the type chip. */
.edit-size-btn {
  font-family: var(--font-mono);
  font-size: 11px !important;
  padding: 3px 8px !important;
  background: var(--bg-card) !important;
  border: 1px solid var(--border-soft);
  text-transform: lowercase;
}
.edit-size-btn:hover { background: var(--accent-soft) !important; color: var(--accent) !important; }
.edit-x {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--fg-muted);
  font-size: 16px; line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
}
.edit-x:hover { background: var(--danger); color: #fff; }
.edit-panel-preview {
  flex: 1;
  pointer-events: none;       /* preview is non-interactive in edit mode */
  filter: saturate(0.85);
}
.edit-panel-preview .panel { box-shadow: none; }

.add-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  min-height: 160px;
  padding: 22px;
  border: 2px dashed var(--border);
  background: transparent;
  border-radius: var(--r-lg);
  color: var(--fg-muted);
  cursor: pointer;
  font: inherit; font-size: 13px;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}
.add-tile:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.add-tile-plus { font-size: 28px; line-height: 1; font-weight: 300; }

/* Modal — Add widget picker */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(40, 30, 20, 0.4);
  display: grid; place-items: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  padding: 22px;
  min-width: 360px; max-width: 480px;
  box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column; gap: 14px;
}
.modal-title {
  font-size: 15px; font-weight: 600;
  letter-spacing: -0.01em;
}
.modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.modal-tile {
  padding: 16px 10px;
  background: var(--bg-card-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  font: inherit; font-size: 13px;
  color: var(--fg);
  cursor: pointer;
  transition: all 120ms ease;
  font-family: var(--font-mono);
}
.modal-tile:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  transform: translateY(-1px);
}
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ── Responsive ──────────────────────────────────────────────
   Below 1100px: drop to 2 cols, clamp every cell to span 1 column
   max so layouts authored for 3-col don't blow horizontally. Row
   spans still apply, so vertically-tall widgets stay tall. */
@media (max-width: 1280px) {
  .stats { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .grid > .panel,
  .grid > .edit-panel-wrap { grid-column: auto !important; }
}
@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid > .panel,
  .grid > .edit-panel-wrap { grid-column: auto !important; grid-row: auto !important; }
}
