:root {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f0f1f4;
  --border: #e2e4e9;
  --text: #16181d;
  --text-muted: #676c76;
  --text-faint: #9aa0ab;
  --accent: #2f6feb;
  --accent-hover: #2559c2;
  --accent-soft: #e8f0fe;
  --green: #1a8a4a;
  --green-soft: #e6f6ec;
  --red: #d92d2d;
  --red-soft: #fdeaea;
  --yellow: #b8860b;
  --yellow-soft: #fdf3d9;
  --zinc-soft: #eceef1;
  --blue: #2f6feb;
  --blue-soft: #e8f0fe;
  --purple: #7c3aed;
  --purple-soft: #f1e9fe;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 1px 1px rgba(16, 20, 30, .04);
  --shadow-lg: 0 12px 32px rgba(16, 20, 30, .16);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 248px;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elevated: #161922;
  --surface: #161922;
  --surface-hover: #1d212c;
  --border: #262b36;
  --text: #eef0f4;
  --text-muted: #9aa0ab;
  --text-faint: #676c76;
  --accent: #5b8def;
  --accent-hover: #7ba2f2;
  --accent-soft: #17253f;
  --green: #3ec178;
  --green-soft: #123722;
  --red: #f2555a;
  --red-soft: #3a1719;
  --yellow: #e0b13c;
  --yellow-soft: #362a0d;
  --zinc-soft: #1d212c;
  --blue: #5b8def;
  --blue-soft: #17253f;
  --purple: #a385f0;
  --purple-soft: #251c3a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --bg-elevated: #161922;
    --surface: #161922;
    --surface-hover: #1d212c;
    --border: #262b36;
    --text: #eef0f4;
    --text-muted: #9aa0ab;
    --text-faint: #676c76;
    --accent: #5b8def;
    --accent-hover: #7ba2f2;
    --accent-soft: #17253f;
    --green: #3ec178;
    --green-soft: #123722;
    --red: #f2555a;
    --red-soft: #3a1719;
    --yellow: #e0b13c;
    --yellow-soft: #362a0d;
    --zinc-soft: #1d212c;
    --blue: #5b8def;
    --blue-soft: #17253f;
    --purple: #a385f0;
    --purple-soft: #251c3a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; }
button { font-family: inherit; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width .15s ease;
}
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .sidebar-label, .sidebar.collapsed .sidebar-group-title, .sidebar.collapsed .brand-text { display: none; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--border); font-weight: 700; }
.sidebar-toggle { margin-left: auto; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: var(--radius-sm); }
.sidebar-toggle:hover { background: var(--surface-hover); }
.sidebar-group { padding: 10px 10px 4px; }
.sidebar-group-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 8px 10px 4px; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: 13.5px; font-weight: 500; white-space: nowrap;
}
.sidebar-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.sidebar-link.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-link .icon { width: 18px; text-align: center; flex-shrink: 0; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--bg-elevated);
  position: sticky; top: 0; z-index: 20;
}
.main-content { flex: 1; padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }

@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 40; left: -100%; }
  .sidebar.mobile-open { left: 0; }
  .main-content { padding: 16px; }
}

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header .eyebrow { color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header .subtitle { color: var(--text-muted); margin-top: 4px; font-size: 13.5px; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; align-items: center; gap: 12px; }
.stat-card .icon { width: 38px; height: 38px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 16px; }
.stat-card .value { font-size: 19px; font-weight: 700; }
.stat-card .label { color: var(--text-muted); font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  background: var(--surface); color: var(--text); border-color: var(--border);
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 34px; height: 34px; padding: 0; border-radius: var(--radius-sm); background: transparent; border: 1px solid var(--border); color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--surface-hover); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge-zinc { background: var(--zinc-soft); color: var(--text-muted); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field .hint { font-size: 11.5px; color: var(--text-faint); }
.field .error { font-size: 11.5px; color: var(--red); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=url], input[type=search],
select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-elevated); color: var(--text); font-size: 13.5px; font-family: inherit;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 16px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

.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: 13.5px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th { color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; background: var(--bg); }
tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: none; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 16, .55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal.modal-wide { max-width: 780px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); box-shadow: var(--shadow-lg); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; min-width: 240px; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 16px; }
.pagination button { min-width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.pagination button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

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

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab-link { padding: 9px 14px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; color: var(--text-muted); font-weight: 600; font-size: 13.5px; border: 1px solid transparent; border-bottom: none; margin-bottom: -1px; }
.tab-link.active { color: var(--accent); border-color: var(--border); background: var(--surface); }

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12.5px; }
.w-full { width: 100%; }
.progress-bar { height: 8px; border-radius: 4px; background: var(--zinc-soft); overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--accent); }

.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 36px 32px; width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card p { color: var(--text-muted); margin-bottom: 22px; font-size: 13.5px; }
.login-card .field { text-align: left; }

.duty-badge { position: fixed; bottom: 18px; right: 18px; background: var(--green); color: #fff; padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow-lg); font-weight: 700; font-size: 13px; z-index: 60; display: flex; align-items: center; gap: 8px; }
.duty-badge:hover { text-decoration: none; filter: brightness(1.05); }

.notif-wrap { position: relative; }
.notif-dot { position: absolute; top: 2px; right: 2px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); border: 2px solid var(--bg-elevated); }
.notif-panel { position: absolute; right: 0; top: 44px; width: 320px; max-height: 400px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); display: none; z-index: 50; }
.notif-panel.open { display: block; }
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.notif-item.unread { background: var(--accent-soft); }
.notif-item .title { font-weight: 700; margin-bottom: 2px; }
.notif-item .time { color: var(--text-faint); font-size: 11px; margin-top: 4px; }

.profile-btn { display: flex; align-items: center; gap: 8px; background: none; border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px 4px 4px; cursor: pointer; color: var(--text); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; overflow: hidden; flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-panel { position: absolute; right: 0; top: 44px; width: 260px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); display: none; z-index: 50; padding: 6px; }
.profile-panel.open { display: block; }
.profile-panel .pp-header { padding: 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.profile-panel a, .profile-panel button.pp-link { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text); background: none; border: none; font-size: 13px; cursor: pointer; }
.profile-panel a:hover, .profile-panel button.pp-link:hover { background: var(--surface-hover); text-decoration: none; }
