/* =========================================================
   CRA Tracker — Design system
   Layout : sidebar permanente + topbar slim (quickbar)
   Themes : auto (prefers-color-scheme), light, dark
   ========================================================= */

:root {
  /* Palette light (default) */
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-soft: #f8f9fc;
  --surface-strong: #eef0f5;
  --card: #ffffff;
  --border: #e6e8ee;
  --border-strong: #cfd3dc;
  --text: #0f172a;
  --text-soft: #334155;
  --muted: #64748b;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-fg: #ffffff;
  --primary-glow: rgba(79, 70, 229, .25);

  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;

  /* Functional kind tints (light) */
  --weekend-bg: #eef0f5;
  --holiday-bg: #fde2e4;
  --kind-work-bg:    #dbeafe;
  --kind-remote-bg:  #ddd6fe;
  --kind-training-bg:#e9d5ff;
  --kind-half-bg:    #eef2ff;
  --kind-leave-bg:   #d1fae5;
  --kind-sick-bg:    #fee2e2;
  --kind-holiday-bg: #fecaca;
  --kind-absence-bg: #e5e7eb;
  --kind-t2-bg:      #fed7aa;
  --kind-half-t2-bg: #ffedd5;
  --t2-marker:       #ea580c;

  /* Heatmap scale (light) */
  --heat-0: #ebedf2;
  --heat-1: #c7d2fe;
  --heat-2: #818cf8;
  --heat-3: #6366f1;
  --heat-4: #4338ca;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, .14), 0 4px 12px rgba(15, 23, 42, .06);
  --ring-primary: 0 0 0 3px rgba(79, 70, 229, .25);

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;

  /* Layout */
  --sidebar-w: 232px;
  --topbar-h: 56px;
}

/* Dark theme — applied via [data-theme="dark"] OR prefers-color-scheme: dark when auto */
[data-theme="dark"] {
  --bg: #0b0e16;
  --surface: #11151f;
  --surface-soft: #161b27;
  --surface-strong: #1d2333;
  --card: #11151f;
  --border: #232a3b;
  --border-strong: #2e3650;
  --text: #e6e9f1;
  --text-soft: #b9c0d2;
  --muted: #7d869c;

  --primary: #818cf8;
  --primary-hover: #a5b4fc;
  --primary-soft: #1e1f3e;
  --primary-fg: #0b0e16;

  --danger: #f87171;
  --danger-soft: #321518;
  --success: #4ade80;
  --success-soft: #0e2a1e;
  --warning: #fbbf24;
  --warning-soft: #2c1f0a;

  --weekend-bg: #161b27;
  --holiday-bg: #3a1a20;
  --kind-work-bg:    #1e2a4f;
  --kind-remote-bg:  #2a1f4d;
  --kind-training-bg:#321b4a;
  --kind-half-bg:    #1a1e30;
  --kind-leave-bg:   #133723;
  --kind-sick-bg:    #3a1d1f;
  --kind-holiday-bg: #4a2024;
  --kind-absence-bg: #232838;
  --kind-t2-bg:      #4a2a10;
  --kind-half-t2-bg: #2e1d10;
  --t2-marker:       #fb923c;

  --heat-0: #1a1f2e;
  --heat-1: #2a2f55;
  --heat-2: #4338ca;
  --heat-3: #6366f1;
  --heat-4: #a5b4fc;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, .55);
  --ring-primary: 0 0 0 3px rgba(129, 140, 248, .35);
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #0b0e16;
    --surface: #11151f;
    --surface-soft: #161b27;
    --surface-strong: #1d2333;
    --card: #11151f;
    --border: #232a3b;
    --border-strong: #2e3650;
    --text: #e6e9f1;
    --text-soft: #b9c0d2;
    --muted: #7d869c;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: #1e1f3e;
    --primary-fg: #0b0e16;
    --danger: #f87171;
    --danger-soft: #321518;
    --success: #4ade80;
    --success-soft: #0e2a1e;
    --warning: #fbbf24;
    --warning-soft: #2c1f0a;
    --weekend-bg: #161b27;
    --holiday-bg: #3a1a20;
    --kind-work-bg:    #1e2a4f;
    --kind-remote-bg:  #2a1f4d;
    --kind-training-bg:#321b4a;
    --kind-half-bg:    #1a1e30;
    --kind-leave-bg:   #133723;
    --kind-sick-bg:    #3a1d1f;
    --kind-holiday-bg: #4a2024;
    --kind-absence-bg: #232838;
    --kind-t2-bg:      #4a2a10;
    --kind-half-t2-bg: #2e1d10;
    --t2-marker:       #fb923c;
    --heat-0: #1a1f2e;
    --heat-1: #2a2f55;
    --heat-2: #4338ca;
    --heat-3: #6366f1;
    --heat-4: #a5b4fc;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, .45);
    --shadow-lg: 0 24px 48px rgba(0, 0, 0, .55);
    --ring-primary: 0 0 0 3px rgba(129, 140, 248, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14.5px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  display: grid; grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
h1, h2, h3, h4 { color: var(--text); letter-spacing: -0.01em; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 600; }
a { color: var(--primary); }
.muted { color: var(--muted); }
kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .75em;
  background: var(--surface-strong); border: 1px solid var(--border-strong);
  padding: 1px 5px; border-radius: 5px; color: var(--text-soft); }

/* ============== Sidebar ============== */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1rem .8rem;
  position: sticky; top: 0; height: 100vh; z-index: 30;
}
.sidebar .brand {
  display: flex; align-items: center; gap: .6rem;
  text-decoration: none; color: var(--text); font-weight: 700;
  font-size: 1rem; padding: .25rem .5rem .75rem; letter-spacing: -0.01em;
}
.sidebar .brand-mark {
  width: 1.7rem; height: 1.7rem; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, #a5b4fc 100%);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.sidebar .brand-mark::after {
  content: ""; position: absolute; inset: 4px; border-radius: 4px;
  background: var(--surface); opacity: .25;
  background-image: linear-gradient(45deg, transparent 49%, var(--surface) 49% 51%, transparent 51%);
}
.sidebar .brand-logo {
  width: 1.9rem; height: 1.9rem; border-radius: 6px;
  object-fit: contain; background: var(--surface);
  padding: 2px;
  box-shadow: var(--shadow-sm);
}
.org-logo-preview img {
  max-width: 180px; max-height: 80px;
  object-fit: contain;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px;
}
.side-nav { display: flex; flex-direction: column; gap: 2px; margin-top: .25rem; }
.nav-item {
  display: flex; align-items: center; gap: .65rem;
  text-decoration: none; color: var(--text-soft);
  font-size: .9rem; font-weight: 500;
  padding: .5rem .65rem; border-radius: var(--r-md);
  transition: background .12s, color .12s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: var(--surface-soft); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
}
.nav-item.active svg { opacity: 1; }
.nav-kbd { margin-left: auto; font-size: .7rem; font-weight: 700;
  color: var(--muted); background: var(--surface-strong);
  border: 1px solid var(--border); padding: 1px 6px; border-radius: 4px; }
