/* AIDA: one stylesheet, token-driven, light + dark. */

/* CuttingKnots brand: Knot Black #0F151B, Cut Orange #FD3F03, Slate #5B6670, Mist #F2F3F5.
   Type: Outfit (display), Figtree (body), JetBrains Mono (data). */
:root {
  color-scheme: light;
  --bg: #f2f3f5;          /* Mist 100 */
  --surface: #ffffff;
  --surface-2: #eceef1;
  --surface-3: #e1e4e8;
  --border: rgba(15, 21, 27, 0.12);
  --grid: #e1e4e8;
  --text: #0f151b;        /* Knot Black */
  --text-2: #3b4650;
  --muted: #5b6670;       /* Slate 500 */
  --accent: #fd3f03;      /* Cut Orange */
  --accent-hover: #e03602;
  --accent-ink: #ffffff;
  --accent-soft: #ffe2d7;
  --link: #c93202;        /* Cut Orange, darkened for readable small text on light grounds */
  --danger: #c42b4a;
  --danger-ink: #a8213c;
  --warning: #e8a200;
  --inbox: #8a949e;

  /* Task statuses (validated as a set for the stacked bars). */
  --st-todo: #5b6670;
  --st-in_progress: #fd3f03;
  --st-blocked: #c42b4a;
  --st-done: #12955a;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 21, 27, 0.05), 0 8px 24px rgba(15, 21, 27, 0.07);
  --shadow-lg: 0 12px 48px rgba(15, 21, 27, 0.2);
  --topbar-h: 60px;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Outfit", "Figtree", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f151b;        /* Knot Black */
    --surface: #161e26;
    --surface-2: #1d2731;
    --surface-3: #27323d;
    --border: rgba(255, 255, 255, 0.1);
    --grid: #232d37;
    --text: #f2f3f5;
    --text-2: #b8c1c9;
    --muted: #8a949e;
    --accent-soft: #4a1d0d;
    --link: #ff6a3d;
    --danger: #ef5a77;
    --danger-ink: #ff8098;
    --st-todo: #8a949e;
    --st-blocked: #ef5a77;
    --st-done: #3cc283;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f151b;
  --surface: #161e26;
  --surface-2: #1d2731;
  --surface-3: #27323d;
  --border: rgba(255, 255, 255, 0.1);
  --grid: #232d37;
  --text: #f2f3f5;
  --text-2: #b8c1c9;
  --muted: #8a949e;
  --accent-soft: #4a1d0d;
  --link: #ff6a3d;
  --danger: #ef5a77;
  --danger-ink: #ff8098;
  --st-todo: #8a949e;
  --st-blocked: #ef5a77;
  --st-done: #3cc283;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* --- Base ------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; }
p { margin: 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.icon { flex: none; vertical-align: -3px; }

.dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c, var(--inbox));
}
.dot.lg { width: 14px; height: 14px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Layout ----------------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  color: var(--text);
}
.brand-name { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name b { font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: 0.01em; }
.brand-name small { font-size: 11px; color: var(--muted); font-weight: 500; }
.brand:hover { text-decoration: none; }
.brand-mark { display: block; flex: none; width: 30px; height: 30px; }
.brand-mark img { display: block; width: 100%; height: 100%; }
.brand-mark .on-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-mark .on-light { display: none; }
  :root:not([data-theme="light"]) .brand-mark .on-dark { display: block; }
}
:root[data-theme="dark"] .brand-mark .on-light { display: none; }
:root[data-theme="dark"] .brand-mark .on-dark { display: block; }

.nav, .folder-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }

.nav a, .folder-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
}
.nav a:hover, .folder-list a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.is-active, .folder-list a.is-active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.folder-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-list .count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 6px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.sidebar-account, .sidebar-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
}
.sidebar-account { padding: 12px 4px 0 10px; border-top: 1px solid var(--border); color: var(--text-2); }
.account-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--topbar-h);
  padding: 10px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
#page-title { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* Every page fits the window: its sections are slots that scroll inside. The container
   only scrolls when the window is too short for the slots' minimum sizes. */
.view-container { flex: 1; min-height: 0; overflow-y: auto; padding: 24px 28px; }
.view { display: flex; flex-direction: column; gap: 20px; height: 100%; min-height: 480px; max-width: 1280px; margin: 0 auto; }
.view > * { flex: none; }
.view > .panes, .view > .scroll-area { flex: 1 1 0; min-height: 0; }
.view-calendar { max-width: none; }

