:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --ink: #1f2933;
    --muted: #6b7280;
    --line: #e2e8f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --ok: #16a34a;
    --warn: #d97706;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Fly-out detail panel — opened purely via :target, so no JavaScript is needed
   under the strict CSP. Hidden until its id matches the URL fragment. */
.flyout { display: none; }
.flyout:target { display: block; }
.flyout-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 40;
}
.flyout-panel {
    position: fixed; top: 0; right: 0; z-index: 41;
    width: min(420px, 92vw); height: 100%; overflow-y: auto;
    background: #fff; box-shadow: -2px 0 12px rgba(0, 0, 0, .25);
    padding: 1rem 1.25rem;
}
.flyout-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.flyout-head h4 { margin: .25rem 0 .75rem; }
.flyout-close { font-size: 1.5rem; line-height: 1; text-decoration: none; color: var(--ink, #0f172a); }
.flyout-panel .table th { width: 45%; white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) {
    .flyout:target .flyout-panel { animation: flyout-in .15s ease-out; }
    @keyframes flyout-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
}

/* Maintenance-mode banner (site-wide, so an active outage is never forgotten) */
.maintenance-banner {
    background: var(--danger); color: #fff;
    padding: .6rem 1.25rem; text-align: center; font-size: .85rem; font-weight: 600;
}
.maintenance-banner a { color: #fff; text-decoration: underline; margin-left: .5rem; }

/* Top bar */
.topbar {
    display: flex; align-items: center; gap: 1.5rem;
    background: #0f172a; color: #fff; padding: .75rem 1.25rem;
}
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: 1rem; flex: 1; }
.mainnav a { color: #cbd5e1; }
.mainnav a:hover { color: #fff; text-decoration: none; }
.userbox { display: flex; align-items: center; gap: .75rem; font-size: .85rem; color: #cbd5e1; }
.inline { display: inline; }
.row-actions { display: flex; gap: .4rem; align-items: center; }
.link-btn { background: none; border: none; color: #93c5fd; cursor: pointer; padding: 0; font-size: .85rem; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

.container { max-width: 1100px; margin: 1.5rem auto; padding: 0 1.25rem; }
.page-title { margin: 0 0 1rem; font-size: 1.5rem; }
.footer { text-align: center; color: var(--muted); padding: 2rem 0; }

/* Cards & tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.table th, .table td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.table th { background: #f8fafc; font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table-compact th, .table-compact td { padding: .35rem .5rem; font-size: .8rem; }

/* List quick-filters, bulk actions, pagination */
.quick-filters { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin: .25rem 0 1rem; }
.quick-label { color: var(--muted); font-size: .85rem; margin-right: .25rem; }
.chip { display: inline-block; padding: .2rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink); font-size: .82rem; }
.chip:hover { text-decoration: none; background: #f1f5f9; }
.chip-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-active:hover { background: var(--primary-dark); }

/* Saved views (per-agent saved searches) */
.saved-views { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin: -.5rem 0 1rem; }
.saved-view-chip { display: inline-flex; align-items: center; gap: .2rem; padding: .2rem .3rem .2rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: .82rem; }
.saved-view-chip.chip-active { background: var(--primary); border-color: var(--primary); }
.saved-view-chip.chip-active .chip-link { color: #fff; }
.saved-view-chip .chip-link { color: var(--ink); }
.saved-view-chip .chip-link:hover { text-decoration: none; }
.chip-remove { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 .25rem; }
.saved-view-chip.chip-active .chip-remove { color: #e2e8f0; }

/* Active-filter summary chips (removable) */
.active-filters { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin: -.25rem 0 1rem; }
.filter-chip { display: inline-flex; align-items: center; gap: .4rem; padding: .2rem .3rem .2rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); font-size: .82rem; }
.filter-chip a { color: var(--muted); font-weight: 700; line-height: 1; text-decoration: none; padding: 0 .2rem; }
.filter-chip a:hover { color: #dc2626; text-decoration: none; }
.chip-clear { color: var(--muted); font-size: .82rem; text-decoration: underline; }

/* Collapsible "Search & filter" disclosure */
.search-details { margin: 0 0 1rem; }
.search-summary { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; font-weight: 600; padding: .35rem 0; list-style: none; }
.search-summary::-webkit-details-marker { display: none; }
.search-summary::before { content: "\25B8"; color: var(--muted); font-size: .8rem; }
.search-details[open] .search-summary::before { content: "\25BE"; }
.search-details > .search-form { margin-top: .5rem; }
.form-row-wide { grid-column: span 2; }
.badge-count { display: inline-flex; min-width: 1.25rem; height: 1.25rem; padding: 0 .35rem; align-items: center; justify-content: center; background: var(--primary); color: #fff; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.btn-primary .badge-count { background: rgba(255, 255, 255, .3); }
.chip-remove:hover { color: var(--danger, #dc2626); }
.saved-view-save { display: inline-flex; align-items: center; gap: .3rem; }
.saved-view-name { padding: .2rem .5rem; border: 1px solid var(--line); border-radius: 6px; font-size: .82rem; }

/* Canned response picker in the comment composer */
.canned-picker { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.canned-label { color: var(--muted); font-size: .85rem; margin: 0; }
.canned-select { padding: .25rem .5rem; border: 1px solid var(--line); border-radius: 6px; font-size: .85rem; max-width: 100%; }

/* Inline field hint text under form controls */
.field-hint { color: var(--muted); font-size: .8rem; margin: .25rem 0 0; }

.bulk-bar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.bulk-label { font-weight: 600; font-size: .85rem; margin: 0; }
.bulk-bar select { width: auto; }
.col-check { width: 1.5rem; text-align: center; }
.pager { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; margin: 1rem 0; }
.pager .btn.disabled { opacity: .5; pointer-events: none; }
.pager-gap { color: var(--muted); padding: 0 .2rem; }

/* Buttons */
.btn { display: inline-block; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; font-size: .9rem; line-height: 1.5; }
.btn:hover { text-decoration: none; background: #f1f5f9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: .25rem .55rem; font-size: .8rem; }
.btn-block { width: 100%; }
.toolbar { display: flex; gap: .5rem; margin: 1rem 0; flex-wrap: wrap; }

/* Toolbar fly-out (native <details>, no JavaScript — CSP-safe). The panel is
   absolutely positioned so it overlays content instead of pushing the layout.
   Uses a dedicated class name so it never collides with the end-user .flyout. */
.resolve-flyout { position: relative; display: inline-block; }
.resolve-flyout > summary { list-style: none; }
.resolve-flyout > summary::-webkit-details-marker { display: none; }
.resolve-flyout > summary::marker { content: ""; }
.resolve-flyout-panel {
    position: absolute;
    top: calc(100% + .4rem);
    left: 0;
    z-index: 30;
    width: 340px;
    max-width: 90vw;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.resolve-flyout-panel .form-row { margin-bottom: .75rem; }

/* Forms */
.card-form, .search-form { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 1.25rem; box-shadow: var(--shadow); }
.card-form + .card-form { margin-top: 1rem; }
.form-row { margin-bottom: 1rem; display: flex; flex-direction: column; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
label { font-weight: 600; margin-bottom: .3rem; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=time], select, textarea {
    padding: .5rem .6rem; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; width: 100%; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
textarea { resize: vertical; }
.checkbox { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; }
.checkbox input { width: auto; }
.checkbox-spaced { margin-top: 1.8rem; }
.fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 1rem; margin: 1rem 0; }
.fieldset legend { font-weight: 600; padding: 0 .4rem; }
.card-form > .fieldset:first-of-type { margin-top: 0; }
.card-form .fieldset legend { color: var(--primary); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
/* Settings page polish: section nav, group descriptions, grid, danger + sticky bar. */
.settings-toc { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: 1rem; padding: .6rem .85rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.settings-toc a { font-size: .85rem; color: var(--muted); padding: .2rem .6rem; border-radius: 999px; }
.settings-toc a:hover { color: var(--ink); background: var(--bg); text-decoration: none; }
.fieldset-desc { margin: 0 0 .85rem; font-size: .85rem; line-height: 1.4; }
.form-grid > .form-row:has(textarea) { grid-column: 1 / -1; }
.unit-hint { font-style: italic; }
.fieldset-danger { border-color: var(--danger); }
.fieldset-danger legend { color: var(--danger); }
.fieldset-danger .fieldset-desc { color: var(--danger); }
.toolbar-sticky { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: .75rem 0 .25rem; margin-top: 1.25rem; box-shadow: 0 -6px 14px rgba(0,0,0,.05); }
/* Mail settings: progressive disclosure with no JavaScript (CSP-safe).
   Rows are visible by default and only hidden when the conditions are met, so
   browsers without :has() support simply show every field. */
.fieldset:has(select[name="settings[mail.transport]"] option[value="mail"]:checked) .mail-graph-only { display: none; }
.fieldset:has(input[name="settings[mail.use_sso_app]"]:checked) .mail-app-cred { display: none; }
.fieldset:has(select[name="settings[mail.graph_auth]"] option[value="certificate"]:checked) .mail-auth-secret { display: none; }
.fieldset:has(select[name="settings[mail.graph_auth]"] option[value="secret"]:checked) .mail-auth-cert { display: none; }
.fieldset:has(select[name="settings[sso.auth_method]"] option[value="certificate"]:checked) .sso-auth-secret { display: none; }
.fieldset:has(select[name="settings[sso.auth_method]"] option[value="secret"]:checked) .sso-auth-cert { display: none; }
/* Inbound mail: the routing fields are hidden until processing is enabled. */
.fieldset:not(:has(input[name="settings[mail.inbound_enabled]"]:checked)) .mail-inbound-only { display: none; }
/* SLA coverage: custom window is shown by default and hidden for fixed presets. */
.sla-coverage:has(select[name="coverage_preset"] option[value="24x7"]:checked) .sla-custom { display: none; }
.sla-coverage:has(select[name="coverage_preset"] option[value="5x8"]:checked) .sla-custom { display: none; }
.sla-coverage:has(select[name="coverage_preset"] option[value="5x10"]:checked) .sla-custom { display: none; }
.checkbox-list { display: flex; flex-wrap: wrap; gap: .75rem; }
.inline-search { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-search input { flex: 1 1 220px; min-width: 180px; max-width: 320px; }
.inline-search select { width: auto; min-width: 180px; }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .9rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert ul { margin: .4rem 0 0 1.1rem; }

/* Badges */
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .72rem; text-transform: capitalize; font-weight: 600; white-space: nowrap; }
.prio-p4 { background: #e0f2fe; color: #075985; }
.prio-p3 { background: #fef9c3; color: #854d0e; }
.prio-p2 { background: #ffedd5; color: #9a3412; }
.prio-p1 { background: #fee2e2; color: #991b1b; }
.status-new { background: #dbeafe; color: #1e40af; }
.status-in_progress { background: #ede9fe; color: #5b21b6; }
.status-on_hold { background: #f3f4f6; color: #374151; }
.status-resolved { background: #dcfce7; color: #166534; }
.status-closed { background: #e5e7eb; color: #374151; }
.role-admin { background: #fee2e2; color: #991b1b; }
.role-agent { background: #dbeafe; color: #1e40af; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef9c3; color: #854d0e; }
.badge-danger { background: #fee2e2; color: #991b1b; }

/* Change management badges */
.chg-type-standard { background: #dbeafe; color: #1e40af; }
.chg-type-normal { background: #e5e7eb; color: #374151; }
.chg-type-emergency { background: #fee2e2; color: #991b1b; }
.risk-low { background: #dcfce7; color: #166534; }
.risk-medium { background: #fef9c3; color: #854d0e; }
.risk-high { background: #ffedd5; color: #9a3412; }
.risk-critical { background: #fee2e2; color: #991b1b; }
.chg-status-draft { background: #f3f4f6; color: #374151; }
.chg-status-assessment { background: #e0f2fe; color: #075985; }
.chg-status-pending_approval { background: #fef9c3; color: #854d0e; }
.chg-status-approved { background: #dbeafe; color: #1e40af; }
.chg-status-scheduled { background: #ede9fe; color: #5b21b6; }
.chg-status-implementing { background: #cffafe; color: #155e75; }
.chg-status-review { background: #fef3c7; color: #92400e; }
.chg-status-completed { background: #dcfce7; color: #166534; }
.chg-status-rejected { background: #fee2e2; color: #991b1b; }
.chg-status-cancelled { background: #e5e7eb; color: #374151; }
.chg-status-failed { background: #fee2e2; color: #991b1b; }
.chg-status-rolled_back { background: #ffedd5; color: #9a3412; }
.task-pending { background: #f3f4f6; color: #374151; }
.task-in_progress { background: #ede9fe; color: #5b21b6; }
.task-completed { background: #dcfce7; color: #166534; }
.task-skipped { background: #e5e7eb; color: #6b7280; }
.inline-add { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .75rem; }
.checkbox-inline { display: flex; align-items: center; gap: .4rem; }
.cal-title { font-weight: 700; padding: 0 .5rem; }
.cal-day { margin-top: 1rem; }

/* Dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 1rem; text-align: center; box-shadow: var(--shadow); }
.stat-number { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .85rem; }

/* Detail layout */
.detail-grid {
    display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: auto 1fr;
    gap: 1.25rem; align-items: start;
}
/* The sidebar sits in the right column and spans the stacked main-column cards
   (ticket summary + activity feed) so the wide column is filled with content
   instead of leaving whitespace beside a short summary card. The flexible second
   row (1fr) absorbs any sidebar overflow at the bottom of the left column, so the
   summary and activity cards stay tightly stacked instead of being pushed apart. */
.detail-grid > .sidecard { grid-column: 2; grid-row: 1 / span 2; }
.sidecard dl.meta { display: grid; grid-template-columns: auto 1fr; gap: .3rem .75rem; font-size: .85rem; align-items: baseline; }
.sidecard dl.meta dt { color: var(--muted); }
.sidecard dl.meta dd { margin: 0; word-break: break-word; }
.sidecard dl.meta dt.meta-section {
    grid-column: 1 / -1; margin: .75rem 0 .15rem; color: var(--primary);
    font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    border-bottom: 1px solid var(--line); padding-bottom: .25rem;
}
.sidecard dl.meta dt.meta-section:first-child { margin-top: 0; }
.sidecard dl.meta dd.meta-spacer { display: none; }

/* End-user flyout (CSS-only, no JS) */
.flyout { position: relative; display: inline-block; }
.flyout > summary { list-style: none; cursor: pointer; color: var(--primary); font-weight: 600; }
.flyout > summary::-webkit-details-marker { display: none; }
.flyout > summary::after { content: " \25BE"; font-size: .7em; color: var(--muted); }
.flyout > summary:hover { text-decoration: underline; }
.flyout[open] > summary::after { content: " \25B4"; }
.flyout-panel {
    position: absolute; z-index: 60; top: 100%; right: 0; margin-top: .35rem;
    width: 260px; background: var(--card); border: 1px solid var(--line);
    border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: .85rem; text-align: left;
}
.flyout-name { margin: 0 0 .5rem; font-weight: 700; font-size: .95rem; display: flex; align-items: center; gap: .4rem; }
dl.flyout-meta { display: grid; grid-template-columns: auto 1fr; gap: .2rem .6rem; font-size: .8rem; margin: 0 0 .6rem; }
dl.flyout-meta dt { color: var(--muted); }
dl.flyout-meta dd { margin: 0; word-break: break-word; }
.readonly-bar { display: flex; gap: 2rem; background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 8px; padding: .75rem 1rem; margin-bottom: 1rem; font-size: .9rem; }
.ticket-desc { white-space: pre-wrap; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: .75rem; margin: .5rem 0 1rem; }
.comments { list-style: none; padding: 0; }
.comments li { border: 1px solid var(--line); border-radius: 6px; padding: .6rem .75rem; margin-bottom: .5rem; }
.comments li.internal { background: #fffbeb; border-color: #fde68a; }
.comment-head { display: flex; gap: .6rem; align-items: center; font-size: .8rem; margin-bottom: .3rem; }
.tag { background: var(--warn); color: #fff; border-radius: 4px; padding: 0 .35rem; font-size: .7rem; }
.tag-email { background: var(--accent, #2563eb); }
.attachments { list-style: none; padding: 0; }
.attachments li { display: flex; gap: .4rem; align-items: center; font-size: .85rem; margin-bottom: .35rem; }
.upload-form { margin-top: .75rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.comment-form { margin-top: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.muted { color: var(--muted); }

/* Unified ticket activity timeline (comments + audit events) */
.activity-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.activity-head h3 { margin: 0; }
.timeline { list-style: none; padding: 0; margin: .75rem 0 0; }
.timeline-item { border-left: 2px solid var(--line); padding: .35rem 0 .6rem .75rem; margin-left: .25rem; position: relative; }
.timeline-item::before { content: ""; position: absolute; left: -5px; top: .55rem; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.timeline-meta { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; font-size: .8rem; margin-bottom: .25rem; }
.timeline-comment { border-left-color: var(--accent, #2563eb); }
.timeline-comment::before { background: var(--accent, #2563eb); }
.timeline-comment.internal { background: #fffbeb; border-left-color: #f59e0b; }
.timeline-comment.internal::before { background: #f59e0b; }
.timeline-body { white-space: normal; }
.timeline-event .timeline-action { font-weight: 600; }
.timeline-detail { font-size: .85rem; color: var(--muted); }
/* The list is rendered newest-first, so the first item is the most recent
   activity. Give it a larger, haloed marker so the latest entry stands out. */
.timeline-item:first-child::before {
    width: 13px; height: 13px; left: -7px; top: .45rem;
    background: var(--primary); box-shadow: 0 0 0 3px var(--card), 0 0 0 4px var(--primary);
}

/* Secondary line inside a table cell (e.g. company under the end-user name) */
.cell-sub { display: block; color: var(--muted); font-size: .8rem; }

/* Admin sub-navigation */
/* Admin section navigation — left sidebar (content flows in the right column).
   Uses grid rather than a float so table/BFC content sits beside the nav
   instead of dropping below it. */
.container:has(> .subnav) { display: grid; grid-template-columns: 190px minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
.container:has(> .subnav) > * { grid-column: 2; min-width: 0; }
.container:has(> .subnav) > .page-title { grid-column: 1 / -1; }
.container:has(> .subnav) > .subnav { grid-column: 1; grid-row: 2 / 100; }
.subnav { display: flex; flex-direction: column; gap: 1.1rem; padding-right: 1rem; border-right: 1px solid var(--line); }
.subnav-group { display: flex; flex-direction: column; gap: .2rem; flex: none; }
.subnav-group-label { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.subnav-links { display: flex; flex-direction: column; gap: .1rem; }
.subnav-links a { display: block; padding: .35rem .6rem; color: var(--muted); border-radius: 6px; border-left: 2px solid transparent; white-space: nowrap; }
.subnav-links a:hover { text-decoration: none; color: var(--ink); background: var(--bg); }
.subnav-links a.active { color: var(--primary); border-left-color: var(--primary); font-weight: 600; background: var(--bg); }

@media (max-width: 820px) {
    .container:has(> .subnav) { display: block; }
    .container:has(> .subnav) > .subnav { grid-row: auto; }
    .subnav { flex-direction: row; flex-wrap: wrap; gap: .75rem 1.5rem; margin: 0 0 1.25rem; padding: 0 0 .75rem; border-right: 0; border-bottom: 1px solid var(--line); }
    .subnav-links { flex-direction: row; flex-wrap: wrap; gap: .15rem; }
    .subnav-links a { border-left: 0; }
}

/* Admin home (card-based landing) */
.admin-home-group { margin-bottom: 1.75rem; }
.admin-home-heading { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 .6rem; }
.admin-home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.admin-home-card { display: flex; flex-direction: column; gap: .25rem; padding: .9rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.admin-home-card:hover { text-decoration: none; border-color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.admin-home-card-title { font-weight: 600; color: var(--primary); }
.admin-home-card-desc { font-size: .85rem; color: var(--muted); }

/* CSS-only dashboard tabs (no JS; CSP-safe) */
.tabs { margin-top: .5rem; }
.tabs .tab-radio { position: absolute; opacity: 0; pointer-events: none; }
.tab-labels { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tab-labels label { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; user-select: none; }
.tab-labels label:hover { color: var(--ink); }
.tab-panel { display: none; }
#tab-mine:checked ~ .tab-labels label[for="tab-mine"],
#tab-unassigned:checked ~ .tab-labels label[for="tab-unassigned"],
#tab-queue:checked ~ .tab-labels label[for="tab-queue"],
#tab-due:checked ~ .tab-labels label[for="tab-due"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
#tab-mine:checked ~ #panel-mine,
#tab-unassigned:checked ~ #panel-unassigned,
#tab-queue:checked ~ #panel-queue,
#tab-due:checked ~ #panel-due { display: block; }
.tab-radio:focus-visible ~ .tab-labels label { outline: 2px solid var(--primary); }
#ctab-mine:checked ~ .tab-labels label[for="ctab-mine"],
#ctab-approval:checked ~ .tab-labels label[for="ctab-approval"],
#ctab-upcoming:checked ~ .tab-labels label[for="ctab-upcoming"],
#ctab-impl:checked ~ .tab-labels label[for="ctab-impl"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
#ctab-mine:checked ~ #cpanel-mine,
#ctab-approval:checked ~ #cpanel-approval,
#ctab-upcoming:checked ~ #cpanel-upcoming,
#ctab-impl:checked ~ #cpanel-impl { display: block; }
.dash-heading { margin: 1.75rem 0 .75rem; font-size: 1.1rem; }
.dash-heading:first-of-type { margin-top: .25rem; }

/* Field-level errors + misc */
.field-error { color: var(--danger); font-size: .8rem; margin-top: .25rem; }
.field-note { display: block; font-size: .8rem; margin-top: .25rem; color: var(--ink); }
.form-row small.muted { margin-top: .25rem; }
code.details { display: block; max-width: 420px; overflow-x: auto; white-space: nowrap; font-size: .75rem; }
.pager { display: flex; gap: .5rem; margin: 1rem 0; }

@media (max-width: 800px) {
    .detail-grid { grid-template-columns: 1fr; grid-template-rows: none; }
    .detail-grid > .sidecard { grid-column: auto; grid-row: auto; }
    .topbar { flex-wrap: wrap; }
}

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #0f172a; }
.login-card { background: #fff; padding: 2rem; border-radius: 10px; width: 100%; max-width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.login-card h1 { margin: 0 0 .25rem; }
.login-card form { display: flex; flex-direction: column; gap: .25rem; }
.login-card label { margin-top: .5rem; }
.login-card .btn { margin-top: 1rem; }
.login-divider { text-align: center; margin: 1rem 0 .25rem; position: relative; }

/* Notification bell */
.notif { position: relative; }
.notif > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; position: relative; color: #cbd5e1; padding: .15rem; }
.notif > summary::-webkit-details-marker { display: none; }
.notif > summary:hover { color: #fff; }
.notif-icon.active { color: #fbbf24; }
.notif-count {
    position: absolute; top: -6px; right: -8px; background: var(--danger); color: #fff;
    border-radius: 999px; font-size: .65rem; line-height: 1; padding: .12rem .3rem; font-weight: 700;
}
.notif-panel {
    position: absolute; right: 0; top: calc(100% + .5rem); width: 340px; max-width: 86vw;
    background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,.2); z-index: 50; overflow: hidden;
}
.notif-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem .8rem; border-bottom: 1px solid var(--line); }
.notif-empty { padding: 1rem .8rem; color: var(--muted); font-size: .85rem; margin: 0; }
.notif-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.notif-item a { display: block; padding: .6rem .8rem; border-bottom: 1px solid var(--line); color: var(--ink); }
.notif-item a:hover { background: #f1f5f9; text-decoration: none; }
.notif-item.unread { background: #eff6ff; }
.notif-item.unread a { border-left: 3px solid var(--primary); }
.notif-title { display: block; font-weight: 600; font-size: .85rem; }
.notif-body { display: block; font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.notif-time { display: block; font-size: .72rem; color: var(--muted); margin-top: .2rem; }
.notif-foot { padding: .55rem .8rem; text-align: center; font-size: .85rem; }
.row-unread { background: #eff6ff; }
.dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 999px; background: var(--primary); }

/* CSV import */
.import-errors { margin: .5rem 0 0 1.1rem; font-size: .85rem; color: #991b1b; }
.import-errors li { margin-bottom: .2rem; }

@media (max-width: 800px) {
    .notif-panel { position: fixed; left: .5rem; right: .5rem; width: auto; top: 56px; }
}

/* Reports */
.report-filters { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.25rem; }
.report-filters .form-row { margin-bottom: 0; }
.report-filters .form-row-actions { flex-direction: row; gap: .5rem; }
.report-email-form { margin: 0 0 1rem; }
.report-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .75rem; margin-top: 1rem; }
.stat { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: .85rem 1rem; text-align: center; }
.stat-num { display: block; font-size: 1.6rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.stat-label { display: block; font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.report-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-top: 1rem; }
.report-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.report-table th, .report-table td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
.report-table td + td, .report-table th + th { text-align: right; }
.report-table tfoot th { border-top: 2px solid var(--line); border-bottom: none; }

@media (max-width: 800px) {
    .report-columns { grid-template-columns: 1fr; }
}

/* KPI strip with trend deltas */
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin-top: 1rem; }
.kpi { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; text-align: center; }
.kpi-num { display: block; font-size: 1.6rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.kpi-label { display: block; font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.kpi-delta { display: block; font-size: .78rem; margin-top: .3rem; font-weight: 600; }
.kpi-delta.up { color: #059669; }
.kpi-delta.down { color: #dc2626; }
.kpi-delta.flat { color: var(--muted); }

/* CSP-safe horizontal bars (width via predefined classes) */
.bar { display: inline-block; vertical-align: middle; width: 90px; height: 8px; margin-left: .4rem; background: #e5e7eb; border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.w-0 { width: 0; } .w-5 { width: 5%; } .w-10 { width: 10%; } .w-15 { width: 15%; }
.w-20 { width: 20%; } .w-25 { width: 25%; } .w-30 { width: 30%; } .w-35 { width: 35%; }
.w-40 { width: 40%; } .w-45 { width: 45%; } .w-50 { width: 50%; } .w-55 { width: 55%; }
.w-60 { width: 60%; } .w-65 { width: 65%; } .w-70 { width: 70%; } .w-75 { width: 75%; }
.w-80 { width: 80%; } .w-85 { width: 85%; } .w-90 { width: 90%; } .w-95 { width: 95%; }
.w-100 { width: 100%; }

