*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #072c93;
    --accent: #4f7fa8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 250px;
    --topbar-height: 52px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

html,
body {
    min-height: 100%;
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    height: var(--topbar-height);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

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

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    min-width: 0;
}

.topbar-logo {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    flex-shrink: 0;
}

.topbar-title {
    font-size: 1.05rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-toggle {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 1.25rem;
}

.sidebar-toggle:hover {
    background: rgba(255,255,255,.15);
}

.environment-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 999px;
    color: rgba(255,255,255,.85);
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
}

.topbar-link {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 4px;
    background: transparent;
    color: #fff;
    font: inherit;
    font-size: .8rem;
    font-weight: 700;
    cursor: pointer;
}

.topbar-link:hover {
    background: rgba(255,255,255,.14);
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.sidebar {
    position: fixed;
    top: var(--topbar-height);
    bottom: 0;
    left: 0;
    z-index: 100;
    width: var(--sidebar-width);
    background: var(--primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1);
}

.sidebar.collapsed {
    width: 0;
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar.expanded {
    width: var(--sidebar-width);
    transform: translateX(0);
}

.sidebar-nav {
    list-style: none;
    padding: 8px 0;
    flex: 1;
    overflow-y: auto;
}

.nav-group {
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.nav-group-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    border: 0;
    background: transparent;
    color: rgba(255,255,255,.58);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.1px;
    cursor: pointer;
}

.nav-group-toggle:hover {
    color: rgba(255,255,255,.86);
    background: rgba(255,255,255,.04);
}

.chevron {
    font-size: .6rem;
    transition: transform .2s ease;
}

.chevron.open {
    transform: rotate(180deg);
}

.nav-group-items {
    list-style: none;
    padding: 0 0 4px;
}

.nav-group-items li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px 8px 24px;
    color: rgba(255,255,255,.76);
    font-size: .84rem;
    border-left: 3px solid transparent;
    transition: all .15s;
}

.nav-group-items li a:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.nav-group-items li a.active {
    background: rgba(255,255,255,.12);
    color: #fff;
    font-weight: 600;
    border-left-color: #fff;
}

.nav-icon {
    width: 18px;
    min-width: 18px;
    text-align: center;
    font-size: .8rem;
    font-weight: 700;
    opacity: .7;
}

.nav-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 12px 18px;
    border-top: 1px solid rgba(255,255,255,.1);
    color: rgba(255,255,255,.38);
    font-size: .72rem;
    text-align: center;
}

.main-content {
    margin-top: var(--topbar-height);
    min-height: calc(100vh - var(--topbar-height));
    transition: margin-left .25s cubic-bezier(.4,0,.2,1);
}

.main-content.sidebar-is-expanded {
    margin-left: var(--sidebar-width);
}

.main-content.sidebar-is-collapsed {
    margin-left: 0;
}

.main-content.public-shell {
    margin-top: 0;
    margin-left: 0;
    min-height: 100vh;
}

.public-shell .content-area {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding-top: 32px;
}

.content-area {
    padding: 24px 32px;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    top: var(--topbar-height);
    background: rgba(15,23,42,.45);
    z-index: 90;
    display: none;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
}

.page-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.eyebrow {
    margin-bottom: 4px;
    color: var(--accent);
    font-size: .72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
}

h1 {
    font-size: 1.75rem;
    line-height: 1.2;
    font-weight: 700;
}

h1:focus {
    outline: 2px solid rgba(79,127,168,.35);
    outline-offset: 3px;
    border-radius: 4px;
}

.page-subtitle,
.muted,
.empty-state {
    color: var(--text-muted);
    font-size: .9rem;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

.portal-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.portal-action {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    color: var(--text);
    min-height: 132px;
}

.portal-action:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.portal-action strong {
    display: block;
    margin-bottom: 6px;
    font-size: 1.05rem;
}

.portal-action small {
    display: block;
    color: var(--text-muted);
    line-height: 1.5;
}

.portal-action-icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    flex-shrink: 0;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 104px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    color: var(--text-muted);
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat-card.total { border-left: 4px solid var(--primary); }
.stat-card.awaiting { border-left: 4px solid var(--accent); }
.stat-card.in-progress { border-left: 4px solid var(--warning); }
.stat-card.resolved { border-left: 4px solid var(--success); }
.stat-card.closed { border-left: 4px solid var(--text-muted); }
.stat-card.today { border-left: 4px solid var(--danger); }

.dashboard-grid,
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.amount-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 130px;
}

