/* KDGP Task Tracker - application styles */

:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef2f7;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-2: #334155;
    --text-3: #64748b;
    --text-4: #94a3b8;

    --brand: #1d4ed8;
    --brand-hover: #1e40af;
    --brand-soft: #eff4ff;
    --brand-ring: rgba(37, 99, 235, 0.18);

    --sidebar: #0b1a33;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(96, 165, 250, 0.16);
    --sidebar-text: #a9b7cf;
    --sidebar-muted: #6a7ea3;
    --gold: #f5b700;

    --success: #15803d; --success-bg: #ecfdf3; --success-row: #f3fcf6; --success-line: #22c55e;
    --warning: #b45309; --warning-bg: #fffbeb; --warning-row: #fffaeb; --warning-line: #f59e0b;
    --danger:  #b91c1c; --danger-bg:  #fef2f2; --danger-row:  #fef4f4; --danger-line:  #ef4444;
    --info:    #1d4ed8; --info-bg:    #eff6ff;
    --neutral: #475569; --neutral-bg: #f1f5f9; --neutral-line: #94a3b8;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.28);
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    --sidebar-w: 252px;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; color: var(--text); line-height: 1.25; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.icon { width: 18px; height: 18px; flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

.muted { color: var(--text-3); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.truncate { display: block; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- App layout ---------- */
.app { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 40;
    border-right: 1px solid rgba(255, 255, 255, 0.04);
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }
.brand-logo { width: 40px; height: 40px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { color: #fff; font-weight: 700; font-size: 16px; letter-spacing: 0.06em; }
.brand-sub { color: var(--sidebar-text); font-size: 12.5px; }

.sidebar-nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.nav-section {
    padding: 14px 10px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav-item.active .icon { color: #93c5fd; }
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255, 255, 255, 0.07); }
button.nav-item { width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }

.sidebar-backdrop { display: none; }

.main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: 64px;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 28px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--border);
}
.topbar-date { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 13.5px; }
.topbar-date .icon { width: 16px; height: 16px; }
.topbar .sidebar-toggle { display: none; }

.content { flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; padding: 28px 32px 40px; }
.app-footer { padding: 16px 32px; color: var(--text-4); font-size: 12.5px; border-top: 1px solid var(--border); }

/* ---------- User menu ---------- */
.user-menu { position: relative; margin-left: auto; }
.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 8px 5px 5px;
    background: none;
    border: 1px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    font: inherit;
    color: inherit;
    text-align: left;
}
.user-menu-btn:hover, .user-menu-btn[aria-expanded="true"] { background: var(--surface-2); border-color: var(--border); }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 600; font-size: 13.5px; }
.user-role { font-size: 12px; color: var(--text-3); }
.user-menu-caret { width: 16px; height: 16px; color: var(--text-3); }

.menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 220px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 50;
}
.menu form { margin: 0; }
.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-2);
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.menu-item .icon { width: 16px; height: 16px; color: var(--text-3); }
.menu-item:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.menu-item-danger, .menu-item-danger .icon { color: var(--danger); }
.menu-item-danger:hover { background: var(--danger-bg); color: var(--danger); }
.menu-divider { height: 1px; margin: 6px 4px; background: var(--border); }

/* ---------- Avatars ---------- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 56px; height: 56px; font-size: 19px; }
.avatar-tone-1 { background: #dbeafe; color: #1e40af; }
.avatar-tone-2 { background: #ede9fe; color: #5b21b6; }
.avatar-tone-3 { background: #ccfbf1; color: #0f766e; }
.avatar-tone-4 { background: #fef3c7; color: #92400e; }
.avatar-tone-5 { background: #ffe4e6; color: #9f1239; }
.avatar-tone-6 { background: #e2e8f0; color: #334155; }

/* ---------- Page header ---------- */
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.page-subtitle { margin-top: 4px; color: var(--text-3); font-size: 14px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin: 28px 0 12px;
}
.section-heading h2 { font-size: 16px; font-weight: 600; }
.section-heading:first-of-type { margin-top: 0; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 20px; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 600; }
.card-subtitle { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 18px 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label { font-size: 13px; font-weight: 600; color: var(--text-3); }
.stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
}
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-meta { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: var(--text-3); }
.stat-meta strong { color: var(--text-2); font-variant-numeric: tabular-nums; }

