/* Design tokens */
:root {
    --justice-navy: #14213d;
    --justice-navy-2: #1d3557;
    --justice-blue: #2563eb;
    --justice-sky: #0ea5e9;
    --justice-gold: #c9a227;
    --justice-bg: #f4f7fb;
    --justice-panel: #ffffff;
    --justice-border: #d8e0eb;
    --justice-muted: #64748b;
    --justice-text: #172033;
    --justice-danger: #dc2626;
    --justice-warning: #f59e0b;
    --justice-success: #16a34a;
    --sidebar-width: 286px;
    --sidebar-collapsed: 86px;
    --topbar-height: 76px;
}

/* Base */
* { box-sizing: border-box; }

body {
    min-height: 100vh;
    background: var(--justice-bg);
    color: var(--justice-text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a { color: var(--justice-blue); text-decoration: none; }
a:hover { color: #1d4ed8; }

:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .28);
    outline-offset: 2px;
}

/* Layout */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns .2s ease;
}

.app-layout.sidebar-collapsed {
    grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr);
}

.content-wrap { min-width: 0; }

.content-area {
    width: 100%;
    max-width: 100%;
    padding: 24px;
    overflow-x: hidden;
}

.guest-shell {
    background: var(--justice-bg);
}

/* Sidebar */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 18px 14px;
    background: linear-gradient(180deg, #101d35, #172a4a);
    color: #e5edf8;
    z-index: 1040;
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 8px 12px;
    color: #e5edf8;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.sidebar-brand:hover {
    color: #fff;
}

.sidebar-logo-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    max-width: 86px;
    min-height: 36px;
    padding: 4px 6px;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .14);
}

.sidebar-logo {
    display: block;
    height: auto;
    object-fit: contain;
}

.sidebar-logo-dugan {
    width: min(72px, 100%);
}

