/* ===== Design tokens ===== */
:root {
  --present: #10B981;
  --absent:  #EF4444;
  --late:    #F59E0B;
  --leave:   #FBBF24;
  --primary: #3B82F6;
  --primary-dark: #2563EB;

  --bg:        #F3F4F6;
  --surface:   #FFFFFF;
  --surface-2: #F9FAFB;
  --border:    #E5E7EB;
  --text:      #111827;
  --text-mut:  #6B7280;
  --shadow:    0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
  --radius: 12px;
  --topbar-h: 60px;
  --sidebar-w: 244px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
[data-theme="dark"] {
  --bg:        #0F172A;
  --surface:   #1E293B;
  --surface-2: #263449;
  --border:    #334155;
  --text:      #F1F5F9;
  --text-mut:  #94A3B8;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ===== Topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .5rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem; }
.brand-logo { display: inline-flex; }
.topbar-actions { margin-left: auto; display: flex; gap: .4rem; }
.hamburger { display: none; }
.hamburger, .icon-btn {
  background: transparent; border: none; color: var(--text);
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.hamburger:hover, .icon-btn:hover { background: var(--surface-2); }
.ico-moon { display: none; }
[data-theme="dark"] .ico-sun { display: none; }
[data-theme="dark"] .ico-moon { display: inline; }

/* ===== Layout ===== */
.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem .75rem;
  display: flex; flex-direction: column;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}
.sidebar nav { display: flex; flex-direction: column; gap: .25rem; }
.nav-link {
  display: flex; align-items: center; gap: .7rem;
  padding: .65rem .8rem; border-radius: 10px;
  color: var(--text-mut); font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); }
.nav-link svg { flex-shrink: 0; }
.sidebar-foot { margin-top: auto; font-size: .78rem; color: var(--text-mut); padding: .5rem .3rem 0; }

.content { flex: 1; padding: 1.5rem; max-width: 100%; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-sub { color: var(--text-mut); margin: 0; }

.scrim { display: none; }

/* ===== Cards ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem; margin-bottom: 1.1rem;
}
.grid { display: grid; gap: 1rem; }
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 1.25rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem;
}
.stat .num { font-size: 2rem; font-weight: 700; }
.stat .lbl { color: var(--text-mut); font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; }
.stat .ico { width: 40px; height: 40px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; margin-bottom: .6rem; color: #fff; }

.quick-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.quick {
  display: flex; align-items: center; gap: .8rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem;
}
.quick:hover { border-color: var(--primary); }
.quick .ico { width: 42px; height: 42px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); flex-shrink: 0; }
.quick strong { display: block; }
.quick small { color: var(--text-mut); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .55rem .95rem; border-radius: 10px; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text); min-height: 40px;
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); filter: none; }
.btn-danger { background: var(--absent); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-sm { padding: .35rem .6rem; min-height: 34px; font-size: .85rem; }
.btn-block { width: 100%; }

/* ===== Forms ===== */
.field { margin-bottom: .85rem; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .9rem; }
input, select, textarea {
  font: inherit; width: 100%;
  padding: .55rem .7rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); min-height: 40px;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; }
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.form-row > * { flex: 1 1 160px; }
.err { color: var(--absent); font-size: .8rem; margin-top: .25rem; display: block; }
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.toolbar .field { margin: 0; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--surface-2); font-weight: 600; color: var(--text-mut); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td .row-actions { display: flex; gap: .4rem; }

/* ===== Status badges & buttons ===== */
.badge { display: inline-flex; align-items: center; padding: .18rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; color: #fff; }
.st-P { background: var(--present); }
.st-A { background: var(--absent); }
.st-L { background: var(--late); }
.st-LEV { background: var(--leave); color: #7c5b00; }
.st-none { background: var(--surface-2); color: var(--text-mut); border: 1px solid var(--border); }

.status-btns { display: inline-flex; gap: .35rem; flex-wrap: wrap; }
.sbtn {
  border: 1.5px solid var(--border); background: var(--surface);
  color: var(--text-mut); font-weight: 700; cursor: pointer;
  min-width: 42px; min-height: 38px; border-radius: 9px; font-size: .82rem;
}
.sbtn:hover { border-color: currentColor; }
.sbtn[data-s="P"].on { background: var(--present); border-color: var(--present); color: #fff; }
.sbtn[data-s="A"].on { background: var(--absent); border-color: var(--absent); color: #fff; }
.sbtn[data-s="L"].on { background: var(--late); border-color: var(--late); color: #fff; }
.sbtn[data-s="LEV"].on { background: var(--leave); border-color: var(--leave); color: #7c5b00; }

/* Attendance list */
.att-row { display: flex; align-items: center; gap: .8rem; padding: .7rem .9rem; border-bottom: 1px solid var(--border); }
.att-row:last-child { border-bottom: none; }
.att-row .who { min-width: 0; flex: 1; }
.att-row .who strong { display: block; overflow: hidden; text-overflow: ellipsis; }
.att-row .who small { color: var(--text-mut); }

/* ===== Empty state ===== */
.empty { text-align: center; color: var(--text-mut); padding: 2.5rem 1rem; }
.empty svg { opacity: .5; margin-bottom: .6rem; }
.empty h3 { color: var(--text); }

/* ===== Toast ===== */
.toast-wrap { position: fixed; bottom: 1rem; right: 1rem; z-index: 80; display: flex; flex-direction: column; gap: .5rem; max-width: 90vw; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  box-shadow: var(--shadow); border-radius: 10px; padding: .7rem .95rem; font-weight: 500;
  animation: slidein .2s ease; max-width: 340px;
}
.toast.ok { border-left-color: var(--present); }
.toast.err { border-left-color: var(--absent); }
@keyframes slidein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 90; padding: 1rem; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.4rem; max-width: 420px; width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }

/* ===== Chart ===== */
.chart-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .6rem; font-size: .85rem; color: var(--text-mut); }
.chart-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .hamburger { display: inline-flex; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 60;
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim.show { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,.4); z-index: 50; }
  .content { padding: 1rem; }
  .brand-name { display: inline; }
}
@media (max-width: 420px) {
  h1 { font-size: 1.35rem; }
  .content { padding: .85rem; }
  .stat .num { font-size: 1.7rem; }
}

/* ===== Print ===== */
@media print {
  .topbar, .sidebar, .scrim, .toast-wrap, .no-print, .btn { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
  .card, .stat, .table-wrap { box-shadow: none; border-color: #ccc; }
}
