:root {
    --font-ui: "Plus Jakarta Sans", "Manrope", "Segoe UI", sans-serif;
    --bg-canvas: #f4f7fb;
    --bg-panel: #ffffff;
    --bg-panel-muted: #f9fbfe;
    --bg-soft: #eef3f8;
    --ink: #0f1b2d;
    --ink-muted: #5f6e85;
    --ink-soft: #7f8ca0;
    --line: #d9e2ee;
    --line-strong: #c8d4e2;
    --brand: #0d5bd8;
    --brand-strong: #0844a8;
    --accent: #0f8f95;
    --success: #1f8f4c;
    --warning: #b7710d;
    --danger: #c73633;
    --shadow-sm: 0 6px 18px rgba(13, 27, 45, 0.08);
    --shadow-md: 0 16px 38px rgba(13, 27, 45, 0.12);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    color: var(--ink);
    font-family: var(--font-ui);
    background:
        radial-gradient(circle at 5% 6%, rgba(13, 91, 216, 0.12), transparent 30%),
        radial-gradient(circle at 93% 88%, rgba(15, 143, 149, 0.1), transparent 34%),
        linear-gradient(140deg, #f7faff 0%, #f1f6fd 45%, #f8f9fc 100%);
}

.bg-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        repeating-linear-gradient(
            110deg,
            transparent 0,
            transparent 20px,
            rgba(15, 27, 45, 0.012) 21px,
            transparent 22px
        );
    opacity: 0.65;
}

h1,
h2,
h3,
p {
    margin: 0;
}

.shell {
    position: relative;
    max-width: 1360px;
    margin: 0 auto;
    padding: 28px 24px 44px;
    display: grid;
    gap: 18px;
    animation: shell-fade 380ms ease-out;
}

@keyframes shell-fade {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    padding: 20px 22px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: linear-gradient(130deg, rgba(255, 255, 255, 0.95), rgba(250, 252, 255, 0.82));
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}

h1 {
    font-size: clamp(1.5rem, 1.2rem + 1.3vw, 2rem);
    letter-spacing: -0.02em;
}

h2 {
    font-size: clamp(1.16rem, 1rem + 0.4vw, 1.4rem);
    letter-spacing: -0.015em;
}

h3 {
    font-size: clamp(1.02rem, 0.95rem + 0.2vw, 1.15rem);
}

.header-sub {
    margin-top: 8px;
}

.eyebrow {
    margin-bottom: 8px;
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--ink-soft);
}

.card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 20px;
    background: linear-gradient(150deg, #ffffff 0%, #f9fbff 100%);
    box-shadow: var(--shadow-sm);
}

.login-card {
    max-width: 460px;
}

.stack {
    display: grid;
    gap: 12px;
    margin-top: 14px;
}

label {
    display: inline-block;
    font-size: 13px;
    font-weight: 700;
    color: var(--ink-muted);
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font: inherit;
    color: var(--ink);
    background: var(--bg-panel);
    transition: border-color 130ms ease, box-shadow 130ms ease, background 130ms ease;
}

