/* ─────────────────────────────────────────────────────────────────────────────
   TEFUI Ledger — Design tokens
───────────────────────────────────────────────────────────────────────────── */
:root {
  /* Brand */
  --gold: #b69370;
  --gold-dark: #9c7a5a;
  --plum: #9b4068;
  --plum-dark: #7e3154;
  --charcoal: #2b2b2b;
  --light-grey: #d3d3d3;
  --white: #ffffff;

  /* Semantic */
  --ink: #252323;
  --muted: #706c68;
  --surface: #f5f3f0;
  --surface-strong: #fbfaf8;
  --line: #e5ded8;
  --soft-plum: #f8eef3;
  --soft-gold: #fff8ed;
  --text: var(--ink);
  --page-gradient-start: #fffaf4;
  --page-gradient-end: #f0ede8;
  --login-gradient-start: #faf7f3;
  --login-gradient-mid: #ede5db;
  --login-gradient-end: #e4d9d0;
  --panel-bg: rgba(255,255,255,.94);
  --panel-solid: #ffffff;
  --bg: var(--panel-solid);
  --topbar-bg: rgba(255,255,255,.82);
  --topbar-border: rgba(229,222,216,.9);
  --control-bg: #ffffff;
  --control-readonly-bg: #f0ece6;
  --control-readonly-border: #d8d0c8;
  --control-placeholder: #8a8178;
  --row-hover: #fffdf8;
  --bar-track: #ede7e0;
  --ghost-hover: #ede9e4;
  --focus-ring: rgba(155,64,104,.12);
  --scrollbar-thumb: #d1c8c0;
  --scrollbar-thumb-hover: #b9b0a6;

  /* Status colours */
  --success-bg: #eaf6f0; --success-fg: #1e7a4a;
  --info-bg: #e8f4fd;    --info-fg: #1a6fa8;
  --warn-bg: #fff0e9;    --warn-fg: #c0430d;
  --neutral-bg: #f0f0f0; --neutral-fg: #707070;

  /* Spacing & shape */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-xs: 0 1px 4px rgba(43,43,43,.06);
  --shadow-sm: 0 4px 12px rgba(43,43,43,.07);
  --shadow-md: 0 10px 28px rgba(43,43,43,.09);
  --shadow-lg: 0 20px 48px rgba(43,43,43,.12);

  /* Motion */
  --ease: cubic-bezier(.4,0,.2,1);
  --dur-fast: 100ms;
  --dur: 160ms;

  /* Typography */
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv02","cv03","cv04","cv11";
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f7f1e8;
  --muted: #cfc4ba;
  --surface: #141015;
  --surface-strong: #201a20;
  --line: #433840;
  --soft-plum: #321b28;
  --soft-gold: #2f2519;
  --text: var(--ink);
  --page-gradient-start: #241923;
  --page-gradient-end: #0f0d10;
  --login-gradient-start: #211720;
  --login-gradient-mid: #171217;
  --login-gradient-end: #100d10;
  --panel-bg: rgba(31,26,31,.96);
  --panel-solid: #201a20;
  --bg: var(--panel-solid);
  --topbar-bg: rgba(29,23,29,.9);
  --topbar-border: rgba(74,60,70,.95);
  --control-bg: #181318;
  --control-readonly-bg: #211b21;
  --control-readonly-border: #4a3c46;
  --control-placeholder: #aaa096;
  --row-hover: #2a222a;
  --bar-track: #342b32;
  --ghost-hover: #2b232b;
  --focus-ring: rgba(182,147,112,.24);
  --scrollbar-thumb: #5c4b56;
  --scrollbar-thumb-hover: #766274;
  --success-bg: #143424; --success-fg: #9ee7ba;
  --info-bg: #112c3f;    --info-fg: #9ed5f6;
  --warn-bg: #3b2115;    --warn-fg: #ffb38f;
  --neutral-bg: #28272a; --neutral-fg: #d7d0ca;
  --shadow-xs: 0 1px 4px rgba(0,0,0,.3);
  --shadow-sm: 0 6px 18px rgba(0,0,0,.28);
  --shadow-md: 0 12px 32px rgba(0,0,0,.34);
  --shadow-lg: 0 24px 58px rgba(0,0,0,.42);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Reset & globals
───────────────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 20% 0, var(--page-gradient-start) 0, var(--surface) 40%, var(--page-gradient-end) 100%); color: var(--ink); }
button, input, select, textarea { font: inherit; }

/* Selection */
::selection { background: rgba(155,64,104,.15); color: var(--plum-dark); }

/* Scrollbar (webkit) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: var(--radius-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

html { scroll-behavior: smooth; }

/* ─────────────────────────────────────────────────────────────────────────────
   Typography
───────────────────────────────────────────────────────────────────────────── */
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 30px; font-weight: 800; letter-spacing: -.5px; margin-bottom: 0; }
.topbar h1 { font-size: 22px; letter-spacing: -.4px; line-height: 1.1; }
h2 { font-size: 20px; font-weight: 700; margin-bottom: 16px; letter-spacing: -.2px; }
h3 { font-size: 14px; font-weight: 700; margin: 16px 0 10px; }
small, .muted { color: var(--muted); font-size: 12px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Login
───────────────────────────────────────────────────────────────────────────── */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, var(--login-gradient-start) 0%, var(--login-gradient-mid) 50%, var(--login-gradient-end) 100%);
}
.login-panel {
  width: min(440px, 100%);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 14px;
}
.login-panel .brand-mark {
  color: var(--plum);
  font-size: 32px;
  font-weight: 900;
  letter-spacing: -1px;
  margin-bottom: 4px;
}
.auth-warning { display: grid; gap: 6px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Shell & sidebar
───────────────────────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 268px minmax(0,1fr); min-height: 100vh; }
.sidebar {
  background: linear-gradient(175deg, #1e1a20 0%, #2b1f26 55%, #2e2028 100%);
  color: var(--white);
  padding: 24px 16px 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 2px 0 0 0 rgba(0,0,0,.08), 12px 0 32px rgba(0,0,0,.12);
  position: relative;
  z-index: 10;
}
.sidebar::after {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 1px; height: 100%;
  background: linear-gradient(180deg, rgba(182,147,112,.3) 0%, rgba(155,64,104,.15) 100%);
}
.brand-mark { color: var(--gold); font-size: 26px; font-weight: 900; letter-spacing: -1px; line-height: 1; }
.brand-logo { display: block; max-width: 120px; max-height: 50px; object-fit: contain; }
.app-name { font-size: 12px; color: rgba(255,255,255,.45); font-weight: 600; text-transform: uppercase; letter-spacing: 1.2px; margin-bottom: 2px; }
.field-label { font-size: 11px; color: rgba(255,255,255,.4); font-weight: 600; letter-spacing: .5px; text-transform: uppercase; }
.sidebar .select, .sidebar select {
  border-color: rgba(255,255,255,.14);
  background: #2d2328;
  color: var(--white);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.sidebar select option {
  background: #2d2328;
  color: var(--white);
}
.sidebar select:focus {
  border-color: rgba(182,147,112,.5);
  box-shadow: none;
  background: #2d2328;
}
nav { display: grid; gap: 2px; margin-top: 4px; }
.nav-item {
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: transparent;
  color: rgba(255,255,255,.6);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--dur-fast) var(--ease);
  position: relative;
}
.nav-item:hover {
  background: rgba(182,147,112,.12);
  color: rgba(255,255,255,.9);
  border-color: rgba(182,147,112,.18);
}
.nav-item.active {
  background: linear-gradient(135deg, rgba(182,147,112,.22), rgba(155,64,104,.13));
  border-color: rgba(182,147,112,.32);
  color: var(--white);
  font-weight: 600;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -1px; top: 20%; bottom: 20%;
  width: 3px;
  background: linear-gradient(180deg, var(--gold), var(--plum));
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Main content area
───────────────────────────────────────────────────────────────────────────── */
.main { padding: 28px 32px; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
  padding: 16px 22px;
  background: var(--topbar-bg);
  border: 1px solid var(--topbar-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(16px);
}
.eyebrow { margin: 0 0 2px; color: var(--plum); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 5px 10px 5px 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--panel-solid);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.theme-toggle:hover {
  background: var(--surface-strong);
  border-color: var(--gold);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
.theme-toggle:active { transform: translateY(1px); }
.theme-toggle-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--plum), var(--gold));
  color: var(--white);
  font-size: 13px;
  line-height: 1;
}
.topbar-identity { display: flex; align-items: center; gap: 12px; }
.entity-avatar-tile {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--plum), var(--gold));
  color: var(--white);
  font-size: 15px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  letter-spacing: -0.5px;
  -webkit-user-select: none;
  user-select: none;
}
.user-pill {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 5px 12px 5px 5px;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--plum), var(--gold));
  color: var(--white);
  font-size: 10px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.topbar-search-btn kbd {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  font-family: inherit;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; cursor: help; }
