:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #1a2238;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #1e40af;
  --brand-2: #2563eb;
  --accent: #0ea5e9;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 20px rgba(15,23,42,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--ink); }
body { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: linear-gradient(180deg, #0f1d40 0%, #1e3a8a 100%); color: #cbd5e1; padding: 20px 14px; display: flex; flex-direction: column; }
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 24px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: #fff; color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 20px; }
.brand-name { color: #fff; font-weight: 700; }
.brand-sub { color: #9bb0d6; font-size: 11px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: #cbd5e1; padding: 10px 12px; border-radius: 8px; text-decoration: none; font-size: 14px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.nav-section { color: #93a3c6; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; padding: 14px 12px 4px; }
.kanban { display: grid; grid-template-columns: repeat(7, minmax(180px, 1fr)); gap: 10px; overflow-x: auto; }
.kanban-col { background: #f8fafc; border-radius: 10px; padding: 10px; min-height: 200px; }
.kanban-col h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); display: flex; justify-content: space-between; }
.kanban-col h3 .count { background: var(--brand-2); color: #fff; padding: 1px 8px; border-radius: 999px; font-size: 11px; }
.kanban-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: pointer; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.kanban-card:hover { border-color: var(--brand-2); }
.kanban-card .name { font-weight: 600; font-size: 13px; }
.kanban-card .meta { color: var(--muted); font-size: 11px; margin-top: 4px; }
.kanban-card .source { display: inline-block; padding: 1px 6px; background: #eff6ff; color: var(--brand); border-radius: 4px; font-size: 10px; margin-top: 4px; }
@media (max-width: 1100px) { .kanban { grid-template-columns: repeat(4, minmax(170px, 1fr)); } }
@media (max-width: 720px) { .kanban { grid-template-columns: repeat(2, minmax(150px, 1fr)); } }
.footer-note { margin-top: auto; color: #93a3c6; font-size: 11px; padding: 12px; }

main { padding: 24px 32px; overflow-x: hidden; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 22px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.global-search { position: relative; flex: 1; min-width: 240px; max-width: 420px; }
.global-search input { width: 100%; padding-left: 32px; }
.global-search::before { content: '⌕'; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 16px; }
.search-results { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; max-height: 360px; overflow: auto; z-index: 50; box-shadow: var(--shadow); display: none; }
.search-results.open { display: block; }
.search-results .group { padding: 6px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); background: #f8fafc; }
.search-results a { display: block; padding: 8px 12px; text-decoration: none; color: var(--ink); font-size: 13px; }
.search-results a:hover { background: #eff6ff; }

button, .btn { background: var(--brand-2); color: #fff; border: 0; padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; }
button:hover { background: var(--brand); }
.btn-secondary { background: #fff; color: var(--brand-2); border: 1px solid var(--line); }
.btn-secondary:hover { background: #f0f4ff; }
.btn-danger { background: var(--bad); }
.btn-ghost { background: transparent; color: var(--muted); padding: 4px 8px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--panel); padding: 18px; border-radius: 12px; box-shadow: var(--shadow); }
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.card .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.card.alert { border-left: 4px solid var(--bad); }

.panel { background: var(--panel); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.panel h2 { margin: 0 0 14px; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
.panel h2 .actions { display: flex; gap: 6px; }
.panel h2 .actions button { padding: 5px 10px; font-size: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tr:hover td { background: #fafbff; }
td .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.available { background: #dcfce7; color: #166534; }
.badge.booked { background: #fef3c7; color: #92400e; }
.badge.sold { background: #dbeafe; color: #1e40af; }
.badge.blocked { background: #fee2e2; color: #991b1b; }
.badge.present { background: #dcfce7; color: #166534; }
.badge.absent { background: #fee2e2; color: #991b1b; }
.badge.half-day { background: #fef3c7; color: #92400e; }
.badge.leave { background: #e0e7ff; color: #3730a3; }
.badge.holiday { background: #f3e8ff; color: #6b21a8; }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.paid { background: #dcfce7; color: #166534; }
.badge.overdue { background: #fee2e2; color: #991b1b; }
.badge.waived { background: #e5e7eb; color: #374151; }
.amount-pos { color: var(--good); }
.amount-neg { color: var(--bad); }

.empty { padding: 40px; text-align: center; color: var(--muted); }

.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 12px; padding: 24px; min-width: 460px; width: 100%; max-width: 760px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 16px; }
.modal h4 { margin: 18px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; position: sticky; bottom: 0; background: linear-gradient(transparent, #fff 30%); padding-top: 14px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .half { grid-column: span 2; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; font-family: inherit; color: var(--ink); background: #fff; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea { min-height: 70px; resize: vertical; }
input:disabled, select:disabled { background: #f8fafc; color: var(--muted); }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .split, .form-grid { grid-template-columns: 1fr 1fr !important; } }
@media (max-width: 720px) {
  body { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; padding: 10px; overflow-x: auto; }
  .sidebar .footer-note, .brand-sub { display: none; }
  .sidebar nav { flex-direction: row; }
  main { padding: 16px; }
  .modal { min-width: 90vw; }
  .form-grid { grid-template-columns: 1fr !important; }
}

.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.muted { color: var(--muted); font-size: 12px; }
.right { text-align: right; }

/* Mini bar chart */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 12px 0; }
.bar-chart .bar { flex: 1; min-width: 18px; background: linear-gradient(180deg, var(--brand-2), var(--accent)); border-radius: 6px 6px 0 0; position: relative; transition: opacity .15s; }
.bar-chart .bar:hover { opacity: .8; }
.bar-chart .bar .label { position: absolute; bottom: -22px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--muted); }
.bar-chart .bar .val { position: absolute; top: -18px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--ink); font-weight: 600; }

/* Attendance grid */
.att-grid { overflow-x: auto; }
.att-grid table { min-width: 900px; }
.att-grid td.day { padding: 6px; text-align: center; cursor: pointer; }
.att-grid td.day .dot { display: inline-block; width: 22px; height: 22px; line-height: 22px; border-radius: 5px; font-size: 10px; font-weight: 700; }
.att-grid td.day.present .dot { background: #dcfce7; color: #166534; }
.att-grid td.day.absent .dot { background: #fee2e2; color: #991b1b; }
.att-grid td.day.half-day .dot { background: #fef3c7; color: #92400e; }
.att-grid td.day.leave .dot { background: #e0e7ff; color: #3730a3; }
.att-grid td.day.holiday .dot { background: #f3e8ff; color: #6b21a8; }
.att-grid td.day.empty .dot { background: #f3f4f6; color: #cbd5e1; }

/* Attendance quick-pick (daily view) */
.att-quick { display: inline-flex; gap: 4px; }
.att-quick .att-pick { padding: 4px 8px; font-size: 11px; font-weight: 600; line-height: 1; min-width: 26px; }
.att-quick .att-pick.active { box-shadow: 0 0 0 2px var(--brand-2); }
.att-quick .att-pick[data-status="present"]  { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.att-quick .att-pick[data-status="absent"]   { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.att-quick .att-pick[data-status="half-day"] { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.att-quick .att-pick[data-status="leave"]    { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }
.att-quick .att-pick[data-status="holiday"]  { background: #f3e8ff; color: #6b21a8; border-color: #e9d5ff; }
.att-quick .att-pick:hover { filter: brightness(0.96); }

/* Receipt */
.receipt { font-family: serif; padding: 30px; max-width: 600px; }
.receipt h2 { margin: 0; }
.receipt .org { text-align: center; padding-bottom: 12px; border-bottom: 2px solid var(--ink); }
.receipt .row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.receipt .total { font-size: 18px; font-weight: 700; padding: 12px 0; margin-top: 12px; border-top: 2px solid var(--ink); display: flex; justify-content: space-between; }
@media print {
  /* Hide everything except #modal-root (which contains the printable overlay). */
  body > *:not(#modal-root) { display: none !important; }
  #modal-root { position: static; }
  .modal-overlay { position: static; background: none; padding: 0; display: block; }
  .modal { box-shadow: none; max-height: none; max-width: none; border: none; padding: 0; background: #fff; }
  .modal h3 { display: none; }
  .modal-actions, .no-print { display: none !important; }
  #printable-invoice { max-width: 100% !important; padding: 0 !important; }
  @page { margin: 12mm; }
}

/* ===== Auth pages ===== */
.auth-body { display: block; background: linear-gradient(135deg, #0f1d40 0%, #1e3a8a 60%, #2563eb 100%); min-height: 100vh; }
.auth-card-wrap { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-card { background: #fff; border-radius: 16px; padding: 32px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth-card-wide { max-width: 720px; }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.auth-card h2 { margin: 4px 0 4px; font-size: 22px; }
.auth-card label { display: block; margin: 12px 0; font-size: 12px; color: var(--muted); font-weight: 600; }
.auth-card input { margin-top: 6px; }
.auth-card button[type="submit"] { width: 100%; margin-top: 8px; padding: 11px; }
.auth-foot { margin-top: 18px; text-align: center; }
.error-msg { background: #fee2e2; color: #991b1b; padding: 10px; border-radius: 8px; margin-top: 12px; font-size: 13px; }
.small { font-size: 12px; }

/* Wizard */
.wizard-steps { display: flex; gap: 4px; padding: 0; margin: 14px 0 22px; list-style: none; counter-reset: step; }
.wizard-steps li { flex: 1; padding: 10px; border-radius: 8px; background: #f1f5f9; color: var(--muted); font-size: 12px; font-weight: 600; text-align: center; counter-increment: step; }
.wizard-steps li::before { content: counter(step) ". "; }
.wizard-steps li.active { background: var(--brand-2); color: #fff; }
.wizard-steps li.done { background: #dcfce7; color: #166534; }
.wizard-step.active, .wizard-step:not([hidden]) { display: block; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-2 label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.grid-2 .span-2 { grid-column: 1 / -1; }
.wizard-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

/* Topbar user pill */
.user-pill { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: 12px; }
.user-pill .role { color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-size: 10px; }
.user-pill button { padding: 3px 8px; font-size: 11px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 600; box-shadow: var(--shadow); z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: var(--good); }
.toast-error { background: var(--bad); }
