/* ===== design tokens ===================================================== */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --border: #e3e8f0;
  --text: #17202f;
  --text-muted: #6b7a90;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #e8f0fe;
  --success: #15803d;
  --success-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --info-soft: #eaf1fb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px -12px rgba(16, 24, 40, .18);
  --sidebar-w: 246px;
  --sidebar-bg: #10192b;
  --sidebar-text: #cbd6e6;
  --sidebar-muted: #64748b;
  --font: Vazirmatn, "Segoe UI", Tahoma, "Iranian Sans", sans-serif;
  --pad: 1rem;
}
:root[data-density="compact"] { --pad: .7rem; font-size: 13px; }
:root[data-density="compact"] tbody td { padding: .36rem .6rem; }
:root[data-density="compact"] .card { padding: .75rem .85rem; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.7;
}

body { min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .4rem; font-weight: 700; line-height: 1.4; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; }

/* ===== layout ============================================================ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  /* Fixed (not sticky) so the dark column still covers tall, scrolling pages. */
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  overflow-y: auto;
  z-index: 30;
}
.sidebar .brand {
  padding: 1.1rem 1.15rem;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  display: flex; align-items: center; gap: .6rem;
}
.sidebar .brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #2563eb); color: #fff; font-weight: 700;
}
.sidebar .brand strong { color: #fff; display: block; font-size: .98rem; }
.sidebar .brand span { color: var(--sidebar-muted); font-size: .74rem; }
.sidebar .brand img { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; }

.nav { padding: .7rem .6rem 1.4rem; display: flex; flex-direction: column; gap: .12rem; }
.nav-title {
  color: var(--sidebar-muted); font-size: .7rem; letter-spacing: .04em;
  padding: .9rem .7rem .3rem; text-transform: uppercase;
}
.nav a {
  display: flex; align-items: center; gap: .55rem;
  padding: .55rem .7rem; border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-size: .875rem; transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column;
        margin-inline-start: var(--sidebar-w); }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: .7rem 1.2rem; display: flex; align-items: center; gap: 1rem;
  position: sticky; top: 0; z-index: 20;
}
.topbar .page-title { font-weight: 700; font-size: 1.02rem; }
.topbar .spacer { flex: 1; }
.topbar .topbar-time { text-align: center; line-height: 1.25; }
.topbar .clock { color: var(--text-muted); font-size: .82rem; }
.topbar .topbar-date { color: var(--text-muted); font-size: .72rem; white-space: nowrap; }
@media (max-width: 720px) { .topbar .topbar-date { display: none; } }
.user-chip {
  display: flex; align-items: center; gap: .5rem; padding: .3rem .55rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary-dark); display: grid; place-items: center; font-weight: 700; font-size: .78rem;
}
.user-chip .meta { line-height: 1.25; }
.user-chip .meta b { display: block; font-size: .8rem; }
.user-chip .meta span { font-size: .7rem; color: var(--text-muted); }

.content { padding: 1.2rem; flex: 1; }
.menu-toggle { display: none; background: none; border: 0; font-size: 1.3rem; cursor: pointer; }

