:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-subtle: #eef2f3;
  --ink: #172126;
  --muted: #607078;
  --border: #dce3e6;
  --sidebar: #172126;
  --sidebar-muted: #aebbc0;
  --accent: #087f5b;
  --accent-hover: #066548;
  --success: #16794c;
  --warning: #8a5900;
  --danger: #b42318;
  --danger-hover: #8f1c13;
  --info: #1668a7;
  --focus: #1f7ac0;
  --radius: 8px;
  --z-drawer: 20;
  --z-backdrop: 30;
  --z-modal: 40;
  --z-toast: 50;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { font-size: 14px; line-height: 1.5; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 32%, transparent); outline-offset: 2px; }
[hidden] { display: none !important; }

.login-layout { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--sidebar); }
.login-panel { width: min(420px, 100%); background: var(--surface); border-radius: var(--radius); padding: 36px; display: flex; flex-direction: column; gap: 24px; }
.login-panel h1 { margin: 0; font-size: 24px; line-height: 1.25; text-wrap: balance; }
.login-panel p { margin: 6px 0 0; color: var(--muted); }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: var(--radius); background: var(--accent); color: white; }
.brand-mark.small { width: 32px; height: 32px; }
.brand-mark svg { width: 23px; height: 23px; }
.login-form { display: flex; flex-direction: column; gap: 18px; }
.login-form label { display: flex; flex-direction: column; gap: 7px; font-weight: 600; }
input, select { min-height: 38px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--ink); padding: 7px 10px; }
input::placeholder { color: #687980; }
input:hover, select:hover { border-color: #a7b6bc; }
input:focus, select:focus { border-color: var(--focus); outline: 3px solid color-mix(in srgb, var(--focus) 18%, transparent); }
.form-error { color: var(--danger) !important; margin: -5px 0 0 !important; }

.app-layout { min-height: 100vh; display: flex; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 232px; background: var(--sidebar); color: white; padding: 20px 14px; display: flex; flex-direction: column; z-index: var(--z-drawer); }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 24px; font-size: 17px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item { width: 100%; height: 40px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--sidebar-muted); text-align: left; }
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { background: #233138; color: white; }
.nav-item.active { background: #294239; color: #e8fff6; }
.sidebar-account { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid #344249; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sidebar-account div { min-width: 0; display: flex; flex-direction: column; }
.sidebar-account strong { overflow: hidden; text-overflow: ellipsis; }
.account-label { color: var(--sidebar-muted); font-size: 12px; }

.main-column { width: calc(100% - 232px); min-width: 0; margin-left: 232px; }
.topbar { min-height: 76px; padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 10; }
.topbar > div { flex: 1; min-width: 0; }
.topbar p { margin: 0; color: var(--muted); font-size: 12px; }
.topbar h1 { margin: 1px 0 0; font-size: 20px; line-height: 1.25; text-wrap: balance; }
.content { padding: 24px 28px 48px; }

.button, .icon-button { border: 0; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; transition: background-color 180ms ease, color 180ms ease, transform 180ms ease; }
.button { min-height: 36px; padding: 7px 12px; }
.button svg, .icon-button svg { width: 17px; height: 17px; }
.button:active, .icon-button:active { transform: translateY(1px); }
.button.primary { background: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-hover); }
.button.secondary { background: var(--surface-subtle); color: var(--ink); }
.button.secondary:hover { background: #e2e8ea; }
.button.danger { background: var(--danger); color: white; }
.button.danger:hover { background: var(--danger-hover); }
.button.ghost-danger { background: transparent; color: var(--danger); }
.button.ghost-danger:hover { background: #fff0ef; }
.button.full { width: 100%; }
.button.small { min-height: 30px; padding: 4px 8px; font-size: 13px; }
.icon-button { width: 36px; height: 36px; padding: 0; background: var(--surface-subtle); color: var(--ink); }
.icon-button.inverse { background: transparent; color: white; }
.icon-button.inverse:hover { background: #28373e; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 24px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 17px; display: flex; align-items: center; gap: 13px; }
.metric-icon { width: 38px; height: 38px; border-radius: 7px; display: grid; place-items: center; background: #e6f4ef; color: var(--accent); }
.metric-icon.blue { background: #e9f2f9; color: var(--info); }
.metric-icon.amber { background: #fff4dc; color: var(--warning); }
.metric-icon.red { background: #ffedeb; color: var(--danger); }
.metric-icon svg { width: 19px; height: 19px; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 2px; font-size: 24px; line-height: 1.1; }

.dashboard-columns { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, .8fr); gap: 20px; }
.section { margin-bottom: 24px; }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-header h2 { margin: 0; font-size: 16px; }
.section-header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.toolbar .search-field { width: min(340px, 100%); position: relative; }
.toolbar .search-field svg { width: 16px; height: 16px; position: absolute; left: 11px; top: 11px; color: var(--muted); }
.toolbar .search-field input { width: 100%; padding-left: 34px; }
.toolbar select { min-width: 130px; }
.result-count { margin-left: auto; color: var(--muted); font-size: 13px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: #f8fafb; color: #4b5c64; font-size: 12px; font-weight: 700; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfc; }
.cell-primary { font-weight: 600; }
.cell-secondary { color: var(--muted); font-size: 12px; margin-top: 2px; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-cell { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--surface-subtle); flex: none; }
.avatar-fallback { display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.success { color: var(--success); background: #e8f5ee; }
.badge.warning { color: var(--warning); background: #fff4dc; }
.badge.danger { color: var(--danger); background: #ffedeb; }
.badge.info { color: var(--info); background: #e9f2f9; }
.badge.muted { color: #58666c; background: #edf1f2; }
.row-actions { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.status-select { min-height: 32px; padding: 4px 28px 4px 8px; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.pagination span { color: var(--muted); font-size: 13px; }

.empty-state { min-height: 260px; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 36px; }
.empty-state svg { width: 34px; height: 34px; margin-bottom: 10px; }
.skeleton { height: 14px; width: 80%; border-radius: 4px; background: #e8edef; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

.confirm-dialog { width: min(420px, calc(100% - 32px)); border: 0; border-radius: var(--radius); padding: 0; color: var(--ink); }
.confirm-dialog::backdrop { background: rgba(12, 18, 21, .58); }
.confirm-dialog form { padding: 24px; }
.confirm-dialog h2 { margin: 14px 0 6px; font-size: 18px; }
.confirm-dialog p { margin: 0; color: var(--muted); text-wrap: pretty; }
.dialog-icon { color: var(--warning); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; }
.toast { min-width: 240px; max-width: 360px; padding: 11px 13px; border-radius: 6px; background: var(--sidebar); color: white; box-shadow: 0 4px 8px rgba(0,0,0,.16); }
.toast.error { background: var(--danger); }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(12,18,21,.55); z-index: var(--z-backdrop); }
.mobile-only { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 180ms ease; z-index: calc(var(--z-backdrop) + 1); }
  .sidebar.open { transform: translateX(0); }
  .main-column { width: 100%; margin-left: 0; }
  .mobile-only { display: inline-flex; }
  .dashboard-columns { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .topbar .button span { display: none; }
  .content { padding: 18px 14px 36px; }
  .login-panel { padding: 28px 22px; }
  .toolbar { align-items: stretch; }
  .toolbar .search-field, .toolbar select { width: 100%; }
  .result-count { width: 100%; margin: 0; }
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; min-width: 0; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  tbody { display: flex; flex-direction: column; gap: 10px; }
  tbody tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; }
  td { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); text-align: right; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 700; text-align: left; }
  td:last-child { border-bottom: 0; }
  .user-cell { justify-content: flex-end; }
  .row-actions { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
