/* ── Design Tokens ───────────────────────────────────────────────────────── */
:root {
  --bg: #eef0f5;
  --surface: #ffffff;
  --surface2: #f7f8fa;
  --surface3: #f0f2f6;
  --sidebar: #ffffff;
  --sidebar-hover: #f1f5f9;
  --sidebar-active: #e8eef8;
  --sidebar-border: #e2e5ec;
  --accent: #1447e6;
  --accent-hover: #1040d0;
  --accent-soft: rgba(20,71,230,.08);
  --green: #15803d; --green-soft: #f0fdf4; --green-border: #bbf7d0;
  --red: #b91c1c;   --red-soft: #fef2f2;   --red-border: #fecaca;
  --amber: #b45309; --amber-soft: #fffbeb; --amber-border: #fde68a;
  --text: #0b0f1a; --text-1: #1e293b; --text-2: #374151; --text-3: #6b7280; --text-4: #9ca3af;
  --border: #e2e5ec; --border2: #d1d5db;
  --font-ui: "Plus Jakarta Sans", sans-serif;
  --font-mono: "DM Mono", monospace;
  --r: 10px; --r-lg: 14px;
  --titlebar-h: 44px;
  --sidebar-w: 220px;
  --sh-sm: 0 1px 4px rgba(0,0,0,.07); --sh-md: 0 4px 16px rgba(0,0,0,.08);
}
html.dark {
  --bg: #0f1117; --surface: #1a1d27; --surface2: #1e2130; --surface3: #232636;
  --sidebar: #141620; --sidebar-hover: #1e2130; --sidebar-active: #1e2842; --sidebar-border: #272b3a;
  --text: #f1f5f9; --text-1: #e2e8f0; --text-2: #cbd5e1; --text-3: #94a3b8; --text-4: #64748b;
  --border: #272b3a; --border2: #323648;
  --accent-soft: rgba(96,139,255,.12);
}

*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }
html,body { height:100%; overflow:hidden; background:var(--bg); color:var(--text); font-family:var(--font-ui); font-size:14px; -webkit-font-smoothing:antialiased; }
button { cursor:pointer; background:none; border:none; color:inherit; font-family:inherit; }
input,select,textarea { font-family:var(--font-ui); }
::-webkit-scrollbar { width:4px; height:4px; }
::-webkit-scrollbar-track { background:transparent; }
::-webkit-scrollbar-thumb { background:var(--border2); border-radius:8px; }