.nav-item:hover .nav-kbd, .nav-item.active .nav-kbd { color: var(--text); }

.side-footer {
  margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border);
  display: flex; gap: .3rem;
}
.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  border-radius: var(--r-md); width: 2.1rem; height: 2.1rem;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.icon-btn:hover { background: var(--surface-soft); color: var(--text); border-color: var(--border); }
.icon-btn svg { width: 16px; height: 16px; }

/* Theme-aware sun/moon visibility */
.icon-btn .i-sun { display: none; }
.icon-btn .i-moon { display: inline; }
[data-theme="dark"] .icon-btn .i-sun { display: inline; }
[data-theme="dark"] .icon-btn .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] .icon-btn .i-sun { display: inline; }
  [data-theme="auto"] .icon-btn .i-moon { display: none; }
}

/* ============== App main / Topbar slim ============== */
.app-main { display: flex; flex-direction: column; min-width: 0; }
.topbar-slim {
  height: var(--topbar-h); padding: 0 1.5rem;
  display: flex; align-items: center;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.quickbar-trigger {
  flex: 1; max-width: 560px; height: 36px;
  display: flex; align-items: center; gap: .6rem;
  background: var(--surface-soft); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 0 .75rem;
  cursor: pointer; color: var(--muted);
  transition: background .12s, border-color .12s;
}
.quickbar-trigger:hover { background: var(--surface-strong); border-color: var(--border-strong); }
.quickbar-trigger svg { width: 16px; height: 16px; opacity: .7; }
.quickbar-placeholder { flex: 1; text-align: left; font-size: .85rem; }
.kbd-hint { margin-left: auto; }

.container { max-width: 1200px; width: 100%; margin: 1.75rem auto 3rem; padding: 0 1.75rem; }

/* ============== Buttons ============== */
.btn-primary, .btn-secondary, .btn-danger {
  font-family: inherit; font-weight: 600; font-size: .9rem;
  border-radius: var(--r-md); padding: .55rem 1rem;
  cursor: pointer; border: 1px solid transparent;
  transition: transform .04s, box-shadow .15s, background .15s, border-color .15s;
  display: inline-flex; align-items: center; gap: .4rem; line-height: 1.2;
}
.btn-primary { background: var(--primary); color: var(--primary-fg); box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-sm); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-soft); border-color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-link { color: var(--primary); text-decoration: none; font-size: .9rem;
  font-weight: 500; padding: .25rem 0; }
