:root {
    --navy: #142334;
    --green: #279b48;
    --yellow: #ffea00;
    --white: #ffffff;
    --line: #dfe5ea;
    --soft: #f5f7f9;
    --text: #22303d;
    --muted: #6b7785;
    --danger: #b42318;
    --warning: #946200;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--soft);
}

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

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--navy);
    color: var(--white);
    padding: 22px 18px;
}

.sidebar-head {
    display: grid;
    gap: 12px;
}

.brand {
    display: block;
    padding: 8px 6px 22px;
    border-bottom: 1px solid rgba(255,255,255,.15);
}

.brand img { width: 100%; height: auto; display: block; }

.menu-toggle {
    display: none;
    width: 100%;
    background: rgba(255,255,255,.12);
    color: var(--white);
    border: 1px solid rgba(255,255,255,.22);
}

.nav {
    display: grid;
    gap: 6px;
    padding-top: 18px;
}

.nav a {
    padding: 11px 12px;
    border-radius: 8px;
    color: rgba(255,255,255,.86);
}

.nav a:hover {
    background: rgba(255,255,255,.1);
    color: var(--white);
}

.main {
    min-width: 0;
    padding: 24px;
}

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

.topbar h1 {
    margin: 0;
    font-size: 28px;
    letter-spacing: 0;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--green);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.userbox {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.panel, .metric {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(20,35,52,.05);
}

.panel {
    padding: 20px;
    margin-bottom: 18px;
}

.panel.narrow { max-width: 680px; }

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-title h2, .panel h2 {
    margin: 0;
    font-size: 20px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric {
    padding: 18px;
    border-top: 4px solid var(--green);
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 10px;
}

.metric strong {
    font-size: 34px;
    color: var(--navy);
}

.form, .grid-form, .filters {
    display: grid;
    gap: 14px;
}

.skip-form {
    margin-top: 12px;
}

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

.filters {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
}

.filters-with-search {
    margin-bottom: 16px;
}

.filter-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
}

.field-label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 700;
}

.field-hint {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.check-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 9px;
    border-radius: 6px;
    font-weight: 600;
    justify-content: flex-start;
}

.role-dropdown {
    position: relative;
    max-width: 420px;
}

.role-dropdown.compact {
    min-width: 210px;
    max-width: 260px;
}

.role-dropdown summary {
    list-style: none;
    cursor: pointer;
    border: 1px solid #ccd5dd;
    border-radius: 7px;
    padding: 10px 34px 10px 11px;
    background: var(--white);
    min-height: 41px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.role-dropdown summary::-webkit-details-marker {
    display: none;
}

.role-dropdown summary::after {
    content: "▾";
    position: absolute;
    right: 12px;
    top: 10px;
    color: var(--muted);
}

.role-dropdown[open] summary::after {
    content: "▴";
}

.role-options {
    position: absolute;
    z-index: 20;
    width: min(320px, 90vw);
    max-height: 260px;
    overflow-y: auto;
    margin-top: 6px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--white);
    box-shadow: 0 16px 32px rgba(20,35,52,.14);
}

.role-options .check-option input[type="checkbox"] {
    width: 16px;
    min-width: 16px;
    height: 16px;
    padding: 0;
    margin: 0;
    flex: 0 0 16px;
}

.full { grid-column: 1 / -1; }

input, select, textarea {
    width: 100%;
    border: 1px solid #ccd5dd;
    border-radius: 7px;
    padding: 10px 11px;
    font: inherit;
    background: var(--white);
}

textarea { resize: vertical; }

button, .primary-button, .ghost-button {
    border: 0;
    border-radius: 7px;
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1.2;
}

button, .primary-button {
    background: var(--green);
    color: var(--white);
}

button.secondary {
    background: #e8edf2;
    color: var(--navy);
}

.danger-button {
    background: #ffe4e0;
    color: var(--danger);
}

.ghost-button {
    background: #edf2f6;
    color: var(--navy);
}

.inline { display: inline-block; }

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 820px;
}

.summary-table {
    min-width: 720px;
}

.summary-table td:not(:first-child),
.summary-table th:not(:first-child) {
    text-align: center;
}

.summary-table td {
    font-size: 15px;
}

.percent-cell {
    display: grid;
    grid-template-columns: 64px minmax(90px, 1fr);
    gap: 10px;
    align-items: center;
}

.percent-bar {
    display: block;
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8edf2;
}

.percent-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--green);
}

th, td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    font-size: 14px;
}

