:root {
    --bg: #f6f7fb;
    --card: #ffffff;
    --text: #0c143b;
    --muted: #5f6b85;
    --primary: #0e1c4a;
    --primary-2: #1c2f6c;
    --accent: #1fa76b;
    --accent-dark: #148657;
    --danger: #d13b3b;
    --warning: #d78916;
    --border: rgba(12, 20, 59, .09);
    --shadow: 0 10px 30px rgba(13, 28, 74, .10);
    --radius: 16px;
    --radius-sm: 11px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 10% -10%, #e8eefc 0%, rgba(232, 238, 252, 0) 60%),
        radial-gradient(800px 500px at 110% 0%, #e6fff3 0%, rgba(230, 255, 243, 0) 60%),
        var(--bg);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: var(--accent-dark);
}

button,
input,
select,
textarea {
    font: inherit;
}

.skip-link {
    position: fixed;
    z-index: 1000;
    top: 8px;
    left: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    color: #fff;
    background: var(--primary);
    transform: translateY(-160%);
}

.skip-link:focus {
    transform: translateY(0);
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    z-index: 100;
    top: 0;
    min-height: 76px;
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 12px clamp(18px, 3vw, 42px);
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 6px 20px rgba(13, 28, 74, .06);
    backdrop-filter: blur(14px);
}

.brand {
    min-width: 230px;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--primary);
    text-decoration: none;
}

.brand-logo {
    display: block;
    width: 178px;
    max-width: 100%;
    height: auto;
}

.brand-copy {
    display: none;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .04em;
    line-height: 1.2;
    text-transform: uppercase;
}

.top-context {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

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

.main-layout {
    width: 100%;
    flex: 1;
    display: grid;
    grid-template-columns: 244px minmax(0, 1fr);
}

.sidebar {
    padding: 28px 18px;
    border-right: 1px solid var(--border);
    background: rgba(255, 255, 255, .72);
}

.nav-group {
    padding: 0 12px 10px;
    color: #7c879f;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav a {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 13px 10px 16px;
    border-radius: 11px;
    color: var(--muted);
    font-weight: 700;
    text-decoration: none;
    transition: background .16s ease, color .16s ease, transform .16s ease;
}

.nav a::before {
    position: absolute;
    top: 12px;
    bottom: 12px;
    left: 5px;
    width: 3px;
    border-radius: 99px;
    background: transparent;
    content: "";
}

.nav a:hover {
    color: var(--primary);
    background: rgba(28, 47, 108, .07);
    transform: translateX(2px);
}

.nav a.active {
    color: var(--primary);
    background: rgba(31, 167, 107, .10);
}

.nav a.active::before {
    background: var(--accent);
}

.content {
    width: 100%;
    max-width: 1540px;
    margin: 0 auto;
    padding: 34px clamp(18px, 3vw, 44px) 48px;
}

.page-heading {
    margin-bottom: 24px;
}

.page-title {
    color: var(--primary);
    font-size: clamp(25px, 3vw, 34px);
    font-weight: 850;
    letter-spacing: -.025em;
    line-height: 1.2;
}

.page-sub {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-top: 7px;
    color: var(--muted);
    font-size: 14px;
}

.page-sub .context-value {
    color: var(--primary);
    font-weight: 750;
}

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: 22px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    margin: 0;
    color: var(--primary);
    font-size: 18px;
    line-height: 1.3;
}

.card-subtitle {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.card-body {
    padding: 22px 24px 24px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(300px, .78fr) minmax(520px, 1.65fr);
    gap: 24px;
    align-items: start;
}

.project-card {
    position: sticky;
    top: 100px;
    overflow: hidden;
}

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

.data-grid,
.table-modern {
    width: 100%;
    border: 0;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
}

.data-grid th,
.data-grid td,
.table-modern th,
.table-modern td {
    padding: 13px 14px;
    border: 0;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.data-grid th,
.table-modern th,
.dg-header th {
    color: #6b7690;
    background: #f8f9fc;
    font-size: 11px;
    font-weight: 850;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.data-grid tr:last-child td,
.table-modern tr:last-child td {
    border-bottom: 0;
}

.data-grid tr:hover td,
.table-modern tr:hover td,
.dg-row:hover td,
.dg-alt:hover td {
    background: rgba(31, 167, 107, .055);
}

.dg-alt td {
    background: rgba(246, 247, 251, .65);
}

.dg-selected td {
    background: rgba(31, 167, 107, .12) !important;
}

.data-grid input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.actions-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
}

.actions-heading h2 {
    margin: 0;
    color: var(--primary);
    font-size: 21px;
}

.actions-heading p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 13px;
}

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

.action-card {
    position: relative;
    min-width: 0;
    overflow: hidden;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 7px 22px rgba(13, 28, 74, .07);
}

.action-card::after {
    position: absolute;
    right: -30px;
    bottom: -38px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(31, 167, 107, .06);
    content: "";
}

.action-card-header {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 11px;
    margin-bottom: 15px;
}

.action-icon {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    color: var(--accent-dark);
    background: rgba(31, 167, 107, .11);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .05em;
}

.action-card h3 {
    margin: 0;
    color: var(--primary);
    font-size: 16px;
}

.action-stack {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 9px;
}

.action-button,
.btn,
input.btn,
button.btn {
    min-height: 42px;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: 11px;
    color: #fff;
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-2) 100%);
    box-shadow: 0 6px 14px rgba(13, 28, 74, .12);
    font-size: 14px;
    font-weight: 750;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: box-shadow .16s ease, transform .16s ease, filter .16s ease;
}

