:root {
    color-scheme: light;
    --bg: #f5f6f8;
    --paper: #ffffff;
    --line: #e7eaef;
    --text: #161a20;
    --muted: #697487;
    --primary: #146c5f;
    --primary-soft: #e8f4f2;
    --danger: #b33f53;
    --warning: #b9802e;
    --success: #2f7d56;
    --radius: 16px;
    --shadow: 0 10px 28px rgba(18, 31, 45, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: radial-gradient(circle at top left, #fdfdfd 0, var(--bg) 50%, #eef1f6 100%);
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--paper);
    border-right: 1px solid var(--line);
    padding: 24px 16px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 20px;
}

.brand {
    width: fit-content;
    padding: 9px 12px;
    border-radius: 999px;
    background: var(--text);
    color: #fff;
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.14em;
}

.nav {
    display: grid;
    align-content: start;
    gap: 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 12px;
    padding: 11px 12px;
    color: var(--muted);
    font-weight: 600;
    transition: background .2s ease, color .2s ease;
}

.nav-link:hover,
.nav-link.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
}

.nav-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.nav-icon.small {
    width: 14px;
    height: 14px;
}

.sidebar-footer {
    display: grid;
    gap: 10px;
}

.user-chip {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    display: grid;
    gap: 3px;
    background: #fafbfc;
}

.user-chip span,
.page-meta,
.muted {
    color: var(--muted);
    font-size: 0.88rem;
}

.main {
    padding: 24px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.page-header h1,
.auth-card h1 {
    margin: 0;
    font-size: clamp(1.8rem, 2.8vw, 2.4rem);
    letter-spacing: -0.02em;
}

.page-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mini-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 10px;
    font-weight: 600;
}

.page-grid,
.split {
    display: grid;
    gap: 14px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.card,
.panel,
.auth-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel,
.card {
    padding: 16px;
}

.auth-card {
    width: min(100%, 460px);
    padding: 24px;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 20px;
}

.auth-card p {
    color: var(--muted);
}

.auth-link {
    display: inline-block;
    margin-top: 10px;
    color: var(--primary);
    font-weight: 600;
}

.stat-label {
    margin: 0;
    color: var(--muted);
    font-size: .88rem;
}

.stat-value {
    margin: 4px 0 0;
    font-size: 1.48rem;
    font-weight: 700;
}

.grid-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 11px 8px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: .78rem;
    font-weight: 700;
}

.badge-success {
    background: #e8f6ee;
    color: var(--success);
}

.badge-warning {
    background: #fff2df;
    color: var(--warning);
}

.badge-danger {
    background: #fdeaf0;
    color: var(--danger);
}

.badge-neutral {
    background: #f0f3f7;
    color: var(--muted);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.section-title h2 {
    margin: 0;
    font-size: 1.05rem;
}

.view-switch {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.chip-btn {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 12px;
    font-size: .86rem;
    font-weight: 700;
    color: var(--muted);
    background: #fff;
}

.chip-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-soft);
}

.form-grid,
.form-stack {
    display: grid;
    gap: 10px;
}

.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
    display: grid;
    gap: 6px;
    font-size: .86rem;
    color: var(--muted);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
    color: var(--text);
    background: #fff;
    font: inherit;
}

textarea {
    min-height: 100px;
    resize: vertical;
}

.button {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 9px 12px;
    font-weight: 700;
    font-size: .86rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.button-primary {
    background: var(--primary);
    color: #fff;
}

.button-ghost {
    border-color: var(--line);
    background: #fff;
    color: var(--text);
}

.button-danger {
    border-color: #f3ccd4;
    background: #fff4f7;
    color: var(--danger);
}

.button-xs {
    padding: 6px 8px;
    font-size: .74rem;
    border-radius: 8px;
}

.actions-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.renew-inline-form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.renew-date-input {
    min-width: 150px;
}

.app-modal {
    width: min(720px, 92vw);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 16px;
}

.app-modal::backdrop {
    background: rgba(12, 20, 30, 0.35);
}

.app-modal h3 {
    margin-top: 0;
    margin-bottom: 12px;
}

.modal-close-row {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.pending-cell {
    font-weight: 700;
}

.billing-matrix th,
.billing-matrix td {
    min-width: 150px;
}

.billing-matrix th:first-child,
.billing-matrix td:first-child {
    min-width: 190px;
    position: sticky;
    left: 0;
    background: var(--paper);
    z-index: 1;
}

.billing-client-cell {
    font-weight: 700;
}

.billing-month-cell {
    display: grid;
    gap: 6px;
}

.billing-check-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.billing-check-wrap input {
    width: 16px;
    height: 16px;
}

.billing-month-amount {
    font-weight: 700;
    color: var(--text);
}

.billing-month-meta {
    margin: 0;
    font-size: 0.8rem;
}

.alert {
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid transparent;
    font-size: .9rem;
}

.alert-success {
    background: #eaf7ef;
    color: #256b47;
    border-color: #cbead7;
}

.alert-error {
    background: #feeff3;
    color: #973249;
    border-color: #f8d1db;
}

.compact-grid {
    display: grid;
    gap: 12px;
}

.detail-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.detail-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
    background: #fafbfd;
}

.detail-item strong {
    display: block;
    margin-bottom: 4px;
    font-size: .78rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

@media (max-width: 1040px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .stats,
    .grid-two,
    .detail-list,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .main {
        padding: 16px;
    }
}
