/* ============================================================
   TimeInvoice Pro Suite — stylesheet
   Aesthetic: Swiss-design influenced refined minimalism.
   Body: Manrope · Mono: JetBrains Mono
   ============================================================ */

:root {
  --c-bg:        #fafaf7;
  --c-surface:   #ffffff;
  --c-surface-2: #f4f3ee;
  --c-border:    #e7e5e0;
  --c-border-2:  #d6d3cc;
  --c-text:      #1c1c1a;
  --c-text-2:    #5a5852;
  --c-text-3:    #8a8780;
  --c-accent:    #2a52be;
  --c-accent-2:  #1f3f95;
  --c-success:   #117a3a;
  --c-warning:   #b56705;
  --c-danger:    #b91c1c;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 12px rgba(0,0,0,.06);
  --radius:    8px;
  --radius-sm: 4px;

  --font-sans: 'Manrope', -apple-system, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
}

[data-theme="dark"] {
  --c-bg:        #0e0e0c;
  --c-surface:   #1a1a17;
  --c-surface-2: #232320;
  --c-border:    #2c2c28;
  --c-border-2:  #3d3d38;
  --c-text:      #f4f3ee;
  --c-text-2:    #b0aea6;
  --c-text-3:    #797770;
  --c-accent:    #6b8aff;
  --c-accent-2:  #93a9ff;
  --c-success:   #4ade80;
  --c-warning:   #fbbf24;
  --c-danger:    #f87171;
  --shadow:      0 4px 12px rgba(0,0,0,.4);
  --shadow-sm:   0 1px 2px rgba(0,0,0,.3);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
  transition: background .25s, color .25s;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- App layout ---------- */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ============== SIDEBAR ============== */
.sidebar {
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky; top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px 18px;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 14px;
}
.brand__logo {
  width: 38px; height: 38px;
  background: var(--c-text);
  color: var(--c-bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -.5px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}
.brand__logo span { opacity: .55; margin: 0 1px; }
.brand__title { font-weight: 700; font-size: 14px; letter-spacing: -.3px; }
.brand__sub   { font-size: 11px; color: var(--c-text-3); letter-spacing: 1.2px; text-transform: uppercase; margin-top: 1px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav__item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--c-text-2);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav__item:hover { background: var(--c-surface-2); color: var(--c-text); }
.nav__item.is-active {
  background: var(--c-text);
  color: var(--c-bg);
  font-weight: 600;
}
.nav__icon { width: 18px; text-align: center; opacity: .85; }

.sidebar__bottom { border-top: 1px solid var(--c-border); padding-top: 12px; }
.theme-toggle {
  width: 100%;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-2);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.theme-toggle:hover { background: var(--c-surface-2); }
[data-theme="light"] .theme-toggle .t-dark  { display: inline; }
[data-theme="light"] .theme-toggle .t-light { display: none; }
[data-theme="dark"]  .theme-toggle .t-dark  { display: none; }
[data-theme="dark"]  .theme-toggle .t-light { display: inline; }

.profile-badge {
  margin-top: 10px;
  font-size: 12px;
  color: var(--c-text-3);
  padding: 6px 10px;
  text-align: center;
}

/* ============== MAIN ============== */
.main {
  padding: 28px 36px 60px;
  max-width: 1280px;
  width: 100%;
}
.route { display: none; }
.route.is-visible { display: block; animation: fadeUp .3s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 28px; padding-bottom: 16px; border-bottom: 1px solid var(--c-border);
}
.page-head h1 {
  font-size: 30px; font-weight: 800; margin: 0; letter-spacing: -1px; line-height: 1;
}
.page-head .sub {
  font-size: 13px; color: var(--c-text-3); margin-top: 6px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--c-border-2);
  background: var(--c-surface);
  color: var(--c-text);
  border-radius: var(--radius-sm);
  font-weight: 500; font-size: 13px;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--c-surface-2); }
