:root {
  /* Tells the browser this page handles its own theming - without this, some browsers'
     auto-dark-mode "enhance website colors" heuristic can mis-recolor inherited-color
     text (e.g. table cells turning blue while explicitly-styled headings don't). */
  color-scheme: light;
  --primary: #4152d6; --primary-dark: #2f3eb0; --primary-tint: #eef0ff;
  --accent: #19a974; --accent-tint: #e6f7ef; --accent-dark: #0e7a4f;
  --warn: #c9752f; --warn-tint: #fdeee0;
  --bad: #d23a5a; --bad-tint: #fbe6ea;
  --border: #dde0ee; --border-soft: #eceefa;
  --text: #1b1e3d; --muted: #666c95;
  --bg: #f5f6fc; --card-bg: #fff;
  --radius: 10px; --shadow-sm: 0 1px 3px rgba(23,27,80,0.08);
  --sidebar-w: 230px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14.5px; }
a { color: inherit; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 32px 28px; }
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 8px; }
.field input:focus { outline: none; border-color: var(--primary); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 8px; border: none; font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--primary-tint); color: var(--primary-dark); }
.btn.danger { background: var(--bad-tint); color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.error-box { background: var(--bad-tint); color: var(--bad); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ---- Shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); flex-shrink: 0; background: #1b1e3d; color: #cfd2ef; display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; transition: transform 200ms ease; z-index: 20; }
.sidebar .brand { padding: 18px 20px; font-weight: 800; font-size: 15px; color: #fff; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar .brand .sub { display: block; font-weight: 400; font-size: 11.5px; color: #9ba0d6; margin-top: 2px; }
.sidebar nav { flex: 1; padding: 10px 10px; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; text-decoration: none; color: #cfd2ef; font-size: 13.5px; font-weight: 600; margin-bottom: 2px; }
.sidebar nav a:hover { background: rgba(255,255,255,0.06); }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.nav-icon { flex-shrink: 0; opacity: 0.85; }
.sidebar nav a.active .nav-icon { opacity: 1; }
.sidebar .userbox { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 12.5px; }
.sidebar .userbox .name { color: #fff; font-weight: 700; font-size: 13px; }
.sidebar .userbox .role { color: #9ba0d6; margin: 2px 0 10px; }
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
.topbar { display: none; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--card-bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar .hamburger { background: none; border: none; font-size: 20px; padding: 4px 8px; }
.content { padding: 24px 28px; max-width: 1200px; }
.content h2 { margin: 0 0 4px; font-size: 20px; }
.content .page-sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

/* ---- Cards / stats ---- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 14px 16px; }
.stat-card .n { font-size: 24px; font-weight: 800; }
.stat-card .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px 20px; margin-bottom: 18px; }
.card h3 { margin: 0 0 12px; font-size: 14.5px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; padding: 9px 10px; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1.5px solid var(--border); white-space: nowrap; }
table.data td { padding: 10px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; color: var(--text); }
table.data td.t-nowrap { white-space: nowrap; }

/* ---- Attendance monthly grid (muster roll) ---- */
.muster-legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.muster-chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.muster-table { border-collapse: separate; border-spacing: 0; }
.muster-table th, .muster-table td { text-align: center; }
.muster-table thead th { background: var(--card-bg); position: sticky; top: 0; z-index: 2; }
.muster-name-col { text-align: left !important; position: sticky; left: 0; background: var(--card-bg); z-index: 1; min-width: 150px; font-weight: 600; white-space: nowrap; }
th.muster-name-col { z-index: 3; }
.muster-day-col { min-width: 30px; font-size: 11px; }
.muster-cell { font-weight: 800; font-size: 12px; border-radius: 5px; min-width: 28px; }
.muster-cell.m-p, .muster-chip.m-p { background: var(--accent-tint); color: var(--accent-dark); }
.muster-cell.m-half, .muster-chip.m-half { background: var(--warn-tint); color: var(--warn); }
.muster-cell.m-missed, .muster-chip.m-missed { background: #fde9cf; color: #a35c0a; }
.muster-cell.m-absent, .muster-chip.m-absent { background: var(--bad-tint); color: var(--bad); }
.muster-cell.m-off, .muster-chip.m-off { background: var(--border-soft); color: var(--muted); }
.muster-cell.m-reg, .muster-chip.m-reg { background: var(--primary-tint); color: var(--primary-dark); }
.muster-cell.m-pending, .muster-chip.m-pending { background: transparent; color: var(--muted); font-weight: 400; }
.muster-name-col.clickable { cursor: pointer; color: var(--primary-dark); }
.muster-name-col.clickable:hover { text-decoration: underline; }

/* ---- Worker month calendar (drill-down from the muster grid) ---- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 16px; }
.cal-dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; padding-bottom: 4px; }
.cal-cell { border-radius: 8px; padding: 6px 4px; min-height: 56px; display: flex; flex-direction: column; gap: 2px; background: var(--border-soft); }
.cal-cell.cal-blank { background: transparent; }
.cal-day { font-size: 11.5px; font-weight: 700; opacity: 0.75; }
.cal-time { font-size: 10.5px; font-weight: 700; line-height: 1.25; }
.cal-code { font-size: 9.5px; font-weight: 700; line-height: 1.2; opacity: 0.9; }
.cal-cell.m-p { background: var(--accent-tint); color: var(--accent-dark); }
.cal-cell.m-half { background: var(--warn-tint); color: var(--warn); }
.cal-cell.m-missed { background: #fde9cf; color: #a35c0a; }
.cal-cell.m-absent { background: var(--bad-tint); color: var(--bad); }
.cal-cell.m-off { background: var(--border-soft); color: var(--muted); }
.cal-cell.m-reg { background: var(--primary-tint); color: var(--primary-dark); }
.cal-cell.m-pending { background: var(--border-soft); color: var(--muted); opacity: 0.6; }
table.data tr:hover td { background: var(--primary-tint); }
table.data tr.clickable { cursor: pointer; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.approved, .badge.active, .badge.match { background: var(--accent-tint); color: var(--accent-dark); }
.badge.pending, .badge.no_invoice { background: var(--warn-tint); color: var(--warn); }
.badge.rejected, .badge.blacklisted, .badge.overbilled { background: var(--bad-tint); color: var(--bad); }
.badge.underbilled { background: var(--primary-tint); color: var(--primary-dark); }

/* ---- Filter bar / forms ---- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: flex-end; }
.filter-bar .field { margin-bottom: 0; min-width: 140px; }
.filter-bar .field select, .filter-bar .field input { width: 100%; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: 8px; }

/* ---- Modal / detail drawer ---- */
.overlay { position: fixed; inset: 0; background: rgba(20,22,50,0.4); display: flex; justify-content: flex-end; z-index: 30; }
.drawer { width: 100%; max-width: 480px; background: var(--card-bg); height: 100%; overflow-y: auto; padding: 24px; }
.drawer.drawer-wide { max-width: 640px; }
.drawer .close { float: right; background: none; border: none; font-size: 20px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; font-size: 13.5px; margin: 14px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: #fff; padding: 12px 18px; border-radius: 8px; font-size: 13.5px; z-index: 50; box-shadow: var(--shadow-sm); }
.toast.error { background: var(--bad); }
.toast.success { background: var(--accent-dark); }
.empty { color: var(--muted); font-size: 13.5px; padding: 20px 0; text-align: center; }
.muted { color: var(--muted); }
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar { display: flex; }
  .content { padding: 16px; }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 15; }
}