.amount-card strong {
    margin-top: 8px;
    font-size: 1.8rem;
}

.metric-list,
.meta-grid {
    display: grid;
    gap: 10px;
}

.metric-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: .9rem;
}

.metric-row:last-child {
    border-bottom: 0;
}

.meta-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.meta-label {
    color: var(--text-muted);
    font-size: .73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.meta-value {
    font-size: .92rem;
    word-break: break-word;
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

thead th {
    text-align: left;
    padding: 12px 16px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 2px solid var(--border);
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:hover {
    background: #f8fafc;
}

.empty-cell {
    color: var(--text-muted);
    text-align: center;
}

.link-strong,
.back-link {
    color: var(--primary);
    font-weight: 700;
}

.back-link {
    display: inline-flex;
    margin-bottom: 16px;
    font-size: .9rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
}

.badge-awaiting { background: #dbeafe; color: var(--primary); }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-resolved { background: #dcfce7; color: #166534; }
.badge-critical { background: #fecaca; color: #991b1b; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 8px 16px;
    border: 0;
    border-radius: var(--radius);
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    filter: brightness(1.08);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg);
}

.btn-sm {
    min-height: 28px;
    padding: 4px 10px;
    font-size: .8rem;
}

.btn:disabled,
.pagination button:disabled {
    opacity: .45;
    cursor: default;
}

.filters-bar {
    display: flex;
    align-items: end;
    flex-wrap: wrap;
    gap: 12px;
}

.filters-bar.card {
    padding: 16px;
}

.lookup-card {
    padding: 16px;
}

.filters-bar .form-group {
    min-width: 180px;
}

.search-input {
    min-width: min(360px, 100%);
    flex: 1;
}

.form-card {
    display: grid;
    gap: 18px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-label {
    color: var(--text-muted);
    font-size: .85rem;
    font-weight: 600;
}

.form-control {
    width: 100%;
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font: inherit;
    outline: none;
    transition: border .15s, box-shadow .15s;
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,127,168,.16);
}

.validation-message,
.validation-summary {
    color: var(--danger);
    font-size: .82rem;
}

.actions,
.status-form {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
}

.table-actions {
    text-align: right;
}

.biodata-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.biodata-summary > div {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.status-form .form-group {
    min-width: 220px;
    flex: 1;
}

.auth-shell {
    min-height: calc(100vh - var(--topbar-height) - 48px);
    display: grid;
    place-items: center;
}

.auth-card {
    width: min(460px, 100%);
}

.checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: .9rem;
    font-weight: 600;
}

.alert {
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: .9rem;
    font-weight: 600;
}

.alert-link {
    display: inline-flex;
    margin-left: 10px;
    color: inherit;
    text-decoration: underline;
    font-weight: 800;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 18px;
}

.pagination button {
    min-width: 78px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
}

.page-info {
    color: var(--text-muted);
    font-size: .85rem;
    padding: 0 8px;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 64px 24px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .75s linear infinite;
}

.loading-text {
    font-size: .9rem;
    font-weight: 600;
}

.pre-wrap {
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: .92rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 768px) {
    .environment-pill {
        display: none;
    }

    .topbar {
        padding: 0 14px;
    }

    .topbar-title {
        font-size: .95rem;
    }

    .sidebar.collapsed {
        width: var(--sidebar-width);
        transform: translateX(calc(-1 * var(--sidebar-width)));
    }

    .sidebar.expanded {
        width: var(--sidebar-width);
        transform: translateX(0);
    }

    .sidebar-overlay.mobile-only {
        display: block;
    }

    .main-content.sidebar-is-expanded,
    .main-content.sidebar-is-collapsed {
        margin-left: 0;
    }

    .content-area {
        padding: 16px;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-actions {
        justify-content: stretch;
    }

    .page-actions .btn {
        flex: 1;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filters-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .filters-bar .form-group,
    .search-input {
        min-width: 100%;
    }
}
