:root {
    --navy: #0B1F33;
    --navy-deep: #071525;
    --navy-soft: #132a42;
    --teal: #0F766E;
    --teal-bright: #14A39A;
    --teal-soft: #E6F5F3;
    --ink: #0B1F33;
    --muted: #5B6B7A;
    --line: #E2E8EF;
    --line-strong: #C9D4E0;
    --surface: #F3F6F9;
    --surface-2: #EAF0F5;
    --card: #FFFFFF;
    --danger: #B42318;
    --danger-soft: #FEF3F2;
    --warn: #B54708;
    --warn-soft: #FFFAEB;
    --ok: #067647;
    --ok-soft: #ECFDF3;
    --info: #175CD3;
    --info-soft: #EFF8FF;
    --shadow: 0 1px 2px rgba(11, 31, 51, 0.04), 0 8px 24px rgba(11, 31, 51, 0.06);
    --radius: 14px;
    --sidebar-w: 248px;
    --font: "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--surface);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--teal-bright); }

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85em;
    background: var(--surface-2);
    padding: 0.12em 0.4em;
    border-radius: 6px;
    color: var(--navy-soft);
}

/* —— Shell —— */
.app-shell {
    min-height: 100%;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
}

.app-shell.is-guest {
    display: block;
}

.sidebar {
    background:
        radial-gradient(ellipse 120% 80% at 0% 0%, rgba(15, 118, 110, 0.28), transparent 55%),
        linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
    color: #fff;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px;
    color: #fff;
}

.sidebar-brand img {
    height: 36px;
    width: auto;
    display: block;
}

.sidebar-brand .mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.sidebar-brand .mark img {
    width: 22px;
    height: 22px;
}

.sidebar-brand .meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.sidebar-brand .meta strong {
    font-size: 15px;
    letter-spacing: -0.02em;
}

.sidebar-brand .meta span {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.72);
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 550;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-nav a.is-active {
    background: rgba(15, 118, 110, 0.45);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.sidebar-nav svg {
    width: 18px;
    height: 18px;
    opacity: 0.9;
    flex-shrink: 0;
}

.sidebar-foot {
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-foot form { margin: 0; }

.workspace {
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background:
        radial-gradient(ellipse 70% 40% at 100% -10%, rgba(15, 118, 110, 0.08), transparent 50%),
        radial-gradient(ellipse 50% 30% at 0% 100%, rgba(11, 31, 51, 0.05), transparent 45%),
        linear-gradient(180deg, #F7F9FB 0%, var(--surface) 40%, var(--surface-2) 100%);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 28px 0;
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

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

.page {
    padding: 20px 28px 40px;
    max-width: 1120px;
    width: 100%;
}

/* —— Surfaces —— */
.card {
    background: var(--card);
    border: 1px solid rgba(11, 31, 51, 0.06);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

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

.card-head h2,
.card h2 {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.section-title {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stack { display: flex; flex-direction: column; gap: 14px; }

.stat-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-row.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat {
    background: linear-gradient(180deg, #fff 0%, #F8FBFC 100%);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
}

.stat .label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
}

.stat .value {
    margin-top: 6px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.02em;
    word-break: break-word;
}

.stat .value-wrap {
    font-size: 14px;
    line-height: 1.35;
    word-break: normal;
}

.muted { color: var(--muted); font-size: 13px; }

.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--ok-soft);
    color: var(--ok);
    border: 1px solid #ABEFC6;
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 550;
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid #FECDCA;
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-warn {
    background: var(--warn-soft);
    color: var(--warn);
    border: 1px solid #FEDF89;
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 14px;
}

/* —— Tables —— */
.table-wrap {
    overflow-x: auto;
    margin: 0 -6px;
    padding: 0 6px;
}

table.data {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

table.data th,
table.data td {
    text-align: left;
    padding: 12px 10px;
    font-size: 13.5px;
    vertical-align: middle;
    border-bottom: 1px solid var(--line);
}

table.data th {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 650;
    background: transparent;
}

table.data tbody tr {
    transition: background 0.12s ease;
}

table.data tbody tr:hover {
    background: rgba(15, 118, 110, 0.04);
}

table.data tbody tr:last-child td {
    border-bottom: 0;
}

table.data a {
    font-weight: 650;
    color: var(--navy);
}

table.data a:hover { color: var(--teal); }

.empty {
    text-align: center;
    padding: 36px 16px;
    color: var(--muted);
    font-size: 14px;
}

.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0 0 12px;
}

.inline-form input[type="text"] {
    flex: 1;
    min-width: 0;
    margin: 0;
}

.card-head .inline-form {
    margin: 0;
    min-width: min(360px, 100%);
}

.report {
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--surface-2);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 13px;
    margin: 0;
}

.message-cell {
    max-width: 240px;
    white-space: normal;
}

.otp-toggle {
    border: 0;
    background: transparent;
    color: var(--teal);
    font: inherit;
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
    margin-left: 6px;
    padding: 0;
}

/* —— Badges —— */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 650;
    letter-spacing: 0.01em;
    text-transform: capitalize;
    white-space: nowrap;
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.85;
}

.badge-active,
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-trialing,
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-past_due,
.badge-grace,
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-suspended,
.badge-canceled,
.badge-inactive,
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--muted); }
.badge-dev { background: #F4F3FF; color: #5925DC; }

/* —— Forms & buttons —— */
label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 6px;
    color: var(--ink);
}

.field { margin-bottom: 14px; }

.field-hint {
    margin: -6px 0 14px;
    color: var(--muted);
    font-size: 12.5px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
}

.form-grid .span-2 { grid-column: 1 / -1; }

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

.action-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
}

.action-panel.danger {
    background: var(--danger-soft);
    border-color: #FECDCA;
}

.action-panel h3 {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 700;
}

input[type="text"],
input[type="password"],
input[type="number"],
input:not([type]),
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    margin: 0 0 0;
    font-family: inherit;
    font-size: 14px;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

input:focus,
textarea:focus,
select:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.check {
    width: auto;
    margin: 0 8px 0 0;
    accent-color: var(--teal);
}

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 8px;
}