th {
    color: var(--navy);
    background: #f8fafb;
    font-size: 12px;
    text-transform: uppercase;
}

.sort-link {
    color: var(--navy);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

td small {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-success { background: #e8f6ed; color: #12652d; }
.badge-warning { background: #fff7d1; color: var(--warning); }
.badge-danger { background: #ffe4e0; color: var(--danger); }
.badge-muted, .badge-stage { background: #edf2f6; color: var(--navy); }

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-weight: 700;
}

.alert-success { background: #e8f6ed; color: #12652d; }
.alert-error { background: #ffe4e0; color: var(--danger); }

.empty-state {
    padding: 22px;
    border: 1px dashed #b9c4cf;
    border-radius: 8px;
    color: var(--muted);
    background: #fbfcfd;
}

.inline-actions, .row-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.stack-form {
    display: grid;
    gap: 8px;
    min-width: 220px;
}

.action-cell { min-width: 260px; }

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, var(--navy), #20364e);
}

.login-card {
    width: min(430px, 100%);
    padding: 30px;
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 22px 60px rgba(0,0,0,.24);
}

.login-logo {
    width: 220px;
    max-width: 100%;
    display: block;
    margin-bottom: 22px;
}

.login-card h1 {
    margin: 0 0 20px;
    font-size: 24px;
}

.floating-alert {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10;
}

.muted { color: var(--muted); }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: sticky;
        top: 0;
        z-index: 30;
        padding: 12px 14px;
    }
    .sidebar-head {
        grid-template-columns: minmax(0, 1fr) 112px;
        align-items: center;
    }
    .brand {
        padding: 0;
        border-bottom: 0;
    }
    .brand img { max-width: 210px; }
    .menu-toggle { display: inline-flex; justify-content: center; }
    .nav {
        display: none;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding-top: 12px;
    }
    .nav.is-open { display: grid; }
    .nav a {
        min-height: 42px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 10px 8px;
    }
    .topbar, .userbox { align-items: flex-start; flex-direction: column; }
    .topbar {
        gap: 10px;
        margin-bottom: 16px;
    }
    .topbar h1 { font-size: 24px; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-form, .filters { grid-template-columns: 1fr; }
    .main { padding: 16px; }
    .panel { padding: 16px; }
    .section-title {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }
    .filter-actions,
    .inline-actions,
    .row-form {
        width: 100%;
    }
    .filter-actions > *,
    .inline-actions > *,
    .row-form > *,
    .stack-form button,
    .primary-button,
    .ghost-button {
        width: 100%;
        justify-content: center;
        text-align: center;
    }
    .stack-form {
        min-width: 0;
        width: 100%;
    }
    .action-cell { min-width: 0; }
    .table-wrap {
        overflow: visible;
    }
    table {
        min-width: 0;
    }
    table thead {
        display: none;
    }
    table, tbody, tr, td {
        display: block;
        width: 100%;
    }
    tr {
        margin-bottom: 12px;
        padding: 12px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--white);
    }
    td {
        display: grid;
        grid-template-columns: minmax(100px, 38%) minmax(0, 1fr);
        gap: 10px;
        padding: 9px 0;
        border-bottom: 1px solid #edf2f6;
        align-items: start;
    }
    td:last-child {
        border-bottom: 0;
        padding-bottom: 0;
    }
    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 700;
        text-transform: uppercase;
    }
    td:not([data-label])::before {
        content: "";
    }
    .summary-table td {
        grid-template-columns: minmax(120px, 42%) minmax(0, 1fr);
    }
    .percent-cell {
        grid-template-columns: 54px minmax(70px, 1fr);
    }
}

@media (max-width: 520px) {
    .main { padding: 12px; }
    .sidebar-head { grid-template-columns: 1fr; }
    .brand img { max-width: 190px; }
    .nav { grid-template-columns: 1fr; }
    .metric-grid { grid-template-columns: 1fr; }
    .metric {
        padding: 14px;
    }
    .metric strong {
        font-size: 28px;
    }
    .login-card {
        padding: 22px;
    }
    td {
        grid-template-columns: 1fr;
        gap: 4px;
    }
}

.mobile-header,
.menu-backdrop,
.sidebar-close {
    display: none;
}

@media (max-width: 900px) {
    body.app-shell {
        display: block;
        padding-top: 64px;
    }

    .mobile-header {
        position: fixed;
        inset: 0 0 auto 0;
        z-index: 60;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        min-height: 64px;
        padding: 10px 12px;
        background: var(--navy);
        color: var(--white);
        box-shadow: 0 8px 18px rgba(20,35,52,.22);
    }

    .hamburger-button {
        width: 44px;
        height: 44px;
        display: inline-grid;
        place-content: center;
        gap: 5px;
        padding: 0;
        border: 1px solid rgba(255,255,255,.24);
        border-radius: 8px;
        background: rgba(255,255,255,.12);
    }

    .hamburger-button span {
        width: 20px;
        height: 2px;
        display: block;
        border-radius: 99px;
        background: var(--white);
    }

    .mobile-user {
        min-width: 0;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 8px;
        flex: 1;
    }

    .mobile-user span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 13px;
        font-weight: 700;
    }

    .mobile-user .ghost-button {
        width: auto;
        flex: 0 0 auto;
        padding: 9px 11px;
        background: rgba(255,255,255,.16);
        color: var(--white);
    }

    .mobile-logout {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 38px;
        padding: 9px 12px;
        border-radius: 8px;
        background: #edf2f6;
        color: var(--navy);
        font-weight: 700;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 80;
        width: min(86vw, 320px);
        height: 100vh;
        overflow-y: auto;
        padding: 18px;
        transform: translateX(-105%);
        transition: transform .22s ease;
        box-shadow: 18px 0 36px rgba(0,0,0,.24);
    }

    body.menu-open .sidebar {
        transform: translateX(0);
    }

    .menu-backdrop {
        position: fixed;
        inset: 0;
        z-index: 70;
        background: rgba(20,35,52,.48);
    }

    body.menu-open .menu-backdrop {
        display: block;
    }

    .sidebar-head {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 12px;
    }

    .sidebar-close {
        display: inline-flex;
        width: auto;
        background: rgba(255,255,255,.12);
        color: var(--white);
        border: 1px solid rgba(255,255,255,.22);
    }

    .brand {
        padding: 0 0 14px;
        border-bottom: 0;
    }

    .brand img {
        max-width: 190px;
    }

    .nav,
    .nav.is-open {
        display: grid;
        grid-template-columns: 1fr;
        padding-top: 16px;
    }

    .nav a {
        justify-content: flex-start;
        min-height: 44px;
        padding: 12px;
        text-align: left;
    }

    .main {
        padding-top: 16px;
    }

    .topbar .userbox {
        display: none;
    }
}

@media (max-width: 900px) {
    body.app-shell {
        display: block !important;
        padding-top: 64px !important;
    }

    .mobile-header {
        position: fixed !important;
        inset: 0 0 auto 0 !important;
        z-index: 90 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        min-height: 64px !important;
        padding: 10px 12px !important;
        background: var(--navy) !important;
        color: var(--white) !important;
    }

    .hamburger-button.menu-toggle {
        display: inline-grid !important;
        width: 44px !important;
        min-width: 44px !important;
        max-width: 44px !important;
        height: 44px !important;
        padding: 0 !important;
        border-radius: 8px !important;
        place-content: center !important;
        gap: 5px !important;
        background: var(--green) !important;
        color: transparent !important;
    }

    .hamburger-button.menu-toggle span {
        display: block !important;
        width: 21px !important;
        height: 2px !important;
        background: var(--white) !important;
    }

    .mobile-user {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        min-width: 0 !important;
    }

    .mobile-user span {
        max-width: calc(100vw - 170px) !important;
    }

    .mobile-logout {
        width: auto !important;
        white-space: nowrap !important;
    }

    .sidebar {
        position: fixed !important;
        top: 0 !important;
        right: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        z-index: 100 !important;
        width: min(86vw, 320px) !important;
        max-width: 320px !important;
        height: 100dvh !important;
        padding: 18px !important;
        overflow-y: auto !important;
        transform: translateX(-105%) !important;
        transition: transform .22s ease !important;
        background: var(--navy) !important;
    }

    body.menu-open .sidebar {
        transform: translateX(0) !important;
    }

    .menu-backdrop {
        display: none !important;
        position: fixed !important;
        inset: 0 !important;
        z-index: 95 !important;
        background: rgba(20,35,52,.52) !important;
    }

    body.menu-open .menu-backdrop {
        display: block !important;
    }

    .sidebar-head {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto !important;
        align-items: center !important;
    }

    .sidebar-close {
        display: inline-flex !important;
        width: auto !important;
        justify-content: center !important;
    }

    .nav,
    .nav.is-open {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 6px !important;
    }

    .nav a {
        justify-content: flex-start !important;
        text-align: left !important;
        font-size: 16px !important;
    }
}
