:root {
    --green: #009b57;
    --green-dark: #005f3d;
    --green-soft: #eaf8f0;
    --amber: #c88217;
    --ink: #10251c;
    --muted: #6f817b;
    --line: #d6e5df;
    --bg: #f3faf6;
    --white: #ffffff;
}

* {
    box-sizing: border-box;
}

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

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

button {
    border: 0;
    cursor: pointer;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--green);
    font-weight: 800;
    font-size: 12px;
    letter-spacing: 0;
}

.admin-login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-panel {
    width: min(420px, 100%);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 32px;
    box-shadow: 0 18px 60px rgba(0, 95, 61, 0.12);
}

.login-logo {
    width: 132px;
    display: block;
    margin-bottom: 24px;
}

.login-panel h1 {
    margin: 0 0 24px;
    font-size: 28px;
    line-height: 1.2;
}

.login-form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

input,
select,
textarea {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--ink);
    background: var(--white);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(0, 155, 87, 0.12);
}

.login-form button,
.toolbar button,
.action-button {
    height: 44px;
    min-height: 44px;
    border-radius: 8px;
    padding: 0 18px;
    color: var(--white);
    background: linear-gradient(135deg, var(--green), #06d47c);
    font-weight: 800;
}

.ghost-button {
    height: 44px;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 18px;
    color: var(--green-dark);
    background: var(--white);
    font-weight: 800;
}

.danger-button {
    color: #9a3412;
}

.form-error,
.message.error {
    color: #b42318;
}

.admin-page {
    min-height: 100vh;
}

.admin-shell {
    min-height: 100vh;
    width: 100%;
    margin: 0;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    align-items: stretch;
}

.admin-sidebar {
    position: sticky;
    top: 0;
    min-height: 100vh;
    display: grid;
    align-content: start;
    gap: 22px;
    padding: 22px 12px 32px;
    background: #8eaa93;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.sidebar-brand {
    min-height: 54px;
    display: flex;
    align-items: flex-start;
    padding: 0 6px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.24);
}

.sidebar-brand img {
    width: 174px;
    height: auto;
}

.admin-main {
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 16px;
    padding: 24px 28px 56px;
    background: #f7f8f7;
}

.admin-header {
    position: relative;
    min-height: 92px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px 18px 24px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 12px 34px rgba(0, 95, 61, 0.06);
}

.admin-header::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    background: linear-gradient(180deg, var(--green), #3f925d);
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand img {
    width: 120px;
}

.brand h1 {
    margin: 0;
    font-size: 22px;
}

.admin-header h2 {
    margin: 0;
    font-size: 28px;
    line-height: 1.15;
}

.page-heading {
    position: relative;
    display: grid;
    gap: 4px;
}

.page-heading .eyebrow {
    margin: 0;
}

.page-heading span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.admin-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
}

.admin-user-chip {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #f8fbf9;
    font-size: 13px;
    font-weight: 800;
}

.logout-button {
    height: 40px;
    padding: 0 14px;
    border-radius: 8px;
    color: var(--green-dark);
    background: var(--green-soft);
    font-weight: 800;
}

.tabs {
    display: grid;
    gap: 8px;
}

.tab {
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.78);
    background: transparent;
    border: 0;
    font-size: 17px;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
}

.tab.active {
    color: var(--white);
    background: #3f925d;
    border-color: #3f925d;
    font-weight: 800;
}

.nav-icon {
    width: 20px;
    min-width: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: currentColor;
    font-size: 16px;
    line-height: 1;
}