input:hover,
textarea:hover,
select:hover {
    border-color: #adc0d6;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.btn:focus-visible,
.tab-btn:focus-visible {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(13, 91, 216, 0.18);
}

textarea {
    resize: vertical;
}

.btn {
    border: 0;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    white-space: nowrap;
    transition: transform 110ms ease, filter 120ms ease, box-shadow 130ms ease;
}

.btn:hover {
    filter: brightness(1.02);
}

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

.btn.solid {
    color: #ffffff;
    background: linear-gradient(140deg, var(--brand), var(--brand-strong));
    box-shadow: 0 10px 20px rgba(13, 91, 216, 0.25);
}

.btn.ghost {
    color: var(--ink);
    border: 1px solid var(--line);
    background: linear-gradient(140deg, #ffffff, #f3f7fc);
}

.btn.warn {
    background: linear-gradient(140deg, #e34b47, #b92a28);
    color: #ffffff;
}

.btn:disabled {
    opacity: 0.56;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.section-tabs {
    display: inline-flex;
    gap: 8px;
    margin-bottom: 16px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: linear-gradient(140deg, #f6f9fd, #edf3fa);
}

.tab-btn {
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--ink-muted);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    padding: 8px 16px;
    cursor: pointer;
}

.tab-btn.active {
    color: var(--ink);
    background: var(--bg-panel);
    box-shadow: 0 5px 14px rgba(13, 27, 45, 0.11);
}

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

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

.api-hint {
    margin-bottom: 14px;
}

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

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

.stat-card {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: linear-gradient(152deg, #ffffff 0%, #f2f8ff 100%);
}

.stat-label {
    color: var(--ink-muted);
    font-size: 12px;
    margin-bottom: 6px;
}

.stat-value {
    font-size: clamp(1.03rem, 0.95rem + 0.5vw, 1.3rem);
    font-weight: 800;
    letter-spacing: -0.02em;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--bg-panel-muted);
}

.search-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: min(100%, 360px);
}

.search-group input {
    flex: 1;
    min-width: 150px;
}

.pager-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.pager-group .muted {
    font-size: 12px;
    font-weight: 700;
}

.pager-group select,
.pager-group input {
    width: auto;
    min-width: 100px;
}

.toolbar-subscriptions {
    align-items: flex-start;
}

.sub-search-group {
    min-width: min(100%, 410px);
}

.sub-filter-group {
    justify-content: flex-end;
}

#resultSummary,
#subResultSummary {
    margin: 8px 0 10px;
    color: var(--ink-muted);
}

.loading-text {
    margin: 4px 0 10px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
}

.table-wrap {
    overflow: auto;
    max-height: 66vh;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #ffffff;
}

table {
    width: 100%;
    border-collapse: collapse;
}

#tableWrap table {
    min-width: 760px;
}

#subTableWrap table {
    min-width: 1320px;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: linear-gradient(180deg, #f2f7ff, #ecf3fb);
    border-bottom: 1px solid var(--line);
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 11px;
}

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

tbody tr:nth-child(2n) {
    background: #fbfdff;
}

tbody tr:hover {
    background: #eff6ff;
}

.virtual-spacer td {
    padding: 0;
    border: 0;
    background: transparent;
}

td code {
    font-size: 12px;
    color: var(--ink-muted);
}

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

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

#jumpPageInput,
#subJumpPageInput {
    width: 94px;
}

.inline-input,
.inline-textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 6px 8px;
    font: inherit;
    font-size: 13px;
}

.inline-textarea {
    min-height: 56px;
    resize: vertical;
}

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

.inline-actions .btn.saving {
    background: linear-gradient(140deg, #6a89be, #4d6da2);
}

.row-saving-badge {
    display: inline-block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--accent);
    font-weight: 700;
}

dialog {
    border: none;
    border-radius: var(--radius-md);
    width: min(680px, 96vw);
    padding: 0;
}

dialog::backdrop {
    background: rgba(15, 27, 45, 0.45);
}

#editForm {
    padding: 18px;
}

.dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 10px;
}

.status-chip,
.days-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
}

.status-active,
.days-ok {
    color: #106034;
    background: #d7f3e2;
}

.status-expiring-soon,
.days-soon {
    color: #7f510a;
    background: #ffe8be;
}

.days-urgent {
    color: #7b1e1b;
    background: #ffd8d6;
}

.status-expired,
.days-expired {
    color: #7b1e1b;
    background: #ffd1cf;
}

.status-unknown,
.days-neutral {
    color: #3d4a61;
    background: #e9eef5;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    background: rgba(15, 27, 45, 0.55);
    padding: 14px;
}

.modal[hidden] {
    display: none !important;
}

.modal-card {
    width: min(860px, 96vw);
    max-height: 92vh;
    overflow: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: #ffffff;
    box-shadow: var(--shadow-md);
    padding: 18px;
}

.modal-card-small {
    width: min(520px, 96vw);
}

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

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

.form-grid label {
    display: block;
    margin-bottom: 6px;
}

.form-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 6px;
}

.delete-detail {
    margin-top: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #f8fbff;
    padding: 11px;
    font-size: 13px;
    line-height: 1.45;
}

