/* ── Design tokens ── */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-warm: #f5f7fa;
  --fg: #111111;
  --fg-2: #333333;
  --muted: #6b6b6b;
  --border: #e5e5e5;
  --accent: #2f6feb;
  --accent-on: #ffffff;
  --accent-hover: color-mix(in oklab, var(--accent), black 8%);
  --accent-active: color-mix(in oklab, var(--accent), black 14%);
  --accent-soft: #eff6ff;
  --success: #17a34a;
  --success-soft: #f0fdf4;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --font-display: "Inter", "Microsoft JhengHei", -apple-system, system-ui, sans-serif;
  --font-body:    "Inter", "Microsoft JhengHei", -apple-system, system-ui, sans-serif;
  --font-mono:    ui-monospace, "JetBrains Mono", monospace;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 21px;
  --text-2xl: 26px;
  --text-3xl: 34px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --sidebar-w: 220px;
  --sidebar-collapsed: 56px;
  --topbar-h: 56px;
  --motion-fast: 150ms;
  --motion-base: 200ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: #1a2235;
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: width var(--motion-base) var(--ease);
  overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: var(--topbar-h);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  white-space: nowrap;
}
.sidebar-logo {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 15px; color: #fff; font-weight: 700;
}
.sidebar-title { color: #fff; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  padding: 16px 16px 6px;
  white-space: nowrap;
}
.sidebar.collapsed .sidebar-section-label { display: none; }

.nav-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px 0; }
.nav-scroll::-webkit-scrollbar { width: 4px; }
.nav-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  white-space: nowrap;
  font-size: var(--text-sm);
  text-decoration: none;
  border-left: 2px solid transparent;
  user-select: none;
  transition: background var(--motion-fast), color var(--motion-fast);
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(47,111,235,0.18); color: #fff; border-left-color: var(--accent); }

