:root {
    --navy: #071c33;
    --navy-soft: #102b49;
    --red: #d71920;
    --red-dark: #b50f15;
    --blue: #1769aa;
    --green: #18794e;
    --ink: #17202b;
    --muted: #667484;
    --line: #dfe5eb;
    --surface: #ffffff;
    --background: #f3f6f8;
    --shadow: 0 12px 34px rgba(7, 28, 51, .08);
    --radius: 14px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--ink);
    background: var(--background);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a { color: inherit; }
button, input, select { font: inherit; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    padding: 0 5vw;
    color: white;
    background: var(--navy);
    box-shadow: 0 4px 18px rgba(0, 0, 0, .18);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: white;
    text-decoration: none;
}

.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .01em; }
.brand small { margin-top: 1px; color: #b9c9d9; font-size: .72rem; }

.nav { display: flex; align-items: center; gap: 24px; }
.nav a, .nav-button {
    color: #e7eef5;
    background: none;
    border: 0;
    padding: 8px 0;
    text-decoration: none;
    cursor: pointer;
    font-size: .9rem;
}
.nav a:hover, .nav-button:hover { color: white; }
.menu-toggle { display: none; color: white; background: none; border: 0; font-size: 1.5rem; }

.page-shell { width: min(1180px, 90vw); margin: 0 auto; padding: 48px 0 72px; }
.auth-layout {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 10%, rgba(215, 25, 32, .22), transparent 28%),
        linear-gradient(135deg, #06172a, #0d3457);
}

.login-card {
    width: min(440px, 100%);
    padding: 40px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .3);
}