.btn-link:hover { text-decoration: underline; }
button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: none; box-shadow: var(--ring-primary);
}

/* ============== Inputs ============== */
input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="password"],
select, textarea {
  font-family: inherit; font-size: .9rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); padding: .5rem .65rem;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

/* ============== Controls ============== */
.calendar-controls, .cra-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1rem;
  margin-bottom: 1.25rem;
}
.month-nav {
  display: inline-flex; align-items: center; gap: .25rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: .25rem; box-shadow: var(--shadow-xs);
}
.month-nav h2 { margin: 0; padding: 0 .75rem; font-size: 1rem; font-weight: 600;
  min-width: 11rem; text-align: center; }
.month-nav a {
  text-decoration: none; font-size: 1rem; padding: .35rem .65rem;
  border-radius: var(--r-md); color: var(--text-soft); font-weight: 600;
  transition: background .12s;
}
.month-nav a:hover { background: var(--surface-soft); color: var(--text); }
.contract-picker label { font-size: .85rem; color: var(--muted); margin-right: .4rem; }
.contract-picker select { min-width: 14rem; }
.quota-badge {
  background: var(--primary-soft); color: var(--primary);
  padding: .4rem .85rem; border-radius: 999px;
  font-size: .85rem; font-weight: 600;
}
.empty { color: var(--muted); font-style: italic; }

/* View switcher (Month/Week/Year) */
.view-switch {
  display: inline-flex; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 3px; gap: 2px; box-shadow: var(--shadow-xs);
}
.view-switch a {
  text-decoration: none; padding: .35rem .8rem; font-size: .85rem; font-weight: 600;
  color: var(--muted); border-radius: 7px; transition: background .12s, color .12s;
}
.view-switch a:hover { color: var(--text); }
.view-switch a.active { background: var(--primary); color: #fff; }

/* ============== Legend ============== */
.legend {
  list-style: none; display: flex; flex-wrap: wrap; gap: .5rem .9rem;
  padding: .6rem .85rem; margin: 0 0 .75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); font-size: .78rem; color: var(--text-soft);
}
.legend li { display: flex; align-items: center; gap: .4rem; }
.legend .sw {
  display: inline-block; width: .85rem; height: .85rem;
  border-radius: 4px; border: 1px solid rgba(0, 0, 0, .05);
}
.legend .sw.kind-WORK         { background: var(--kind-work-bg); }
.legend .sw.kind-REMOTE       { background: var(--kind-remote-bg); }
.legend .sw.kind-TRAINING     { background: var(--kind-training-bg); }
.legend .sw.kind-HALF_DAY_AM  { background: var(--kind-half-bg); }
.legend .sw.kind-LEAVE        { background: var(--kind-leave-bg); }
.legend .sw.kind-SICK         { background: var(--kind-sick-bg); }
.legend .sw.kind-PUBLIC_HOLIDAY { background: var(--kind-holiday-bg); }
.legend .sw.kind-ABSENCE      { background: var(--kind-absence-bg); }
.legend .sw.kind-WORK_T2      { background: var(--kind-t2-bg); }

/* ============== T2 settings ============== */
.t2-period {
  background: var(--surface-soft); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 1rem 1.1rem; margin-bottom: .9rem;
}
.t2-period h3 { margin: .1rem 0 .6rem; font-size: .95rem; }
.t2-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .65rem; }
.t2-dates {
  list-style: none; padding: 0; margin: .25rem 0 0;
  display: flex; flex-wrap: wrap; gap: .4rem;
}
.t2-dates li {
  display: flex; align-items: center; gap: .3rem;
  background: var(--kind-t2-bg); color: var(--warning);
  padding: .2rem .55rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600;
}
.t2-dates .btn-link { color: var(--warning); font-weight: 700; padding: 0 .15rem; line-height: 1; }
.inline-form { display: inline-flex; align-items: center; gap: .4rem; }