.check-row label { margin: 0; font-weight: 550; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--teal);
    color: #fff;
    border: 1px solid transparent;
    padding: 9px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 650;
    line-height: 1.2;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn:hover {
    background: #0C6560;
    color: #fff;
}

.btn:active { transform: translateY(1px); }

.btn-secondary {
    background: #fff;
    color: var(--navy);
    border-color: var(--line-strong);
}

.btn-secondary:hover {
    background: var(--surface);
    color: var(--navy);
}

.btn-ghost {
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    border-color: rgba(255, 255, 255, 0.18);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover { background: #912018; color: #fff; }

.btn-block { width: 100%; }

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

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 550;
    margin-bottom: 10px;
}

.back-link:hover { color: var(--teal); }

/* —— Pagination —— */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    font-size: 13px;
    color: var(--muted);
}

.pager-links {
    display: flex;
    gap: 6px;
}

.pager-links a,
.pager-links span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--navy);
    font-weight: 600;
}

.pager-links a:hover {
    border-color: var(--teal);
    color: var(--teal);
}

.pager-links .is-current {
    background: var(--navy);
    border-color: var(--navy);
    color: #fff;
}

.pager-links .is-disabled {
    opacity: 0.45;
    pointer-events: none;
}

/* —— Login —— */
.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 16px;
    background:
        radial-gradient(ellipse 80% 50% at 15% 20%, rgba(15, 118, 110, 0.18), transparent 55%),
        radial-gradient(ellipse 60% 40% at 90% 80%, rgba(11, 31, 51, 0.12), transparent 50%),
        linear-gradient(145deg, #0B1F33 0%, #0F3D3A 48%, #0B1F33 100%);
    position: relative;
    overflow: hidden;
}

.login-screen::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 20%, transparent 75%);
    pointer-events: none;
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: rgba(255, 255, 255, 0.97);
    border-radius: 20px;
    padding: 32px 28px 28px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
    margin-bottom: 24px;
}

.login-brand img.logo {
    height: 40px;
    width: auto;
}

.login-brand h1 {
    margin: 8px 0 0;
    font-size: 22px;
    font-weight: 750;
    letter-spacing: -0.03em;
}

.login-brand p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    max-width: 28ch;
}

.login-card .btn { margin-top: 8px; }

@media (max-width: 860px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: relative;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 12px;
        padding: 14px 16px;
    }
    .sidebar-nav {
        flex-direction: row;
        flex: 1 1 auto;
        gap: 4px;
    }
    .sidebar-nav a span { display: none; }
    .sidebar-foot { border: 0; padding: 0; margin-left: auto; }
    .stat-row,
    .stat-row.cols-3 { grid-template-columns: 1fr 1fr; }
    .form-grid,
    .action-grid { grid-template-columns: 1fr; }
    .page, .topbar { padding-left: 16px; padding-right: 16px; }
}