.toolbar {
    display: flex;
    gap: 12px;
    align-items: end;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.toolbar label {
    width: 180px;
}

.message {
    margin-bottom: 16px;
    padding: 12px 14px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 800;
}

.overview-debt {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.overview-debt[hidden] {
    display: none;
}

.period-overview {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
}

.overview-section-title,
.period-section-title {
    margin-bottom: 0;
}

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

.content {
    display: grid;
    gap: 16px;
}

.grid {
    display: grid;
    gap: 16px;
}

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

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

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

.card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

.overview-stat-card {
    min-height: 112px;
    display: grid;
    align-content: center;
    gap: 6px;
}

.debt-overview-card {
    min-height: 112px;
    display: grid;
    align-content: center;
    gap: 6px;
}

.debt-card {
    background: linear-gradient(135deg, #fff7e8 0%, #ffffff 72%);
    border-color: rgba(193, 124, 20, 0.32);
}

.debt-card .muted {
    margin: 0;
    font-weight: 800;
}

.stat-title {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.stat-value {
    margin-top: 8px;
    color: var(--green-dark);
    font-size: 28px;
    font-weight: 900;
}

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

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

.filters {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.filters label {
    width: 220px;
}

.filters .action-button,
.filters .ghost-button {
    height: 44px;
    min-height: 44px;
    min-width: 64px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 64px;
    padding: 0 18px;
    line-height: 1;
    text-align: center;
}

.toolbar .action-button,
.toolbar .ghost-button {
    flex: 0 0 auto;
}

.section-title .action-button,
.form-actions .action-button,
.form-actions .ghost-button,
.pager .ghost-button {
    width: auto;
    flex: none;
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

table {
    width: 100%;
    min-width: 960px;
    border-collapse: collapse;
    background: var(--white);
}

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

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

tr:last-child td {
    border-bottom: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 4px 10px;
    color: var(--green-dark);
    background: var(--green-soft);
    font-weight: 800;
    font-size: 12px;
}

.badge.warn {
    color: #9a5d00;
    background: #fff4dd;
}

.status-badge {
    min-width: 132px;
    justify-content: center;
    text-align: center;
    border: 1px solid transparent;
}

.status-pending_payment {
    color: #9a5d00;
    background: #fff4dd;
    border-color: #f3d19b;
}

.status-payment_failed,
.status-cancelled,
.status-refunded,
.status-expired {
    color: #b42318;
    background: #fff0f0;
    border-color: #f3b4b4;
}

.status-payment_success {
    color: #006d49;
    background: #e6f8ef;
    border-color: #9fe6c3;
}

.status-key_issued,
.status-issued {
    color: #075985;
    background: #e8f5ff;
    border-color: #a7d8f5;
}

.status-key_sent,
.status-activation_processing {
    color: #5b21b6;
    background: #f2ecff;
    border-color: #ccb8ff;
}

.status-activated,
.status-active {
    color: #006d49;
    background: #e6f8ef;
    border-color: #9fe6c3;
}

.status-inactive,
.status-paused,
.status-draft {
    color: #465954;
    background: #f0f5f3;
    border-color: #d6e5df;
}

.status-ended {
    color: #6b3f00;
    background: #fff4dd;
    border-color: #f3d19b;
}

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

.row-actions .ghost-button {
    width: 110px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 110px;
    padding: 0 12px;
    line-height: 1;
    text-align: center;
}

.pager .ghost-button:disabled,
.row-actions .ghost-button:disabled {
    cursor: not-allowed;
    opacity: .45;
}

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

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

.pager span {
    height: 44px;
    display: inline-flex;
    align-items: center;
    color: var(--muted);
    font-weight: 800;
}

.empty {
    padding: 28px;
    color: var(--muted);
    text-align: center;
    font-weight: 800;
}

.admin-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
}

.admin-modal.hidden {
    display: none;
}

.admin-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(16, 37, 28, 0.48);
}

.admin-modal-panel {
    position: relative;
    width: min(900px, 100%);
    max-height: min(86vh, 920px);
    overflow: auto;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 24px 80px rgba(0, 95, 61, 0.22);
}

.admin-form {
    display: grid;
    gap: 16px;
}

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

.form-wide {
    grid-column: 1 / -1;
    display: grid;
    gap: 14px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

.form-warning {
    margin: 0;
    padding: 12px;
    border: 1px solid #f1c57d;
    border-radius: 8px;
    color: #8a5200;
    background: #fff7e8;
    font-weight: 800;
}

.form-note {
    align-self: end;
    margin: 0;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--green-dark);
    background: #f4fbf7;
    font-weight: 800;
}

.detail-grid {
    display: grid;
    gap: 12px;
}

.detail-grid p {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr);
    gap: 16px;
    margin: 0;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.detail-grid p:last-child {
    border-bottom: 0;
}

.detail-grid strong {
    color: var(--muted);
}

@media (max-width: 900px) {
    .admin-shell {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        position: static;
        min-height: auto;
        padding: 18px 12px;
        gap: 18px;
    }

    .sidebar-brand {
        min-height: auto;
        align-items: center;
    }

    .sidebar-brand img {
        width: 148px;
    }

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

    .tab {
        min-height: 48px;
        padding: 0 14px;
        font-size: 16px;
        gap: 10px;
    }

    .admin-main {
        padding: 12px;
    }

    .admin-header {
        height: auto;
        padding: 16px;
        align-items: flex-start;
        gap: 16px;
    }

    .toolbar,
    .filters {
        display: grid;
    }

    .toolbar label,
    .filters label {
        width: 100%;
    }

    .grid.cols-4,
    .grid.cols-3,
    .grid.cols-2,
    .overview-metric-grid {
        grid-template-columns: 1fr;
    }

    .form-grid,
    .detail-grid p {
        grid-template-columns: 1fr;
    }
}