/* ============== Calendar grid ============== */
.calendar-grid {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm);
}
.calendar-grid th {
  padding: .55rem .75rem; font-size: .72rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-soft); border-bottom: 1px solid var(--border);
  text-align: left;
}
.calendar-grid td.cell {
  height: 6.5rem; vertical-align: top; padding: .45rem;
  border-top: 1px solid var(--border); border-left: 1px solid var(--border);
  cursor: pointer; position: relative; transition: background .12s, transform .04s;
}
.calendar-grid td.cell:first-child { border-left: 0; }
.calendar-grid tr:first-child td { border-top: 0; }
.calendar-grid td.cell:hover { background: var(--primary-soft); }
.cell .day-num { font-size: .85rem; font-weight: 600; color: var(--text-soft); }
.cell.out { background: var(--surface-soft); color: #cbd3df; }
.cell.out .day-num { color: var(--muted); opacity: .5; }
.cell.weekend { background: var(--weekend-bg); }
.cell.holiday { background: var(--holiday-bg); }
.cell.today { box-shadow: inset 0 0 0 2px var(--primary); }
.cell .tag { font-size: .68rem; color: #9a3030; margin-top: .1rem; font-weight: 600; }
.cell .entry {
  margin-top: .3rem; font-size: .72rem; padding: .15rem .4rem;
  background: rgba(255, 255, 255, .55); border-radius: 5px;
  display: inline-block; font-weight: 600; color: var(--text);
}
[data-theme="dark"] .cell .entry { background: rgba(0, 0, 0, .25); color: var(--text); }
@media (prefers-color-scheme: dark) { [data-theme="auto"] .cell .entry { background: rgba(0, 0, 0, .25); } }
.cell.has-entry { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .04); }
.cell.kind-WORK         { background: var(--kind-work-bg); }
.cell.kind-REMOTE       { background: var(--kind-remote-bg); }
.cell.kind-TRAINING     { background: var(--kind-training-bg); }
.cell.kind-HALF_DAY_AM,
.cell.kind-HALF_DAY_PM  { background: var(--kind-half-bg); }
.cell.kind-LEAVE        { background: var(--kind-leave-bg); }
.cell.kind-SICK         { background: var(--kind-sick-bg); }
.cell.kind-PUBLIC_HOLIDAY { background: var(--kind-holiday-bg); }
.cell.kind-ABSENCE      { background: var(--kind-absence-bg); }
.cell.kind-WORK_T2      { background: var(--kind-t2-bg); }
.cell.kind-HALF_DAY_AM_T2,
.cell.kind-HALF_DAY_PM_T2 { background: var(--kind-half-t2-bg); }
.cell.weekend.has-entry { border-left: 3px solid #c5cad5; }
.cell.holiday.has-entry { border-left: 3px solid #c87171; }
.cell.t2-eligible::after {
  content: "T2"; position: absolute; top: .25rem; right: .35rem;
  font-size: .58rem; font-weight: 700; color: #fff;
  background: var(--t2-marker); padding: 1px 5px; border-radius: 4px;
  letter-spacing: .03em; box-shadow: var(--shadow-xs);
}

/* ============== Modal (entry) ============== */
dialog#entry-modal {
  border: 0; border-radius: var(--r-lg); padding: 1.5rem;
  min-width: 22rem; box-shadow: var(--shadow-lg);
  background: var(--surface); color: var(--text);
}
dialog#entry-modal::backdrop { background: rgba(15, 23, 42, .55); backdrop-filter: blur(3px); }
dialog form label { display: block; margin: .65rem 0; font-size: .85rem; color: var(--muted); font-weight: 500; }
dialog form label select, dialog form label input { width: 100%; margin-top: .3rem; }
dialog form footer { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }

/* ============== Quick Bar modal ============== */
dialog.quickbar-modal {
  border: 0; padding: 0; background: transparent;
  margin-top: 8vh; max-width: 640px; width: 92vw;
}
dialog.quickbar-modal::backdrop {
  background: rgba(15, 23, 42, .55); backdrop-filter: blur(4px);
}
dialog.quickbar-modal form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg); overflow: hidden;
}
.qb-input-row {
  display: flex; align-items: center; gap: .65rem;
  padding: 1rem 1.1rem; border-bottom: 1px solid var(--border);
}
.qb-input-row svg { width: 20px; height: 20px; color: var(--muted); }
#quickbar-input {
  flex: 1; border: 0; outline: none; background: transparent;
  font-size: 1rem; color: var(--text); padding: 0;
}
#quickbar-input:focus { box-shadow: none; }
.qb-preview { padding: .85rem 1.1rem; font-size: .9rem; border-bottom: 1px solid var(--border);
  min-height: 2.4rem; }
.qb-preview.ok { color: var(--success); background: var(--success-soft); }
.qb-preview.error { color: var(--danger); background: var(--danger-soft); }
.qb-hints { padding: .75rem 1.1rem; font-size: .78rem; color: var(--muted);
  background: var(--surface-soft); }