.btn--primary {
  background: var(--c-text); color: var(--c-bg); border-color: var(--c-text);
}
.btn--primary:hover { background: var(--c-text-2); }
.btn--accent {
  background: var(--c-accent); color: #fff; border-color: var(--c-accent);
}
.btn--accent:hover { background: var(--c-accent-2); }
.btn--danger { color: var(--c-danger); border-color: var(--c-danger); }
.btn--danger:hover { background: var(--c-danger); color: #fff; }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--icon { padding: 6px 8px; line-height: 1; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--c-border);
  color: var(--c-text-2);
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 16px;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  vertical-align: middle;
  flex: 0 0 36px;
  box-sizing: border-box;
}
.icon-btn:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
  border-color: var(--c-border-2);
}
/* ensure consistent spacing when several icon-btns sit together */
.actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap;
}
.actions > * { flex: 0 0 auto; }
/* keep emojis crisp and same baseline across rows */
.icon-btn { font-feature-settings: normal; }
.icon-btn svg,
.nav__icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  flex: 0 0 18px;
  stroke: currentColor;
  fill: none;
  vertical-align: middle;
}
.nav__icon { margin-right: 10px; }
.nav__item { display: flex; align-items: center; }

/* ---------- Cards / KPI ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.kpi {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  padding: 18px;
  border-radius: var(--radius);
}
.kpi .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--c-text-3); margin-bottom: 8px;
}
.kpi .value {
  font-family: var(--font-mono);
  font-size: 26px; font-weight: 700; letter-spacing: -.5px;
}
.kpi .delta {
  font-size: 11px; color: var(--c-text-3); margin-top: 4px;
}

/* ---------- Section box ---------- */
.box {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.box__head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.box__head h2 {
  font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -.3px;
}

/* ---------- Calendar ---------- */
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.cal-head .month-name {
  font-size: 17px; font-weight: 700; letter-spacing: -.3px;
  font-feature-settings: "tnum";
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-grid .dow {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--c-text-3); text-align: center; padding: 6px 0;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 5px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative;
  min-height: 80px;
}
.cal-cell:hover { background: var(--c-surface-2); border-color: var(--c-border-2); }
.cal-cell.is-today { border-color: var(--c-accent); border-width: 2px; }
.cal-cell.is-other { opacity: .35; }
.cal-cell.is-selected { background: var(--c-text); color: var(--c-bg); border-color: var(--c-text); }
.cal-cell.is-selected .cal-cell__day,
.cal-cell.is-selected .cal-cell__dot { color: var(--c-bg); }

.cal-cell__hours {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 10.5px;
  background: var(--c-accent);
  color: #fff;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: .2px;
}
.cal-cell.is-selected .cal-cell__hours { background: var(--c-bg); color: var(--c-text); }

.cal-cell__day {
  align-self: flex-end;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14px;
  color: var(--c-text);
}
.cal-cell.has-entries:not(.is-selected):not(.is-today) {
  background: linear-gradient(180deg, var(--c-surface) 0%, var(--c-surface-2) 100%);
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--c-border); }
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--c-surface);
}
table.data th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--c-text-3);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface-2);
}
table.data td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--c-border);
  font-size: 13.5px;
}
table.data tr:last-child td { border-bottom: none; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
table.data td.actions { white-space: nowrap; text-align: right; }
table.data tr:hover td { background: var(--c-surface-2); }

/* ---------- Pills / status ---------- */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  border: 1px solid var(--c-border-2);
}
.pill.draft   { background: var(--c-surface-2); color: var(--c-text-2); }
.pill.sent    { background: rgba(42,82,190,.1);  color: var(--c-accent);  border-color: rgba(42,82,190,.3); }
.pill.paid    { background: rgba(17,122,58,.1);  color: var(--c-success); border-color: rgba(17,122,58,.3); }
.pill.overdue { background: rgba(185,28,28,.1);  color: var(--c-danger);  border-color: rgba(185,28,28,.3); }

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 18px;
}
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--c-text-3);
  font-weight: 600;
}
.field input,
.field select,
.field textarea {
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border-2);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(42,82,190,.12);
}
.field textarea { min-height: 70px; resize: vertical; }

/* multi-client picker */
.client-picker {
  border: 1px solid var(--c-border-2);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  max-height: 180px;
  overflow-y: auto;
  padding: 6px;
}
.client-picker__row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}
.client-picker__row:hover { background: var(--c-surface-2); }
.client-picker__row input { margin: 0; }
.client-picker__rate { margin-left: auto; color: var(--c-text-3); font-family: var(--font-mono); font-size: 11px; }