.slot { display: flex; flex-direction: column; min-height: 0; }
.slot > * { flex: none; }
.slot > .slot-body {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 -18px -16px;
  padding: 0 18px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.scroll-area { overflow-y: auto; overscroll-behavior: contain; margin: -4px; padding: 4px 4px 12px; }

/* Phone tabs (components/panes.js): hidden on wider screens, where every pane shows. */
.pane-tabs { display: none; }
.phone-only { display: none; }

/* --- Cards, buttons, forms -------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.card-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.card-header h2 { flex: 1; }
.count {
  min-width: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.subhead { margin: 18px 0 8px; color: var(--text-2); }
.empty { color: var(--muted); padding: 6px 0; }
.empty-state { text-align: center; padding: 32px; color: var(--text-2); }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-danger-ghost { color: var(--danger-ink); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn:disabled { opacity: 0.6; cursor: default; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 26px; height: 26px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  min-width: 0;
}
input, select { height: 34px; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

label.stacked { display: flex; flex-direction: column; gap: 6px; color: var(--text-2); font-size: 12px; font-weight: 500; }
label.stacked input, label.stacked select, label.stacked textarea { font-size: 14px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.quick-add { display: flex; gap: 8px; padding: 10px; }
.quick-add input[name="title"] { flex: 1; font-size: 15px; border-color: transparent; background: transparent; }
.quick-add input[name="title"]:focus { background: var(--surface); }

/* --- KPI tiles -------------------------------------------------------------------- */

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi-label { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 12px; }
.kpi-value { font-family: var(--font-display); font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.kpi.is-alert .kpi-label .icon { color: var(--danger); }
.kpi-row.compact { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.kpi-row.compact .kpi { box-shadow: none; background: var(--surface-2); border-color: transparent; padding: 10px 12px; }
.kpi-row.compact .kpi-value { font-size: 17px; }

/* --- Task rows -------------------------------------------------------------------- */

.task-list { display: flex; flex-direction: column; }

.task-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 8px 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.task-row::before {
  /* folder color stripe */
  content: "";
  position: absolute;
  left: 4px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 2px;
  background: var(--c);
}
.task-row + .task-row { border-top: 1px solid var(--grid); }
.task-row:hover { background: var(--surface-2); }
.task-row:hover + .task-row, .task-row:hover { border-top-color: transparent; }

.check {
  display: grid;
  place-items: center;
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  padding: 0;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  color: transparent;
  cursor: pointer;
}
.check .icon { width: 12px; height: 12px; }
.check:hover { border-color: var(--st-done); color: var(--st-done); }
.task-row.is-done .check { background: var(--st-done); border-color: var(--st-done); color: #fff; }

.task-main { flex: 1; min-width: 0; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task-row.is-done .task-title { color: var(--muted); text-decoration: line-through; }
.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}
.task-meta > span { display: inline-flex; align-items: center; gap: 4px; }
.task-meta .icon { width: 13px; height: 13px; }
.meta-folder { color: var(--text-2); }
.meta-prio { color: var(--text-2); font-weight: 600; }
.meta-prio .icon { color: var(--danger); }
.meta-late { color: var(--danger-ink); font-weight: 500; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-2);
  font-weight: 500;
}
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--st); }

.timer-btn { color: var(--muted); }
.task-row:not(:hover) .timer-btn:not(.is-running) { opacity: 0; }
.task-row:focus-within .timer-btn { opacity: 1 !important; }
.timer-btn.is-running { color: var(--danger); }

.task-row.is-compact { padding: 6px 6px 6px 12px; align-items: center; gap: 8px; }
.task-row.is-compact .check { width: 16px; height: 16px; margin: 0; }
.task-row.is-compact .check .icon { width: 10px; height: 10px; }
.task-row.is-compact .task-title { font-size: 13px; font-weight: 400; }
.task-row.is-compact::before { top: 8px; bottom: 8px; }

/* --- Status colors ----------------------------------------------------------------- */

.st-todo { --st: var(--st-todo); }
.st-in_progress { --st: var(--st-in_progress); }
.st-blocked { --st: var(--st-blocked); }
.st-done { --st: var(--st-done); }

/* Stacked status bar: 2px surface gaps, square at the baseline, 4px round at the end. */
.status-bar {
  display: flex;
  gap: 2px;
  height: 12px;
  margin: 10px 0;
}
.status-bar .seg {
  min-width: 4px;
  background: var(--st);
  cursor: default;
}
.status-bar .seg:last-child { border-radius: 0 4px 4px 0; }
.status-bar .seg:hover, .status-bar .seg:focus-visible { filter: brightness(1.12); outline-offset: 1px; }
.status-bar.is-empty { background: var(--surface-2); border-radius: 0 4px 4px 0; }

.status-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
}
.status-legend li { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.status-legend .lg-label { flex: 1; }
.status-legend .lg-count { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.status-legend .lg-pct { width: 36px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.swatch { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 2px; background: var(--st); }

.completion { display: flex; align-items: baseline; gap: 8px; }
.completion-value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }

/* --- Overview --------------------------------------------------------------------- */

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: repeat(2, minmax(140px, 1fr));
  grid-template-areas: "today active next" "today overdue next";
  gap: 20px;
}
.pane-today { grid-area: today; }
.pane-active { grid-area: active; }
.pane-overdue { grid-area: overdue; }
.pane-next { grid-area: next; }

.schedule { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.schedule-item {
  display: grid;
  grid-template-columns: 96px 4px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.schedule-item:hover { background: var(--surface-2); }
.sch-time { color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.sch-bar { height: 22px; border-radius: 2px; background: var(--c); }
.sch-bar.kind-planned { background: color-mix(in srgb, var(--c) 35%, var(--surface)); box-shadow: inset 0 0 0 1px var(--c); }
.sch-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sch-duration { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.kind-tag {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
}
.kind-tag.kind-running { background: var(--danger); color: #fff; }

.day-group + .day-group { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--grid); }
.day-group-header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 8px; margin-bottom: 4px; }
.day-group .empty { padding: 2px 0; font-size: 13px; }

/* --- Projects & folder ------------------------------------------------------------ */

.page-intro { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); align-content: start; gap: 16px; }
.project-card { display: flex; flex-direction: column; gap: 6px; cursor: pointer; border-top: 3px solid var(--c); }
.project-card:hover { border-color: var(--border); border-top-color: var(--c); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.project-header { display: flex; align-items: center; gap: 10px; }
.project-header h3 { flex: 1; font-size: 16px; }
.project-header a { color: var(--text); }
.project-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--text-2); font-size: 12px; }
.project-foot span { display: inline-flex; align-items: center; gap: 5px; }

.folder-header { display: flex; align-items: center; gap: 8px; }
.folder-stats { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 1.4fr); gap: 24px; align-items: center; }

.folder-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(220px, 1fr);
  grid-template-areas: "stats stats" "tasks appts";
  gap: 20px;
}
.pane-stats { grid-area: stats; }
.pane-tasks { grid-area: tasks; }
.pane-tasks .toolbar { margin-bottom: 8px; }
.pane-tasks .empty { padding: 16px 0; }
.pane-appts { grid-area: appts; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar input[type="search"] { width: 220px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip.is-active { border-color: var(--text); color: var(--text); font-weight: 600; }
.chip-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.appt-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.appt-row {
  display: grid;
  grid-template-columns: 110px 4px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.appt-row:hover { background: var(--surface-2); }
.appt-row .sch-bar { align-self: stretch; height: auto; min-height: 22px; }
.appt-when { display: flex; flex-direction: column; font-size: 13px; font-variant-numeric: tabular-nums; }
.appt-when span { color: var(--text-2); font-size: 12px; }
.appt-main { display: flex; flex-direction: column; min-width: 0; }
.appt-title { font-weight: 500; overflow-wrap: anywhere; }
.appt-location { min-width: 0; overflow-wrap: anywhere; }
.appt-past { margin-top: 8px; }
.appt-past summary { padding: 4px 8px; color: var(--text-2); font-size: 13px; cursor: pointer; }
.appointments .card-header { align-items: center; }

/* --- Top bar timer ---------------------------------------------------------------- */

.timer-widget { display: flex; align-items: center; min-width: 0; }
.timer-idle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.timer-running {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  min-width: 0;
}
.timer-task {
  max-width: 260px;
  overflow: hidden;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.timer-elapsed { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }
.timer-running .btn { border-radius: 999px; }
.pulse { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--c); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* --- Drawer ----------------------------------------------------------------------- */

.drawer { position: fixed; inset: 0; z-index: 20; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.28); }
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(480px, 100vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: slide-in 0.16s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.drawer-panel:focus { outline: none; }
.drawer-header { display: flex; align-items: flex-start; gap: 10px; padding: 14px 12px 14px 20px; border-bottom: 1px solid var(--border); }
.drawer-heading { display: flex; flex: 1; flex-direction: column; gap: 4px; min-width: 0; }
.drawer-kicker { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
.drawer-title-row { display: flex; align-items: flex-start; gap: 4px; }
.drawer-title { flex: 1; min-width: 0; padding: 3px 0; font-size: 20px; line-height: 1.3; overflow-wrap: anywhere; }
.drawer-title-row .icon-btn { margin-top: 3px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.drawer-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }

.title-input {
  flex: 1;
  min-width: 0;
  padding: 2px 6px;
  margin-left: -7px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  resize: none;
  overflow: hidden;
}

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--text-2); font-size: 12px; font-weight: 500; }

.drawer-section { padding-top: 14px; border-top: 1px solid var(--grid); }
.drawer-section h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.time-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.time-summary > div, .summary-totals > div { display: flex; flex-direction: column; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.time-summary .label, .summary-totals .label { color: var(--text-2); font-size: 12px; }
.time-summary strong, .summary-totals strong { font-size: 16px; }

/* Meter: accent fill on a lighter step of the same hue; warning once over estimate. */
.meter { height: 8px; margin-top: 12px; background: var(--accent-soft); border-radius: 0 4px 4px 0; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.meter.is-over { background: color-mix(in srgb, var(--warning) 30%, var(--surface)); }
.meter.is-over span { background: var(--warning); }
.meter-caption { display: flex; align-items: center; gap: 5px; margin-top: 6px; color: var(--text-2); font-size: 12px; }
.meter-caption .icon { color: var(--warning); }

.block-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.block-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.block-item:hover { background: var(--surface-2); }
.block-item .kind-tag { text-align: center; }

.comment-list { margin: 0 0 12px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.comment-list li { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.comment-meta { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; margin: -4px -6px 2px 0; }
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.comment-form textarea { width: 100%; }

/* --- Dialogs ---------------------------------------------------------------------- */

dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog.confirm { width: min(420px, calc(100vw - 32px)); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 0 20px; }
.dialog-body { display: flex; flex-direction: column; gap: 14px; padding: 16px 20px 20px; }
.dialog-footer { display: flex; align-items: center; gap: 8px; padding-top: 4px; }
.confirm .dialog-footer { padding: 0 20px 18px; }
.confirm-message { font-size: 15px; }

.segmented { display: inline-flex; padding: 3px; border-radius: 8px; background: var(--surface-2); align-self: flex-start; }
.segmented label { display: flex; align-items: center; gap: 6px; padding: 5px 14px; border-radius: 6px; color: var(--text-2); font-weight: 500; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.segmented + .hint { margin-top: -8px; }
.appointment-fields { display: flex; flex-direction: column; gap: 14px; }

.repeat-fields, .repeat-details { display: flex; flex-direction: column; gap: 14px; }
.inline-field { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; font-weight: 400; }
.inline-field input { width: 72px; }
.weekday-picker { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.weekday-picker legend { padding: 0; margin-bottom: 6px; color: var(--text-2); font-size: 12px; font-weight: 500; }
.weekday-picker label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
}
.weekday-picker input { position: absolute; opacity: 0; pointer-events: none; }
.weekday-picker label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.weekday-picker label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.series-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
}

/* Import appointments */
dialog.import-dialog { width: min(640px, calc(100vw - 32px)); }
dialog.meeting-dialog { width: min(680px, calc(100vw - 32px)); }
.record-btn.is-recording { color: var(--danger); border-color: var(--danger); font-variant-numeric: tabular-nums; }
.record-btn.is-recording .icon { animation: rec-pulse 1.2s ease-in-out infinite; }
@keyframes rec-pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .record-btn.is-recording .icon { animation: none; } }
.team-list { display: flex; flex-direction: column; gap: 24px; }
.team-member-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.team-member-header h2 { font-family: var(--font-display); font-size: 18px; margin: 0; }
.written-pane { max-height: 45vh; overflow-y: auto; overscroll-behavior: contain; }
.written-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.written-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.written-report { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.written-report > summary { cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.wr-title { font-weight: 600; }
.wr-body { margin-top: 10px; line-height: 1.55; }
.wr-body h3, .wr-body h4, .wr-body h5 { font-family: var(--font-display); margin: 14px 0 6px; }
.wr-body ul, .wr-body ol { margin: 4px 0 8px; padding-left: 22px; }
.wr-body p { margin: 6px 0; }
.wr-actions { display: flex; gap: 6px; margin-top: 10px; }
.drop-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 28px 16px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-2);
  text-align: center;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.is-dropping { border-color: var(--accent); color: var(--text); }
.drop-zone .icon { width: 22px; height: 22px; color: var(--accent); }
.drop-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; height: auto; }
.drop-zone:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.import-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: -8px; }
.import-list { display: flex; flex-direction: column; max-height: min(46vh, 420px); overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.import-list .empty { padding: 12px; }
.import-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; cursor: pointer; }
.import-row + .import-row { border-top: 1px solid var(--grid); }
.import-row:hover { background: var(--surface-2); }
.import-row input { flex: none; margin: 3px 0 0; height: auto; accent-color: var(--accent); }
.import-row.is-empty .import-title, .import-row.is-empty .import-when { color: var(--muted); }
.import-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.import-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 500; overflow-wrap: anywhere; }
.import-when { color: var(--text-2); font-size: 13px; }
.import-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--text-2); font-size: 12px; }
.import-meta > span { display: inline-flex; align-items: center; gap: 4px; min-width: 0; overflow-wrap: anywhere; }
.import-meta .icon { width: 13px; height: 13px; }
.import-warning { display: flex; align-items: flex-start; gap: 6px; color: var(--text-2); font-size: 12px; }
.import-warning .icon { width: 13px; height: 13px; margin-top: 1px; color: var(--warning); }
.kind-tag.status-new { background: var(--accent-soft); color: var(--text); }
.kind-tag.status-cancel { background: color-mix(in srgb, var(--danger) 18%, var(--surface)); color: var(--danger-ink); }
.is-dropping { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: var(--radius); }

.choice-list { display: flex; flex-direction: column; gap: 2px; }
.choice { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.choice:hover { background: var(--surface-2); }
.choice input { margin: 0; height: auto; accent-color: var(--accent); }

.color-field, .space-field { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.color-field legend, .space-field legend { padding: 0; margin-bottom: 6px; color: var(--text-2); font-size: 12px; font-weight: 500; }
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.swatch-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.swatch-btn.is-selected { box-shadow: 0 0 0 2px var(--text); }
.custom-color { position: relative; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: conic-gradient(#e34948, #eda100, #1baf7a, #2a78d6, #4a3aa7, #e87ba4, #e34948); cursor: pointer; box-shadow: 0 0 0 1px var(--border); }
.custom-color input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; padding: 0; border: 0; }
.color-preview { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.color-preview .preview-planned, .color-preview .preview-tracked { padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; }
.preview-planned { background: color-mix(in srgb, var(--c) 18%, var(--surface)); border: 1px solid var(--c); border-left-width: 3px; color: var(--text); }
.preview-tracked { background: var(--c); color: var(--c-ink); }

/* --- Calendar --------------------------------------------------------------------- */

.calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; grid-template-rows: minmax(420px, 1fr); gap: 20px; }
.calendar-main { min-height: 0; padding: 14px; }
/* Fixed cards on top; the time summary shrinks and the open tasks take the rest, both
   scrolling inside. The column itself scrolls only in a very short window. */
.calendar-side { display: flex; flex-direction: column; gap: 16px; min-height: 0; overflow-y: auto; }
.calendar-options, .calendar-summary { flex: 0 1 auto; min-height: 140px; }
.calendar-tasks { flex: 1 0 260px; }
.calendar-side h3 { margin-bottom: 8px; }
.calendar-side .options-divider { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--grid); }
.calendar-side input[type="search"] { width: 100%; margin-bottom: 8px; }

.toggle { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--text); cursor: pointer; }
.toggle input { margin: 0; height: auto; accent-color: var(--accent); }
.legend-swatch { display: inline-block; flex: none; width: 18px; height: 12px; border-radius: 3px; vertical-align: -1px; --c: var(--text-2); }
.legend-swatch.planned { background: color-mix(in srgb, var(--c) 18%, var(--surface)); border: 1px solid var(--c); border-left-width: 3px; }
.legend-swatch.tracked { background: var(--c); }
.legend-swatch.daytask { background: var(--surface); border: 1px solid var(--grid); border-left: 3px solid var(--c); }
.hint .legend-swatch { width: 14px; height: 8px; margin: 0 2px 0 6px; }
.hint .legend-swatch:first-child { margin-left: 0; }

.summary-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.time-bars { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.tb-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 13px; }
.tb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-values { font-weight: 600; font-variant-numeric: tabular-nums; }
.tb-track { height: 6px; margin-top: 2px; }
.tb-bar { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.tb-bar.tracked { background: var(--c); }
.tb-bar.planned { background: color-mix(in srgb, var(--c) 30%, var(--surface)); }

.drag-list { display: flex; flex-direction: column; gap: 4px; }
.drag-task {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  grid-template-areas: "grip dot title" "grip . meta";
  align-items: center;
  gap: 0 8px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--c);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: grab;
  user-select: none;
}
.drag-task:hover { background: var(--surface-2); }
.drag-task .grip { grid-area: grip; color: var(--muted); }
.drag-task .dot { grid-area: dot; }
.drag-task .drag-title { grid-area: title; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.drag-task .drag-meta { grid-area: meta; color: var(--muted); font-size: 12px; }

/* FullCalendar theme */
.fc {
  --fc-border-color: var(--grid);
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: var(--surface-2);
  --fc-neutral-text-color: var(--text-2);
  --fc-today-bg-color: color-mix(in srgb, var(--accent) 7%, transparent);
  --fc-now-indicator-color: var(--danger);
  --fc-highlight-color: color-mix(in srgb, var(--accent) 16%, transparent);
  --fc-list-event-hover-bg-color: var(--surface-2);
  --fc-button-text-color: var(--text);
  --fc-button-bg-color: var(--surface);
  --fc-button-border-color: var(--border);
  --fc-button-hover-bg-color: var(--surface-2);
  --fc-button-hover-border-color: var(--border);
  --fc-button-active-bg-color: var(--surface-3);
  --fc-button-active-border-color: var(--border);
  --fc-event-border-color: transparent;
  --fc-event-bg-color: transparent;
  font-size: 13px;
}
.fc .fc-toolbar-title { font-size: 17px; font-weight: 600; }
.fc .fc-button { font-weight: 500; text-transform: none; box-shadow: none !important; padding: 5px 12px; }
.fc .fc-button-primary:not(:disabled).fc-button-active { color: var(--text); font-weight: 600; }
.fc .fc-col-header-cell-cushion, .fc .fc-daygrid-day-number { color: var(--text-2); font-weight: 500; }
.fc .fc-timegrid-slot-label-cushion, .fc .fc-timegrid-axis-cushion { color: var(--muted); font-size: 12px; }
/* ~36px per half hour: a 30-minute block fits its title and time, 15 minutes a title. */
.fc .fc-timegrid-slot { height: 2.75em; }
.fc a:hover { text-decoration: none; }

/* Title first, so a block that fits one line shows what it is, not when. */
.fc .fc-v-event .fc-event-main-frame { overflow: hidden; }
.fc .fc-v-event .fc-event-title-container { order: -1; flex: none; }
.fc .fc-v-event .fc-event-title { font-size: 12px; line-height: 1.3; }
.fc .fc-v-event .fc-event-time { flex: 0 1 auto; min-height: 0; line-height: 1.3; }
/* Under ~25 minutes (eventShortHeight in calendar.js): one line of title, no time. */
.fc .fc-timegrid-event-short .fc-event-main { padding-top: 0; padding-bottom: 0; }
.fc .fc-timegrid-event-short .fc-event-time { display: none; }
.fc .fc-timegrid-event-short .fc-event-title-container { flex: 1; min-width: 0; }
.fc .fc-timegrid-event-short .fc-event-title { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Planned: tinted fill in the folder color. Time spent: solid folder color. */
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev { border-radius: 5px; box-shadow: 0 0 0 1px var(--surface); }
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-planned {
  background: color-mix(in srgb, var(--ev) 18%, var(--surface));
  border-width: 1px 1px 1px 3px;
  border-style: solid;
}
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-planned .fc-event-main { color: var(--text); }
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-tracked { background: var(--ev); }
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-tracked .fc-event-main { color: var(--ev-ink); }
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-daytask {
  background: var(--surface);
  border-width: 1px 1px 1px 3px;
  border-style: solid;
}
.fc .ev-daytask .fc-event-main { color: var(--text); font-weight: 500; }
.fc .ev-daytask.is-done .fc-event-title { color: var(--muted); text-decoration: line-through; }
.fc .ev-running { animation: pulse 1.6s ease-in-out infinite; }

/* Current time: a 2px line with a dot across today, and the time on the hour axis. */
.fc .fc-timegrid-now-indicator-line { z-index: 5; border-top-width: 2px; }
.fc .fc-timegrid-now-indicator-line::before {
  content: "";
  position: absolute;
  left: -1px;
  top: -6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--fc-now-indicator-color);
}
.fc .fc-timegrid-now-indicator-arrow {
  left: 2px;
  right: 2px;
  z-index: 5;
  height: 18px;
  margin-top: -9px;
  border: 0;
  border-radius: 4px;
  background: var(--fc-now-indicator-color);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.fc .fc-event-main { padding: 2px 5px; }
.fc .fc-event-time { font-size: 11px; font-weight: 500; opacity: 0.85; }
.fc .fc-event-title { font-weight: 500; }
.fc .fc-event-mirror { opacity: 0.85; }
.fc .fc-list-event-title { color: var(--text); }

/* --- Tooltip & toast -------------------------------------------------------------- */

.tooltip {
  position: fixed;
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--text);
  color: var(--surface);
  font-size: 12px;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.tooltip strong { font-size: 13px; }
.tooltip span { opacity: 0.75; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* --- Reports ---------------------------------------------------------------------- */

.range-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
a.btn, a.btn:hover { text-decoration: none; }
.report {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  grid-template-rows: minmax(300px, 1fr);
  gap: 20px;
  transition: opacity 0.15s;
}
.report.is-loading { opacity: 0.6; }
.report-summary { display: flex; flex-direction: column; gap: 20px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: -4px; padding: 4px 4px 12px; }
.report-summary > * { flex: none; }
.report-summary .kpi-row { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.report-tasks .report-table th { position: sticky; top: 0; z-index: 1; background: var(--surface); }

/* Column chart: one series, thin rounded columns on hairline gridlines. */
.bar-chart { --gutter: 44px; padding-top: 8px; }
.bc-plot { position: relative; height: 200px; margin-left: var(--gutter); }
.bc-gridline { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--grid); }
.bc-tick {
  position: absolute;
  right: calc(100% + 8px);
  top: 0;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bc-columns { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.bc-col { display: flex; flex: 1 1 0; align-items: flex-end; justify-content: center; min-width: 0; height: 100%; border-radius: 4px; }
.bc-col:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.bc-col:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.bc-bar { display: block; width: min(24px, calc(100% - 2px)); background: var(--accent); border-radius: 4px 4px 0 0; }
.bc-col:hover .bc-bar, .bc-col:focus-visible .bc-bar { filter: brightness(1.12); }
.bc-axis { display: flex; height: 16px; margin: 6px 0 0 var(--gutter); }
.bc-axis span { display: flex; flex: 1 1 0; justify-content: center; min-width: 0; color: var(--muted); font-size: 11px; white-space: nowrap; }
.chart-table { margin-top: 12px; }
.chart-table summary { color: var(--text-2); font-size: 13px; cursor: pointer; }
.chart-table table { margin-top: 8px; }

.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th { padding: 6px 8px; border-bottom: 1px solid var(--border); color: var(--text-2); font-size: 12px; font-weight: 500; text-align: left; }
.report-table td { padding: 8px; border-bottom: 1px solid var(--grid); }
.report-table tr:last-child td { border-bottom: 0; }
.report-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.report-table tr.is-link { cursor: pointer; }
.report-table tr.is-link:hover td { background: var(--surface-2); }
.rt-name { display: flex; align-items: center; gap: 8px; }

/* --- Login page ------------------------------------------------------------------- */

.login-page { display: grid; place-items: center; padding: 24px 16px; }
.login { display: flex; flex-direction: column; align-items: center; gap: 18px; width: min(360px, 100%); }
.login-card { display: flex; flex-direction: column; gap: 14px; width: 100%; padding: 24px; }
.login-card .btn { justify-content: center; margin-top: 4px; }
.login-error { color: var(--danger-ink); font-size: 13px; }

/* --- Responsive ------------------------------------------------------------------- */

@media (max-width: 1100px) {
  /* Calendar on top, the side cards in a strip of fixed height below it. */
  .calendar-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(360px, 1fr) 230px; }
  .calendar-side { flex-direction: row; overflow: hidden; }
  .calendar-side > * { flex: 1 1 0; min-width: 0; min-height: 0; }

  .overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(120px, 1fr));
    grid-template-areas: "today active" "today overdue" "today next";
  }
  .folder-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(200px, 3fr) minmax(110px, 1fr);
    grid-template-areas: "stats" "tasks" "appts";
  }
  /* The status chips above the list already give these counts. */
  .folder-stats .status-legend { display: none; }
  .report { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(2, minmax(220px, 1fr)); }
}

@media (max-width: 960px) {
  .folder-stats { grid-template-columns: 1fr; gap: 16px; }
}

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  /* Brand and account on one row, the pages below. */
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    padding: 12px 16px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0; }
  .nav { order: 1; flex-basis: 100%; flex-direction: row; margin-left: -10px; }
  .sidebar-section, .sidebar-links { display: none; }
  .sidebar-footer { margin: 0 0 0 auto; min-width: 0; }
  .sidebar-account { padding: 0; border-top: 0; }
  .view-container { padding: 12px 16px 16px; }
  .view { gap: 12px; min-height: 380px; }
  .topbar { min-height: 0; padding: 8px 16px; flex-wrap: wrap; }
  .wide-only { display: none; }
  .phone-only { display: revert; }

  /* One section at a time: the chosen tab's pane fills what is left of the screen. */
  .pane-tabs {
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: 8px;
    background: var(--surface-2);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .pane-tabs::-webkit-scrollbar { display: none; }
  .pane-tab {
    display: inline-flex;
    flex: 1 0 auto;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 34px;
    padding: 0 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-2);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
  }
  .pane-tab.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
  .pane-tab .count { min-width: 18px; padding: 0 5px; background: var(--surface-3); font-size: 11px; }
  .panes { display: flex; flex-direction: column; }
  .panes .pane { flex: 1 1 0; min-height: 0; }
  .pane:not(.is-active) { display: none !important; }
  /* Reports: the written reports' tab gets the whole screen. */
  .report:not(:has(> .pane.is-active)) { display: none; }
  .written-pane.is-active { flex: 1 1 0; min-height: 0; max-height: none; }
  .calendar-side { display: contents; }
  .pane-stats { overflow-y: auto; overscroll-behavior: contain; }
  .folder-stats .status-legend { display: grid; } /* its own tab: no chips beside it */

  /* Overview: today's numbers in one sideways-scrolling row. */
  .kpi-strip { display: flex; gap: 8px; margin: 0 -16px; padding: 0 16px 2px; overflow-x: auto; scrollbar-width: none; }
  .kpi-strip::-webkit-scrollbar { display: none; }
  .kpi-strip .kpi { flex: none; min-width: 118px; gap: 2px; padding: 8px 12px; box-shadow: none; }
  .kpi-strip .kpi-value { font-size: 17px; }

  .folder-header p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }

  /* 16px text keeps iOS from zooming in on every field it focuses. */
  input, select, textarea,
  label.stacked :is(input, select, textarea),
  .quick-add input[name="title"] { font-size: 16px; }
  input, select { height: 40px; }

  /* Quick add is one row; its other fields open up while you type. */
  .quick-add { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; gap: 6px; padding: 6px; }
  .quick-add input[name="title"] { grid-column: 1 / 3; }
  .quick-add .btn { grid-column: 3; grid-row: 1; height: 40px; }
  .quick-add input[type="date"] { grid-column: 2 / -1; }
  .quick-add:not(:focus-within) :is(select, input[type="date"]) { display: none; }

  /* Status chips scroll sideways in one row; search takes the full width. */
  /* nowrap: a wrapping column is as wide as its widest item, the unscrolled chips. */
  .toolbar { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 10px; }
  .toolbar input[type="search"] { width: 100%; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -18px; padding: 0 18px 2px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }

  /* Range, project and export on one row; the dates only for a custom range. */
  .range-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; }
  .range-bar > span { display: none; }
  .range-bar:not(.is-custom) input[type="date"] { display: none; }
  .range-bar [name="preset"] { order: 1; }
  .range-bar [name="project"] { order: 2; }
  .range-bar .btn { order: 3; width: 40px; height: 40px; padding: 0; justify-content: center; }
  .range-bar .btn-label { display: none; }
  .range-bar [name="from"] { order: 4; }
  .range-bar [name="to"] { order: 5; grid-column: 2 / -1; }

  .report-summary { gap: 12px; }
  .report-summary .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .report-summary .kpi { box-shadow: none; }
  .report-summary .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }

  .field-grid, .grid-2 { grid-template-columns: 1fr; }
  .schedule-item { grid-template-columns: 84px 4px minmax(0, 1fr) auto; }
  .schedule-item .kind-tag { display: none; }
  .appt-row { grid-template-columns: 84px 4px minmax(0, 1fr); }
  .appt-row .sch-duration { display: none; }
  .report-table .hide-sm { display: none; }

  /* Calendar: the grid gets the width. The toolbar is two rows (see headerToolbar() in
     calendar.js): arrows around the title, then Today and the views. */
  .calendar-main { padding: 8px; }
  .fc .fc-toolbar.fc-header-toolbar { flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 10px; }
  .fc .fc-toolbar.fc-header-toolbar .fc-toolbar-chunk { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .fc .fc-toolbar.fc-header-toolbar .fc-toolbar-chunk:empty { display: none; }
  .fc .fc-toolbar.fc-header-toolbar .fc-toolbar-chunk > * { margin-left: 0; }
  .fc .fc-toolbar-title { font-size: 16px; text-align: center; }
  .fc .fc-button { padding: 5px 10px; }
}