.qb-hints div { margin: .15rem 0; }

/* ============== Toaster ============== */
.toaster {
  position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 100;
  display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
.toast {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: var(--r-md); padding: .65rem .9rem;
  box-shadow: var(--shadow-md); min-width: 16rem; max-width: 24rem;
  font-size: .88rem; pointer-events: auto;
  animation: toastIn .2s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============== Dashboard cards & KPIs ============== */
.dashboard-head h1 { margin: .25rem 0 1.5rem; }
.dashboard-section { margin-top: 2rem; }
.dashboard-section h2 { font-size: 1.05rem; margin-bottom: .85rem; }

.kpi-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: .85rem; margin-bottom: 1.5rem;
}
.kpi {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 1rem 1.1rem;
  box-shadow: var(--shadow-xs); position: relative; overflow: hidden;
}
.kpi-label { font-size: .72rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: .05em; font-weight: 600; }
.kpi-value { font-size: 1.6rem; font-weight: 700; margin-top: .35rem;
  letter-spacing: -0.02em; line-height: 1; }
.kpi-sub { font-size: .78rem; color: var(--muted); margin-top: .35rem; }
.kpi-sub.positive { color: var(--success); }
.kpi-sub.negative { color: var(--danger); }
.kpi-accent { position: absolute; top: 0; right: 0; width: 60px; height: 60px;
  background: radial-gradient(circle at 100% 0%, var(--primary-soft) 0%, transparent 70%);
  pointer-events: none; }
.kpi.success .kpi-accent { background: radial-gradient(circle at 100% 0%, var(--success-soft) 0%, transparent 70%); }
.kpi.warning .kpi-accent { background: radial-gradient(circle at 100% 0%, var(--warning-soft) 0%, transparent 70%); }
.kpi.danger .kpi-accent { background: radial-gradient(circle at 100% 0%, var(--danger-soft) 0%, transparent 70%); }
.kpi .spark { margin-top: .65rem; height: 26px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
  gap: 1rem;
}
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-xs);
  border-top: 3px solid var(--primary);
  transition: box-shadow .15s, transform .04s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card.status-green { border-top-color: var(--success); }
.card.status-orange { border-top-color: var(--warning); }
.card.status-red { border-top-color: var(--danger); }
.card header { display: flex; justify-content: space-between; align-items: center;
  gap: .5rem; margin-bottom: .8rem; }
.card header h3 { margin: 0; font-size: 1rem; }
.card .ref { color: var(--muted); font-weight: 400; font-size: .85rem; }