/* preset chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  font-size: 11.5px;
  cursor: pointer;
  font-family: var(--font-mono);
}
.chip:hover { background: var(--c-text); color: var(--c-bg); }

.hint {
  font-size: 11px; color: var(--c-text-3); margin-top: 3px;
}

/* ---------- Modal ---------- */
.modal-root { position: fixed; inset: 0; display: none; z-index: 50; }
.modal-root.is-open { display: block; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}
.modal {
  position: relative;
  margin: 6vh auto;
  width: min(640px, 92vw);
  max-height: 86vh;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: zoomIn .18s ease;
}
@keyframes zoomIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
}
.modal__header h3 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.3px; }
.modal__body { padding: 20px; overflow-y: auto; flex: 1; }
.modal__footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
}

/* wider modal variant */
.modal--wide .modal { width: min(900px, 95vw); }

/* ---------- Heatmap (dashboard) ---------- */
.heat {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.heat__cell {
  aspect-ratio: 1 / 1;
  border-radius: 3px;
  background: var(--c-surface-2);
}
.heat__cell.h1 { background: rgba(42,82,190,.25); }
.heat__cell.h2 { background: rgba(42,82,190,.5); }
.heat__cell.h3 { background: rgba(42,82,190,.75); }
.heat__cell.h4 { background: var(--c-accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--c-text); color: var(--c-bg);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 60;
}
.toast.is-show { opacity: 1; transform: none; }
.toast.is-error { background: var(--c-danger); color: #fff; }

/* ---------- helpers ---------- */
.row-flex { display: flex; gap: 10px; align-items: center; }
.row-flex.between { justify-content: space-between; }
.muted { color: var(--c-text-3); }
.tnum  { font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.divider { height: 1px; background: var(--c-border); margin: 14px 0; }
.empty {
  padding: 50px 20px;
  text-align: center;
  color: var(--c-text-3);
  font-size: 13px;
}

/* ---------- responsive ---------- */
/* (legacy mobile rules removed — now handled by the drawer media query below) */

/* ============================================================
   AUTH PAGES (login.php, setup.php)
   ============================================================ */
.auth-body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fafaf7 0%, #ece9e0 100%);
  font-family: 'Manrope', system-ui, sans-serif;
  padding: 24px;
}
@media (prefers-color-scheme: dark) {
  .auth-body { background: linear-gradient(135deg, #0e0e0c 0%, #1a1a17 100%); color: #f4f3ee; }
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border: 1px solid #e5e2d8;
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.18);
}
@media (prefers-color-scheme: dark) {
  .auth-card { background: #1c1c19; border-color: #2c2c28; }
}
.auth-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}
.auth-mark {
  width: 44px; height: 44px;
  border-radius: 11px;
  background: #2a52be;
  display: inline-block;
  position: relative;
}
.auth-mark::after {
  content: 'T·I';
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.auth-brand p {
  margin: 2px 0 0 0;
  font-size: 13px;
  color: #6b6760;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.auth-form label span {
  font-weight: 500;
  color: #5b5852;
}
.auth-form input {
  padding: 11px 13px;
  border: 1px solid #d8d4c8;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: #1c1c1a;
}
.auth-form input:focus {
  outline: none;
  border-color: #2a52be;
  box-shadow: 0 0 0 3px rgba(42, 82, 190, 0.12);
}
@media (prefers-color-scheme: dark) {
  .auth-form input { background: #2c2c28; border-color: #3a3a35; color: #f4f3ee; }
  .auth-brand p, .auth-form label span { color: #a09b91; }
}
.auth-btn {
  margin-top: 6px;
  padding: 12px 16px;
  border: 0;
  border-radius: 8px;
  background: #2a52be;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.auth-btn:hover { background: #1f3f93; }
.auth-error {
  background: #fdecea;
  color: #8c2519;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid #f5c5be;
}
.auth-success {
  background: #ebf6ee;
  color: #1f6336;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid #c4e2ce;
}
.auth-success a {
  color: #1f6336;
  font-weight: 600;
}
.auth-foot {
  margin-top: 20px;
  font-size: 12px;
  color: #8a857b;
  text-align: center;
}

/* sidebar additions for auth-aware UI */
.profile-badge__name { font-weight: 600; font-size: 13px; color: var(--c-text); }
.profile-badge__role { font-size: 11px; color: var(--c-text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.signout {
  display: block;
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--c-text-muted);
  text-decoration: none;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  text-align: center;
  transition: all 0.15s;
}
.signout:hover {
  color: var(--c-text);
  border-color: var(--c-border-2);
  background: var(--c-surface-2);
}

/* inline checkbox + label inside a form-grid cell */
.field--inline {
  flex-direction: row !important;
  align-items: center;
  gap: 10px !important;
}
.field--inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex: 0 0 auto;
  cursor: pointer;
}
.field--inline span {
  font-size: 13px;
  color: var(--c-text);
  cursor: pointer;
}

/* hint banner inside form-grids (e.g., "no clients yet") */
.hint {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
  border: 1px solid var(--c-border);
  background: var(--c-surface-2);
  color: var(--c-text);
}
.hint--warn {
  background: rgba(225, 165, 60, 0.12);
  border-color: rgba(225, 165, 60, 0.45);
  color: var(--c-text);
}
.hint strong { color: var(--c-text); }
.hint em { font-style: normal; font-weight: 600; }

/* logo images (replace text fallback when assets/img/logo.* exists) */
.brand__img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: contain;
  background: var(--c-surface);
  padding: 4px;
  flex: 0 0 44px;
}
.auth-logo {
  width: 52px;
  height: 52px;
  border-radius: 11px;
  object-fit: contain;
  background: #fff;
  padding: 6px;
  flex: 0 0 52px;
  box-shadow: 0 4px 12px -4px rgba(0,0,0,0.15);
}
@media (prefers-color-scheme: dark) {
  .auth-logo { background: #f4f3ee; }
}

/* ============================================================
   THEME-AWARE LOGO SWAP
   Show only the logo matching the current data-theme.
   Falls back gracefully if only one of the two exists.
   ============================================================ */
[data-theme="dark"]  .logo--light { display: none !important; }
[data-theme="light"] .logo--dark  { display: none !important; }

/* keep the brand row clean even if the wrapper holds 2 imgs */
.brand__imgwrap {
  display: contents;
}

/* auth pages: respect data-theme on <html> instead of OS preference */
[data-theme="dark"] .auth-body {
  background: linear-gradient(135deg, #0e0e0c 0%, #1a1a17 100%);
  color: #f4f3ee;
}
[data-theme="dark"] .auth-card {
  background: #1c1c19;
  border-color: #2c2c28;
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.6);
}
[data-theme="dark"] .auth-brand p,
[data-theme="dark"] .auth-form label span { color: #a09b91; }
[data-theme="dark"] .auth-form input {
  background: #2c2c28;
  border-color: #3a3a35;
  color: #f4f3ee;
}
[data-theme="dark"] .auth-logo { background: #f4f3ee; }
[data-theme="dark"] .auth-foot { color: #6f6a60; }

/* ============================================================
   INVOICE PREVIEW (inside generate-invoice modal)
   ============================================================ */
.inv-prev__head {
  font-size: 13px;
  color: var(--c-text);
  margin-bottom: 10px;
}
.inv-prev__tbl {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  margin-bottom: 12px;
}
.data--compact th, .data--compact td {
  padding: 6px 10px;
  font-size: 12.5px;
}
.inv-prev__totals {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  font-size: 13px;
}
.inv-prev__totals > div {
  display: flex;
  gap: 16px;
  min-width: 220px;
  justify-content: space-between;
}
.inv-prev__totals .muted { color: var(--c-text-muted); }
.inv-prev__grand {
  border-top: 1px solid var(--c-border);
  padding-top: 6px;
  margin-top: 4px;
  font-size: 15px;
}
.inv-prev__grand strong { font-size: 16px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   MOBILE TOPBAR + HAMBURGER  (visible only on small screens)
   ============================================================ */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 50;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  height: 56px;
}
.topbar__btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  border-radius: 8px;
  cursor: pointer;
  color: var(--c-text);
  text-decoration: none;
  font-size: 18px;
}
.topbar__btn:hover { background: var(--c-surface-2); }
.topbar__title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  color: var(--c-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar__logo {
  width: 28px; height: 28px;
  border-radius: 6px;
  object-fit: contain;
  flex: 0 0 28px;
}
.hamburger {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  width: 18px;
}
.hamburger > span {
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
body.menu-open .hamburger > span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.menu-open .hamburger > span:nth-child(2) { opacity: 0; }
body.menu-open .hamburger > span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 60;
  opacity: 0;
  transition: opacity 0.2s;
}
body.menu-open .sidebar-backdrop { opacity: 1; }

/* ============================================================
   RESPONSIVE LAYOUT
   ============================================================ */
@media (max-width: 980px) {
  .topbar { display: flex; }

  /* sidebar becomes a slide-out drawer */
  .app {
    grid-template-columns: 1fr !important;
    display: block !important;
  }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: min(82vw, 320px);
    height: 100vh;          /* explicit so flex children get proper space */
    height: 100dvh;         /* better on mobile (handles dynamic toolbars) */
    max-height: 100vh;
    max-height: 100dvh;
    z-index: 70;
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    box-shadow: 0 0 40px -10px rgba(0,0,0,0.4);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 16px 14px;
  }
  /* nav must claim the leftover space without collapsing */
  .sidebar > .nav {
    flex: 1 1 auto !important;
    min-height: 0;
    display: flex !important;
    flex-direction: column;
    overflow-y: auto;       /* if too many items, scroll within nav */
  }
  /* nav buttons full-width and visible (some flex contexts collapse them) */
  .sidebar .nav__item {
    width: 100%;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .sidebar__bottom {
    flex: 0 0 auto;
    margin-top: auto;
  }
  body.menu-open .sidebar { transform: translateX(0); }
  body.menu-open .sidebar-backdrop { display: block; }

  .main {
    padding: 14px !important;
  }

  /* page heads stack vertically and the action button goes full width */
  .page-head {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .page-head h1 { font-size: 22px !important; }
  .page-head .btn { width: 100%; }

  /* form grids collapse to single column */
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  /* dashboard KPIs single column on phones */
  .kpis {
    grid-template-columns: 1fr 1fr !important;
  }

  /* let big tables scroll horizontally so they never break the layout */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .data {
    min-width: 560px;
  }
  .data th, .data td {
    padding: 8px 10px !important;
    font-size: 13px !important;
  }

  /* modals fill nearly the whole viewport */
  .modal {
    width: calc(100vw - 24px) !important;
    max-width: 100% !important;
    max-height: calc(100vh - 24px);
  }
  .modal__body { max-height: 60vh; overflow-y: auto; }
  .modal__footer { flex-wrap: wrap; gap: 8px; }
  .modal__footer .btn { flex: 1 1 auto; }

  /* calendar shrinks */
  .cal-grid {
    gap: 4px !important;
  }
  .cal-day {
    min-height: 56px !important;
    padding: 4px !important;
    font-size: 12px;
  }
  .cal-day__num { font-size: 13px !important; }

  /* invoice preview totals stretch */
  .inv-prev__totals { align-items: stretch; }
  .inv-prev__totals > div { min-width: 0; }

  /* hide redundant signout in sidebar (it's in topbar already) */
  .signout { margin-top: 14px; }
}

@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr !important; }
  .topbar__title span { display: none; }       /* keep just logo on tiny phones */
  .main { padding: 10px !important; }
  .auth-card { padding: 22px !important; }
}

/* prevent body scroll while drawer is open */
body.menu-open { overflow: hidden; }

/* ============================================================
   INVOICES — filter bar + aggregate KPIs + clickable rows
   ============================================================ */
.inv-filterbar {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.inv-filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 240px;
  max-width: 360px;
}
.inv-filter span {
  font-size: 11px;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.inv-filter select {
  padding: 9px 12px;
  border: 1px solid var(--c-border-2);
  border-radius: 8px;
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 13px;
  font-family: inherit;
}
.btn--ghost {
  background: transparent;
  border: 1px solid var(--c-border-2);
  color: var(--c-text-muted);
  font-size: 12px;
  padding: 9px 14px;
}
.btn--ghost:hover { color: var(--c-text); border-color: var(--c-text-muted); }

.inv-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.inv-kpi {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.inv-kpi__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--c-text-muted);
  font-weight: 600;
}
.inv-kpi__val {
  font-size: 22px;
  font-weight: 700;
  color: var(--c-text);
  line-height: 1.1;
  word-break: break-word;
}
.inv-kpi__unit {
  font-size: 13px;
  color: var(--c-text-muted);
  margin-left: 2px;
  font-weight: 500;
}
.inv-kpi__sub {
  font-size: 11px;
  color: var(--c-text-muted);
  margin-top: 2px;
}
.inv-kpi__split {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.inv-kpi__split .pill {
  font-size: 10.5px;
  padding: 3px 8px;
}

/* clickable rows in invoices table */
.data--clickable .row-clickable { cursor: pointer; }
.data--clickable .row-clickable:hover { background: var(--c-surface-2); }
.data--clickable .row-clickable .actions a,
.data--clickable .row-clickable .actions button { cursor: pointer; }

/* mobile tweaks for invoice KPIs */
@media (max-width: 980px) {
  .inv-kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .inv-kpi { padding: 10px 12px; }
  .inv-kpi__val { font-size: 17px; }
}
@media (max-width: 480px) {
  .inv-kpis { grid-template-columns: 1fr; }
}

/* theme toggle: align icon + label */
.theme-toggle .t-light,
.theme-toggle .t-dark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
[data-theme="light"] .theme-toggle .t-light { display: none !important; }
[data-theme="dark"]  .theme-toggle .t-dark  { display: none !important; }

/* topbar SVGs inherit size and color from button */
.topbar__btn svg { display: block; }

/* ============================================================
   DASHBOARD — month nav + improved heatmap
   ============================================================ */
.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.month-nav .btn--sm {
  padding: 7px 12px;
  font-size: 12px;
}
.kpi__unit {
  font-size: 14px;
  color: var(--c-text-muted);
  margin-left: 3px;
  font-weight: 500;
}

/* dotted heatmap (calendar layout) */
.heat--cal {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.heat__dows {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.heat__dow {
  font-size: 10px;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  text-align: center;
  padding-bottom: 2px;
}
.heat__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.heat__cell {
  aspect-ratio: 1 / 1;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: 6px;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 4px 6px;
  font-size: 10.5px;
  color: var(--c-text-muted);
  font-variant-numeric: tabular-nums;
  transition: transform 0.1s;
}
.heat__cell:hover { transform: scale(1.05); z-index: 1; }
.heat__cell--blank {
  visibility: hidden;
  border: none;
}
.heat__cell--today {
  outline: 2px solid var(--c-accent, #2a52be);
  outline-offset: -1px;
}
.heat__num {
  font-weight: 600;
  color: inherit;
}
.heat__cell.h1 { background: rgba(42, 82, 190, 0.18); border-color: rgba(42, 82, 190, 0.3); color: var(--c-text); }
.heat__cell.h2 { background: rgba(42, 82, 190, 0.36); border-color: rgba(42, 82, 190, 0.5); color: var(--c-text); }
.heat__cell.h3 { background: rgba(42, 82, 190, 0.58); border-color: rgba(42, 82, 190, 0.75); color: #fff; }
.heat__cell.h4 { background: rgba(42, 82, 190, 0.85); border-color: rgba(42, 82, 190, 1); color: #fff; }

[data-theme="dark"] .heat__cell.h1 { background: rgba(107, 138, 255, 0.18); border-color: rgba(107, 138, 255, 0.3); }
[data-theme="dark"] .heat__cell.h2 { background: rgba(107, 138, 255, 0.36); border-color: rgba(107, 138, 255, 0.5); }
[data-theme="dark"] .heat__cell.h3 { background: rgba(107, 138, 255, 0.6);  border-color: rgba(107, 138, 255, 0.8); color: #fff; }
[data-theme="dark"] .heat__cell.h4 { background: rgba(107, 138, 255, 0.9);  border-color: rgba(107, 138, 255, 1);   color: #fff; }

.heat__legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--c-text-muted);
  margin-top: 6px;
}
.heat__legend .heat__cell {
  width: 14px;
  height: 14px;
  aspect-ratio: auto;
  padding: 0;
  display: inline-block;
}
.heat__legend-max { margin-left: auto; }

/* mobile heatmap */
@media (max-width: 980px) {
  .heat__cell { font-size: 9.5px; padding: 2px 4px; border-radius: 4px; }
  .heat__grid, .heat__dows { gap: 3px; }
  .month-nav .btn--sm { padding: 5px 8px; }
}