/* --- AIDA ------------------------------------------------------------------------- */

.nav-badge {
  margin-left: auto;
  min-width: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav a { display: flex; align-items: center; }
.folder-space { padding: 8px 10px 2px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }

.view-aida { height: auto; }
.capture { display: flex; flex-direction: column; gap: 10px; }
.capture textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  outline: none;
}
.capture-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.capture-hint { margin-top: -2px; }
.space-toggle { display: inline-flex; padding: 2px; border-radius: var(--radius-sm); background: var(--surface-2); }
.space-toggle label { position: relative; }
.space-toggle input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.space-toggle span { display: block; padding: 4px 12px; border-radius: 4px; color: var(--text-2); font-size: 13px; font-weight: 500; }
.space-toggle input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.space-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.notice { display: flex; gap: 10px; align-items: flex-start; border-color: color-mix(in srgb, var(--warning) 50%, var(--border)); }
.notice .icon { color: var(--warning); margin-top: 2px; }
.notice code { font-family: var(--font-mono); font-size: 12px; }

.aida-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.aida-grid .card-header { align-items: center; }
.aida-grid .card-header input[type="date"] { width: auto; }
.proposal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.proposal-list .empty-state { padding: 20px 8px; }
.proposal, .agenda-row, .inbox-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 2px;
  border-top: 1px solid var(--border);
}
.proposal:first-child, .agenda-row:first-child, .inbox-item:first-child { border-top: none; }
.proposal-kind {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}
.inbox-item .proposal-kind { background: var(--surface-2); color: var(--text-2); }
.proposal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.proposal-title { font-weight: 600; overflow-wrap: anywhere; }
.proposal-reason { color: var(--text-2); font-size: 13px; }
.proposal-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proposal-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.agenda-time { flex: none; min-width: 96px; display: flex; flex-direction: column; font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; padding-top: 1px; }
.agenda-summary:empty { display: none; }
.agenda-summary { margin-bottom: 8px; }
.agenda-foot { display: flex; justify-content: flex-end; }
.agenda-foot .btn[hidden] { display: none; }
.inbox-status { font-weight: 500; }
.inbox-item.status-failed .inbox-status { color: var(--danger-ink); }
.inbox-item.status-new .inbox-status { color: var(--accent); }
.inbox-item.status-archived { opacity: 0.6; }