.status-dot.warn { background: #e8923a; box-shadow: 0 0 0 3px rgba(232,146,58,.2), 0 0 8px rgba(232,146,58,.3); animation: pulse-warn 2s ease infinite; }
@keyframes pulse-warn { 0%,100% { box-shadow: 0 0 0 3px rgba(232,146,58,.2); } 50% { box-shadow: 0 0 0 5px rgba(232,146,58,.1); } }
.warning-notice {
  background: var(--soft-gold);
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--warn-fg);
  font-size: 13px;
  line-height: 1.5;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Form elements
───────────────────────────────────────────────────────────────────────────── */
.select, select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  background: var(--control-bg);
  color: var(--ink);
  min-height: 40px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  outline: none;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--plum);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
input[readonly], textarea[readonly] {
  background: var(--control-readonly-bg);
  color: var(--muted);
  border-color: var(--control-readonly-border);
  cursor: not-allowed;
  box-shadow: none;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--control-placeholder); }
label { display: grid; gap: 5px; color: var(--muted); font-size: 12.5px; font-weight: 500; }

/* ─────────────────────────────────────────────────────────────────────────────
   Buttons
───────────────────────────────────────────────────────────────────────────── */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  color: var(--white);
  background: var(--plum);
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  min-height: 40px;
  transition: background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  box-shadow: 0 1px 3px rgba(155,64,104,.2), 0 4px 12px rgba(155,64,104,.15);
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.button:hover:not(:disabled) { background: var(--plum-dark); box-shadow: 0 2px 6px rgba(155,64,104,.25), 0 6px 18px rgba(155,64,104,.18); }
.button:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 3px rgba(155,64,104,.2); }
.button:focus-visible { outline: 2px solid var(--plum); outline-offset: 3px; }
.button:disabled { opacity: .45; cursor: not-allowed; }

.button.ghost {
  background: var(--panel-solid);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
}
.button.ghost:hover:not(:disabled) { background: var(--surface-strong); border-color: var(--gold); box-shadow: var(--shadow-sm); }
.button.ghost:active:not(:disabled) { background: var(--ghost-hover); transform: translateY(1px); }

.button.danger {
  background: #7d2f34;
  box-shadow: 0 1px 3px rgba(125,47,52,.2), 0 4px 12px rgba(125,47,52,.12);
  margin-top: 0;
}
.button.danger:hover:not(:disabled) { background: #6a2329; }

.button.small { min-height: 32px; padding: 5px 11px; font-size: 12.5px; }
.button.tiny  { min-height: 26px; padding: 4px 8px;  font-size: 12px; }

.link-button { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 3px 0; font-size: 13px; transition: color var(--dur-fast) var(--ease); }
.link-button:hover { color: var(--plum); }

/* ─────────────────────────────────────────────────────────────────────────────
   Layout helpers
───────────────────────────────────────────────────────────────────────────── */
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.invoice-row-actions { max-width: 360px; align-items: center; }
.invoice-status-control {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) auto;
  gap: 5px;
  width: 100%;
}
.invoice-status-control select {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 12.5px;
}
.two-column { display: grid; grid-template-columns: minmax(0,1fr) minmax(320px,.8fr); gap: 18px; align-items: start; }
.wide-left { grid-template-columns: minmax(0,1.1fr) minmax(420px,.9fr); }
.invoice-workspace { display: grid; grid-template-columns: minmax(0,1fr); gap: 18px; align-items: start; }
.compact-heading { margin: 0; }
.compact-heading h3 { margin: 0; }