.action-button {
    width: 100%;
}

.action-button:hover,
.btn:hover {
    box-shadow: 0 9px 18px rgba(13, 28, 74, .18);
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.btn.secondary,
.btn.ghost {
    color: var(--primary);
    border-color: rgba(12, 20, 59, .15);
    background: #fff;
    box-shadow: none;
}

.btn.ghost {
    min-height: 36px;
    padding: 8px 12px;
}

.status-message,
.status-callout,
.message {
    display: block;
    margin: 14px 0 0;
    padding: 11px 13px;
    border: 1px solid rgba(209, 59, 59, .18);
    border-radius: 10px;
    color: #9e2e2e;
    background: rgba(209, 59, 59, .07);
    font-size: 13px;
}

.status-message:empty,
.status-callout:empty,
.message:empty {
    display: none;
}

.status-callout {
    margin-top: 18px;
    border-color: rgba(31, 167, 107, .22);
    color: var(--accent-dark);
    background: rgba(31, 167, 107, .08);
}

.field {
    margin-top: 15px;
}

.field-label {
    display: block;
    margin-bottom: 6px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 750;
}

.input,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 11px 13px;
    border: 1px solid rgba(12, 20, 59, .16);
    border-radius: 11px;
    color: var(--text);
    background: #fff;
    font-size: 15px;
}

.input:focus,
input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-2);
    box-shadow: 0 0 0 3px rgba(28, 47, 108, .13);
    outline: 0;
}

.login-wrap {
    width: 100%;
    max-width: 440px;
    margin: 12px auto 50px;
}

.login-card {
    padding: 28px;
}

.login-card h2 {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 24px;
}

.login-intro {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: 14px;
}

.login-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 11px;
    margin-top: 19px;
}

.login-actions .btn {
    width: 100%;
}

.remember-row {
    margin-top: 13px;
    color: var(--muted);
    font-size: 14px;
}

.remember-row input {
    width: 17px;
    height: 17px;
    margin: 0 7px 0 0;
    vertical-align: -3px;
    accent-color: var(--accent);
}

.helper-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: 14px;
    font-size: 13px;
}

.helper-links a {
    color: var(--accent-dark);
    text-decoration: none;
}

.helper-links a:hover {
    text-decoration: underline;
}

.field-error {
    display: block;
    margin-top: 5px;
    color: var(--danger);
    font-size: 12px;
}

.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 19px clamp(18px, 3vw, 42px);
    border-top: 1px solid var(--border);
    color: var(--muted);
    background: rgba(255, 255, 255, .7);
    font-size: 12px;
}

.footer a {
    color: var(--muted);
    text-decoration: none;
}

.footer a:hover {
    color: var(--primary);
}

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

    .project-card {
        position: static;
    }
}

@media (max-width: 860px) {
    .topbar {
        min-height: 68px;
        gap: 12px;
    }

    .brand {
        min-width: 0;
    }

    .brand-logo {
        width: 142px;
    }

    .top-context {
        display: none;
    }

    .main-layout {
        display: block;
    }

    .sidebar {
        padding: 10px 14px;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        background: rgba(255, 255, 255, .84);
    }

    .nav-group {
        display: none;
    }

    .nav {
        width: max-content;
        min-width: 100%;
        flex-direction: row;
    }

    .nav a {
        min-height: 38px;
        padding: 8px 13px;
        white-space: nowrap;
    }

    .nav a::before {
        display: none;
    }

    .content {
        padding-top: 26px;
    }
}

@media (max-width: 620px) {
    .topbar {
        padding: 10px 14px;
    }

    .top-actions .muted {
        display: none;
    }

    .content {
        padding-right: 13px;
        padding-left: 13px;
    }

    .action-grid {
        grid-template-columns: 1fr;
    }

    .card-header,
    .card-body,
    .login-card {
        padding-right: 18px;
        padding-left: 18px;
    }

    .login-actions {
        grid-template-columns: 1fr;
    }

    .footer {
        align-items: flex-start;
        flex-direction: column;
    }
}


/* ---------- Legacy WebForms compatibility ---------- */
.legacy-page {
    min-width: 0;
    display: grid;
    gap: 18px;
}

.legacy-page > table,
.standalone-form > div > table {
    width: 100% !important;
    margin: 0 0 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 6px 18px rgba(13, 28, 74, .055);
}