@media (max-width: 1180px) {
  .aida-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .proposal, .inbox-item { flex-wrap: wrap; }
  .proposal-actions { width: 100%; justify-content: flex-end; }
}

/* AIDA: hours of work and private life */
.setup { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.setup-text { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 4px; }
.setup-text h2 { display: flex; align-items: center; gap: 8px; }
.setup-text h2 .icon { color: var(--accent); }
.setup-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.proposal-warning { display: inline-flex; align-items: center; gap: 5px; color: var(--danger-ink); font-size: 12px; font-weight: 600; }
.proposal-warning .icon { width: 13px; height: 13px; }

.schedule-dialog { width: min(560px, calc(100vw - 32px)); }
.hours-space { border: 0; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.hours-space legend { display: flex; align-items: center; gap: 6px; padding: 0; margin-bottom: 2px; font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.hours-space [data-rows] { display: flex; flex-direction: column; gap: 8px; }
.hours-space > .btn { align-self: flex-start; }
.hours-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hours-row input[type="time"] { width: auto; }
.day-toggles { display: inline-flex; gap: 3px; }
.day-toggles label { position: relative; }
.day-toggles input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.day-toggles span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}
.day-toggles input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.day-toggles input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.flex-field select { width: auto; }

.language-select {
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
}

.ev-allday { border: 1px dashed var(--border) !important; background: var(--surface-2) !important; color: var(--text-2) !important; font-weight: 500; }
.ev-allday.is-busy { border-style: solid !important; border-color: var(--danger) !important; background: color-mix(in srgb, var(--danger) 12%, var(--surface)) !important; color: var(--text) !important; }
.away-note { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.away-note span { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--text); font-size: 12px; font-weight: 500; }
.calendar-note { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); font-size: 13px; }
.calendar-note .icon { flex: none; margin-top: 2px; color: var(--accent); }

/* AIDA: connections */
.connections-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; }
.connections-grid .subhead { margin-bottom: 8px; }
.connections .button-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.space-chip { padding: 0 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.space-chip.space-work { background: var(--accent-soft); color: var(--link); }
.address-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; min-width: 0; }
.address-label { width: 64px; flex: none; color: var(--text-2); font-size: 12px; font-weight: 600; }
.address { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 4px 8px; border-radius: var(--radius-sm); background: var(--surface-2); font-family: var(--font-mono); font-size: 12px; user-select: all; }
.link-btn { border: 0; background: none; padding: 0; color: var(--link); font: inherit; cursor: pointer; text-decoration: underline; }