/* ===== cards & grids ===================================================== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.card > header {
  display: flex; align-items: center; gap: .6rem; margin: -.2rem 0 .8rem;
}
.card > header h2, .card > header h3 { margin: 0; }
.card > header .spacer { flex: 1; }

.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        padding: .85rem 1rem; box-shadow: var(--shadow); }
.stat .label { color: var(--text-muted); font-size: .78rem; }
.stat .value { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
.stat .hint { font-size: .74rem; color: var(--text-muted); }
.stat.accent { background: linear-gradient(135deg, #2563eb, #1e40af); color: #fff; border-color: transparent; }
.stat.accent .label, .stat.accent .hint { color: rgba(255, 255, 255, .82); }

/* ===== tables ============================================================ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th {
  background: var(--surface-2); color: var(--text-muted); font-weight: 600;
  text-align: right; padding: .6rem .7rem; border-bottom: 1px solid var(--border);
  white-space: nowrap; font-size: .78rem;
}
tbody td { padding: .58rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { font-variant-numeric: tabular-nums; }
.empty { padding: 2.2rem 1rem; text-align: center; color: var(--text-muted); }

/* ===== forms & buttons =================================================== */
.field { margin-bottom: .75rem; }
.field label { display: block; font-size: .8rem; color: var(--text-muted); margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-family: inherit; font-size: .87rem;
  background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { min-height: 84px; resize: vertical; }
.form-row { display: grid; gap: .7rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .48rem .95rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-family: inherit; font-size: .85rem;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: .3rem .6rem; font-size: .78rem; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

.filters {
  display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .9rem;
}
.filters .field { margin: 0; min-width: 150px; }

/* ===== badges & misc ===================================================== */
.badge {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; white-space: nowrap;
}
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }
.badge.blue { background: var(--info-soft); color: var(--primary-dark); }
.badge.gray { background: #eef1f6; color: var(--text-muted); }

/* Times and dates are LTR runs; isolating them stops RTL bidi from
   rendering '23:10:00' as '00:10:23'. */
.tabular, .clock, .clock-now, .punch-times b {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: right;
}

.muted { color: var(--text-muted); }
.small { font-size: .78rem; }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.right { text-align: left; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.flex { display: flex; gap: .6rem; align-items: center; }
.flex.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.progress { height: 7px; border-radius: 999px; background: #eef1f6; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }

.pipeline { display: grid; gap: .6rem; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.pipeline .col {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .6rem;
}
.pipeline .col h4 { font-size: .78rem; color: var(--text-muted); margin-bottom: .3rem; }
.pipeline .col .count { font-size: 1.25rem; font-weight: 700; }
.pipeline .col .amount { font-size: .74rem; color: var(--text-muted); }

/* ===== punch clock ======================================================= */
.clock-card { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.clock-now { font-size: 2.4rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.clock-meta { flex: 1; min-width: 190px; }
.punch-times { display: flex; gap: 1.4rem; flex-wrap: wrap; }
.punch-times div span { display: block; font-size: .74rem; color: var(--text-muted); }
.punch-times div b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }

/* ===== login ============================================================= */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: linear-gradient(140deg, #172554 0%, #1e3a8a 45%, #2563eb 100%);
}
.login-box {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px;
  padding: 1.7rem 1.6rem; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .5);
}
.login-box h1 { text-align: center; margin-bottom: .2rem; }
.login-box .sub { text-align: center; color: var(--text-muted); margin-bottom: 1.2rem; font-size: .84rem; }
.login-hint {
  margin-top: 1rem; padding: .6rem .7rem; background: var(--surface-2);
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  font-size: .76rem; color: var(--text-muted);
}

/* ===== modal ============================================================= */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  display: grid; place-items: center; padding: 1rem; z-index: 60;
}
.modal {
  background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .45);
}
.modal header {
  padding: .85rem 1.1rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .6rem; position: sticky; top: 0; background: var(--surface);
}
.modal .body { padding: 1.1rem; }
.modal footer {
  padding: .8rem 1.1rem; border-top: 1px solid var(--border);
  display: flex; gap: .5rem; justify-content: flex-start; background: var(--surface-2);
}

/* ===== toast ============================================================= */
.toasts { position: fixed; bottom: 1rem; left: 1rem; display: grid; gap: .5rem; z-index: 90; }
.toast {
  background: var(--sidebar-bg); color: #fff; padding: .6rem .9rem; border-radius: var(--radius-sm);
  font-size: .84rem; box-shadow: var(--shadow); animation: pop .18s ease-out;
  max-width: 380px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.loader { padding: 2.5rem; text-align: center; color: var(--text-muted); }
.spinner {
  width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; margin: 0 auto .6rem; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.6rem;
  text-align: center; color: var(--text-muted); background: var(--surface-2); cursor: pointer;
}
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }

/* ===== responsive ======================================================== */
@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .sidebar { z-index: 50; transform: translateX(100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { margin-inline-start: 0; }
  .menu-toggle { display: block; }
  /* minmax(0, …) rather than a bare 1fr, exactly as the wider rules above do:
     a grid track defaults to min-width:auto, so a single `1fr` column still
     refuses to go narrower than its widest child and pushes the page sideways. */
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .form-row, .form-row.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .pipeline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content { padding: .85rem; }
}

/**
 * Phones. This product is a PWA and an employee punches in from a phone, so
 * every page has to survive 390px — and none of them did: the top bar alone
 * pushed all thirty of them sideways by 26 to 76 pixels.
 */
@media (max-width: 560px) {
  .topbar { padding: .6rem .7rem; gap: .5rem; }
  /* The title is what should give way, so it has to be allowed to shrink at
     all — a flex item will not go below its content width without this. */
  .topbar .page-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .topbar-time { display: none; }        /* the dashboard has a larger clock */
  .user-chip { padding: 0; border: 0; background: none; }
  .user-chip .meta { display: none; }            /* the name is in the sidebar */
  .content { padding: .7rem; }
  .card { padding: .8rem .7rem; }
  /* A filter field wider than the screen is what makes a filter bar overflow. */
  .filters .field { min-width: 0; flex: 1 1 100%; }
  /* A card header is a title and however many buttons the page needs; on a
     phone that is more than one line's worth, and it never wrapped. */
  .card > header { flex-wrap: wrap; }
  .pipeline { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .filters, .btn, .no-print, .demo-bar, .toasts { display: none !important; }
  /* The sidebar is gone, so the room kept for it has to go too — otherwise
     every printed page carries a blank 246px strip. It only looked right
     before because A4 portrait happens to be narrow enough to trip the phone
     rule that zeroes this margin; any wider paper printed the strip. */
  .main { margin-inline-start: 0 !important; }
  .content { padding: 0; }
  html, body, .app, .main, .content { background: #fff !important; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  /* A table that spans pages keeps its heading on each, and a row is not
     split across two of them. */
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
}


/* ===== v2: topbar tools ================================================== */
.icon-btn {
  position: relative; background: none; border: 1px solid var(--border); border-radius: 50%;
  width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; font-size: 1rem;
  color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .dot {
  position: absolute; top: -4px; inset-inline-end: -4px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: .68rem; display: grid; place-items: center;
}
.dropdown {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0; width: 360px; max-width: calc(100vw - 2rem);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 70; overflow: hidden;
}
.dropdown header { padding: .6rem .9rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .5rem; }
.dropdown .list { max-height: 380px; overflow-y: auto; }
.notif {
  display: block; padding: .6rem .9rem; border-bottom: 1px solid var(--border); color: var(--text);
}
.notif.unread { background: var(--primary-soft); }
.notif b { display: block; font-size: .84rem; }
.notif p { margin: .15rem 0 0; font-size: .78rem; color: var(--text-muted); white-space: pre-line; }
.notif time { font-size: .7rem; color: var(--text-muted); }
.topbar-tools { position: relative; display: flex; gap: .5rem; align-items: center; }

/* command palette */
.palette-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 65; display: grid; place-items: start center; padding-top: 12vh; }
.palette { width: 100%; max-width: 560px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.palette input { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: .9rem 1rem; font-size: 1rem; }
.palette .results { max-height: 50vh; overflow-y: auto; }
.palette .hit { display: flex; align-items: center; gap: .6rem; padding: .55rem 1rem; cursor: pointer; border-bottom: 1px solid var(--border); color: var(--text); }
.palette .hit:hover, .palette .hit.active { background: var(--surface-2); }
.palette .hit .kind { font-size: .7rem; color: var(--text-muted); width: 68px; }
.palette .hit .sub { font-size: .76rem; color: var(--text-muted); }

/* ===== v2: kanban ======================================================== */
.kanban { display: flex; gap: .8rem; overflow-x: auto; padding-bottom: .6rem; align-items: flex-start; min-height: 60vh; }
.kanban .column {
  flex: 0 0 280px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; max-height: 78vh;
}
.kanban .column > header { padding: .6rem .75rem; display: flex; align-items: center; gap: .4rem; font-weight: 700; font-size: .88rem; }
.kanban .column > header .count { font-size: .72rem; color: var(--text-muted); font-weight: 400; }
.kanban .cards { padding: .3rem .5rem .5rem; overflow-y: auto; display: flex; flex-direction: column; gap: .45rem; min-height: 40px; flex: 1; }
.kanban .column.over .cards { outline: 2px dashed var(--primary); outline-offset: -4px; border-radius: var(--radius-sm); }
.kcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .55rem .65rem;
  cursor: grab; box-shadow: 0 1px 2px rgba(16,24,40,.05); font-size: .84rem;
}
.kcard:active { cursor: grabbing; }
.kcard.dragging { opacity: .45; }
.kcard.done { opacity: .6; text-decoration: line-through; }
.kcard .labels { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .3rem; }
.kcard .label { height: 6px; width: 34px; border-radius: 999px; }
.kcard .meta { display: flex; gap: .5rem; align-items: center; margin-top: .35rem; font-size: .72rem; color: var(--text-muted); flex-wrap: wrap; }
.kcard .meta .due.overdue { color: var(--danger); font-weight: 600; }
.kanban .add-col { flex: 0 0 240px; }
.avatar.xs { width: 22px; height: 22px; font-size: .62rem; }

/* ===== v2: badges & misc ================================================= */
.badge.hot { background: #fde8dc; color: #c2410c; }
.badge.warm { background: var(--warn-soft); color: var(--warn); }
.badge.cold { background: #eef1f6; color: var(--text-muted); }
.score-bar { height: 6px; background: #eef1f6; border-radius: 999px; overflow: hidden; width: 90px; display: inline-block; vertical-align: middle; }
.score-bar > span { display: block; height: 100%; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .55rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: .76rem; }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; display: inline-block; }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }
.theme-card { border: 2px solid var(--border); border-radius: var(--radius); padding: .5rem; cursor: pointer; }
.theme-card.active { border-color: var(--primary); }
.theme-card .preview { height: 54px; border-radius: 8px; display: flex; overflow: hidden; margin-bottom: .35rem; }
.theme-card .preview i { flex: 1; }
.playbook { border-inline-start: 3px solid var(--primary); padding: .2rem .8rem; margin: .4rem 0; }
.playbook ol { padding-inline-start: 1.2rem; margin: .3rem 0; }
.playbook details { margin-top: .3rem; }
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .4rem; }
.week-grid .day { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem; text-align: center; font-size: .8rem; }
.week-grid .day.off { opacity: .55; }
.week-grid .day b { display: block; margin-bottom: .25rem; }
.announce { border-inline-start: 4px solid var(--primary); background: var(--surface-2); padding: .6rem .8rem; border-radius: var(--radius-sm); margin-bottom: .5rem; }
.announce.pinned { border-inline-start-color: var(--warn); }
.announce h4 { margin: 0 0 .2rem; font-size: .9rem; }
.announce p { margin: 0; font-size: .82rem; white-space: pre-line; }
.offline-banner { background: var(--warn-soft); color: var(--warn); padding: .35rem .9rem; font-size: .78rem; text-align: center; }
.quote-doc { max-width: 900px; margin: 0 auto; background: var(--surface); padding: 1.4rem; }
.quote-doc .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 2px solid var(--primary); padding-bottom: .8rem; margin-bottom: 1rem; }
.quote-doc table td, .quote-doc table th { border: 1px solid var(--border); }
.quote-doc .totals { margin-inline-start: auto; width: 320px; margin-top: 1rem; }
.quote-doc .totals div { display: flex; justify-content: space-between; padding: .3rem 0; border-bottom: 1px dashed var(--border); }
.quote-doc .totals div.grand { font-weight: 700; font-size: 1.05rem; border-bottom: 0; }
@media print { .quote-doc { padding: 0; max-width: none; } }
@media (max-width: 820px) { .dropdown { width: calc(100vw - 1.5rem); inset-inline-end: -3rem; } .week-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ===== charts (see dataviz method) ======================================= */
:root {
  --viz-1: #2a78d6; --viz-2: #eb6834; --viz-3: #1baf7a;
  --viz-seq-1: #86b6ef; --viz-seq-2: #5598e7; --viz-seq-3: #2a78d6; --viz-seq-4: #1c5cab; --viz-seq-5: #104281;
  --viz-zero: #edf1f6; --viz-off: #f4f5f7; --viz-grid: #e6eaf0;
}
.viz-root { position: relative; }
.viz { width: 100%; height: auto; display: block; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { stroke: var(--border); stroke-width: 1; }
.viz-tick { font-size: 11px; fill: var(--text-muted); font-family: var(--font); }
.viz-label { font-size: 12px; fill: var(--text); font-family: var(--font); }
.viz-value { font-size: 11px; fill: var(--text-muted); font-family: var(--font); font-variant-numeric: tabular-nums; }
.viz-cell-label { font-size: 11px; fill: var(--text); font-family: var(--font); pointer-events: none; }
.viz-hit { cursor: default; }
.viz-hit:hover path, .viz-hit:hover rect[rx] { filter: brightness(.92); }
.viz-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .3rem; }
.viz-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .76rem; color: var(--text-muted); }
.viz-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: .35rem; vertical-align: middle; }
.viz-tip { position: absolute; background: var(--sidebar-bg); color: #fff; padding: .35rem .6rem; border-radius: 6px; font-size: .74rem; white-space: pre-line; pointer-events: none; z-index: 5; box-shadow: var(--shadow); }
.viz-table { width: 100%; font-size: .8rem; margin-top: .3rem; }
.viz-toggle { flex: 0 0 auto; }

/* v2.4: quota meter on the leaves page */
.stat.warn { border-color: var(--danger, #dc2626); }
.stat.warn .value { color: var(--danger, #dc2626); }
.meter { display: inline-block; width: 60px; height: 6px; border-radius: 3px; background: var(--border); vertical-align: middle; position: relative; overflow: hidden; }
.meter::after { content: ''; position: absolute; inset: 0; width: var(--pct, 0%); background: var(--accent); }

/* v2.5: team leave calendar */
.teamcal-wrap { overflow-x: auto; }
.teamcal { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.teamcal th, .teamcal td { padding: .2rem .15rem; text-align: center; border-bottom: 1px solid var(--border); font-size: .78rem; min-width: 26px; }
.teamcal th.tc-name, .teamcal td.tc-name { text-align: right; min-width: 150px; padding-right: .6rem; position: sticky; right: 0; background: var(--surface); z-index: 1; }
.teamcal .tc-wd { color: var(--text-muted); font-size: .68rem; line-height: 1; }
.teamcal .tc-d { font-variant-numeric: tabular-nums; line-height: 1.4; }
.teamcal th.off, .teamcal td.off { background: var(--surface-2); color: var(--text-muted); }
.teamcal th.today, .teamcal td.today { box-shadow: inset 0 -2px 0 var(--primary); }
.teamcal .tc-total td { font-weight: 700; background: var(--surface-2); }
.tc-cell, .tc-swatch { display: inline-block; width: 20px; height: 18px; border-radius: 4px; vertical-align: middle; background: var(--primary); }
.tc-swatch { width: 14px; height: 12px; margin-left: .3rem; }
.tc-cell.paid, .tc-swatch.paid { background: #2a78d6; }
.tc-cell.unpaid, .tc-swatch.unpaid { background: #64748b; }
.tc-cell.sick, .tc-swatch.sick { background: #eb6834; }
.tc-cell.mission, .tc-swatch.mission { background: #1baf7a; }
.tc-cell.hourly, .tc-swatch.hourly { background: #a855f7; }
.tc-cell.pending, .tc-swatch.pending { background: repeating-linear-gradient(45deg, #f59e0b 0 4px, #fde68a 4px 8px); }
.tc-swatch.off { background: var(--surface-2); border: 1px solid var(--border); }
.legend span { display: inline-flex; align-items: center; margin-left: .9rem; font-size: .8rem; color: var(--text-muted); }

/* ===== v3: billing ======================================================== */
.aging-row { display: grid; grid-template-columns: 110px 1fr auto; gap: .6rem; align-items: center; padding: .3rem 0; }
.aging-bar { display: block; height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.aging-bar i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.meter.ok::after { background: #1baf7a; }
.meter.mid::after { background: #d97706; }
.meter.low::after { background: #dc2626; }
.stat.warn .value { color: var(--danger); }

/* ===== permission switch ================================================= */
.switch { display: inline-flex; align-items: center; cursor: pointer; vertical-align: middle; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span {
  width: 38px; height: 21px; border-radius: 999px; background: var(--border);
  position: relative; transition: background .15s ease;
}
.switch span::after {
  content: ''; position: absolute; inset-inline-start: 3px; top: 3px; width: 15px; height: 15px;
  border-radius: 50%; background: #fff; transition: inset-inline-start .15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { inset-inline-start: 20px; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