/* ── Titlebar ────────────────────────────────────────────────────────────── */
.titlebar { height:var(--titlebar-h); background:var(--sidebar); display:flex; align-items:center; justify-content:space-between; position:fixed; top:0; left:0; right:0; z-index:1000; -webkit-app-region:drag; border-bottom:1px solid var(--sidebar-border); }
.titlebar-drag { flex:1; height:100%; }
.titlebar-controls { display:flex; -webkit-app-region:no-drag; }
.win-btn { width:46px; height:var(--titlebar-h); font-size:13px; color:#475569; display:flex; align-items:center; justify-content:center; transition:background .15s,color .15s; }
.win-btn:hover { background:rgba(0,0,0,.06); color:#1e293b; }
.win-btn.close:hover { background:var(--red); color:#fff; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout { display:flex; height:100vh; padding-top:var(--titlebar-h); }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar { width:var(--sidebar-w); background:var(--sidebar); display:flex; flex-direction:column; flex-shrink:0; border-right:1px solid var(--sidebar-border); }
.sidebar-brand { padding:14px 16px; border-bottom:1px solid var(--sidebar-border); display:flex; align-items:center; justify-content:center; }
.sidebar-logo { width:100%; max-width:160px; height:auto; object-fit:contain; display:block; margin:0 auto; }
.nav-section { flex:1; padding:10px 8px; overflow-y:auto; display:flex; flex-direction:column; gap:2px; }
.nav-item { width:100%; display:flex; align-items:center; gap:9px; padding:9px 10px; border-radius:8px; font-size:13px; font-weight:500; color:var(--text-3); transition:background .12s,color .12s; text-align:left; }
.nav-item:hover  { background:var(--sidebar-hover); color:var(--text-1); }
.nav-item.active { background:var(--sidebar-active); color:var(--accent); font-weight:600; }
.nav-icon { width:22px; height:22px; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.sidebar-bottom { padding:12px 8px; border-top:1px solid var(--sidebar-border); display:flex; flex-direction:column; gap:4px; }
.dark-toggle-btn { width:100%; display:flex; align-items:center; gap:8px; padding:8px 10px; border-radius:8px; font-size:12px; color:var(--text-3); transition:background .12s; }
.dark-toggle-btn:hover { background:var(--sidebar-hover); color:var(--text-1); }
.dark-toggle-label { flex:1; text-align:left; }
.icon-moon { display:none; }
html.dark .icon-sun  { display:none; }
html.dark .icon-moon { display:block; }
.sys-row { display:flex; align-items:center; justify-content:space-between; padding:4px 10px; }
.sys-label,.sys-val { font-size:11px; color:var(--text-4); font-family:var(--font-mono); }
.user-row { display:flex; align-items:center; gap:9px; padding:8px 10px; border-radius:8px; }
.user-avatar { width:28px; height:28px; border-radius:50%; background:#f0f2f5; overflow:hidden; display:flex; align-items:center; justify-content:center; flex-shrink:0; border:1px solid var(--border2); }
.user-info { flex:1; min-width:0; }
.user-name { font-size:12px; font-weight:700; color:var(--text-1); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.user-role { font-size:10px; color:var(--text-4); }
.logout-btn { flex-shrink:0; width:28px; height:28px; border-radius:7px; border:none; background:transparent; color:var(--text-4); cursor:pointer; display:flex; align-items:center; justify-content:center; transition:background .12s, color .12s; }
.logout-btn:hover { background:#fee2e2; color:#dc2626; }

/* ── Content ─────────────────────────────────────────────────────────────── */
.content { flex:1; overflow-y:auto; background:var(--bg); }
.page { padding:28px 32px 40px; max-width:1400px; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:24px; flex-wrap:wrap; }
.page-eyebrow { font-size:11px; font-weight:700; color:var(--accent); text-transform:uppercase; letter-spacing:.08em; margin-bottom:4px; }
.page-title   { font-size:24px; font-weight:800; color:var(--text-1); line-height:1.2; }
.page-subtitle{ font-size:13px; color:var(--text-3); margin-top:4px; }
.header-actions { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn { display:inline-flex; align-items:center; gap:6px; padding:8px 14px; border-radius:8px; font-size:13px; font-weight:600; transition:all .15s; white-space:nowrap; }
.btn-primary { background:var(--accent); color:#fff; }
.btn-primary:hover { background:var(--accent-hover); }
.btn-ghost   { border:1px solid var(--border2); color:var(--text-2); background:var(--surface); }
.btn-ghost:hover { background:var(--surface2); border-color:var(--border2); }
.btn-export  { background:var(--surface2); border:1px solid var(--border); color:var(--text-3); font-size:12px; padding:6px 12px; }
.btn-export:hover { background:var(--surface3); }
.btn-danger  { background:var(--red-soft); color:var(--red); border:1px solid var(--red-border); }
.btn-danger:hover { background:var(--red-border); }
.btn-sm { font-size:11px; padding:4px 10px; border-radius:6px; }
button:disabled { opacity:.5; cursor:not-allowed; }

/* ── Search ──────────────────────────────────────────────────────────────── */
.search-wrap  { position:relative; display:flex; align-items:center; }
.search-icon  { position:absolute; left:10px; font-size:16px; color:var(--text-4); pointer-events:none; }
.search-input { padding:7px 12px 7px 32px; border:1px solid var(--border2); border-radius:8px; font-size:13px; background:var(--surface); color:var(--text); width:220px; outline:none; transition:border-color .15s; }
.search-input:focus { border-color:var(--accent); }

/* ── Tab bar ─────────────────────────────────────────────────────────────── */
.tab-bar { display:flex; gap:2px; margin-bottom:16px; border-bottom:1px solid var(--border); padding-bottom:0; }
.tab-btn { padding:7px 14px; font-size:12px; font-weight:600; color:var(--text-3); border-radius:7px 7px 0 0; border-bottom:2px solid transparent; transition:all .12s; }
.tab-btn:hover  { color:var(--text-1); background:var(--surface2); }
.tab-btn.active { color:var(--accent); border-bottom-color:var(--accent); background:transparent; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { background:var(--surface); border:1px solid var(--border); border-radius:var(--r-lg); overflow:hidden; }
.data-table { width:100%; border-collapse:collapse; }
.data-table thead th { background:var(--surface2); padding:10px 14px; text-align:left; font-size:11px; font-weight:700; color:var(--text-3); text-transform:uppercase; letter-spacing:.06em; border-bottom:1px solid var(--border); white-space:nowrap; }
.th-sortable { cursor:pointer; user-select:none; }
.th-sortable:hover { color:var(--text-1); }
.sort-arrow { color:var(--text-4); font-size:10px; }
.data-table tbody td { padding:11px 14px; border-bottom:1px solid var(--border); font-size:13px; color:var(--text-2); vertical-align:middle; }
.data-table tbody tr:last-child td { border-bottom:none; }
.data-table tbody tr:hover td { background:var(--surface2); }
.col-actions { width:1%; white-space:nowrap; }
.row-actions { display:flex; align-items:center; gap:4px; opacity:0; transition:opacity .12s; }
tr:hover .row-actions { opacity:1; }
.table-loading { display:flex; align-items:center; justify-content:center; padding:48px; }
.loading-spinner { width:20px; height:20px; border:2px solid var(--border2); border-top-color:var(--accent); border-radius:50%; animation:spin .6s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state { text-align:center; padding:48px 20px; }
.empty-icon  { font-size:32px; margin-bottom:10px; }
.empty-title { font-size:15px; font-weight:700; color:var(--text-2); margin-bottom:4px; }
.empty-sub   { font-size:13px; color:var(--text-4); }

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge { display:inline-flex; align-items:center; padding:3px 9px; border-radius:99px; font-size:11px; font-weight:600; }
.badge-active   { background:var(--green-soft); color:var(--green); border:1px solid var(--green-border); }
.badge-inactive { background:var(--red-soft);   color:var(--red);   border:1px solid var(--red-border); }
.badge-warn     { background:var(--amber-soft);  color:var(--amber); border:1px solid var(--amber-border); }
.badge-purple   { background:#f3e8ff; color:#7c3aed; border:1px solid #d8b4fe; }

/* ── KPI cards ───────────────────────────────────────────────────────────── */
.kpi-row { display:flex; gap:12px; margin-bottom:24px; overflow-x:auto; padding-bottom:4px; }
.kpi-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--r-lg); padding:16px 20px; min-width:140px; flex-shrink:0; }
.kpi-label { font-size:11px; font-weight:600; color:var(--text-3); text-transform:uppercase; letter-spacing:.06em; margin-bottom:6px; }
.kpi-value { font-size:22px; font-weight:800; color:var(--text-1); line-height:1.1; }
.kpi-sub   { font-size:11px; color:var(--text-4); margin-top:4px; }
.kpi-bar-track { height:3px; background:var(--border); border-radius:99px; margin-top:10px; overflow:hidden; }
.kpi-bar  { height:100%; border-radius:99px; transition:width .4s ease; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.4); z-index:500; display:none; align-items:center; justify-content:center; backdrop-filter:blur(2px); }
.modal-overlay.open { display:flex; }
.modal { background:var(--surface); border-radius:16px; width:480px; max-width:calc(100vw - 40px); max-height:calc(100vh - 80px); display:flex; flex-direction:column; box-shadow:0 24px 60px rgba(0,0,0,.2); border:1px solid var(--border2); }
.modal-header { display:flex; align-items:center; justify-content:space-between; padding:18px 22px 14px; border-bottom:1px solid var(--border); }
.modal-header h3 { font-size:15px; font-weight:700; color:var(--text-1); }
.modal-close { width:28px; height:28px; border-radius:6px; font-size:13px; color:var(--text-3); display:flex; align-items:center; justify-content:center; }
.modal-close:hover { background:var(--surface2); }
.modal-body { padding:18px 22px; overflow-y:auto; flex:1; display:flex; flex-direction:column; gap:14px; }
.modal-footer { padding:14px 22px; border-top:1px solid var(--border); display:flex; justify-content:flex-end; gap:8px; }
.modal-field { display:flex; flex-direction:column; gap:5px; }
.modal-field label { font-size:12px; font-weight:600; color:var(--text-3); }
.modal-field input, .modal-field select, .modal-field textarea { padding:8px 11px; border:1px solid var(--border2); border-radius:7px; font-size:13px; background:var(--surface); color:var(--text); outline:none; transition:border-color .15s; }
.modal-field input:focus, .modal-field select:focus, .modal-field textarea:focus { border-color:var(--accent); }
.field-error { font-size:11px; color:var(--red); min-height:14px; }

/* ── Detail panel ────────────────────────────────────────────────────────── */
.detail-overlay { position:fixed; inset:0; background:rgba(0,0,0,.25); z-index:400; opacity:0; pointer-events:none; transition:opacity .2s; }
.detail-overlay.open { opacity:1; pointer-events:all; }
.detail-panel { position:fixed; right:-440px; top:var(--titlebar-h); bottom:0; width:400px; background:var(--surface); border-left:1px solid var(--border); z-index:401; display:flex; flex-direction:column; transition:right .25s cubic-bezier(.25,.46,.45,.94); box-shadow:var(--sh-md); }
.detail-panel.open { right:0; }
.detail-header { display:flex; align-items:flex-start; justify-content:space-between; padding:20px 20px 16px; border-bottom:1px solid var(--border); }
.detail-eyebrow { font-size:11px; font-weight:700; color:var(--accent); text-transform:uppercase; letter-spacing:.08em; margin-bottom:3px; }
.detail-title   { font-size:17px; font-weight:800; color:var(--text-1); }
.detail-close   { width:30px; height:30px; border-radius:7px; color:var(--text-3); display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.detail-close:hover { background:var(--surface2); }
.detail-body { flex:1; overflow-y:auto; padding:16px 20px; display:flex; flex-direction:column; gap:2px; }
.detail-row  { display:flex; gap:8px; padding:10px 0; border-bottom:1px solid var(--border); }
.detail-row:last-child { border-bottom:none; }
.detail-key  { font-size:12px; font-weight:600; color:var(--text-3); min-width:120px; flex-shrink:0; padding-top:1px; }
.detail-val  { font-size:13px; color:var(--text-1); flex:1; word-break:break-word; }
.detail-actions { padding:14px 20px; border-top:1px solid var(--border); display:flex; gap:8px; flex-wrap:wrap; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container { position:fixed; bottom:20px; right:20px; z-index:900; display:flex; flex-direction:column; gap:8px; }
.toast { padding:10px 16px; border-radius:10px; font-size:13px; font-weight:500; max-width:320px; box-shadow:var(--sh-md); transform:translateY(8px); opacity:0; transition:all .25s; border:1px solid transparent; }
.toast.show { transform:translateY(0); opacity:1; }
.toast-success { background:var(--green-soft); color:var(--green); border-color:var(--green-border); }
.toast-error   { background:var(--red-soft);   color:var(--red);   border-color:var(--red-border); }
.toast-info    { background:var(--surface); color:var(--text-2); border-color:var(--border2); }

/* ── Panel ───────────────────────────────────────────────────────────────── */
.panel { background:var(--surface); border:1px solid var(--border); border-radius:var(--r-lg); overflow:hidden; }
.panel-header { display:flex; align-items:center; justify-content:space-between; padding:14px 20px; border-bottom:1px solid var(--border); background:var(--surface2); }
.panel-title  { font-size:13px; font-weight:700; color:var(--text-1); }

/* ── Survey form overlay ─────────────────────────────────────────────────── */
.survey-overlay { position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:600; display:flex; align-items:center; justify-content:center; backdrop-filter:blur(3px); padding:20px; }
.survey-panel { background:var(--surface); border-radius:16px; width:760px; max-width:100%; max-height:calc(100vh - 40px); display:flex; flex-direction:column; box-shadow:0 32px 80px rgba(0,0,0,.25); border:1px solid var(--border2); }
.survey-panel-header { display:flex; align-items:center; justify-content:space-between; padding:20px 26px 16px; border-bottom:1px solid var(--border); flex-shrink:0; }
.survey-panel-title  { font-size:16px; font-weight:800; color:var(--text-1); }
.survey-panel-close  { width:30px; height:30px; border-radius:7px; font-size:14px; color:var(--text-3); display:flex; align-items:center; justify-content:center; }
.survey-panel-close:hover { background:var(--surface2); }
.survey-panel-body   { padding:22px 26px; overflow-y:auto; display:flex; flex-direction:column; gap:0; flex:1; min-height:0; }
.survey-panel-footer { padding:16px 26px; border-top:1px solid var(--border); display:flex; justify-content:flex-end; gap:10px; flex-shrink:0; }

.sf-section-head { font-size:10px; font-weight:700; letter-spacing:.09em; text-transform:uppercase; color:var(--accent); background:var(--accent-soft); padding:6px 10px; border-radius:6px; margin:18px 0 12px; }
.sf-meta-grid    { display:grid; grid-template-columns:1fr 1fr; gap:12px 20px; margin-bottom:4px; }
.sf-questions-grid { display:grid; grid-template-columns:1fr 1fr; gap:10px 20px; margin-bottom:4px; }
.sf-field { display:flex; flex-direction:column; gap:5px; }
.sf-field-full { grid-column:1 / -1; }
.sf-field label { font-size:12px; font-weight:600; color:var(--text-3); }
.sf-field input, .sf-field select, .sf-field textarea { padding:8px 11px; border:1px solid var(--border2); border-radius:7px; font-size:13px; background:var(--surface); color:var(--text); outline:none; transition:border-color .15s; resize:vertical; }
.sf-field input:focus, .sf-field select:focus, .sf-field textarea:focus { border-color:var(--accent); }