/* ─────────────────────────────────────────────────────────────────────────────
   Panels & cards
───────────────────────────────────────────────────────────────────────────── */
.metric, .panel, .folder, .report-card {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.panel { padding: 22px; margin-bottom: 18px; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
.panel-heading h2 { margin: 0; }

/* Metrics dashboard */
.grid { display: grid; gap: 16px; }
.metrics { grid-template-columns: repeat(4, minmax(160px,1fr)); margin-bottom: 20px; }
.metric {
  padding: 18px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-top: 3px solid rgba(182,147,112,.5);
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.metric span { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.metric strong { display: block; font-size: 28px; font-weight: 900; color: var(--ink); margin: 6px 0 4px; letter-spacing: -1px; line-height: 1; }
.metric-clickable { cursor: pointer; }
.metric-clickable:hover, .metric-clickable:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-top-color: var(--gold);
  outline: none;
}
.metric-attention-overdue { border-top-color: #e8923a !important; border-color: #f5c4b0; }
.metric-attention-overdue strong { color: var(--warn-fg); }
.metric-attention-overdue small { color: #b0441a; }
.metric-attention-uncategorised { border-top-color: #d4a04a !important; border-color: #e8d0a8; }
.metric-attention-uncategorised strong { color: #7a5420; }
.metric-attention-uncategorised small { color: #7a5420; }

/* Insight panels */
.insight-grid { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 18px; align-items: stretch; }
.insight-panel { min-height: 240px; }
.bar-list { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(150px,1fr) minmax(140px,1.2fr) auto; gap: 12px; align-items: center; }
.bar-row span { color: var(--muted); font-size: 12px; }
.trend-column span { color: var(--muted); }
.bar-track { height: 8px; border-radius: var(--radius-pill); background: var(--bar-track); overflow: hidden; }
.bar-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--plum), var(--gold)); }
.trend-bars {
  display: grid;
  grid-template-columns: repeat(6, minmax(70px,1fr));
  gap: 12px;
  align-items: stretch;
  min-height: 185px;
}
/* Each column is a flex column so the bar-well stretches and the labels sit below */
.trend-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  min-width: 0;
}
/* Bar well grows to fill the column; bar sits at the bottom of the well */
.trend-bar-well {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
}
.trend-bar { width: 100%; max-width: 40px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, var(--gold) 0%, var(--plum) 100%); }
.trend-column strong { font-size: 11px; font-weight: 700; line-height: 1.2; }
/* Fixed min-height so 1-line and 2-line labels don't shift the bar wells */
.trend-column > span { font-size: 11px; min-height: 30px; display: flex; align-items: flex-start; justify-content: center; }

.empty-state {
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 13px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Forms
───────────────────────────────────────────────────────────────────────────── */
.form { display: grid; gap: 14px; }
.invoice-form { gap: 18px; max-width: none; }
.form-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--surface-strong);
  display: grid;
  gap: 14px;
}
.form-section h3 { margin: 0; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.invoice-details-grid { grid-template-columns: repeat(2, minmax(220px,1fr)); }
.invoice-terms-grid { grid-template-columns: repeat(4, minmax(150px,1fr)); }
.import-mapping-grid { grid-template-columns: repeat(4, minmax(150px,1fr)); }
.form-grid.compact { grid-template-columns: repeat(4, minmax(120px,1fr)); margin-top: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Tables
───────────────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; min-width: 620px; }
th, td { border-bottom: 1px solid var(--line); padding: 11px 12px; text-align: left; vertical-align: top; font-size: 13.5px; }
th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  background: var(--surface-strong);
  border-bottom: 2px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--dur-fast) var(--ease); }
tbody tr:hover td { background: var(--row-hover); }
.table-actions { white-space: nowrap; }
.table-actions .button + .button { margin-left: 5px; }
.inline-actions { display: grid; grid-template-columns: minmax(170px,1fr) auto; gap: 6px; align-items: center; min-width: 240px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Status pills
───────────────────────────────────────────────────────────────────────────── */
.status {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  background: var(--soft-plum);
  color: var(--plum);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .2px;
  white-space: nowrap;
}
.status-draft    { background: var(--info-bg); color: var(--info-fg); }
.status-sent     { background: var(--info-bg); color: var(--info-fg); }
.status-paid     { background: var(--success-bg); color: var(--success-fg); }
.status-overdue  { background: var(--warn-bg); color: var(--warn-fg); }
.status-void     { background: var(--neutral-bg); color: var(--neutral-fg); text-decoration: line-through; }
.status-active   { background: var(--success-bg); color: var(--success-fg); }
.status-inactive { background: var(--neutral-bg); color: var(--neutral-fg); }
.status-received { background: var(--success-bg); color: var(--success-fg); }
.status-pending_payment { background: var(--soft-gold); color: var(--warn-fg); }
.status-director,
.status-consultant     { background: var(--info-bg); color: var(--info-fg); }
.status-admin          { background: var(--soft-gold); color: var(--warn-fg); }
.status-super_admin    { background: var(--soft-plum); color: var(--plum); }
.status-read_only      { background: var(--neutral-bg); color: var(--neutral-fg); }

/* ─────────────────────────────────────────────────────────────────────────────
   Lists
───────────────────────────────────────────────────────────────────────────── */
.list { display: grid; gap: 8px; }
.list-row {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: left;
  display: grid;
  gap: 4px;
  color: var(--ink);
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.list-row[data-select-user], .list-row.user-row { cursor: pointer; }
.list-row:hover, .list-row.selected { background: var(--soft-gold); border-color: rgba(182,147,112,.35); }
.list-row span { color: var(--muted); font-size: 12.5px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Notices & alerts
───────────────────────────────────────────────────────────────────────────── */
.notice, .path-check {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--success-bg);
  border: 1px solid var(--success-fg);
  color: var(--success-fg);
  display: grid;
  gap: 4px;
  font-size: 13px;
  line-height: 1.5;
}
.path-check span { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.path-check.danger { background: var(--warn-bg); border-color: var(--warn-fg); color: var(--warn-fg); }
.warning { border-color: var(--gold); background: var(--soft-gold); color: var(--warn-fg); }

/* Danger zone (security view) */
.danger-zone { margin-top: 14px; padding-top: 14px; border-top: 1px solid #dfb5b5; display: grid; gap: 10px; }
.danger-zone-label { font-size: 11px; color: #7d2f34; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Dashboard
───────────────────────────────────────────────────────────────────────────── */
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.dashboard-section-label {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 20px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dashboard-section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.flow { display: flex; align-items: center; gap: 16px; color: var(--ink); font-weight: 800; font-size: 17px; flex-wrap: wrap; }
.flow span { color: var(--gold); }

/* ─────────────────────────────────────────────────────────────────────────────
   Invoice line items
───────────────────────────────────────────────────────────────────────────── */
.line-items { display: grid; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.line-items-header, .line-item {
  display: grid;
  grid-template-columns: minmax(130px,.8fr) minmax(200px,1.3fr) 72px 108px 110px 86px 34px;
  gap: 10px;
  align-items: start;
  min-width: 840px;
}
.line-items-header { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; padding: 0 2px; }
.line-item input, .line-item select { min-width: 0; }
.line-total-display { font-weight: 700; text-align: right; padding-top: 10px; color: var(--ink); font-size: 14px; white-space: nowrap; }
.remove-line-btn { margin-top: 0 !important; padding: 10px 8px !important; align-self: start; }
.invoice-running-total {
  display: flex;
  justify-content: flex-end;
  gap: 28px;
  padding: 14px 18px;
  background: var(--soft-gold);
  border: 1px solid #dbc09f;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  flex-wrap: wrap;
}
.rt-item { display: grid; gap: 2px; text-align: right; }
.rt-item span { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.rt-item strong { font-size: 17px; color: var(--ink); font-weight: 800; }
.rt-grand strong { font-size: 22px; color: var(--plum); }
.invoice-filter { display: grid; grid-template-columns: minmax(180px,1fr) 160px; gap: 10px; margin-bottom: 12px; }
.work-notes { min-height: 200px; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }

/* ─────────────────────────────────────────────────────────────────────────────
   Mini metrics
───────────────────────────────────────────────────────────────────────────── */
.mini-metrics { display: grid; grid-template-columns: repeat(4, minmax(70px,1fr)); gap: 10px; margin-bottom: 14px; }
.mini-metric {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  padding: 10px 12px;
  display: grid;
  gap: 3px;
}
.mini-metric span { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.mini-metric strong { color: var(--ink); font-size: 20px; font-weight: 800; letter-spacing: -.5px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Settings
───────────────────────────────────────────────────────────────────────────── */
.settings-summary { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin: 16px 0; }
.settings-summary div, .recommendation {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-strong);
  display: grid;
  gap: 5px;
}
.settings-summary div strong { font-size: 13px; color: var(--ink); }
.settings-summary span, .recommendation span { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.settings-layout { display: grid; grid-template-columns: minmax(0,1.35fr) minmax(320px,.65fr); gap: 18px; align-items: start; }
.settings-form { gap: 18px; }
.settings-section {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-bg);
}
.settings-section h3 { margin: 0; color: var(--ink); }
.settings-side { position: sticky; top: 18px; }
.connection-tools { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; }
.brand-settings { display: grid; grid-template-columns: 150px minmax(0,1fr); gap: 16px; align-items: start; }
.logo-preview {
  min-height: 110px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 26px;
  font-weight: 900;
  background: var(--surface-strong);
  padding: 16px;
}
.recommendations { display: grid; gap: 10px; margin-bottom: 20px; }
.recommendation { grid-template-columns: 32px minmax(0,1fr); align-items: start; }
.recommendation strong {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: var(--radius-pill);
  background: var(--plum);
  color: var(--white);
  font-size: 12px;
}
.advanced-box { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 12px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Documents & reports
───────────────────────────────────────────────────────────────────────────── */
.folder-grid, .report-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.folder, .report-card {
  padding: 16px;
  display: grid;
  gap: 6px;
  text-align: left;
  color: var(--ink);
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.folder strong, .report-card > :first-child { font-size: 13.5px; font-weight: 700; }
.folder span, .report-card span { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.report-card { border: 1px solid var(--line); cursor: pointer; min-height: 86px; }
.report-card:hover, .report-card:focus-visible {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--gold);
  outline: none;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Uploads & preview
───────────────────────────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface-strong);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  text-align: center;
}
.upload-zone:hover { border-color: var(--gold); background: var(--soft-gold); }
.preview-box {
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  color: var(--ink);
  padding: 12px 14px;
  font-size: 12.5px;
  min-height: 54px;
  overflow-x: auto;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  line-height: 1.6;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Bank CSV & transaction tools
───────────────────────────────────────────────────────────────────────────── */
.transaction-tools { display: grid; grid-template-columns: minmax(220px,1.4fr) minmax(170px,1fr) minmax(190px,1fr) auto; gap: 12px; align-items: end; margin-bottom: 14px; }
.import-section { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.import-section summary { cursor: pointer; font-weight: 700; color: var(--plum); margin-bottom: 12px; font-size: 13.5px; user-select: none; }
.import-section summary:hover { color: var(--plum-dark); }

/* Client projects */
.client-projects { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); display: grid; gap: 14px; }
.project-form-grid { grid-template-columns: minmax(180px,1.4fr) minmax(100px,.7fr) minmax(120px,.8fr) minmax(150px,1fr) minmax(180px,1.2fr); }

/* Read-only session warning banner */
.read-only-banner {
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-fg);
  padding: 8px 32px;
  font-size: 13px;
  color: var(--warn-fg);
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Setup banner */
.setup-banner {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 6px 12px;
  align-items: center;
  border: 1px solid var(--gold);
  background: var(--soft-gold);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.setup-banner strong { color: var(--warn-fg); }
.setup-banner span { color: var(--muted); font-size: 13px; }
.setup-banner .button { grid-row: span 2; }
.setup-banner.success { border-color: var(--success-fg); background: var(--success-bg); }

/* ─────────────────────────────────────────────────────────────────────────────
   Utility classes
───────────────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.overdue-row td { background: var(--warn-bg) !important; }
.tfoot-summary td { text-align: right; font-weight: 700; font-size: 13.5px; padding: 12px; border-top: 2px solid var(--line); }
.bas-controls { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.checkbox-label { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: auto; min-height: auto; height: 16px; width: 16px; accent-color: var(--plum); cursor: pointer; }

/* Nav enhancements */
.nav-divider { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px; color: rgba(255,255,255,.25); padding: 8px 10px 4px; margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.nav-divider-rule { flex: 1; height: 1px; background: rgba(255,255,255,.06); }
.nav-icon { font-style: normal; flex-shrink: 0; line-height: 1; }
.nav-badge { display: inline-flex; align-items: center; justify-content: center; background: var(--plum); color: var(--white); border-radius: var(--radius-pill); font-size: 10px; font-weight: 800; padding: 1px 6px; margin-left: auto; line-height: 1.4; }
.nav-item { display: flex; align-items: center; gap: 6px; }

/* Loading spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.35); border-top-color: var(--white); border-radius: 50%; animation: spin .6s linear infinite; flex-shrink: 0; }
.spinner-plum { border-color: rgba(155,64,104,.25); border-top-color: var(--plum); }
.button.is-loading { pointer-events: none; opacity: .8; }
.button.is-loading .btn-label { opacity: 0; }

/* Details element styling */
details.settings-details { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
details.settings-details > summary { cursor: pointer; font-weight: 700; font-size: 14px; padding: 14px 18px; background: var(--surface-strong); user-select: none; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details.settings-details > summary::after { content: "›"; font-size: 18px; color: var(--muted); transition: transform var(--dur) var(--ease); }
details.settings-details[open] > summary::after { transform: rotate(90deg); }
details.settings-details > summary::-webkit-details-marker { display: none; }
details.settings-details > .settings-section { border-top: 1px solid var(--line); border-radius: 0; }

/* Danger zone section in settings */
.danger-zone-section { margin-top: 8px; }
.danger-zone-section > summary { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-fg); }
.danger-zone-section > summary::after { color: var(--warn-fg); }

/* Stripe admin box */
.stripe-status-box { background: var(--soft-gold); border: 1px solid var(--gold); border-radius: var(--radius-sm); padding: 14px; font-size: 13px; line-height: 1.6; }
.stripe-status-box strong { color: var(--ink); }
details.stripe-refs { margin-top: 8px; }
details.stripe-refs > summary { cursor: pointer; font-size: 12px; color: var(--muted); user-select: none; list-style: none; }
details.stripe-refs > summary::-webkit-details-marker { display: none; }
details.stripe-refs .refs-grid { display: grid; gap: 4px; padding-top: 8px; }
details.stripe-refs .refs-grid small { color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; word-break: break-all; }

/* Upload zone with drag-and-drop */
.upload-zone { position: relative; cursor: pointer; }
.upload-zone.drag-over { border-color: var(--plum); background: var(--soft-plum); }
.upload-zone-icon { font-size: 28px; margin-bottom: 6px; opacity: .6; }
.upload-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.upload-zone-label { font-weight: 700; font-size: 14px; color: var(--ink); }
.upload-zone-hint { color: var(--muted); font-size: 12.5px; }

/* Report date range filter */
.report-filter { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; padding: 14px 16px; background: var(--surface-strong); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.report-filter label { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--ink); font-size: 13px; font-weight: 600; white-space: nowrap; }
.report-filter input[type="date"] { width: auto; min-height: 36px; padding: 6px 10px; }
.report-download-icon::after { content: " ↓"; font-size: 11px; opacity: .7; }

/* Payments search */
.payments-filter { margin-bottom: 12px; }

/* Client top metrics */
.client-top-metrics { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }

/* Entity list selected state */
.entity-list-btn { transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
.entity-list-btn.is-selected { background: var(--soft-gold) !important; border-color: rgba(182,147,112,.4) !important; }

/* Doc attachment badge on invoice rows */
.doc-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 2px 7px; margin-left: 4px; vertical-align: middle; }

/* Unsaved settings indicator */
.settings-dirty { color: var(--warn-fg); font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Invoice PDF — print view
───────────────────────────────────────────────────────────────────────────── */
.invoice-print { background: #f4f0ea; color: #302738; }
.print-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 58px 64px;
  background: var(--white);
  position: relative;
  box-shadow: var(--shadow-lg);
}
.print-page::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--plum), var(--gold));
  border-radius: var(--radius) var(--radius) 0 0;
}
.invoice-hero {
  display: flex;
  justify-content: space-between;
  gap: 30px;
  align-items: flex-start;
  margin-bottom: 30px;
  padding-bottom: 22px;
  border-bottom: 1px solid #eadde4;
}
.invoice-hero .brand-mark { color: var(--plum); font-size: 36px; font-weight: 900; letter-spacing: -1px; line-height: 1; }
.invoice-hero p, .invoice-title span { margin: 8px 0 0; color: #5a4e61; }
.invoice-title { text-align: right; }
.invoice-title h1 { color: var(--plum); text-transform: uppercase; font-size: 32px; margin: 0 0 6px; letter-spacing: 1px; }
.invoice-title span { display: inline-block; padding: 6px 14px; border-radius: var(--radius-pill); background: var(--soft-plum); color: var(--plum); font-weight: 800; font-size: 13px; }
.invoice-meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 32px; }
.invoice-meta-grid div { padding: 16px 18px; min-height: 96px; border: 1px solid #eadde4; border-radius: var(--radius-sm); background: #fffdfc; }
.invoice-meta-grid strong { display: block; color: var(--plum); margin-bottom: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.invoice-meta-grid span { display: block; color: #4a4055; line-height: 1.45; font-size: 13.5px; }
.print-page h2 { color: var(--plum); font-size: 14px; margin: 28px 0 10px; text-transform: uppercase; letter-spacing: .8px; font-weight: 800; }
.invoice-lines { border-collapse: separate; border-spacing: 0; overflow: hidden; border: 1px solid #eadde4; border-radius: var(--radius-sm); width: 100%; }
.invoice-lines th { background: #2e2030; color: var(--white); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; padding: 12px 14px; }
.invoice-lines td { border: 0; border-bottom: 1px solid #eadde4; background: #fffdfc; padding: 13px 14px; font-size: 13.5px; }
.invoice-lines tbody tr:last-child td { border-bottom: 0; }
.invoice-lines td:nth-child(n+2), .invoice-lines th:nth-child(n+2) { text-align: right; }
.totals {
  margin: 18px 0 28px auto;
  width: 320px;
  text-align: right;
  font-size: 14px;
  border: 1px solid #eadde4;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  background: #fbf8f4;
}
.totals p { display: flex; justify-content: space-between; gap: 18px; margin: 0; padding: 8px 0; }
.totals .total-payable { border-top: 2px solid var(--plum); color: var(--plum); font-weight: 800; font-size: 17px; padding-top: 10px; }
.print-payment-options {
  margin: 24px 0;
  padding: 20px;
  border-radius: var(--radius-sm);
  background: #fbf5f8;
  border: 1px solid #eadde4;
}
.payment-options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.payment-option { border: 1px solid #eadde4; border-radius: var(--radius-sm); padding: 16px; background: var(--white); }
.payment-option p { margin: 0 0 8px; line-height: 1.4; font-size: 13.5px; }
.payment-option p:last-child { margin-bottom: 0; }
.payment-option-card { border-color: var(--plum); border-width: 1.5px; }
.payment-option-heading { font-weight: 800; font-size: 13px; margin-bottom: 10px; color: #3d2f45; text-transform: uppercase; letter-spacing: .4px; }
.card-link { display: inline-block; padding: 8px 14px; border-radius: var(--radius-pill); background: var(--plum); color: var(--white); font-weight: 800; font-size: 12px; text-decoration: none; letter-spacing: .2px; }
.card-link::after { content: " ↗"; }
.subscription-note { font-size: 12px; color: #6d5d70; margin-top: 6px !important; }
.print-work { break-inside: auto; page-break-inside: auto; }
.print-work p { line-height: 1.55; font-size: 13.5px; }
.work-notes-print { white-space: pre-wrap; border: 1px solid #eadde4; border-radius: var(--radius-sm); background: #fffdfc; padding: 14px; line-height: 1.5; font-size: 13px; }
.print-footer { margin-top: 28px; border-top: 1px solid #eadde4; padding-top: 12px; color: #6d5d70; font-size: 11.5px; display: flex; justify-content: space-between; }

/* ─────────────────────────────────────────────────────────────────────────────
   Responsive
───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .metrics { grid-template-columns: repeat(2, minmax(150px,1fr)); }
  .two-column, .wide-left, .invoice-workspace, .settings-layout, .insight-grid { grid-template-columns: 1fr; }
  .settings-side { position: static; }
  .invoice-terms-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .folder-grid, .report-grid, .form-grid.compact, .settings-summary, .connection-tools, .import-mapping-grid, .transaction-tools, .project-form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .line-items-header { display: none; }
}

@media (max-width: 640px) {
  .main { padding: 16px; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 12px; }
  .top-actions { justify-content: flex-start; }
  .setup-banner { grid-template-columns: 1fr; }
  .setup-banner .button { grid-row: auto; }
  .metrics, .form-grid, .invoice-details-grid, .invoice-terms-grid, .folder-grid, .report-grid, .form-grid.compact, .settings-summary, .brand-settings, .connection-tools, .mini-metrics, .import-mapping-grid, .transaction-tools, .inline-actions, .project-form-grid, .bar-row, .payment-options-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .trend-bars { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .line-items-header, .line-item { min-width: 0; }
  .line-items { overflow-x: visible; }
  .line-item { grid-template-columns: 1fr; }
  h1 { font-size: 24px; }
  h2 { font-size: 18px; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   Toast notifications
───────────────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  pointer-events: none;
  max-width: 380px;
}
.toast {
  background: #1c1622;
  color: rgba(255,255,255,.9);
  padding: 13px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: flex-start;
  gap: 11px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,.32), 0 0 0 1px rgba(255,255,255,.05);
  transform: translateX(20px) scale(.96);
  opacity: 0;
  transition: transform 220ms var(--ease), opacity 220ms var(--ease);
  pointer-events: all;
  will-change: transform, opacity;
  border-left: 3px solid transparent;
  line-height: 1.4;
  max-width: 100%;
}
.toast.toast-visible { transform: translateX(0) scale(1); opacity: 1; }
.toast.toast-hiding  { transform: translateX(10px) scale(.96); opacity: 0; }
.toast-success { border-left-color: #4caf82; }
.toast-error   { border-left-color: #c0430d; }
.toast-warn    { border-left-color: #e8923a; }
.toast-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; line-height: 1; }
.toast-success .toast-icon { color: #4caf82; }
.toast-error   .toast-icon { color: #c0430d; }
.toast-warn    .toast-icon { color: #e8923a; }

/* ─────────────────────────────────────────────────────────────────────────────
   Command palette  (Cmd K)
───────────────────────────────────────────────────────────────────────────── */
.cmd-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18,10,16,.52);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 8000;
  display: grid;
  place-items: start center;
  padding: 13vh 20px 20px;
  animation: cmd-bg-in 160ms var(--ease);
}
@keyframes cmd-bg-in { from { opacity: 0; } to { opacity: 1; } }
.cmd-panel {
  width: min(560px, 100%);
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: 0 32px 80px rgba(0,0,0,.32), 0 0 0 1px rgba(0,0,0,.06);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: cmd-panel-in 160ms var(--ease);
}
@keyframes cmd-panel-in {
  from { opacity: 0; transform: scale(.95) translateY(-10px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}
.cmd-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}
.cmd-search-icon { color: #aaa; font-size: 18px; flex-shrink: 0; }
.cmd-input-wrap input {
  border: none !important;
  padding: 0 !important;
  min-height: auto !important;
  box-shadow: none !important;
  background: transparent !important;
  font-size: 15px !important;
  font-weight: 500;
  color: var(--ink);
  flex: 1;
  outline: none !important;
}
.cmd-input-wrap input::placeholder { color: #b8b0a8; }
.cmd-hint-key {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
  letter-spacing: .2px;
  flex-shrink: 0;
  font-family: inherit;
}
.cmd-results { max-height: 360px; overflow-y: auto; padding: 6px 0 8px; }
.cmd-group-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .9px;
  color: var(--muted);
  padding: 10px 18px 4px;
}
.cmd-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
  outline: none;
}
.cmd-item:hover, .cmd-item.is-active { background: var(--soft-gold); }
.cmd-item-icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 13px;
  flex-shrink: 0;
  color: var(--muted);
}
.cmd-item.is-active .cmd-item-icon { background: var(--plum); border-color: var(--plum); color: white; }
.cmd-item-body { flex: 1; min-width: 0; }
.cmd-item-label { font-size: 13.5px; font-weight: 500; color: var(--ink); }
.cmd-item-meta  { font-size: 12px; color: var(--muted); }
.cmd-empty { padding: 32px 20px; text-align: center; color: var(--muted); font-size: 13.5px; }
.cmd-footer {
  padding: 9px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 18px;
  background: var(--surface-strong);
}
.cmd-footer-hint { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Sidebar user footer
───────────────────────────────────────────────────────────────────────────── */
.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, var(--plum), var(--gold));
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
  letter-spacing: -.2px;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 12.5px; font-weight: 600; color: rgba(255,255,255,.82); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: rgba(255,255,255,.36); line-height: 1.5; }
.sidebar-logout-btn {
  background: none;
  border: 1px solid transparent;
  color: rgba(255,255,255,.22);
  cursor: pointer;
  font-size: 11.5px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  white-space: nowrap;
  flex-shrink: 0;
}
.sidebar-logout-btn:hover { color: rgba(255,255,255,.7); border-color: rgba(255,255,255,.12); }

/* Cmd+K search hint in sidebar */
.cmd-hint-sidebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  font-size: 12px;
  color: rgba(255,255,255,.4);
  text-align: left;
  width: 100%;
  margin-top: 4px;
}
.cmd-hint-sidebar:hover { background: rgba(255,255,255,.1); color: rgba(255,255,255,.7); border-color: rgba(255,255,255,.18); }
.cmd-hint-sidebar kbd {
  display: inline-flex;
  align-items: center;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10px;
  font-family: inherit;
  color: rgba(255,255,255,.5);
  margin-left: auto;
  letter-spacing: .2px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Mobile sidebar overlay
───────────────────────────────────────────────────────────────────────────── */
.mobile-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.42);
  z-index: 99;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.mobile-sidebar-backdrop.active { display: block; }
.mobile-nav-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  flex-shrink: 0;
  font-size: 17px;
  line-height: 1;
}
.mobile-nav-btn:hover { background: var(--surface); color: var(--ink); }

/* ─────────────────────────────────────────────────────────────────────────────
   View content fade-in transition
───────────────────────────────────────────────────────────────────────────── */
@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.view-content { animation: view-in 150ms var(--ease); }

/* ─────────────────────────────────────────────────────────────────────────────
   Mobile overrides  (≤768px)
───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed !important;
    left: 0; top: 0;
    height: 100dvh;
    width: 272px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 240ms var(--ease);
    overflow-y: auto;
    box-shadow: 4px 0 32px rgba(0,0,0,.3);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .mobile-nav-btn { display: flex; }
  .user-pill { display: none; }
  #toast-container { bottom: 16px; right: 16px; max-width: calc(100vw - 32px); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   Forecast view
───────────────────────────────────────────────────────────────────────────── */
.forecast-controls .panel-heading { align-items: center; }
.forecast-controls select { margin-left: auto; }

/* 12-month bar chart */
.forecast-chart-bars {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 5px;
  margin-top: 14px;
  padding-bottom: 4px;
}
.fcst-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
  cursor: default;
}
.fcst-col-bars {
  position: relative;
  width: 100%;
  height: 110px;
}
.fcst-bar-bg, .fcst-bar-actual {
  position: absolute;
  bottom: 0;
  left: 3px;
  right: 3px;
  border-radius: 3px 3px 0 0;
}
.fcst-bar-bg { background: color-mix(in srgb, var(--gold) 38%, transparent); }
.fcst-bar-actual { background: var(--plum); }
.fcst-col strong { font-size: 10px; font-weight: 700; color: var(--ink); line-height: 1.2; }
.fcst-col > span { font-size: 10px; color: var(--muted); }
.fcst-col-now .fcst-col-bars { outline: 2px solid var(--plum); outline-offset: 2px; border-radius: 4px; }
.fcst-col-now strong, .fcst-col-now > span { color: var(--plum); font-weight: 700; }
.fcst-legend { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.fcst-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.fcst-dot-actual { background: var(--plum); }
.fcst-dot-proj { background: color-mix(in srgb, var(--gold) 38%, transparent); border: 1px solid var(--gold); }

/* Breakdown table */
.forecast-legend-table { margin-top: 20px; overflow-x: auto; }
.forecast-legend-table table { width: 100%; font-size: 12px; }
.forecast-legend-table td, .forecast-legend-table th { padding: 5px 8px; }
.row-highlight { background: rgba(182,147,112,0.08); }
.row-inactive { opacity: 0.45; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }

/* ─────────────────────────────────────────────────────────────────────────────
   GST suggestion button
───────────────────────────────────────────────────────────────────────────── */
.suggestion-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--plum);
  border-color: color-mix(in srgb, var(--plum) 30%, transparent);
  padding: 2px 7px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggestion-btn:hover {
  background: color-mix(in srgb, var(--plum) 12%, transparent);
  border-color: var(--plum);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Bank transactions — mobile card layout  (≤640px)
───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .bank-tx-table thead { display: none; }
  .bank-tx-table tbody tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto auto auto;
    gap: 2px 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    align-items: start;
  }
  .bank-tx-table tbody tr:last-child { border-bottom: none; }
  /* Checkbox */
  .bank-tx-table td:nth-child(1) { grid-column: 1; grid-row: 1; padding-top: 2px; }
  /* Date */
  .bank-tx-table td:nth-child(2) { grid-column: 2; grid-row: 1; font-size: 11px; color: var(--muted); }
  /* Description */
  .bank-tx-table td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; font-size: 13px; }
  /* Amount */
  .bank-tx-table td:nth-child(4) { grid-column: 3; grid-row: 1; font-weight: 700; font-size: 14px; text-align: right; }
  /* GST treatment */
  .bank-tx-table td:nth-child(5) { grid-column: 1 / -1; grid-row: 3; }
  .bank-tx-table td:nth-child(5) select { width: 100%; }
  /* Invoice match */
  .bank-tx-table td:nth-child(6) { grid-column: 1 / -1; grid-row: 4; }
  .bank-tx-table td:nth-child(6) .inline-actions { flex-wrap: wrap; }
  .bank-tx-table td:nth-child(6) select { min-width: 0; flex: 1; }
  /* Business use — hide on mobile */
  .bank-tx-table td:nth-child(7) { display: none; }
  /* Delete */
  .bank-tx-table td:nth-child(8) { display: none; }
}

/* ── Client Briefs view ─────────────────────────────────────────────────── */
.brief-client-list { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.brief-client-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.12s;
}
.brief-client-row:hover { background: var(--surface); }
.brief-client-row.active { background: color-mix(in srgb, var(--plum) 12%, var(--surface)); }
.brief-client-row > div { display: flex; flex-direction: column; gap: 2px; }
.brief-client-row strong { font-size: 13.5px; color: var(--text); }
.brief-client-row span { font-size: 11.5px; color: var(--muted); }
.brief-count-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface);
  color: var(--muted);
  padding: 2px 7px;
  border-radius: 20px;
  border: 1px solid var(--line);
}
.brief-client-row.active .brief-count-badge { background: var(--plum); color: #fff; border-color: var(--plum); }

/* Activity chart */
.brief-activity-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 4px;
  padding: 14px 0 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.brief-act-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.brief-act-col span { font-size: 10px; color: var(--muted); }
.brief-act-bars { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 100%; }
.brief-act-bar {
  width: 100%;
  max-width: 28px;
  border-radius: 3px 3px 0 0;
  background: var(--plum);
  opacity: 0.7;
  transition: height 0.2s;
}
.brief-act-col.has-monthly .brief-act-bar { opacity: 1; }
.brief-act-monthly {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  flex-shrink: 0;
}

/* Rollup buttons row */
.brief-rollup-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 0 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

/* Brief history list */
.brief-history-list { display: flex; flex-direction: column; gap: 0; }
.brief-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 10px 0 4px;
}
.brief-history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.1s;
}
.brief-history-row:last-child { border-bottom: none; }
.brief-history-row:hover { background: color-mix(in srgb, var(--plum) 5%, transparent); }
.brief-history-row.selected { background: color-mix(in srgb, var(--plum) 8%, transparent); }
.brief-history-row > div:first-child { display: flex; flex-direction: column; gap: 2px; }
.brief-history-row strong { font-size: 13px; color: var(--text); }
.brief-history-row span { font-size: 11.5px; color: var(--muted); }

/* ── Project tracker ─────────────────────────────────────────────────────── */
.project-task-list { display: flex; flex-direction: column; gap: 6px; }
.project-task-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.project-task-row:last-child { border-bottom: none; }
.task-due { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.task-due.overdue { color: #c0392b; font-weight: 700; }
.task-due.due-soon { color: #d97706; font-weight: 600; }
.task-due-input { flex-shrink: 0; }
.task-status-btn {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.1s;
}
.task-status-btn:hover { opacity: 0.75; }
.task-main { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 3px; }
.task-desc { font-size: 13px; color: var(--text); }
.task-completion-comment { font-size: 11.5px; color: var(--muted); line-height: 1.35; }

/* ── AI Analysis Panel ───────────────────────────────────────────────────── */
.ai-analysis-panel {
  border: 1px solid color-mix(in srgb, var(--plum) 30%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--plum) 4%, var(--bg));
  margin-bottom: 16px;
}
.ai-analysis-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: color-mix(in srgb, var(--plum) 8%, var(--surface));
  border-bottom: 1px solid color-mix(in srgb, var(--plum) 20%, var(--line));
  font-size: 12px;
  font-weight: 700;
  color: var(--plum);
  letter-spacing: 0.04em;
}
.ai-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  font-size: 13px;
  color: var(--muted);
}
.ai-dots { display: flex; gap: 5px; align-items: center; }
.ai-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--plum);
  animation: ai-pulse 1.2s ease-in-out infinite;
}
.ai-dots span:nth-child(2) { animation-delay: 0.2s; background: #a8567a; }
.ai-dots span:nth-child(3) { animation-delay: 0.4s; background: var(--gold); }
@keyframes ai-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}
.ai-analysis-content {
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.65;
}
.ai-analysis-content p { margin: 8px 0; color: var(--text); }
.ai-analysis-content h3.brief-h3 {
  font-size: 13px;
  font-weight: 700;
  margin: 16px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid color-mix(in srgb, var(--plum) 25%, var(--line));
  color: var(--plum);
}
.ai-analysis-content h4.brief-h4 {
  font-size: 12.5px;
  font-weight: 700;
  margin: 10px 0 4px;
  color: var(--text);
}
.ai-analysis-panel .muted { padding: 10px 14px; display: block; }

/* ── Tefui Agent shared styles ───────────────────────────────────────────── */
.tefui-agent-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--plum);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.agent-btn {
  color: var(--plum) !important;
  border-color: color-mix(in srgb, var(--plum) 35%, var(--line)) !important;
}
.agent-btn:hover { background: color-mix(in srgb, var(--plum) 8%, transparent) !important; }
.agent-briefing-box {
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(229,222,216,0.8);
  border-radius: 8px;
  padding: 14px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-line;
}
.tefui-agent-card {
  background: linear-gradient(135deg, rgba(155,64,104,0.05) 0%, rgba(182,147,112,0.06) 100%);
  border-color: rgba(155,64,104,0.14);
  position: relative;
}
.tefui-agent-card::before {
  content: "";
  position: absolute;
  top: -24px; right: -24px;
  width: 96px; height: 96px;
  background: radial-gradient(circle, rgba(182,147,112,0.22), transparent 70%);
  pointer-events: none;
  z-index: 0;
}
.tefui-agent-card > * { position: relative; z-index: 1; }

/* ── Agent suggestions panel ─────────────────────────────────────────────── */
.agent-suggestions-panel {
  border: 1px solid color-mix(in srgb, var(--plum) 30%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--plum) 4%, var(--bg));
  margin-top: 14px;
  overflow: hidden;
}
.agent-suggestions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: color-mix(in srgb, var(--plum) 8%, var(--surface));
  border-bottom: 1px solid color-mix(in srgb, var(--plum) 20%, var(--line));
  gap: 8px;
}
.agent-suggestion-card {
  padding: 12px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--plum) 12%, var(--line));
}
.agent-suggestion-card:last-child { border-bottom: none; }
.agent-suggestion-name { font-size: 13.5px; font-weight: 700; margin-bottom: 2px; }
.agent-task-list { margin: 6px 0 8px 16px; padding: 0; font-size: 12.5px; color: var(--muted); }
.agent-task-list li { margin: 2px 0; }
.agent-suggestions-empty { padding: 12px 14px; font-size: 13px; color: var(--muted); }
.tx-suggestions { margin-bottom: 14px; }
.tx-suggestions-list { padding: 8px 14px; display: flex; flex-direction: column; gap: 4px; }
.tx-suggestion-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center; font-size: 12.5px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.tx-suggestion-row:last-child { border-bottom: none; }
.tx-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-treatment { font-weight: 600; font-size: 11.5px; }
.tx-confidence { font-size: 11px; }

/* ── View toggle ─────────────────────────────────────────────────────────── */
.view-mode-toggle { display: flex; gap: 2px; background: var(--line); border-radius: 6px; padding: 2px; flex-shrink: 0; }
.toggle-btn { font-size: 12px; font-weight: 600; padding: 3px 12px; border: none; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; transition: background 0.15s, color 0.15s; }
.toggle-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.toggle-btn:hover:not(.active) { color: var(--text); }

/* ── Gantt chart ─────────────────────────────────────────────────────────── */
.gt-wrap { width: 100%; overflow-x: auto; padding-bottom: 4px; }

/* Shared row layout */
.gt-header, .gt-row, .gt-group-header { display: flex; align-items: stretch; }
.gt-label {
  width: 210px;
  min-width: 210px;
  flex-shrink: 0;
  padding: 0 14px 0 2px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}
.gt-track {
  flex: 1;
  min-width: 300px;
  position: relative;
  border-left: 1px solid var(--line);
  overflow: hidden;
}

/* Month header */
.gt-header { height: 36px; margin-bottom: 2px; }
.gt-month-track {
  background: var(--surface-strong);
  border-radius: 6px 6px 0 0;
  border: 1px solid var(--line);
  border-bottom: 2px solid var(--line);
}
.gt-month-label {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}
.gt-today-label {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 800;
  color: var(--plum);
  white-space: nowrap;
  letter-spacing: 0.03em;
  pointer-events: none;
}

/* Client group header */
.gt-group-header { border-top: 2px solid var(--line); }
.gt-group:first-child .gt-group-header { border-top: none; }
.gt-client-label {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--plum);
  padding: 6px 14px 6px 2px;
  min-height: 30px;
}
.gt-group-track {
  background: color-mix(in srgb, var(--plum) 3%, var(--surface-strong));
  border-bottom: 1px solid var(--line);
}

/* Project rows */
.gt-row {
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid var(--line);
}
.gt-row:hover { background: color-mix(in srgb, var(--plum) 5%, transparent); }
.gt-row .gt-label { min-height: 52px; padding: 10px 14px 10px 2px; }
.gt-project-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
.gt-project-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.gt-row .gt-track { min-height: 52px; background: var(--surface-strong); }
.gt-row:nth-child(even) .gt-track { background: var(--surface); }

/* Gridlines */
.gt-vline {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line);
  pointer-events: none;
}
.gt-today {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--plum) 55%, transparent);
  pointer-events: none;
  z-index: 2;
}

/* Bars */
.gt-bar {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 20px;
  border-radius: 10px;
  overflow: hidden;
  min-width: 6px;
  cursor: pointer;
  background: var(--gt-bar-color);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2), 0 0 0 1px color-mix(in srgb, var(--gt-bar-color) 55%, #000);
  transition: filter 0.12s, box-shadow 0.12s;
  z-index: 1;
}
.gt-bar:hover { filter: brightness(1.1); box-shadow: 0 3px 8px rgba(0,0,0,0.22); }
.gt-bar--overdue { box-shadow: 0 0 0 2px #e74c3c, 0 1px 4px rgba(0,0,0,0.15); }
.gt-bar--complete {
  background: linear-gradient(90deg, #176f38, #24a852);
  box-shadow: 0 1px 4px rgba(0,0,0,0.18), 0 0 0 1px #176f38;
}
.gt-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: linear-gradient(90deg, #1f8f49, #35b864);
  border-right: 2px solid rgba(255,255,255,0.85);
  border-radius: 10px 0 0 10px;
  pointer-events: none;
}
.gt-progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 10.5px;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  pointer-events: none;
}

/* Legend */
.gt-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0 2px 214px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.gt-legend-item { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
.gt-legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.gt-legend-note { font-size: 11px; color: var(--muted); font-style: italic; margin-left: 6px; }

/* Expand/open controls */
.gt-label-top { display: flex; align-items: center; gap: 4px; overflow: hidden; }
.gt-label-top .gt-project-name { flex: 1; min-width: 0; }
.gt-open-btn { flex-shrink: 0; background: none; border: none; font-size: 13px; color: var(--muted); cursor: pointer; padding: 0 2px; line-height: 1; opacity: 0; transition: opacity 0.15s, color 0.15s; }
.gt-row:hover .gt-open-btn { opacity: 1; }
.gt-open-btn:hover { color: var(--plum); }
.gt-row--expanded { background: color-mix(in srgb, var(--plum) 4%, transparent); }
.gt-row--expanded .gt-track { background: color-mix(in srgb, var(--plum) 4%, var(--surface-strong)); }

/* Task sub-rows */
.gt-task-row { display: flex; align-items: stretch; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.gt-task-label { width: 210px; min-width: 210px; flex-shrink: 0; padding: 5px 14px 5px 16px; display: flex; align-items: center; gap: 6px; overflow: hidden; background: color-mix(in srgb, var(--plum) 2%, var(--surface)); }
.gt-task-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.gt-task-desc { font-size: 11.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.gt-task-desc.done { text-decoration: line-through; color: var(--muted); }
.gt-task-due-text { font-size: 10.5px; color: var(--muted); flex-shrink: 0; white-space: nowrap; }
.gt-task-nodate { font-size: 10.5px; color: var(--muted); font-style: italic; flex-shrink: 0; }
.gt-task-track { min-height: 30px; background: color-mix(in srgb, var(--plum) 2%, var(--surface)); border-left: 1px solid var(--line); flex: 1; min-width: 300px; position: relative; overflow: hidden; }
.gt-task-marker { position: absolute; top: 50%; transform: translate(-50%, -50%) rotate(45deg); width: 9px; height: 9px; z-index: 2; pointer-events: none; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.gt-task-marker--done { opacity: 0.55; }
.gt-task-row--empty .gt-task-label { background: transparent; }

/* No-dates footer */
.gantt-no-dates { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.tag-btn { font-size: 11.5px; padding: 2px 10px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; transition: background 0.12s, color 0.12s; }
.tag-btn:hover { background: var(--plum); color: #fff; border-color: var(--plum); }

/* ── Weekly Brief Panel ──────────────────────────────────────────────────── */
.brief-panel { margin-top: 18px; }
.brief-meta-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.brief-workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.brief-editor-col,
.brief-preview-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.brief-editor-col { border-right: 1px solid var(--line); }
.brief-editor-col > .field-label,
.brief-preview-header {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.brief-preview-header {
  background: color-mix(in srgb, var(--plum) 8%, var(--surface));
  color: var(--plum);
}
.brief-textarea {
  flex: 1;
  min-height: 340px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
  resize: none;
  padding: 12px;
  border: none;
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  tab-size: 4;
  width: 100%;
  outline: none;
}
.brief-textarea:focus { background: color-mix(in srgb, var(--plum) 3%, var(--bg)); }
.brief-preview {
  flex: 1;
  min-height: 340px;
  padding: 16px;
  background: var(--surface);
  font-size: 13px;
  line-height: 1.65;
  overflow-y: auto;
}
.brief-preview p { margin: 8px 0; color: var(--text); }
.brief-preview h3.brief-h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 18px 0 6px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--gold);
  color: var(--text);
}
.brief-preview h4.brief-h4 {
  font-size: 13px;
  font-weight: 700;
  margin: 12px 0 4px;
  color: var(--text);
}
.brief-preview .brief-table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 12px;
}
.brief-preview .brief-table th {
  background: var(--bg);
  font-weight: 700;
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}
.brief-preview .brief-table td {
  border: 1px solid var(--line);
  padding: 5px 10px;
}
.brief-preview .brief-table tr:nth-child(even) td { background: color-mix(in srgb, var(--surface) 60%, var(--bg)); }

@media (max-width: 860px) {
  .brief-workspace { grid-template-columns: 1fr; }
  .brief-editor-col { border-right: none; border-bottom: 1px solid var(--line); }
  .brief-preview { min-height: 200px; }
}

@media print {
  .print-page { padding: 20px; box-shadow: none; }
  .button { display: none; }
  .invoice-print { background: var(--white); }
  .print-page { max-width: none; }
  .print-page::before { border-radius: 0; }
}

.view-loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 200px;
}
