:root {
    color-scheme: light;
    --ink: #18202a;
    --muted: #687486;
    --line: #dfe5ec;
    --panel: #ffffff;
    --paper: #f5f7fa;
    --brand: #106b5b;
    --brand-dark: #0d5146;
    --accent: #f2b84b;
    --danger: #c63f3f;
    --success: #1b8a5a;
    --shadow: 0 20px 50px rgba(18, 31, 46, 0.12);
}

* {
    box-sizing: border-box;
}

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

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(16, 107, 91, 0.18), rgba(242, 184, 75, 0.12)),
        var(--paper);
}

.login-panel {
    width: min(100%, 420px);
    padding: 34px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    background: var(--brand);
    color: white;
    border-radius: 8px;
    font-weight: 800;
    letter-spacing: 0;
}

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

h1,
h2,
p {
    margin-top: 0;
}

.login-panel h1 {
    margin-bottom: 10px;
    font-size: 30px;
}

.login-copy {
    color: var(--muted);
    line-height: 1.55;
}

.login-form,
.login-form label,
.toolbar label,
.form-grid label {
    display: grid;
    gap: 7px;
}

.login-form {
    gap: 15px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
    color: var(--ink);
    padding: 9px 11px;
}

input,
select {
    min-height: 42px;
}

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

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(16, 107, 91, 0.18);
    border-color: var(--brand);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
    min-height: 40px;
    border-radius: 6px;
    padding: 9px 14px;
    font-weight: 750;
    white-space: nowrap;
}

.primary-button {
    background: var(--brand);
    color: white;
}

.primary-button:hover {
    background: var(--brand-dark);
}

.secondary-button {
    background: #edf5f3;
    color: var(--brand-dark);
}

.ghost-button {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: transparent;
    color: white;
}

.danger-button {
    background: #fae7e7;
    color: var(--danger);
}

.icon-button {
    width: 40px;
    padding: 0;
    background: #eef2f6;
    color: var(--ink);
}

.alert {
    padding: 11px 12px;
    border-radius: 6px;
    margin-bottom: 15px;
    font-weight: 700;
}

.alert-danger {
    background: #fae7e7;
    color: var(--danger);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 24px;
    background: #17212b;
    color: white;
}

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

.brand-row span {
    display: block;
    margin-top: 3px;
    color: rgba(255, 255, 255, 0.65);
    font-size: 13px;
}

.sidebar nav {
    display: grid;
    gap: 8px;
}

.sidebar a {
    color: rgba(255, 255, 255, 0.82);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 6px;
}

.sidebar a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.logout-form {
    margin-top: auto;
}

.dashboard {
    min-width: 0;
    padding: 28px;
}

.topbar,
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar {
    margin-bottom: 22px;
}

.topbar h1,
.section-heading h2 {
    margin-bottom: 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric,
.panel,
.table-section {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metric {
    padding: 18px;
}

.metric span,
.metric small,
.section-heading span {
    color: var(--muted);
}

.metric strong {
    display: block;
    margin: 9px 0 4px;
    font-size: 30px;
}

.toolbar {
    display: grid;
    grid-template-columns: minmax(210px, 1.5fr) repeat(3, minmax(130px, 0.7fr)) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 18px;
    padding: 14px;
    background: #e9eef4;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.table-section,
.panel {
    padding: 18px;
}

.table-wrap {
    width: 100%;
    overflow: visible;
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

table {
    width: 100%;
    min-width: 1120px;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
}

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

th {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #f7f9fb;
    box-shadow: 0 1px 0 var(--line), 0 8px 14px rgba(24, 32, 42, 0.08);
    color: #4b5868;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
}

tr:hover td {
    background: #fbfcfd;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.badge.active {
    background: #ddf3e9;
    color: var(--success);
}

.badge.expired {
    background: #fae7e7;
    color: var(--danger);
}

.badge.soon {
    background: #fff3d4;
    color: #8b5e00;
}

.pack-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 850;
    white-space: nowrap;
}

.pack-badge.pack-1month {
    background: #f4c430;
    color: #4a3500;
}

.pack-badge.pack-2months {
    background: #d9ecff;
    color: #1556a8;
}

.pack-badge.pack-3months {
    background: #ffe0bd;
    color: #a34d00;
}

.pack-badge.pack-6months {
    background: #dff6e7;
    color: #0b7f5b;
}

.pack-badge.pack-12months {
    background: #0b7f5b;
    color: #ffffff;
}

.pack-badge.pack-24months {
    background: #174ea6;
    color: #ffffff;
}

.pack-badge.pack-unknown {
    background: #eef2f6;
    color: #4b5868;
}

.payment-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.payment-badge.paid {
    background: #ddf3e9;
    color: var(--success);
}

.payment-badge.no-paid {
    background: #fff3d4;
    color: #8b5e00;
}

.payment-badge.gift {
    background: #e8efff;
    color: #315ca8;
}

.payment-badge.scam {
    background: #fae7e7;
    color: var(--danger);
}

.note-cell {
    max-width: 220px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.whatsapp-link {
    color: #0b7f5b;
    font-weight: 750;
    text-decoration: none;
}

.whatsapp-link:hover {
    text-decoration: underline;
}

.action-cell {
    width: 72px;
    text-align: center;
    white-space: nowrap;
}

.edit-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 26px;
    padding: 3px 9px;
    border: 1px solid #d9e2ec;
    border-radius: 999px;
    background: #f5f8fb;
    color: #243244;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
}

.edit-button:hover {
    background: #e8f1ff;
    border-color: #bfd6ff;
    color: #1556a8;
}

.renewals-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
    margin-top: 18px;
}

.mini-list,
.bars {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.mini-item {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.mini-item strong {
    display: block;
}

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

.bar-row {
    display: grid;
    grid-template-columns: 90px minmax(0, 1fr) 50px;
    gap: 10px;
    align-items: center;
}

.bar-track {
    height: 10px;
    overflow: hidden;
    background: #e7ecf2;
    border-radius: 999px;
}

.bar-fill {
    height: 100%;
    background: var(--brand);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(14, 21, 30, 0.58);
}

.modal[hidden] {
    display: none;
}

.modal-panel {
    width: min(900px, 100%);
    max-height: min(90vh, 820px);
    overflow: auto;
    padding: 22px;
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.modal-header,
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-header {
    margin-bottom: 18px;
}

.modal-header h2 {
    margin-bottom: 0;
}

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

.field-wide {
    grid-column: 1 / -1;
}

.modal-actions {
    margin-top: 18px;
}

.form-message {
    color: var(--muted);
    margin-left: auto;
}

.empty-state {
    padding: 24px;
    color: var(--muted);
    text-align: center;
}

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

    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .sidebar nav {
        grid-auto-flow: column;
        overflow: auto;
    }

    .logout-form {
        margin-top: 0;
        margin-left: auto;
    }

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

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

@media (max-width: 640px) {
    .dashboard {
        padding: 18px;
    }

    .topbar,
    .section-heading,
    .modal-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .stats-grid,
    .renewals-grid,
    .toolbar,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        padding: 18px;
    }

    .logout-form,
    .primary-button,
    .secondary-button,
    .danger-button {
        width: 100%;
    }
}