.badge {
  font-size: .7rem; padding: .2rem .55rem; border-radius: 999px;
  background: var(--surface-soft); color: var(--muted); font-weight: 600;
  border: 1px solid var(--border);
}
.badge-green  { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-orange { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-red    { background: var(--danger-soft);  color: var(--danger); border-color: transparent; }

.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: .5rem; margin: 0 0 .85rem; font-size: .85rem;
}
.stats-grid > div {
  background: var(--surface-soft); padding: .5rem .65rem;
  border-radius: var(--r-md); border: 1px solid var(--border);
}
.stats-grid dt { color: var(--muted); font-size: .68rem; text-transform: uppercase;
  letter-spacing: .05em; margin: 0; font-weight: 600; }
.stats-grid dd { margin: .15rem 0 0; font-weight: 700; font-size: 1rem; }
.stats-grid dd.positive { color: var(--success); }
.stats-grid dd.negative { color: var(--danger); }

.progress { height: 6px; background: var(--border); border-radius: 999px;
  overflow: hidden; margin: .25rem 0 .85rem; }
.progress .bar { height: 100%; background: var(--primary);
  border-radius: 999px; transition: width .25s; }
.card.status-orange .progress .bar { background: var(--warning); }
.card.status-red .progress .bar { background: var(--danger); }

.card-actions a { font-size: .85rem; color: var(--primary); text-decoration: none; font-weight: 500; }
.card-actions a:hover { text-decoration: underline; }

/* ============== Heatmap annuelle (style GitHub) ============== */
.heatmap-wrap {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow-xs); margin-bottom: 1.5rem;
  overflow-x: auto;
}
.heatmap-head { display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap; }
.heatmap-head h2 { margin: 0; }
.heatmap-controls { display: inline-flex; gap: .3rem; align-items: center; }
.heatmap-controls .year-nav {
  display: inline-flex; gap: .15rem; background: var(--surface-soft);
  border: 1px solid var(--border); border-radius: var(--r-md); padding: 2px;
}
.heatmap-controls .year-nav a, .heatmap-controls .year-nav span {
  text-decoration: none; padding: .25rem .55rem; font-size: .85rem;
  color: var(--text-soft); border-radius: 6px; font-weight: 600;
}
.heatmap-controls .year-nav a:hover { background: var(--surface); color: var(--text); }
.heatmap-controls .year-nav .current { background: var(--primary); color: #fff; }

.heatmap {
  display: grid; grid-auto-flow: column;
  grid-template-rows: auto repeat(7, 1fr); grid-auto-columns: 14px;
  gap: 3px; font-size: 10px; color: var(--muted);
}
.heatmap .col-label {
  grid-row: 1; font-size: 10px; color: var(--muted);
  font-weight: 500; text-align: left; padding-bottom: 2px;
  white-space: nowrap;
}
.heatmap .row-label {
  grid-column: 1; font-size: 10px; color: var(--muted);
  display: flex; align-items: center; padding-right: 4px;
}
.heatmap-week { display: contents; }
.heatmap-day {
  width: 14px; height: 14px; border-radius: 3px;
  background: var(--heat-0); cursor: default;
  position: relative;
  transition: transform .08s, box-shadow .08s;
}
.heatmap-day.h-1 { background: var(--heat-1); }
.heatmap-day.h-2 { background: var(--heat-2); }
.heatmap-day.h-3 { background: var(--heat-3); }
.heatmap-day.h-4 { background: var(--heat-4); }
/* Special-kind overlays as left bar */
.heatmap-day.kind-LEAVE  { background: var(--kind-leave-bg); }
.heatmap-day.kind-SICK   { background: var(--kind-sick-bg); }
.heatmap-day.kind-PUBLIC_HOLIDAY,
.heatmap-day.kind-ABSENCE { background: var(--kind-absence-bg); }
.heatmap-day.kind-WORK_T2,
.heatmap-day.kind-HALF_DAY_AM_T2,
.heatmap-day.kind-HALF_DAY_PM_T2 {
  background: var(--kind-t2-bg);
  box-shadow: inset 0 0 0 1px var(--t2-marker);
}
.heatmap-day:hover { transform: scale(1.4); z-index: 5; box-shadow: var(--shadow-sm); }
.heatmap-day.empty { background: transparent; cursor: default; }
.heatmap-day.today { box-shadow: inset 0 0 0 2px var(--primary); }
.heatmap-day a { display: block; width: 100%; height: 100%; border-radius: inherit; }

.heatmap-legend {
  display: flex; align-items: center; justify-content: flex-end; gap: .35rem;
  font-size: .72rem; color: var(--muted); margin-top: .9rem;
}
.heatmap-legend .scale { display: inline-flex; gap: 2px; }
.heatmap-legend .scale i {
  width: 12px; height: 12px; border-radius: 3px; display: inline-block;
}

/* ============== Tables ============== */
.leave-table, .cra-history, .data-table {
  width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  overflow: hidden; border-collapse: separate; border-spacing: 0;
  box-shadow: var(--shadow-xs);
}
.leave-table th, .cra-history th, .data-table th {
  text-align: left; padding: .65rem .85rem;
  background: var(--surface-soft); color: var(--muted);
  font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.leave-table td, .cra-history td, .data-table td {
  padding: .65rem .85rem; border-bottom: 1px solid var(--border);
  font-size: .9rem; vertical-align: middle;
}
.leave-table tr:last-child td, .cra-history tr:last-child td, .data-table tr:last-child td {
  border-bottom: 0;
}
.data-table tr:hover td, .cra-history tr:hover td, .leave-table tr:hover td { background: var(--surface-soft); }
.data-table input[type="text"], .data-table input[type="date"],
.data-table input[type="email"], .data-table input[type="number"] {
  width: 100%; padding: .35rem .5rem; font-size: .85rem;
}

/* ============== CRA preview head ============== */
.cra-head h1 { margin: .25rem 0; display: flex; align-items: center; gap: .7rem; }
.cra-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0 1rem; }
.cra-actions button {
  font-family: inherit; padding: .5rem .9rem; border-radius: var(--r-md);
  border: 1px solid var(--border-strong); background: var(--surface);
  cursor: pointer; font-weight: 600; font-size: .88rem;
  transition: background .15s, border-color .15s;
}
.cra-actions button:hover { background: var(--surface-soft); }
.cra-actions .btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.cra-actions .btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.cra-actions .btn-link { padding: .5rem .9rem; color: var(--primary); text-decoration: none; font-weight: 500; }

/* ============== CRA grid (smaller monthly view) ============== */
.cra-grid {
  width: 100%; border-collapse: separate; border-spacing: 0; margin: 1rem 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-xs);
}
.cra-grid th {
  padding: .5rem .65rem; font-size: .7rem; font-weight: 600;
  background: var(--surface-soft); color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); text-align: left;
}
.cra-grid td.cra-cell {
  border-top: 1px solid var(--border); border-left: 1px solid var(--border);
  padding: .45rem; height: 4.7rem; vertical-align: top;
  font-size: .78rem; background: var(--surface); position: relative;
}
.cra-grid td.cra-cell:first-child { border-left: 0; }
.cra-grid tr:first-child td { border-top: 0; }
.cra-cell.t2-eligible::after {
  content: "T2"; position: absolute; top: .25rem; right: .3rem;
  font-size: .55rem; font-weight: 700; color: #fff;
  background: var(--t2-marker); padding: 1px 4px; border-radius: 3px;
}
.cra-grid td.cra-cell.out { background: var(--surface-soft); color: var(--muted); opacity: .55; }
.cra-grid td.cra-cell.weekend { background: var(--weekend-bg); }
.cra-grid td.cra-cell.holiday { background: var(--holiday-bg); }
.cra-cell .num { font-weight: 600; font-size: .85rem; color: var(--text-soft); }
.cra-cell .code {
  display: inline-block; background: rgba(255, 255, 255, .65); padding: .1rem .4rem;
  border-radius: 4px; font-size: .72rem; margin-top: .2rem; font-weight: 600; color: var(--text);
}
[data-theme="dark"] .cra-cell .code { background: rgba(0, 0, 0, .25); }
@media (prefers-color-scheme: dark) { [data-theme="auto"] .cra-cell .code { background: rgba(0, 0, 0, .25); } }
.cra-grid td.cra-cell.kind-WORK         { background: var(--kind-work-bg); }
.cra-grid td.cra-cell.kind-REMOTE       { background: var(--kind-remote-bg); }
.cra-grid td.cra-cell.kind-TRAINING     { background: var(--kind-training-bg); }
.cra-grid td.cra-cell.kind-HALF_DAY_AM,
.cra-grid td.cra-cell.kind-HALF_DAY_PM  { background: var(--kind-half-bg); }
.cra-grid td.cra-cell.kind-LEAVE        { background: var(--kind-leave-bg); }
.cra-grid td.cra-cell.kind-SICK         { background: var(--kind-sick-bg); }
.cra-grid td.cra-cell.kind-PUBLIC_HOLIDAY { background: var(--kind-holiday-bg); }
.cra-grid td.cra-cell.kind-ABSENCE      { background: var(--kind-absence-bg); }
.cra-grid td.cra-cell.kind-WORK_T2      { background: var(--kind-t2-bg); }
.cra-grid td.cra-cell.kind-HALF_DAY_AM_T2,
.cra-grid td.cra-cell.kind-HALF_DAY_PM_T2 { background: var(--kind-half-t2-bg); }
.cra-cell .qty { float: right; color: var(--muted); font-size: .72rem; font-weight: 600; }

