:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #1c2333;
  --muted: #6b7486;
  --border: #e3e7ef;
  --primary: #2563eb;
  --primary-soft: #e8f0ff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --success: #15803d;
  --success-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fff4dc;
  --purple: #7c3aed;
  --purple-soft: #f1eaff;
  --grey-soft: #eef0f4;
  /* edited-row colours */
  --edited-self-bg: #fff6d9;
  --edited-self-bar: #f59e0b;
  --edited-other-bg: #f3ecff;
  --edited-other-bar: #8b5cf6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
[hidden] { display: none !important; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h1, h2, h3, h4 { margin: 0; }

/* ---------- buttons & inputs */
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--grey-soft); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--grey-soft); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.btn.icon-only { padding: 6px 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit; color: inherit; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 64px; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
label.check { flex-direction: row; align-items: center; font-weight: 400; }
label.check input { width: auto; }
.form-error { color: var(--danger); min-height: 18px; font-size: 13px; }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 20% 10%, #dbe7ff, transparent 50%), var(--bg); }
.login-card { background: var(--panel); padding: 32px; border-radius: 16px; box-shadow: var(--shadow);
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 22px; }
.login-card p { margin: -8px 0 4px; }

/* ---------- layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 236px; background: #111a2e; color: #cfd6e4; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; flex-shrink: 0; z-index: 20; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid #1f2a44; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.brand-mark.big { width: 48px; height: 48px; font-size: 18px; }
.brand-name { color: #fff; font-weight: 600; }
.brand-sub { font-size: 12px; color: #8b96ad; }
#nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
#nav a { color: #cfd6e4; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
#nav a:hover { background: #1b2640; color: #fff; }
#nav a.active { background: var(--primary); color: #fff; }
#nav .ico { width: 18px; text-align: center; }
.sidebar-foot { padding: 12px; border-top: 1px solid #1f2a44; display: flex; flex-direction: column; gap: 10px; }
.sidebar-foot .btn.ghost { color: #cfd6e4; border-color: #2a3654; }
.sidebar-foot .btn.ghost:hover { background: #1b2640; }
.me { display: flex; gap: 10px; align-items: center; }
.me-name { color: #fff; font-weight: 600; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #2a3654; color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar h2 { font-size: 18px; flex: 1; }
.topbar-right { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-btn { display: none; }
.content { padding: 24px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- cards */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head h3 { font-size: 15px; }
.card-body { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.two-col { grid-template-columns: 1fr 1fr; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.accent-blue { border-top: 3px solid var(--primary); }
.kpi.accent-green { border-top: 3px solid var(--success); }
.kpi.accent-amber { border-top: 3px solid var(--edited-self-bar); }
.kpi.accent-red { border-top: 3px solid var(--danger); }
.kpi.accent-purple { border-top: 3px solid var(--purple); }

/* bar list */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 56px; gap: 10px; align-items: center; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--grey-soft); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 6px; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--grey-soft); padding: 4px 10px; border-radius: 999px; font-size: 12px; }
.chip.warn { background: var(--danger-soft); color: var(--danger); }

/* ---------- filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 14px 18px; }
.filters label { min-width: 140px; flex: 1; max-width: 220px; }
.filters .grow { max-width: none; flex: 2; }
.week-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.week-nav input { width: auto; }
.week-nav .range { font-weight: 600; margin: 0 6px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f8f9fc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafbfd; }
tfoot td { font-weight: 700; background: #f8f9fc; }
td .sub { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: pre-wrap; }
td.actions { white-space: nowrap; text-align: right; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.zero { color: #c0c6d2; }

/* edited rows */
tr.edited-self { background: var(--edited-self-bg); }
tr.edited-self td:first-child { box-shadow: inset 4px 0 0 var(--edited-self-bar); }
tr.edited-other { background: var(--edited-other-bg); }
tr.edited-other td:first-child { box-shadow: inset 4px 0 0 var(--edited-other-bar); }
tr.edited-self:hover { background: #ffefc2; }
tr.edited-other:hover { background: #ebe0ff; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border); display: inline-block; }
.swatch.self { background: var(--edited-self-bg); box-shadow: inset 3px 0 0 var(--edited-self-bar); }
.swatch.other { background: var(--edited-other-bg); box-shadow: inset 3px 0 0 var(--edited-other-bar); }
.swatch.normal { background: #fff; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.s-pending { background: var(--grey-soft); color: #4b5565; }
.badge.s-in-progress { background: var(--primary-soft); color: var(--primary); }
.badge.s-completed { background: var(--success-soft); color: var(--success); }
.badge.s-on-hold { background: var(--warn-soft); color: var(--warn); }
.badge.s-cancelled { background: var(--danger-soft); color: var(--danger); }
.badge.p-low { background: var(--grey-soft); color: var(--muted); }
.badge.p-normal { background: #eef6ff; color: #2b5fb4; }
.badge.p-high { background: var(--warn-soft); color: var(--warn); }
.badge.p-urgent { background: var(--danger-soft); color: var(--danger); }
.badge.edited { background: var(--edited-self-bar); color: #fff; cursor: pointer; border: 0; font: inherit; font-size: 11px; font-weight: 600; }
.badge.edited.other { background: var(--edited-other-bar); }
.badge.role-admin { background: var(--purple-soft); color: var(--purple); }
.badge.role-staff { background: var(--grey-soft); color: #4b5565; }
.badge.active { background: var(--success-soft); color: var(--success); }
.badge.inactive { background: var(--danger-soft); color: var(--danger); }

/* ---------- modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; padding: 16px; z-index: 100; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 680px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.history-item { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px; overflow: hidden; }
.history-item .h-head { background: #f8f9fc; padding: 8px 12px; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.history-item table td, .history-item table th { padding: 6px 12px; font-size: 13px; }
.old { color: var(--danger); text-decoration: line-through; }
.new { color: var(--success); font-weight: 600; }

/* toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111a2e; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 200; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); }

details.staff-detail { border-top: 1px solid var(--border); }
details.staff-detail summary { padding: 12px 18px; cursor: pointer; font-weight: 600; display: flex; justify-content: space-between; }
details.staff-detail[open] summary { background: #f8f9fc; }

.print-head { display: none; }

/* ---------- responsive */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span-2 { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .filters label { max-width: none; min-width: 45%; }
  .bar-row { grid-template-columns: 90px 1fr 48px; }
}

/* ---------- print */
@media print {
  .sidebar, .topbar, .no-print, .filters, td.actions, th.actions { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  body { background: #fff; }
  .print-head { display: block; margin-bottom: 10px; }
  details.staff-detail { display: block; }
  details.staff-detail > *:not(summary) { display: block !important; }
  tr.edited-self, tr.edited-other { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