.sidebar-logo-letter {
    display: none;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 9px;
    background: #fff;
    color: #12385a;
    font-size: 1.35rem;
    font-weight: 850;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.sidebar-brand-text strong {
    color: inherit;
    font-size: .86rem;
    font-weight: 700;
}

.sidebar-brand-text small {
    margin-top: 2px;
    color: #b7c5da;
    font-size: .7rem;
}

.sidebar-nav {
    display: grid;
    gap: 4px;
}

.sidebar-link {
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #dce7f7;
    font-size: .94rem;
}

.sidebar-link:hover,
.sidebar-link.active {
    color: #fff;
    background: rgba(255, 255, 255, .11);
}

.sidebar-link.disabled {
    color: rgba(220, 231, 247, .45);
    cursor: not-allowed;
}

.sidebar-link i {
    width: 22px;
    text-align: center;
    font-size: 1.05rem;
}

.sidebar-user {
    margin-top: auto;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 34px;
    align-items: center;
    gap: 10px;
    padding: 12px 8px 4px;
    border-top: 1px solid rgba(255, 255, 255, .12);
}

.avatar {
    width: 42px;
    height: 42px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: #e8eef8;
    color: var(--justice-navy);
    font-weight: 700;
}

.avatar-sm {
    width: 30px;
    height: 30px;
    font-size: .82rem;
}

.user-name {
    overflow: hidden;
    color: #fff;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role {
    color: #b7c5da;
    font-size: .78rem;
}

.logout-link {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    color: #dce7f7;
}

.logout-link:hover { background: rgba(255, 255, 255, .1); color: #fff; }

.sidebar-collapsed .sidebar-brand-text,
.sidebar-collapsed .sidebar-link span,
.sidebar-collapsed .user-meta,
.sidebar-collapsed .logout-link {
    display: none;
}

.sidebar-collapsed .sidebar-brand,
.sidebar-collapsed .sidebar-link,
.sidebar-collapsed .sidebar-user {
    justify-content: center;
}

.sidebar-collapsed .sidebar-brand {
    align-items: center;
    padding-inline: 0;
}

.sidebar-collapsed .sidebar-logo-wrap {
    width: 42px;
    min-height: 42px;
    padding: 4px;
    border-radius: 10px;
}

.sidebar-collapsed .sidebar-logo {
    display: none;
}

.sidebar-collapsed .sidebar-logo-letter {
    display: grid;
}

.sidebar-collapsed .sidebar-user {
    grid-template-columns: 42px;
}

/* Topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    min-height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    background: rgba(244, 247, 251, .92);
    border-bottom: 1px solid var(--justice-border);
    backdrop-filter: blur(14px);
}

.topbar-left,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-actions > * {
    min-width: 0;
}

.breadcrumb-line {
    color: var(--justice-muted);
    font-size: .78rem;
}

.page-title {
    margin: 0;
    color: var(--justice-navy);
    font-size: 1.25rem;
    font-weight: 750;
}

.icon-btn,
.user-menu {
    min-width: 42px;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--justice-border);
    border-radius: 8px;
    background: #fff;
    color: var(--justice-navy);
}

.global-search {
    position: relative;
    width: min(320px, 28vw);
}

.global-search i {
    position: absolute;
    top: 50%;
    left: 12px;
    color: var(--justice-muted);
    transform: translateY(-50%);
}

.global-search input {
    width: 100%;
    min-height: 42px;
    padding: 8px 12px 8px 38px;
    border: 1px solid var(--justice-border);
    border-radius: 8px;
}

/* Cards */
.panel,
.metric-card,
.info-card {
    background: var(--justice-panel);
    border: 1px solid var(--justice-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(20, 33, 61, .06);
}

.section-title {
    margin: 0;
    color: var(--justice-navy);
    font-size: 1rem;
    font-weight: 750;
}

.metric-card {
    min-height: 128px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px;
}

.metric-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.metric-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #eef4ff;
    color: var(--justice-blue);
}

.metric-icon.warn { background: #fff7ed; color: var(--justice-warning); }
.metric-icon.danger { background: #fef2f2; color: var(--justice-danger); }
.metric-icon.success { background: #ecfdf5; color: var(--justice-success); }
.metric-icon.gold { background: #fff8db; color: #a17710; }

.metric-label {
    color: var(--justice-muted);
    font-size: .82rem;
}

.metric-value {
    margin-top: 4px;
    color: var(--justice-navy);
    font-size: 1.85rem;
    font-weight: 800;
}

.metric-note {
    color: var(--justice-muted);
    font-size: .78rem;
}

.alert-sla { border-left: 5px solid var(--justice-warning); }
.alert-substitute { border-left: 5px solid var(--justice-danger); }

/* Tables */
.table {
    margin-bottom: 0;
    min-width: 860px;
}

.table thead th {
    color: #475569;
    font-size: .76rem;
    font-weight: 750;
    text-transform: uppercase;
    white-space: nowrap;
}

.table td {
    vertical-align: middle;
}

.row-sla-danger {
    box-shadow: inset 4px 0 0 var(--justice-danger);
}

.table-action {
    min-width: 92px;
}

.empty-state {
    padding: 34px 18px;
    text-align: center;
    color: var(--justice-muted);
}

/* Forms */
.form-label {
    color: #334155;
    font-size: .86rem;
    font-weight: 650;
}

.form-control,
.form-select {
    border-color: var(--justice-border);
    border-radius: 8px;
    min-height: 42px;
}

.btn {
    border-radius: 8px;
    min-height: 40px;
}

.btn-primary {
    background: var(--justice-blue);
    border-color: var(--justice-blue);
}

.btn-primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.filter-toolbar {
    display: grid;
    grid-template-columns: 1.4fr repeat(3, minmax(140px, .8fr)) auto auto;
    gap: 10px;
    align-items: end;
}

.form-section {
    padding: 20px;
    border-bottom: 1px solid var(--justice-border);
}

.form-section:last-child { border-bottom: 0; }

.choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.choice-card {
    position: relative;
}

.choice-card input {
    position: absolute;
    opacity: 0;
}

.choice-card span {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 54px;
    padding: 12px;
    border: 1px solid var(--justice-border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}

.choice-card input:checked + span {
    border-color: var(--justice-blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.upload-zone {
    display: grid;
    place-items: center;
    min-height: 132px;
    padding: 18px;
    border: 1px dashed #9fb1c8;
    border-radius: 8px;
    background: #f8fbff;
    text-align: center;
}

/* Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: .32rem;
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: 999px;
    padding: .32rem .55rem;
    font-size: .72rem;
    font-weight: 750;
    letter-spacing: .01em;
    box-shadow: 0 2px 6px rgba(15, 23, 42, .07);
    white-space: nowrap;
}

.status-badge i {
    font-size: .72rem;
}

.sla-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: .36rem .62rem;
    font-size: .82rem;
    font-weight: 700;
}

.sla-normal { background: #ecfdf5; color: #166534; }
.sla-watch { background: #fff8db; color: #854d0e; }
.sla-critical { background: #fff7ed; color: #9a3412; }
.sla-overdue { background: #fef2f2; color: #991b1b; }

.sla-meter {
    --sla-color: #16a34a;
    --sla-soft: #ecfdf5;
    display: grid;
    grid-template-columns: 26px minmax(54px, 1fr) auto;
    align-items: center;
    gap: .38rem;
    min-width: 142px;
    max-width: 168px;
    padding: .34rem .42rem .3rem;
    border: 1px solid #e2e8f0;
    border-color: color-mix(in srgb, var(--sla-color) 24%, white);
    border-radius: 8px;
    background: linear-gradient(135deg, #fff, var(--sla-soft));
    box-shadow: 0 2px 7px rgba(15, 23, 42, .05);
}

.sla-meter.sla-watch { --sla-color: #ca8a04; --sla-soft: #fffbeb; }
.sla-meter.sla-critical { --sla-color: #ea580c; --sla-soft: #fff7ed; }
.sla-meter.sla-overdue { --sla-color: #dc2626; --sla-soft: #fef2f2; }

.sla-meter-icon {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 7px;
    color: #fff;
    background: var(--sla-color);
    font-size: .7rem;
    box-shadow: 0 2px 6px rgba(15, 23, 42, .1);
    box-shadow: 0 2px 6px color-mix(in srgb, var(--sla-color) 24%, transparent);
}

.sla-meter-copy { min-width: 0; }
.sla-meter-label { color: #64748b; font-size: .56rem; font-weight: 750; letter-spacing: .05em; line-height: 1; text-transform: uppercase; }
.sla-meter-value { color: #172033; font-size: .76rem; font-weight: 800; line-height: 1.1; white-space: nowrap; }
.sla-meter-state { color: var(--sla-color); font-size: .6rem; font-weight: 800; white-space: nowrap; }
.sla-meter-track { grid-column: 2 / 4; height: 3px; margin-top: -1px; overflow: hidden; border-radius: 999px; background: rgba(148, 163, 184, .2); }
.sla-meter-bar { height: 100%; border-radius: inherit; background: var(--sla-color); }

.duration-chip {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .3rem .52rem;
    border: 1px solid #fed7aa;
    border-radius: 999px;
    color: #9a3412;
    background: #fff7ed;
    font-size: .7rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(154, 52, 18, .07);
}

.duration-chip.is-overdue {
    border-color: #fecaca;
    color: #b91c1c;
    background: #fef2f2;
}

.duration-chip.is-complete {
    border-color: #bbf7d0;
    color: #166534;
    background: #f0fdf4;
}

/* Auth/Login */
.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(360px, .95fr) minmax(360px, 1.05fr);
    background: #fff;
}

.auth-hero {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: clamp(32px, 7vw, 80px);
    background:
        linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px),
        linear-gradient(135deg, #0f1d35, #1d4f8f);
    background-size: 28px 28px, 28px 28px, auto;
    color: #fff;
}

.auth-hero::after {
    content: "";
    position: absolute;
    inset: auto -15% -20% 20%;
    height: 280px;
    background: linear-gradient(90deg, rgba(201, 162, 39, .2), rgba(14, 165, 233, .12));
    transform: rotate(-8deg);
}

.login-brand {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    max-width: 100%;
    padding: 14px 20px;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .12);
}

.login-brand-logo {
    display: block;
    height: auto;
    object-fit: contain;
}

.login-brand-dugan {
    width: min(185px, 58vw);
}

.auth-hero h1 {
    position: relative;
    z-index: 1;
    max-width: 620px;
    margin: 28px 0 14px;
    font-size: clamp(2rem, 4vw, 3.2rem);
    line-height: 1.05;
}

.auth-hero p {
    position: relative;
    z-index: 1;
    max-width: 620px;
    color: #dbe8ff;
    font-size: 1.02rem;
}

.auth-credit {
    position: relative;
    z-index: 1;
    margin-top: 24px;
    color: #c8d7ef;
    font-size: .9rem;
}

.auth-feature-list {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 10px;
    margin-top: 26px;
    padding: 0;
    list-style: none;
}

.auth-feature-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #eef5ff;
}

.auth-panel-wrap {
    display: grid;
    place-items: center;
    padding: clamp(24px, 6vw, 72px);
    background: var(--justice-bg);
}

.auth-panel {
    width: min(100%, 440px);
    padding: 32px;
    background: #fff;
    border: 1px solid var(--justice-border);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(20, 33, 61, .12);
}

.password-field {
    position: relative;
}

.password-field .form-control {
    padding-right: 48px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--justice-muted);
    transform: translateY(-50%);
}

/* Utilities */
.app-alert { margin-bottom: 18px; }
.text-muted-strong { color: #475569; }
.small-label { color: var(--justice-muted); font-size: .78rem; }
.progress-thin { height: 8px; }
.nowrap { white-space: nowrap; }

.timeline {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.timeline-step {
    min-height: 68px;
    padding: 10px;
    border: 1px solid var(--justice-border);
    border-radius: 8px;
    background: #fff;
    color: var(--justice-muted);
    font-size: .82rem;
}

.timeline-step.done {
    border-color: rgba(22, 163, 74, .35);
    background: #f0fdf4;
    color: #166534;
}

.timeline-step.current {
    border-color: rgba(37, 99, 235, .45);
    background: #eff6ff;
    color: #1d4ed8;
}

/* Responsive breakpoints */
@media (max-width: 1180px) {
    .filter-toolbar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .global-search { width: 260px; }
}

@media (max-width: 991.98px) {
    .app-layout {
        display: block;
    }
    .sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-100%);
        width: min(var(--sidebar-width), 86vw);
        transition: transform .2s ease;
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }
    .sidebar-logo,
    .sidebar-collapsed .sidebar-logo {
        display: block;
    }
    .sidebar-logo-letter,
    .sidebar-collapsed .sidebar-logo-letter {
        display: none;
    }
    .sidebar-brand-text,
    .sidebar-collapsed .sidebar-brand-text {
        display: flex;
    }
    .sidebar-collapsed .sidebar-brand {
        align-items: flex-start;
        padding: 4px 8px 12px;
    }
    .sidebar-collapsed .sidebar-logo-wrap {
        width: auto;
        max-width: 86px;
        min-height: 36px;
        padding: 4px 6px;
    }
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        display: none;
        background: rgba(15, 23, 42, .44);
        z-index: 1030;
    }
    body.sidebar-open .sidebar-backdrop {
        display: block;
    }
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        position: relative;
    }
    .topbar-actions {
        width: 100%;
        flex-wrap: wrap;
    }
    .global-search {
        order: 3;
        width: 100%;
    }
    .quick-action {
        flex: 1 1 auto;
    }
    .content-area {
        padding: 16px;
        overflow-x: clip;
    }
    .auth-page {
        grid-template-columns: 1fr;
    }
    .auth-hero {
        min-height: 260px;
        padding: 28px;
    }
    .auth-hero h1 {
        font-size: 1.8rem;
    }
    .login-brand-dugan {
        width: min(165px, 56vw);
    }
}

@media (max-width: 575.98px) {
    .filter-toolbar,
    .choice-grid,
    .timeline {
        grid-template-columns: 1fr;
    }
    .metric-value {
        font-size: 1.55rem;
    }
    .auth-panel {
        padding: 24px;
    }
    .login-brand {
        padding: 12px 16px;
        border-radius: 12px;
    }
    .login-brand-dugan {
        width: min(132px, 52vw);
    }
    .btn,
    .form-control,
    .form-select {
        min-height: 44px;
    }
    .topbar-actions .dropdown {
        width: 100%;
    }
    .user-menu {
        width: 100%;
        justify-content: space-between;
    }
}