/* ============== Week view ============== */
.week-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: .65rem;
  margin: 1rem 0;
}
.week-day {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: .85rem .9rem;
  box-shadow: var(--shadow-xs); min-height: 11rem;
  display: flex; flex-direction: column; gap: .5rem;
  position: relative; transition: box-shadow .12s;
}
.week-day:hover { box-shadow: var(--shadow-sm); }
.week-day.weekend { background: var(--weekend-bg); }
.week-day.holiday { background: var(--holiday-bg); }
.week-day.today { box-shadow: 0 0 0 2px var(--primary), var(--shadow-sm); }
.week-day.t2-eligible::after {
  content: "T2"; position: absolute; top: .35rem; right: .55rem;
  font-size: .6rem; font-weight: 700; color: #fff;
  background: var(--t2-marker); padding: 1px 6px; border-radius: 5px;
}
.week-day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 1px solid var(--border); padding-bottom: .35rem;
}
.week-day-head .dow { font-size: .72rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.week-day-head .dom { font-size: 1.4rem; font-weight: 700; color: var(--text); line-height: 1; }
.week-day .holi-name { font-size: .7rem; color: #9a3030; font-weight: 600; }
.week-day-kind, .week-day-qty {
  width: 100%; font-size: .85rem; padding: .35rem .45rem;
  border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface);
}
.week-day-qty { width: 100%; }
.week-day-comment { font-size: .8rem; color: var(--muted); font-style: italic; }
.week-day.kind-WORK         { background: var(--kind-work-bg); }
.week-day.kind-REMOTE       { background: var(--kind-remote-bg); }
.week-day.kind-TRAINING     { background: var(--kind-training-bg); }
.week-day.kind-HALF_DAY_AM,
.week-day.kind-HALF_DAY_PM  { background: var(--kind-half-bg); }
.week-day.kind-LEAVE        { background: var(--kind-leave-bg); }
.week-day.kind-SICK         { background: var(--kind-sick-bg); }
.week-day.kind-PUBLIC_HOLIDAY { background: var(--kind-holiday-bg); }
.week-day.kind-ABSENCE      { background: var(--kind-absence-bg); }
.week-day.kind-WORK_T2      { background: var(--kind-t2-bg); }
.week-day.kind-HALF_DAY_AM_T2,
.week-day.kind-HALF_DAY_PM_T2 { background: var(--kind-half-t2-bg); }

/* ============== CRA totals tables ============== */
.cra-totals {
  border-collapse: separate; border-spacing: 0; max-width: 26rem;
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow-xs);
}
.cra-totals th, .cra-totals td {
  padding: .5rem .85rem; border-bottom: 1px solid var(--border);
  font-size: .88rem; text-align: left;
}
.cra-totals tr:last-child td { border-bottom: 0; }
.cra-totals th { background: var(--surface-soft); color: var(--muted);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.cra-totals .total-row { background: var(--primary-soft); }
.cra-totals .total-row td { color: var(--primary); font-weight: 700; }

/* ============== Status tags ============== */
.status-tag {
  padding: .2rem .55rem; border-radius: 999px;
  font-size: .7rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
}
.status-tag.status-draft, .status-tag.status-closed, .status-tag.status-suspended {
  background: var(--surface-soft); color: var(--muted); border: 1px solid var(--border);
}
.status-tag.status-submitted { background: var(--warning-soft); color: var(--warning); }
.status-tag.status-validated, .status-tag.status-active { background: var(--success-soft); color: var(--success); }
.status-tag.status-rejected { background: var(--danger-soft); color: var(--danger); }

/* ============== Settings ============== */
.settings-head { margin-bottom: 1rem; }
.settings-head h1 { margin: .25rem 0; }
.settings-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1rem;
}
.settings-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 1.4rem 1.5rem; margin-top: 1.25rem;
  box-shadow: var(--shadow-xs);
}
.settings-section h2 { margin-top: 0; font-size: 1.1rem; }
.settings-section h3 { font-size: .95rem; margin: 1.5rem 0 .6rem; color: var(--text-soft); }