.legacy-page td,
.legacy-page th,
.standalone-form td,
.standalone-form th {
    padding: 9px 11px;
    vertical-align: middle;
}

.legacy-page h1,
.legacy-page h2,
.legacy-page h3,
.standalone-page h1,
.standalone-page h2,
.standalone-page h3 {
    color: var(--primary);
    letter-spacing: -.015em;
}

.legacy-page h1 {
    margin: 0;
    font-size: 25px;
}

.legacy-page [style*="width:"] {
    max-width: 100% !important;
}

.legacy-page td[style*="background-color: #336600"],
.legacy-page td[style*="background-color:#336600"] {
    color: #fff !important;
    background: var(--primary) !important;
    font-weight: 800;
    letter-spacing: .03em;
}

.legacy-page [style*="background-color: buttonface"] {
    background: #f8f9fc !important;
}

.button,
input.button,
a.button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 15px;
    border: 1px solid transparent;
    border-radius: 11px;
    color: #fff;
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-2) 100%);
    box-shadow: 0 6px 14px rgba(13, 28, 74, .12);
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
}

.secondary-button {
    color: var(--primary);
    border-color: rgba(12, 20, 59, .14);
    background: #fff;
    box-shadow: none;
}

.select-control,
.file-control {
    min-height: 42px;
    max-width: 100%;
    padding: 9px 11px;
    border: 1px solid rgba(12, 20, 59, .16);
    border-radius: 10px;
    background: #fff;
}

.choice-control {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
}

.choice-control input {
    width: 17px;
    height: 17px;
    margin-right: 6px;
    accent-color: var(--accent);
}

.responsive-image,
.legacy-page img,
.standalone-page img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
}

.legacy-page .data-grid,
.standalone-page .data-grid {
    min-width: 620px;
}

.calendar-modern {
    width: 100%;
    max-width: 340px;
    overflow: hidden;
    border: 1px solid var(--border) !important;
    border-radius: 12px;
    background: #fff;
    border-collapse: separate !important;
    border-spacing: 0;
}

.calendar-modern td,
.calendar-modern th {
    padding: 7px !important;
    border: 0 !important;
    text-align: center;
}

.calendar-modern a {
    color: var(--primary);
    font-weight: 700;
    text-decoration: none;
}

.standalone-page {
    min-height: 100vh;
    padding: 28px 16px;
}

.standalone-form {
    width: 100%;
    max-width: 1240px;
    min-height: calc(100vh - 56px);
    margin: 0 auto;
}

.standalone-form > div {
    min-height: 100%;
    padding: 24px;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
}

.standalone-page #visualization {
    max-width: 100% !important;
}

.standalone-page form > div > div[style*="position:absolute"] {
    position: static !important;
    margin: 14px 0;
}

/* ---------- Audit pages ---------- */
.audit-layout {
    display: grid;
    gap: 20px;
}

.audit-toolbar {
    overflow: hidden;
}

.period-days {
    min-width: 96px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.audit-toolbar-grid {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr) minmax(220px, .7fr);
    gap: 22px;
    align-items: start;
}

.calendar-block h3 {
    margin: 0 0 10px;
    color: var(--primary);
    font-size: 14px;
}

.audit-actions {
    display: grid;
    gap: 10px;
    padding-top: 28px;
}

.audit-actions .button {
    width: 100%;
}

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

.metric-card {
    min-width: 0;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, .95);
    box-shadow: 0 7px 22px rgba(13, 28, 74, .065);
}

.metric-kicker {
    display: block;
    color: var(--accent-dark);
    font-size: 11px;
    font-weight: 850;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.metric-heading {
    display: block;
    margin: 5px 0 13px;
    color: var(--primary);
    font-size: 16px;
}

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

.metric-row > span:last-child {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    color: var(--primary);
    font-weight: 800;
}

.output-field {
    width: 90px !important;
    min-height: 35px !important;
    padding: 7px 8px !important;
    color: var(--primary) !important;
    background: #f6f8fb !important;
    text-align: right;
}

.compact-output {
    width: 54px !important;
}

.shortfall-card {
    border-color: rgba(215, 137, 22, .20);
    background: linear-gradient(145deg, #fff, #fffaf2);
}

.data-section {
    overflow: hidden;
}

.meter-section-header {
    align-items: center;
}

.filter-options {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 9px 14px;
}

@media (max-width: 1120px) {
    .audit-toolbar-grid {
        grid-template-columns: 1fr 1fr;
    }

    .audit-actions {
        grid-column: 1 / -1;
        grid-template-columns: repeat(3, 1fr);
        padding-top: 0;
    }

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

@media (max-width: 720px) {
    .audit-toolbar-grid,
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .audit-actions {
        grid-column: auto;
        grid-template-columns: 1fr;
    }

    .meter-section-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .filter-options {
        justify-content: flex-start;
    }

    .legacy-page > table {
        display: block;
        overflow-x: auto;
    }
}