/* --- Settings ------------------------------------------------------------------------ */

.view-settings { height: auto; }
.settings-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: 0; display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500; }
.settings-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.settings-content { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.settings-section { scroll-margin-top: 12px; }
.setting-row { display: flex; align-items: center; gap: 16px; padding: 8px 0; border-top: 1px solid var(--border); min-width: 0; flex-wrap: wrap; }
.settings-section [data-body] > .setting-row:first-child { border-top: none; }
.setting-label { width: 160px; flex: none; color: var(--text-2); font-size: 13px; font-weight: 600; }
.setting-row select { width: auto; min-width: 180px; }
.password-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; width: 100%; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { width: auto; min-width: 220px; }
.member-list { list-style: none; margin: 0 0 8px; padding: 0; }
.member-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--border); }
.member-row:first-child { border-top: none; }
.member-row select { width: auto; }
.usage { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 200px; max-width: 420px; }
.usage-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.usage-bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.usage-bar.is-high span { background: var(--danger); }
.license-form { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.license-form label { flex: 1; min-width: 220px; max-width: 420px; }
.license-form input { font-family: var(--font-mono); letter-spacing: 0.04em; }
.member-actions { display: inline-flex; align-items: center; gap: 6px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form .btn { justify-content: center; margin-top: 4px; }

@media (max-width: 900px) {
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; flex-direction: row; flex-wrap: wrap; }
  .grid-3 { grid-template-columns: 1fr; }
  .setting-label { width: 100%; }
}