.toast {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 60;
    color: #ffffff;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(15, 27, 45, 0.28);
    background: linear-gradient(140deg, #2a9d5a, #1f7d47);
}

.toast.error {
    background: linear-gradient(140deg, #da4a46, #b9302d);
}

.advanced-row td {
    background: #f6faff;
}

.advanced-panel {
    display: grid;
    gap: 8px;
    padding: 9px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-sm);
}

body[data-density="compact"] th,
body[data-density="compact"] td {
    padding: 7px 8px;
    font-size: 12px;
}

body[data-density="compact"] .inline-input,
body[data-density="compact"] .inline-textarea {
    font-size: 12px;
    padding: 5px 6px;
}

@media (max-width: 1160px) {
    .shell {
        padding-inline: 16px;
    }

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

    .toolbar {
        align-items: stretch;
    }

    .search-group,
    .pager-group {
        width: 100%;
    }
}

@media (max-width: 820px) {
    .shell {
        padding: 14px 12px 24px;
        gap: 12px;
    }

    .topbar,
    .card {
        border-radius: var(--radius-md);
        padding: 14px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    #logoutBtn {
        width: 100%;
    }

    .section-tabs {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .tab-btn {
        text-align: center;
    }

    .stats-grid,
    #usersSection .stats-grid {
        grid-template-columns: 1fr;
    }

    .search-group,
    .sub-search-group {
        min-width: 100%;
        flex-wrap: wrap;
    }

    .search-group input,
    .search-group .btn {
        width: 100%;
    }

    .pager-group {
        align-items: flex-start;
    }

    .pager-group select,
    .pager-group input {
        min-width: 100%;
    }

    .pagination {
        justify-content: space-between;
    }

    .pagination .btn,
    .pagination input,
    .pagination span {
        flex: 1 1 calc(50% - 8px);
        min-width: 110px;
    }

    .pagination span {
        text-align: center;
    }

    .table-wrap {
        max-height: none;
        overflow: visible;
        border: 0;
        background: transparent;
    }

    .table-wrap table {
        min-width: 0 !important;
        border-collapse: separate;
        border-spacing: 0 10px;
    }

    .table-wrap thead {
        display: none;
    }

    .table-wrap tbody {
        display: grid;
        gap: 10px;
    }

    .table-wrap tbody tr {
        display: block;
        border: 1px solid var(--line);
        border-radius: var(--radius-md);
        background: #ffffff;
        padding: 8px 10px;
        box-shadow: var(--shadow-sm);
    }

    .table-wrap tbody tr.virtual-spacer {
        display: none !important;
    }

    .table-wrap tbody tr:hover {
        background: #ffffff;
    }

    .table-wrap tbody td {
        display: grid;
        grid-template-columns: minmax(90px, 38%) 1fr;
        gap: 8px;
        align-items: start;
        border: 0;
        border-bottom: 1px dashed var(--line);
        padding: 8px 0;
    }

    .table-wrap tbody td:last-child {
        border-bottom: 0;
        padding-bottom: 2px;
    }

    .table-wrap tbody td::before {
        content: "";
        color: var(--ink-soft);
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        line-height: 1.25;
    }

    #tableWrap tbody td:nth-child(1)::before {
        content: "Username";
    }

    #tableWrap tbody td:nth-child(2)::before {
        content: "Expire Date";
    }

    #tableWrap tbody td:nth-child(3)::before {
        content: "Days Left";
    }

    #tableWrap tbody td:nth-child(4)::before {
        content: "Action";
    }

    #subTableWrap tbody td:nth-child(1)::before {
        content: "Entry Date";
    }

    #subTableWrap tbody td:nth-child(2)::before {
        content: "Buyer Name";
    }

    #subTableWrap tbody td:nth-child(3)::before {
        content: "User Name";
    }

    #subTableWrap tbody td:nth-child(4)::before {
        content: "Plan SKU";
    }

    #subTableWrap tbody td:nth-child(5)::before {
        content: "Payment";
    }

    #subTableWrap tbody td:nth-child(6)::before {
        content: "Amount";
    }

    #subTableWrap tbody td:nth-child(7)::before {
        content: "Start Date";
    }

    #subTableWrap tbody td:nth-child(8)::before {
        content: "End Date";
    }

    #subTableWrap tbody td:nth-child(9)::before {
        content: "Status";
    }

    #subTableWrap tbody td:nth-child(10)::before {
        content: "Platform";
    }

    #subTableWrap tbody td:nth-child(11)::before {
        content: "Action";
    }

    .advanced-row td::before {
        content: "";
    }

    .inline-actions {
        width: 100%;
    }

    .inline-actions .btn {
        flex: 1 1 auto;
    }

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

    .dialog-actions .btn {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .toolbar,
    .modal-card {
        padding: 12px;
    }

    .section-tabs {
        padding: 4px;
        gap: 6px;
    }

    .tab-btn {
        padding: 8px 10px;
        font-size: 13px;
    }

    .pagination .btn,
    .pagination input,
    .pagination span {
        flex: 1 1 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0ms !important;
    }
}