.login-brand { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.login-brand h1 { margin: 0; font-size: 1.8rem; }
.login-brand-centered {
    display: block;
    text-align: center;
}
.login-brand-centered .eyebrow { text-align: center; }
.admin-login-link {
    display: block;
    margin-top: 20px;
    color: var(--blue);
    text-align: center;
    font-size: .88rem;
    font-weight: 700;
    text-decoration: none;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; color: var(--navy); font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.16; }
h2 { margin-bottom: 5px; color: var(--navy); font-size: 1.3rem; }
h3 { color: var(--navy); }

.eyebrow {
    margin-bottom: 8px;
    color: var(--red);
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.muted, .page-heading p, .section-heading p { color: var(--muted); }
.page-heading { margin-bottom: 26px; }
.heading-actions { display: flex; align-items: center; justify-content: space-between; gap: 30px; }

.card {
    padding: 28px;
    margin-top: 24px;
    background: var(--surface);
    border: 1px solid rgba(7, 28, 51, .07);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-narrow { width: min(720px, 100%); margin-right: auto; margin-left: auto; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 24px; }
.metric-card {
    padding: 24px;
    background: white;
    border-left: 4px solid var(--navy);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.metric-card span, .metric-card strong { display: block; }
.metric-card span { color: var(--muted); font-size: .85rem; }
.metric-card strong { margin-top: 7px; color: var(--navy); font-size: 2rem; }
.metric-blue { border-color: var(--blue); }
.metric-green { border-color: var(--green); }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
    transition: .16s ease;
}
.button:hover { transform: translateY(-1px); }
.button-primary { color: white; background: var(--red); }
.button-primary:hover { background: var(--red-dark); }
.button-secondary { color: var(--navy); background: white; border-color: #bdc8d3; }
.button-danger { color: white; background: var(--navy); }
.button-large { min-height: 52px; padding: 13px 22px; }
.button-full { width: 100%; }

.form-stack { display: grid; gap: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.span-2 { grid-column: span 2; }
label { display: grid; gap: 7px; color: #324252; font-size: .88rem; font-weight: 700; }
label small { color: var(--muted); font-weight: 400; }
input, select {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    color: var(--ink);
    background: white;
    border: 1px solid #bac5d0;
    border-radius: 7px;
    outline: none;
}
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 170, .12); }
.input-large { min-height: 54px; font-size: 1.12rem; }
.optional { margin-left: 5px; color: var(--muted); font-size: .75rem; font-weight: 500; }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
.form-actions-end { justify-content: flex-end; margin-top: 24px; }
.form-actions form { margin: 0; }
hr { width: 100%; margin: 4px 0; border: 0; border-top: 1px solid var(--line); }

.inline-form { display: flex; align-items: end; gap: 14px; }
.inline-form .grow { flex: 1; }
.inline-form-wrap { flex-wrap: wrap; }
.checkbox-label { display: flex; align-items: center; gap: 8px; min-height: 46px; }
.checkbox-label input { width: 18px; min-height: auto; }
.selection-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-config-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.panel-config-item {
    display: grid;
    gap: 9px;
    padding: 12px;
    background: #f8fafb;
    border: 1px solid var(--line);
    border-radius: 9px;
}
.check-option {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    padding: 10px 12px;
    background: white;
    border: 1px solid #ccd5de;
    border-radius: 7px;
    cursor: pointer;
}
.check-option:has(input:checked) { color: var(--navy); background: #edf5fb; border-color: #86afd0; }
.check-option input { width: 17px; min-height: auto; flex: 0 0 auto; }
.check-option span { overflow: hidden; text-overflow: ellipsis; }

.steps {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    width: min(720px, 100%);
    padding: 0;
    margin: 0 auto 22px;
    list-style: none;
}
.steps li {
    position: relative;
    display: grid;
    place-items: center;
    gap: 7px;
    color: #8793a0;
    font-size: .75rem;
    font-weight: 700;
}
.steps li::after {
    position: absolute;
    z-index: -1;
    top: 15px;
    left: 50%;
    width: 100%;
    height: 2px;
    content: "";
    background: #d7dee5;
}
.steps li:last-child::after { display: none; }
.steps span {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    background: #e2e7ec;
    border-radius: 50%;
}
.steps .active { color: var(--navy); }
.steps .active span { color: white; background: var(--red); }
.steps .active::after { background: var(--red); }

.package-list { display: grid; gap: 12px; }
.package-option {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 9px;
    cursor: pointer;
}
.package-option:hover { border-color: #9aabba; }
.package-option input { position: absolute; opacity: 0; pointer-events: none; }
.package-radio { width: 20px; height: 20px; border: 2px solid #9ba9b6; border-radius: 50%; }
.package-option input:checked + .package-radio { border: 6px solid var(--red); }
.package-option strong, .package-option small { display: block; }
.package-option small { margin-top: 3px; }

.notice, .error-panel {
    padding: 15px 17px;
    color: #29445d;
    background: #edf5fb;
    border-left: 4px solid var(--blue);
    border-radius: 6px;
}
.notice-error, .error-panel { color: #76262a; background: #fff0f0; border-color: var(--red); }
.notice-warning { color: #76520c; background: #fff6dc; border-color: #d79b1e; }
.error-panel { margin-bottom: 24px; }

.account-hero {
    padding: 34px;
    margin-bottom: 24px;
    color: white;
    text-align: center;
    background: linear-gradient(135deg, var(--navy), #17466f);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.account-hero span, .account-hero strong { display: block; }
.account-hero span { color: #bdd0e2; font-size: .82rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.account-hero strong { margin: 12px 0 6px; font-size: clamp(1.5rem, 5vw, 2.5rem); letter-spacing: .04em; }
.account-hero p { margin: 0; color: #d7e3ee; }
.account-closed { background: linear-gradient(135deg, #11553a, #1e7d57); }

.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.detail-grid div { padding: 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-grid div:nth-child(4n) { border-right: 0; }
.detail-grid div:nth-last-child(-n+4) { border-bottom: 0; }
.detail-grid dt { color: var(--muted); font-size: .74rem; font-weight: 700; text-transform: uppercase; }
.detail-grid dd { margin: 5px 0 0; color: var(--navy); font-weight: 700; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { color: #647282; font-size: .72rem; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #f8fafb; }
.table-separated { margin-top: 24px; }
.table-sub { display: block; margin-top: 3px; color: var(--muted); }

.status {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    padding: 5px 9px;
    color: #4b5865;
    background: #e9edf1;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 800;
}
.status-active, .status-creating { color: #135287; background: #e2f1fd; }
.status-closed { color: #11633f; background: #dff5e9; }
.status-failed { color: #9b2228; background: #ffe5e6; }
.status-closing { color: #76520c; background: #fff1ca; }
.status-large { padding: 8px 13px; font-size: .8rem; }

.text-link, .text-button { color: var(--blue); font-weight: 700; text-decoration: none; }
.text-button { padding: 0; background: none; border: 0; cursor: pointer; }
.text-danger { color: var(--red); }
.table-actions { display: flex; align-items: center; gap: 12px; }
.table-actions form { margin: 0; }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

.empty-state { padding: 40px 20px; color: var(--muted); text-align: center; }
.empty-state > span { display: inline-grid; width: 48px; height: 48px; place-items: center; margin-bottom: 12px; color: var(--red); background: #ffebec; border-radius: 50%; font-size: 1.4rem; font-weight: 800; }
.empty-state h3 { margin-bottom: 5px; }

.flash-stack { display: grid; gap: 8px; margin-bottom: 18px; }
.auth-layout .flash-stack { position: fixed; top: 20px; width: min(440px, calc(100vw - 48px)); }
.flash { padding: 12px 15px; background: white; border-left: 4px solid var(--blue); border-radius: 7px; box-shadow: var(--shadow); }
.flash-error { border-color: var(--red); }
.flash-success { border-color: var(--green); }

@media (max-width: 900px) {
    .menu-toggle { display: block; cursor: pointer; }
    .nav {
        position: absolute;
        top: 72px;
        right: 0;
        left: 0;
        display: none;
        align-items: stretch;
        padding: 14px 5vw 20px;
        background: var(--navy);
        border-top: 1px solid rgba(255,255,255,.12);
    }
    .nav.is-open { display: grid; gap: 4px; }
    .nav a, .nav-button { width: 100%; text-align: left; }
    .metric-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: repeat(2, 1fr); }
    .detail-grid div:nth-child(4n) { border-right: 1px solid var(--line); }
    .detail-grid div:nth-child(2n) { border-right: 0; }
    .detail-grid div:nth-last-child(-n+4) { border-bottom: 1px solid var(--line); }
    .detail-grid div:nth-last-child(-n+2) { border-bottom: 0; }
    .panel-config-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 650px) {
    .page-shell { width: min(92vw, 1180px); padding-top: 30px; }
    .heading-actions, .section-heading { align-items: stretch; flex-direction: column; }
    .heading-actions .button { width: 100%; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .inline-form { align-items: stretch; flex-direction: column; }
    .selection-toolbar { align-items: flex-start; flex-direction: column; }
    .panel-config-grid { grid-template-columns: 1fr; }
    .form-actions { align-items: stretch; flex-direction: column-reverse; }
    .form-actions .button, .form-actions form, .form-actions form .button { width: 100%; }
    .login-card, .card { padding: 22px; }
    .steps li { font-size: .65rem; }
    .detail-grid { grid-template-columns: 1fr; }
    .detail-grid div, .detail-grid div:nth-child(2n), .detail-grid div:nth-child(4n) { border-right: 0; border-bottom: 1px solid var(--line); }
    .detail-grid div:last-child { border-bottom: 0; }
}