.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem 1.25rem;
}
.form-grid label { display: flex; flex-direction: column; font-size: .8rem;
  color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.form-grid label input, .form-grid label select, .form-grid label textarea {
  margin-top: .3rem; font-size: .92rem; text-transform: none; letter-spacing: 0;
  font-weight: 400; color: var(--text);
}
.form-grid label input[type="checkbox"] { width: auto; margin-top: .4rem; }
.form-grid .form-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .25rem; }

/* ============== Alert ============== */
.alert {
  padding: .75rem 1rem; border-radius: var(--r-md);
  margin-bottom: 1rem; font-size: .9rem; font-weight: 500;
  display: flex; align-items: center; gap: .5rem;
}
.alert-error {
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid var(--danger);
}

/* ============== Responsive ============== */
@media (max-width: 900px) {
  body { grid-template-columns: 0 1fr; }
  .sidebar { position: fixed; left: -260px; width: 260px; transition: left .2s; }
  .sidebar.open { left: 0; }
  .week-grid { grid-template-columns: 1fr; }
}

/* ---------- Login ---------- */
.login-body {
  display: grid;
  /* Override the global app body grid-template-columns (sidebar+content)
     so place-items: center centers on the full viewport, not in the
     sidebar column. */
  grid-template-columns: 1fr;
  place-items: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-wrap { width: 100%; max-width: 380px; padding: 24px; }
.login-card { display: flex; flex-direction: column; gap: 14px; padding: 32px; }
.login-logo { display: block; max-width: 120px; max-height: 60px; margin: 0 auto 8px;
  object-fit: contain; }
.login-title { margin: 0; font-size: 1.4rem; text-align: center; }
.login-sub { margin: 0 0 8px; color: var(--muted); text-align: center; }
.login-card .form-full { display: flex; flex-direction: column; gap: 6px; }
.login-card .form-actions { margin-top: 8px; }
.login-card .btn-primary { width: 100%; }