.nav-icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.sidebar-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-username { font-size: 12px; font-weight: 600; color: #fff; }
.sidebar-role { font-size: 11px; color: rgba(255,255,255,0.4); }

/* ── Sidebar toggle button ── */
.sidebar-toggle-btn {
  position: fixed;
  top: 16px;
  left: calc(var(--sidebar-w) - 12px);
  width: 24px; height: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  transition: left var(--motion-base) var(--ease);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
body.sidebar-collapsed .sidebar-toggle-btn { left: calc(var(--sidebar-collapsed) - 12px); }

/* ── Main ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  transition: margin-left var(--motion-base) var(--ease);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
body.sidebar-collapsed .main { margin-left: var(--sidebar-collapsed); }

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-title { font-size: var(--text-lg); font-weight: 600; color: var(--fg); flex: 1; }
.topbar-date { font-size: var(--text-sm); color: var(--muted); }
.topbar-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
}

/* ── Content area ── */
.content {
  padding: 24px 28px;
  flex: 1;
}

/* ── Flash messages ── */
.flash {
  background: #fef2f2;
  border-left: 4px solid var(--danger);
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.panel-title { font-size: 14px; font-weight: 600; flex: 1; }
.panel-body { padding: 20px; }

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.kpi-card.red::before    { background: var(--danger); }
.kpi-card.green::before  { background: var(--success); }
.kpi-card.teal::before   { background: #0d9488; }
.kpi-card.purple::before { background: var(--purple); }
.kpi-card.blue::before   { background: var(--accent); }
.kpi-label { font-size: var(--text-xs); color: var(--muted); font-weight: 500; margin-bottom: 8px; }
.kpi-value { font-size: var(--text-3xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1; margin-bottom: 4px; }
.kpi-value.red { color: var(--danger); }
.kpi-value.muted { color: var(--fg); }
.kpi-sub { font-size: var(--text-xs); color: var(--muted); }

/* ── Data table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--surface-warm);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--fg-2);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-warm); }
.data-table td.mono { font-family: var(--font-mono); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--text-xs); font-weight: 600;
  white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge.normal  { background: var(--success-soft); color: var(--success); }
.badge.warn    { background: var(--warn-soft); color: var(--warn); }
.badge.danger  { background: var(--danger-soft); color: var(--danger); }
.badge.muted   { background: #f3f4f6; color: var(--muted); }
.badge.blue    { background: var(--accent-soft); color: var(--accent); }
.badge.purple  { background: var(--purple-soft); color: var(--purple); }
.badge.teal    { background: #f0fdfa; color: #0d9488; }

/* ── Punch chip ── */
.punch-chip {
  display: inline-flex;
  padding: 3px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs); font-weight: 600;
}

/* ── Stat boxes ── */
.stat-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-grid { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.stat-box {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; align-items: center;
  min-width: 72px;
  font-size: var(--text-xs); font-weight: 500; color: var(--muted);
}
.stat-box .stat-num { font-size: 22px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.stat-box .num { font-size: 22px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.stat-box .lbl { font-size: 11px; }
.stat-box.normal  { background: var(--success-soft); color: var(--success); }
.stat-box.warn    { background: var(--warn-soft); color: var(--warn); }
.stat-box.danger  { background: var(--danger-soft); color: var(--danger); }
.stat-box.muted   { background: #f3f4f6; color: var(--muted); }
.stat-box.purple  { background: var(--purple-soft); color: var(--purple); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: 500;
  cursor: pointer; border: none;
  transition: background var(--motion-fast), color var(--motion-fast);
  white-space: nowrap; text-decoration: none;
}
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--fg); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-warm); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-warn      { background: var(--warn); color: #fff; }
.btn-teal      { background: #0d9488; color: #fff; }
.btn-sm        { padding: 5px 10px; font-size: var(--text-xs); }

/* ── Form fields ── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--fg-2); }
.field input, .field select, .field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-family: var(--font-body);
  color: var(--fg); background: var(--surface); outline: none;
  transition: border-color var(--motion-fast);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent), transparent 80%);
}
.field textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: 11px; color: var(--muted); }

/* ── Info banner ── */
.info-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in oklab, var(--accent), transparent 70%);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm); color: var(--accent);
  margin-bottom: 20px;
}

/* ── Month nav (legacy) ── */
.month-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.month-nav h2 { font-size: 20px; }
.month-nav a { text-decoration: none; color: var(--accent); font-size: 18px; }
.month-nav a:hover { color: var(--accent-hover); }

/* ── Calendar / month report ── */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-hdr { text-align: center; font-size: var(--text-xs); font-weight: 600; color: var(--muted); padding: 4px 0; }
.cal-cell {
  min-height: 32px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: 600; cursor: default;
}
.cal-cell.normal  { background: #dcfce7; color: #166534; }
.cal-cell.absent  { background: #fee2e2; color: #991b1b; }
.cal-cell.late    { background: #fef3c7; color: #92400e; }
.cal-cell.off     { background: #f3f4f6; color: var(--muted); }
.cal-cell.holiday { background: var(--purple-soft); color: #6d28d9; }
.cal-cell.leave   { background: #e0e7ff; color: #3730a3; }
.cal-cell.today   { outline: 2px solid var(--accent); outline-offset: -2px; }

.month-report { overflow-x: auto; }
.month-table { border-collapse: collapse; font-size: var(--text-sm); min-width: 1200px; }
.month-table th, .month-table td {
  border: 1px solid var(--border); padding: 6px 8px;
  text-align: center; white-space: nowrap;
}
.month-table th { background: #1a2235; color: #fff; font-weight: 600; }
.month-table td.employee-name { text-align: left; font-weight: 600; background: var(--surface-warm); position: sticky; left: 0; }
.month-table td.cell-normal  { background: #86efac; color: #14532d; }
.month-table td.cell-absent  { background: #fca5a5; color: #7f1d1d; }
.month-table td.cell-late    { background: #fde68a; color: #78350f; }
.month-table td.cell-punch   { background: #93c5fd; color: #1e3a5f; }
.month-table td.cell-holiday { background: #ddd6fe; color: #4c1d95; }
.month-table td.cell-leave   { background: #a5f3fc; color: #164e63; }
.month-table td.cell-off     { background: #f3f4f6; color: #9ca3af; }

/* ── Anomaly pill ── */
.day-pill { display: inline-flex; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 700; margin: 1px; }
.day-pill.absent { background: #fca5a5; color: #7f1d1d; }
.day-pill.punch  { background: #fed7aa; color: #7c2d12; }
.day-pill.late   { background: #fde68a; color: #78350f; }

/* ── Leave card ── */
.leave-card {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 16px; margin-bottom: 12px;
  border-left: 4px solid var(--accent); background: var(--surface);
}
.leave-card.approved { border-left-color: var(--success); }
.leave-card.pending  { border-left-color: var(--warn); }
.leave-card.rejected { border-left-color: var(--danger); }

/* ── Split layout (detail page) ── */
.split-layout { display: flex; gap: 0; height: calc(100vh - var(--topbar-h)); overflow: hidden; margin: -24px -28px; }
.split-left { width: 180px; flex-shrink: 0; border-right: 1px solid var(--border); overflow-y: auto; background: var(--surface); }
.split-right { flex: 1; overflow-y: auto; padding: 24px 28px; }
.emp-list-item {
  padding: 10px 16px; font-size: var(--text-sm); cursor: pointer;
  color: var(--fg-2); border-bottom: 1px solid var(--border);
  transition: background var(--motion-fast); display: block; text-decoration: none;
}
.emp-list-item:hover { background: var(--surface-warm); }
.emp-list-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ── Legacy detail layout ── */
.detail-layout { display: flex; gap: 16px; align-items: flex-start; }
.emp-sidebar {
  width: 110px; flex-shrink: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 6px 0; max-height: calc(100vh - 80px); overflow-y: auto; position: sticky; top: 20px;
}
.emp-sidebar-title { font-size: 11px; color: var(--muted); padding: 5px 10px 6px; border-bottom: 1px solid var(--border); }
.emp-sidebar-item {
  display: block; padding: 6px 10px; font-size: 12px; color: var(--fg-2);
  text-decoration: none; border-left: 3px solid transparent; line-height: 1.3;
}
.emp-sidebar-item:hover { background: var(--surface-warm); }
.emp-sidebar-item.active { background: var(--accent-soft); border-left-color: var(--accent); color: var(--accent); font-weight: bold; }
.detail-content { flex: 1; min-width: 0; }

/* ── Comp leave table ── */
.comp-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; margin-bottom: 20px; }
.comp-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; padding: 12px 20px; border-bottom: 1px solid var(--border); align-items: center; font-size: var(--text-sm); }
.comp-row.header { background: #1a2235; color: #fff; font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.comp-row:last-child { border-bottom: none; }

/* ── Tabs ── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; gap: 0; }
.tab-btn {
  padding: 10px 20px; font-size: var(--text-sm); font-weight: 500;
  cursor: pointer; color: var(--muted); background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color var(--motion-fast), border-color var(--motion-fast);
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Device log ── */
.log-area {
  background: #0f172a; color: #94a3b8;
  font-family: var(--font-mono); font-size: 11px; line-height: 1.6;
  padding: 16px; border-radius: var(--radius-sm);
  max-height: 300px; overflow-y: auto;
}
.log-area .log-ok   { color: #34d399; }
.log-area .log-info { color: #64748b; }

/* ── Permission table ── */
.perm-table th:first-child, .perm-table td:first-child { text-align: left; }
.perm-check {
  width: 18px; height: 18px; border-radius: 4px;
  border: 2px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background var(--motion-fast), border-color var(--motion-fast);
}
.perm-check.checked { background: var(--accent); border-color: var(--accent); }
.perm-check.checked::after { content: '✓'; color: #fff; font-size: 11px; font-weight: 700; }

/* ── Drag handle ── */
.drag-handle { color: var(--muted); cursor: grab; font-size: 14px; padding: 0 8px; }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius-md);
  padding: 32px; text-align: center; color: var(--muted);
  font-size: var(--text-sm); cursor: pointer;
  transition: border-color var(--motion-fast), background var(--motion-fast);
}
.upload-zone:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ── Tooltip ── */
.tooltip-wrap { position: relative; display: inline-block; }
.tooltip-wrap:hover .tooltip-box { display: block; }
.tooltip-box {
  display: none; position: absolute; bottom: calc(100% + 6px);
  left: 50%; transform: translateX(-50%);
  background: #1a2235; color: #fff; font-size: var(--text-xs);
  padding: 4px 8px; border-radius: 4px;
  white-space: nowrap; pointer-events: none; z-index: 999;
}

/* ── Utilities ── */
a.link { color: var(--accent); text-decoration: none; font-size: var(--text-sm); }
a.link:hover { text-decoration: underline; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.gap-8  { display: flex; gap: 8px; align-items: center; }
.gap-12 { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* ── Legacy: chips ── */
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip  { font-size: 11px; padding: 2px 7px; border-radius: 10px; }

/* ── Legacy: attendance table ── */
table.att { border-collapse: collapse; width: 100%; font-size: var(--text-sm); }
table.att th { background: #1a2235; color: #fff; padding: 5px 3px; text-align: center; position: sticky; top: 0; }
table.att td { padding: 2px; text-align: center; }
table.att tr:hover td.emp-name { background: var(--accent-soft); }
.emp-name { text-align: left !important; padding: 2px 6px !important; white-space: nowrap; }
.emp-dept { font-size: 11px; color: var(--muted); }
.day-cell { width: 28px; min-width: 28px; max-width: 28px; height: 28px; border-radius: 3px; font-size: 11px; cursor: default; position: relative; }
.day-cell a { color: inherit; text-decoration: none; display: block; width: 100%; height: 100%; line-height: 28px; }
.weekend-head { color: #e74c3c !important; }
.day-cell.clickable { cursor: pointer !important; }
.day-cell.clickable:hover { filter: brightness(1.12); }
.has-partial-leave  { box-shadow: inset 0 3px 0 #c9a800; }
.has-correction     { box-shadow: inset 0 3px 0 var(--danger); }
.has-deduction      { box-shadow: inset 0 3px 0 #e67e22; }
.has-correction.has-deduction { box-shadow: inset 0 3px 0 #c0392b; }
.has-crossnight     { box-shadow: inset 0 -3px 0 #2980b9; }
.has-crossnight.has-correction { box-shadow: inset 0 3px 0 var(--danger), inset 0 -3px 0 #2980b9; }
.has-crossnight.has-deduction  { box-shadow: inset 0 3px 0 #e67e22, inset 0 -3px 0 #2980b9; }
.has-crossnight.has-correction.has-deduction { box-shadow: inset 0 3px 0 #c0392b, inset 0 -3px 0 #2980b9; }

/* ── Legacy: detail / abnormal table ── */
table.detail { border-collapse: collapse; width: 100%; }
table.detail th { background: #1a2235; color: #fff; padding: 7px 10px; text-align: left; }
table.detail td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
table.detail tr:hover td { background: var(--surface-warm); }
table.abnormal { border-collapse: collapse; width: 100%; }
table.abnormal th { background: #1a2235; color: #fff; padding: 7px 10px; text-align: left; }
table.abnormal td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }

/* ── Legend ── */
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; font-size: var(--text-xs); }
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-box { width: 16px; height: 16px; border-radius: 3px; display: inline-block; }

/* ── Status colors ── */
.s-normal        { background: #27ae60; color: #fff; }
.s-late          { background: #f39c12; color: #fff; }
.s-early         { background: #f1c40f; color: #333; }
.s-late_early    { background: #e67e22; color: #fff; }
.s-missing_punch { background: #e74c3c; color: #fff; }
.s-absent        { background: #922b21; color: #fff; }
.s-weekend       { background: #d5d8dc; color: #7f8c8d; }
.s-holiday       { background: #a8d8ea; color: #2c3e50; }
.s-leave         { background: #f9e79f; color: #7d6608; }
.s-overtime      { background: #1abc9c; color: #fff; }
.s-future        { background: #f8f9fa; color: #ccc; }

/* ── Leave type colors ── */
.lt-annual    { background: #27ae60; color: #fff; }
.lt-personal  { background: #e67e22; color: #fff; }
.lt-caregiver { background: #f39c12; color: #fff; }
.lt-sick      { background: #3498db; color: #fff; }
.lt-mourning  { background: #2c3e50; color: #fff; }
.lt-official  { background: #8e44ad; color: #fff; }
.lt-comp      { background: #16a085; color: #fff; }
.lt-wedding   { background: #c0392b; color: #fff; }
.lt-other     { background: #7f8c8d; color: #fff; }
.lt-paternity { background: #1a78c2; color: #fff; }
.lt-maternity { background: #d81b60; color: #fff; }
.lt-childcare { background: #6a1b9a; color: #fff; }
.lt-childcare-flex { background: #9c4dcc; color: #fff; }
.lt-prenatal  { background: #ad1457; color: #fff; }
.lt-epidemic  { background: #546e7a; color: #fff; }

/* ── Correction slide-in panel ── */
.corr-panel {
  position: fixed; right: -400px; top: 0; width: 380px; height: 100vh;
  background: var(--surface); box-shadow: -3px 0 20px rgba(0,0,0,.25);
  z-index: 2000; transition: right .28s ease; overflow-y: auto;
}
.corr-panel.open { right: 0; }
.corr-overlay {
  position: fixed; top: 0; left: 0; width: 0; height: 100vh;
  background: rgba(0,0,0,.35); z-index: 1999; opacity: 0;
  transition: opacity .28s;
}
.corr-overlay.active { width: 100vw; opacity: 1; }
.corr-header {
  background: #1a2235; color: #fff; padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 1;
}
.corr-header-title { font-weight: bold; font-size: 14px; }
.corr-close {
  background: none; border: none; color: #ecf0f1; font-size: 20px;
  cursor: pointer; padding: 2px 8px; border-radius: 4px; line-height: 1;
}
.corr-close:hover { background: rgba(255,255,255,0.1); }
.corr-body { padding: 14px; }
.corr-info { background: var(--surface-warm); border-radius: 6px; padding: 12px; margin-bottom: 14px; }
.corr-emp  { font-size: 15px; font-weight: bold; color: var(--fg); }
.corr-date { font-size: 13px; color: var(--muted); margin: 2px 0 6px; }
.corr-section { border: 1px solid var(--border); border-radius: 6px; padding: 14px; margin-bottom: 12px; }
.corr-section h4 { font-size: 13px; color: var(--fg); margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.corr-field { margin-bottom: 8px; }
.corr-field label { font-size: 12px; display: block; margin-bottom: 3px; color: var(--muted); }
.corr-field input, .corr-field select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }
.corr-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }
.late-calc-box { background: #fff3cd; border-left: 3px solid #f39c12; padding: 8px 10px; border-radius: 4px; margin-bottom: 10px; font-size: 13px; }
.deduct-already { background: #d5e8d4; border-left: 3px solid #27ae60; padding: 8px 10px; border-radius: 4px; margin-bottom: 10px; font-size: 13px; }
.corr-punch-info { font-size: 12px; margin-top: 6px; }
.corr-punch-orig  { color: var(--muted); }
.corr-punch-fixed { color: var(--accent); font-weight: bold; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  :root { --sidebar-w: 200px; }
}
@media (max-width: 768px) {
  .sidebar { width: var(--sidebar-collapsed) !important; }
  .sidebar .sidebar-title,
  .sidebar .sidebar-section-label,
  .sidebar .sidebar-user-info,
  .sidebar .nav-item span:not(.nav-icon) { display: none; }
  .main { margin-left: var(--sidebar-collapsed) !important; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .topbar-date { display: none; }
  .sidebar-toggle-btn { display: none; }
  table.att th, table.att td { font-size: 10px; padding: 1px; }
  .day-cell { width: 22px; min-width: 22px; max-width: 22px; height: 22px; font-size: 10px; }
  .day-cell a { line-height: 22px; }
  table.detail th, table.detail td { padding: 5px 6px; font-size: 12px; }
  .emp-sidebar { display: none; }
  .detail-layout { display: block; }
}
@media (max-width: 600px) {
  .apply-form-row { flex-direction: column !important; }
  .apply-form-row > div { width: 100% !important; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}