a.stat-card { color: inherit; text-decoration: none; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
a.stat-card:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
a.stat-card:hover .stat-label { color: var(--brand); }
.stat-go { display: inline-flex; color: var(--text-4); opacity: 0; transition: opacity 0.15s, color 0.15s; }
.stat-go .icon { width: 16px; height: 16px; }
a.stat-card:hover .stat-go, a.stat-card:focus-visible .stat-go { opacity: 1; color: var(--brand); }

.tone-total    .stat-icon { background: var(--brand-soft); color: var(--brand); }
.tone-complete .stat-icon { background: var(--success-bg); color: var(--success); }
.tone-progress .stat-icon { background: var(--info-bg); color: #2563eb; }
.tone-waiting  .stat-icon { background: var(--neutral-bg); color: var(--neutral); }
.tone-overdue  .stat-icon { background: var(--danger-bg); color: var(--danger); }
.tone-overdue  .stat-value { color: var(--danger); }

/* Bars drawn with SVG rects (no inline styles, so the strict CSP holds) */
.bar { display: block; width: 100%; height: 6px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.bar-lg { height: 8px; }
.bar svg { display: block; width: 100%; height: 100%; }
.seg-complete { fill: var(--success-line); }
.seg-progress { fill: #3b82f6; }
.seg-waiting  { fill: var(--neutral-line); }
.seg-overdue  { fill: var(--danger-line); }
.seg-total    { fill: var(--brand); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-3); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch-complete { background: var(--success-line); }
.swatch-progress { background: #3b82f6; }
.swatch-waiting  { background: var(--neutral-line); }
.swatch-overdue  { background: var(--danger-line); }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th {
    position: sticky;
    top: 0;
    padding: 11px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    color: var(--text-3);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
}
.table th:first-child { border-top-left-radius: var(--radius-lg); }
.table th:last-child { border-top-right-radius: var(--radius-lg); }
.table td {
    padding: 13px 16px;
    border-bottom: 1px solid #edf1f6;
    vertical-align: middle;
    color: var(--text-2);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color 0.12s; }
.table tbody tr:hover td { background: #f7f9fc; }
.table .col-id { width: 72px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table .cell-title { font-weight: 600; color: var(--text); }
.table .cell-sub { display: block; margin-top: 2px; font-size: 12.5px; color: var(--text-3); }
.table tr[data-href] { cursor: pointer; }

.row-overdue td { background: var(--danger-row); }
.row-overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger-line); }
.row-overdue:hover td { background: #fdecec !important; }
.row-today td { background: var(--warning-row); }
.row-today td:first-child { box-shadow: inset 3px 0 0 var(--warning-line); }
.row-today:hover td { background: #fff4d6 !important; }
.row-complete td { background: var(--success-row); }
.row-complete td:first-child { box-shadow: inset 3px 0 0 var(--success-line); }
.row-complete:hover td { background: #e8f8ee !important; }
.row-open td:first-child { box-shadow: inset 3px 0 0 var(--neutral-line); }

.due { display: flex; flex-direction: column; white-space: nowrap; }
.text-complete { display: inline-flex; align-items: center; gap: 5px; color: var(--success); font-weight: 600; }
.text-complete .icon { width: 15px; height: 15px; }
.due-hint { font-size: 12px; font-weight: 600; }
.row-overdue .due-hint { color: var(--danger); }
.row-today .due-hint { color: var(--warning); }
.due-hint-soon { color: var(--text-3); font-weight: 500; }

.user-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-cell .cell-title { display: block; }
.staff-list { display: flex; flex-direction: column; gap: 2px; }

.empty-state { padding: 56px 24px; text-align: center; color: var(--text-3); }
.empty-state .empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-bottom: 12px;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--text-3);
}
.empty-state .empty-icon .icon { width: 24px; height: 24px; }
.empty-state h3 { font-size: 15px; margin-bottom: 4px; }

/* ---------- Badges & chips ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    background: var(--neutral-bg);
    color: var(--neutral);
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-not-started { background: var(--neutral-bg); color: var(--neutral); }
.badge-not-started .badge-dot { background: var(--neutral-line); }
.badge-in-progress { background: var(--info-bg); color: var(--info); }
.badge-in-progress .badge-dot { background: #3b82f6; }
.badge-complete { background: var(--success-bg); color: var(--success); }
.badge-complete .badge-dot { background: var(--success-line); }
.badge-overdue { background: var(--danger-bg); color: var(--danger); }
.badge-overdue .badge-dot { background: var(--danger-line); }
.badge-admin { background: #eef2ff; color: #4338ca; }
.badge-staff { background: var(--neutral-bg); color: var(--neutral); }
.badge-you { background: var(--warning-bg); color: var(--warning); padding: 1px 8px; font-size: 11px; }
.badge-observer { background: #f0f9ff; color: #0369a1; }

.chip {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 6px;
    background: var(--surface-3);
    color: var(--text-3);
    font-size: 11.5px;
    font-weight: 600;
}
.chip-private { display: inline-flex; align-items: center; gap: 3px; vertical-align: 1px; background: #f3e8ff; color: #7e22ce; }
.chip-private .icon { width: 11px; height: 11px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-2);
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { text-decoration: none; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(29, 78, 216, 0.3); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); border-color: #b6c2d2; color: var(--text); }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-verify { background: #ea580c; color: #fff; box-shadow: 0 1px 2px rgba(234, 88, 12, 0.3); }
.btn-verify:hover { background: #c2410c; }
.btn-xs { height: 26px; padding: 0 9px; gap: 5px; font-size: 12px; border-radius: 6px; }
.btn-xs .icon { width: 13px; height: 13px; }
.verify-form { margin: 6px 0 0; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 7px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.btn-group { display: inline-flex; gap: 6px; align-items: center; }
.btn-group form { display: inline-flex; margin: 0; }
.icon-inline, .auth-foot .icon { width: 15px; height: 15px; vertical-align: -3px; }
.card-header > .icon { color: var(--text-4); width: 22px; height: 22px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field label, .field-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.field-row label { margin-bottom: 6px; }
.field-hint { margin-top: 6px; font-size: 12.5px; color: var(--text-3); }
.required::after { content: " *"; color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="datetime-local"], input[type="search"], select, textarea {
    display: block;
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background-color: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
select {
    appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px var(--brand-ring); }
input:disabled, select:disabled, textarea:disabled, input[readonly] { background-color: var(--surface-2); color: var(--text-2); cursor: default; }
input::placeholder, textarea::placeholder { color: var(--text-4); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); margin: 0; }

.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-4); pointer-events: none; }
.input-icon input { padding-left: 36px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .field { margin-bottom: 0; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field-stack { display: grid; gap: 16px; align-content: start; }

.check-list {
    max-height: 184px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface);
}
.check-item {
    display: flex !important;
    align-items: center;
    gap: 10px;
    margin: 0 !important;
    padding: 7px 8px;
    border-radius: 6px;
    font-weight: 500 !important;
    color: var(--text-2) !important;
    cursor: pointer;
}
.check-item:hover { background: var(--surface-2); }
.check-list.is-disabled { background: var(--surface-2); }
.check-list.is-disabled .check-item { cursor: default; }

/* ---------- Filter bar ---------- */
.toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.filters { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.filters .field { margin: 0; min-width: 170px; }
.filters .field-grow { min-width: 240px; }
.filters label { font-size: 12px; color: var(--text-3); margin-bottom: 5px; }

.context-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 20px;
    background: var(--brand-soft);
    border-bottom: 1px solid #d6e2ff;
    color: #1e3a8a;
    font-size: 13.5px;
}
.context-bar .icon { width: 16px; height: 16px; vertical-align: -3px; margin-right: 6px; }
.context-bar-warning { margin: 0; background: var(--warning-bg); border-bottom-color: #fde68a; color: #78350f; }
.context-bar .btn .icon { margin-right: 0; vertical-align: 0; }

/* ---------- Alerts ---------- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 12px 12px 14px;
    margin-bottom: 18px;
    border: 1px solid;
    border-radius: var(--radius);
    font-size: 14px;
}
.alert > .icon { margin-top: 1px; }
.alert-body { flex: 1; }
.alert-close {
    display: inline-flex;
    padding: 2px;
    border: 0;
    border-radius: 4px;
    background: none;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
}
.alert-close:hover { opacity: 1; }
.alert-close .icon { width: 16px; height: 16px; }
.alert-success { background: var(--success-bg); border-color: #bbf7d0; color: #14532d; }
.alert-error   { background: var(--danger-bg);  border-color: #fecaca; color: #7f1d1d; }
.alert-info    { background: var(--info-bg);    border-color: #bfdbfe; color: #1e3a8a; }
.alert-warning { background: var(--warning-bg); border-color: #fde68a; color: #78350f; }

/* ---------- Pagination ---------- */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-3);
}
.pagination-summary strong { color: var(--text-2); font-weight: 600; }
.pagination { display: flex; gap: 4px; }
.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-2);
    font-weight: 600;
    text-decoration: none;
}
.pagination a:hover { background: var(--surface-2); border-color: var(--border-strong); }
.pagination .current { background: var(--brand); border-color: var(--brand); color: #fff; }
.pagination .disabled { color: var(--text-4); }
.pagination .gap { border-color: transparent; background: none; }
.pagination .icon { width: 16px; height: 16px; }

/* ---------- Dialogs ---------- */
dialog {
    width: min(620px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
}
dialog.dialog-lg { width: min(780px, calc(100vw - 32px)); }
dialog.dialog-sm { width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(2px); }
dialog[open] { animation: dialog-in 0.16s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

.dialog-panel { display: flex; flex-direction: column; max-height: calc(100vh - 48px); margin: 0; }
.dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px 16px;
    border-bottom: 1px solid var(--border);
}
.dialog-title { font-size: 17px; font-weight: 600; }
.dialog-subtitle { margin-top: 3px; font-size: 13px; color: var(--text-3); }
.dialog-body { padding: 20px 22px; overflow-y: auto; }
.dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.dialog-footer-end { display: flex; gap: 10px; margin-left: auto; }

.detail-list { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px 16px; margin: 0; }
.detail-list dt { color: var(--text-3); font-size: 13px; }
.detail-list dd { margin: 0; font-weight: 500; color: var(--text); }
.divider { height: 1px; margin: 18px 0; background: var(--border); border: 0; }
.subheading { margin-bottom: 12px; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.dialog-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 18px;
    padding: 10px 12px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: var(--info-bg);
    color: #1e3a8a;
    font-size: 13.5px;
}
.dialog-note .icon { width: 16px; height: 16px; margin-top: 2px; }
.verify-banner a { color: inherit; text-decoration: underline; }

/* ---------- Reports dialog ---------- */
.report-list { display: grid; gap: 12px; }
.report-item {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px 14px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}
.report-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
}
.report-icon.tone-progress { background: var(--info-bg); color: #2563eb; }
.report-icon.tone-complete { background: var(--success-bg); color: var(--success); }
.report-icon.tone-total    { background: var(--brand-soft); color: var(--brand); }
.report-info h3 { font-size: 14.5px; font-weight: 600; }
.report-info p { margin-top: 2px; font-size: 13px; color: var(--text-3); }
.report-options { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.report-options .field { margin: 0; min-width: 200px; flex: 1; }
.report-options label { font-size: 12px; color: var(--text-3); margin-bottom: 5px; }

/* ---------- Settings dialog ---------- */
.settings-title { font-size: 15px; font-weight: 600; }
.settings-text { margin: 4px 0 16px; color: var(--text-3); font-size: 13.5px; }
.check-list-tall { max-height: 260px; }
.check-text { display: flex; flex-direction: column; line-height: 1.3; }
.settings-note { margin: 18px 0 0; }

/* ---------- Auth pages ---------- */
.auth { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); min-height: 100vh; }
.auth-brand {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 48px 56px;
    overflow: hidden;
    color: #fff;
    background:
        radial-gradient(circle at 85% 15%, rgba(59, 130, 246, 0.35), transparent 45%),
        radial-gradient(circle at 10% 90%, rgba(245, 183, 0, 0.14), transparent 40%),
        linear-gradient(160deg, #0b1a33 0%, #102a55 55%, #163a7a 100%);
}
.auth-brand-inner { position: relative; max-width: 460px; margin: auto 0; }
.auth-logo { width: 88px; height: 88px; object-fit: contain; margin-bottom: 28px; filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.35)); }
.auth-brand h1 { color: #fff; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.auth-brand p { margin-top: 12px; color: #c3cfe4; font-size: 16px; line-height: 1.6; }
.auth-points { list-style: none; margin: 32px 0 0; padding: 0; display: grid; gap: 14px; }
.auth-points li { display: flex; align-items: center; gap: 12px; color: #dbe4f3; font-size: 14.5px; }
.auth-points .icon { width: 20px; height: 20px; color: var(--gold); }
.auth-brand-foot { position: relative; color: #8093b5; font-size: 12.5px; }

.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--bg); }
.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 36px 36px 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}
.auth-card-logo { display: none; width: 64px; height: 64px; margin: 0 auto 16px; }
.auth-card h2 { font-size: 22px; font-weight: 700; }
.auth-card .lead { margin: 6px 0 24px; color: var(--text-3); }
.auth-card .btn-block { margin-top: 8px; }
.auth-foot { margin-top: 22px; text-align: center; font-size: 13.5px; color: var(--text-3); }
.auth-foot a { font-weight: 600; }
.auth-success { text-align: center; }
.auth-success .empty-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 56px; height: 56px; margin-bottom: 16px; border-radius: 50%;
    background: var(--success-bg); color: var(--success);
}
.auth-success .empty-icon .icon { width: 26px; height: 26px; }
.link-sm { font-size: 13px; font-weight: 600; }

/* ---------- Profile ---------- */
.profile-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.profile-grid .card + .card { margin-top: 0; }
.profile-head { display: flex; align-items: center; gap: 16px; padding: 20px; border-bottom: 1px solid var(--border); }
.profile-head h2 { font-size: 18px; }

/* ---------- Error page ---------- */
.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.error-box { max-width: 560px; padding: 32px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.error-box h1 { font-size: 20px; margin-bottom: 8px; }
.error-box p { color: var(--text-3); margin-bottom: 20px; }
.error-detail { margin-top: 20px; padding: 12px; max-height: 320px; overflow: auto; background: var(--surface-2); border-radius: 8px; font-size: 12px; white-space: pre-wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
    .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
    body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(15, 23, 42, 0.45); }
    .topbar .sidebar-toggle { display: inline-flex; }
    .main { margin-left: 0; }
    .topbar { padding: 0 20px; }
    .content { padding: 22px 20px 32px; }
    .app-footer { padding: 16px 20px; }
    .profile-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .auth { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
    .auth-card-logo { display: block; }
}
@media (max-width: 720px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: 1fr; }
    .detail-list { grid-template-columns: 1fr; gap: 2px; }
    .detail-list dd { margin-bottom: 10px; }
    .filters, .filters .field, .filters .field-grow { width: 100%; min-width: 0; }
    .toolbar > .btn { width: 100%; }
    .table { min-width: 760px; }
    .page-actions, .page-actions .btn { width: 100%; }
    .report-item { grid-template-columns: 42px minmax(0, 1fr); }
    .report-item > .btn, .report-options { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
    .topbar-date, .user-meta { display: none; }
    .content { padding: 18px 16px 28px; }
    .auth-card { padding: 28px 22px; }
    .page-title { font-size: 21px; }
    .dialog-footer { flex-wrap: wrap; }
}
@media (max-width: 420px) {
    .stat-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media print {
    .sidebar, .topbar, .app-footer, .toolbar, .pagination, .page-actions, .col-actions { display: none !important; }
    .main { margin: 0; }
    .card { box-shadow: none; }
}
