:root {
    --background: #0b1020;
    --surface: #121a2e;
    --surface-raised: #18233d;
    --surface-soft: #202d49;
    --border: rgba(255, 255, 255, 0.09);
    --text: #f4f7ff;
    --muted: #9eabc4;
    --primary: #6c7cff;
    --primary-strong: #8290ff;
    --positive: #39d98a;
    --warning: #ffbf5f;
    --danger: #ff6b7a;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
    --radius-large: 20px;
    --radius-medium: 14px;
    --radius-small: 9px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--background);
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(108, 124, 255, 0.18), transparent 32rem),
        radial-gradient(circle at top right, rgba(57, 217, 138, 0.08), transparent 28rem),
        var(--background);
}

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

button {
    border: 0;
}

input,
select,
textarea {
    width: 100%;
    color: var(--text);
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input,
select {
    min-height: 44px;
    padding: 10px 12px;
}

textarea {
    resize: vertical;
    padding: 12px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.065);
    box-shadow: 0 0 0 3px rgba(108, 124, 255, 0.16);
}

select option {
    color: #111827;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

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

h1,
h2,
h3 {
    letter-spacing: -0.025em;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(1.55rem, 3vw, 2.2rem);
}

h2 {
    margin-bottom: 8px;
    font-size: 1.35rem;
}

code {
    color: #dbe1ff;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.8rem;
}

/* Shared product logo */
.admin-brand,
.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.admin-brand-link,
.login-brand-link {
    color: inherit;
    text-decoration: none;
}

.admin-brand-link:hover .admin-logo,
.login-brand-link:hover .admin-logo {
    transform: translateY(-1px);
}

.admin-logo {
    display: grid;
    width: 52px;
    height: 52px;
    flex: 0 0 52px;
    place-items: center;
    color: white;
    background: linear-gradient(145deg, var(--primary), #38bdf8);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 16px;
    box-shadow: 0 14px 32px rgba(72, 91, 224, 0.28);
    transition: transform 160ms ease;
}

.admin-logo svg {
    width: 31px;
    height: 31px;
}

.admin-brand .eyebrow {
    margin-bottom: 5px;
}

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

/* Login page */
.login-box {
    width: min(390px, calc(100% - 32px));
    margin: 0;
    padding: 36px;
    background: rgba(18, 26, 46, 0.96);
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow);
}

.login-brand {
    margin-bottom: 28px;
}

.login-logo {
    width: 58px;
    height: 58px;
    flex-basis: 58px;
}

.login-box h1 {
    margin-bottom: 4px;
    font-size: 1.45rem;
}

.login-brand p {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.login-box h2 {
    margin-bottom: 16px;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.login-field {
    display: block;
    margin-top: 12px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
}

.login-field span {
    display: block;
    margin-bottom: 6px;
}

.login-box input {
    margin: 0;
}

.login-box button {
    width: 100%;
    margin-top: 12px;
    padding: 12px 16px;
    color: white;
    background: var(--primary);
    border-radius: var(--radius-small);
    cursor: pointer;
    font-weight: 700;
}

.login-box #message {
    min-height: 22px;
    margin: 14px 0 0;
    color: var(--danger);
}

/* Dashboard shell */
.dashboard-page {
    padding-bottom: 60px;
}

.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 22px max(24px, calc((100vw - 1480px) / 2));
    background: rgba(11, 16, 32, 0.88);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(18px);
}

.topbar-actions {
    display: flex;
    gap: 10px;
}

.dashboard-shell {
    width: min(1480px, calc(100% - 40px));
    margin: 32px auto 0;
}

.eyebrow {
    margin-bottom: 7px;
    color: var(--primary-strong);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.panel-description,
.modal-subtitle {
    margin-bottom: 0;
    color: var(--muted);
    line-height: 1.55;
}

.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: var(--radius-small);
    cursor: pointer;
    font-weight: 750;
    transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

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

.button-primary:hover:not(:disabled) {
    background: var(--primary-strong);
}

.button-secondary {
    color: var(--text);
    background: var(--surface-soft);
    border: 1px solid var(--border);
}

.button-ghost {
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--border);
}

.button-ghost:hover:not(:disabled) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

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

.stat-card {
    min-height: 150px;
    padding: 20px;
    background: linear-gradient(145deg, rgba(24, 35, 61, 0.98), rgba(18, 26, 46, 0.98));
    border: 1px solid var(--border);
    border-radius: var(--radius-medium);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
}

.stat-card-featured {
    background: linear-gradient(145deg, rgba(85, 99, 225, 0.95), rgba(75, 88, 199, 0.88));
}

.stat-label,
.stat-note {
    display: block;
}

.stat-label {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.stat-card-featured .stat-label,
.stat-card-featured .stat-note {
    color: rgba(255, 255, 255, 0.78);
}

.stat-value {
    display: block;
    margin: 20px 0 9px;
    font-size: clamp(1.55rem, 2.4vw, 2.15rem);
    line-height: 1;
}

.stat-note {
    color: var(--muted);
    font-size: 0.78rem;
}

.panel {
    margin-top: 22px;
    overflow: hidden;
    background: rgba(18, 26, 46, 0.94);
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding: 24px;
}

.analytics-heading,
.subscribers-heading {
    align-items: center;
}

.analytics-controls {
    display: flex;
    gap: 12px;
}

.analytics-controls label,
.search-field,
.filter-field {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
}

.analytics-controls label {
    min-width: 150px;
}

.analytics-controls select,
.table-toolbar input,
.table-toolbar select {
    margin-top: 6px;
}

.revenue-chart {
    display: flex;
    min-height: 270px;
    align-items: stretch;
    gap: 12px;
    padding: 12px 24px 26px;
    overflow-x: auto;
}

.chart-column {
    display: grid;
    min-width: 76px;
    flex: 1;
    grid-template-rows: 34px 170px 28px;
    gap: 7px;
    align-items: end;
}

.chart-value {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-track {
    position: relative;
    width: 100%;
    height: 170px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.035);
    border-radius: 10px 10px 5px 5px;
}

.chart-bar {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    background: linear-gradient(180deg, var(--primary-strong), var(--primary));
    border-radius: 9px 9px 4px 4px;
    box-shadow: 0 0 24px rgba(108, 124, 255, 0.28);
}

.chart-label {
    color: var(--muted);
    font-size: 0.72rem;
    text-align: center;
}

.table-toolbar {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) 190px;
    gap: 14px;
    padding: 0 24px 20px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border-top: 1px solid var(--border);
}

.data-table {
    width: 100%;
    min-width: 1080px;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 17px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    text-align: left;
}

.data-table th:first-child,
.data-table td:first-child {
    padding-left: 24px;
}

.data-table th:last-child,
.data-table td:last-child {
    padding-right: 24px;
}

.data-table th {
    color: var(--muted);
    background: rgba(255, 255, 255, 0.018);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.data-table tbody tr {
    transition: background 150ms ease;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.025);
}

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

.subscriber-cell {
    display: flex;
    min-width: 230px;
    align-items: center;
    gap: 11px;
}

.subscriber-avatar {
    display: grid;
    width: 39px;
    height: 39px;
    flex: 0 0 39px;
    place-items: center;
    color: #dfe4ff;
    background: rgba(108, 124, 255, 0.17);
    border: 1px solid rgba(108, 124, 255, 0.3);
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 900;
}

.subscriber-cell strong,
.subscriber-cell span,
.account-cell strong,
.account-cell span,
.cell-note,
.data-table td > strong {
    display: block;
}

.subscriber-cell span,
.account-cell span,
.cell-note {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.4;
}

.license-cell {
    display: flex;
    min-width: 205px;
    align-items: center;
    gap: 8px;
}

.text-button {
    padding: 4px 7px;
    color: var(--primary-strong);
    background: transparent;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 800;
}

.text-button:hover {
    background: rgba(108, 124, 255, 0.1);
}

.account-cell {
    min-width: 170px;
}

.account-protected strong {
    color: #b9f7d6;
}

.account-unset strong {
    color: var(--warning);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 9px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 850;
}

.status-active {
    color: #9af1c6;
    background: rgba(57, 217, 138, 0.12);
}

.status-due {
    color: #ffd99d;
    background: rgba(255, 191, 95, 0.13);
}

.status-expired {
    color: #ffb1ba;
    background: rgba(255, 107, 122, 0.13);
}

.status-suspended {
    color: #d5c0ff;
    background: rgba(157, 115, 255, 0.14);
}

.status-inactive {
    color: #c8d0df;
    background: rgba(158, 171, 196, 0.13);
}

.actions-column {
    width: 255px;
    min-width: 255px;
}

.actions-cell {
    display: flex;
    width: 100%;
    min-width: 220px;
    align-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
}

.action-button {
    min-height: 31px;
    padding: 6px 9px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 800;
}

.action-button:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.075);
}

.action-primary {
    color: #dfe4ff;
    background: rgba(108, 124, 255, 0.14);
    border-color: rgba(108, 124, 255, 0.26);
}

.action-positive {
    color: #9af1c6;
    background: rgba(57, 217, 138, 0.09);
}

.action-warning {
    color: #ffd99d;
    background: rgba(255, 191, 95, 0.09);
}

.loading-cell {
    height: 130px;
    color: var(--muted);
    text-align: center !important;
}

.empty-state {
    padding: 38px 20px;
    color: var(--muted);
    line-height: 1.55;
    text-align: center;
}

.empty-state.compact {
    display: grid;
    min-width: 100%;
    min-height: 200px;
    place-items: center;
}

/* Modals */
.modal {
    position: fixed;
    z-index: 100;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 22px;
}

.modal.open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(3, 7, 18, 0.78);
    backdrop-filter: blur(8px);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(520px, 100%);
    max-height: calc(100vh - 44px);
    overflow-y: auto;
    padding: 25px;
    background: #151f36;
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow);
}

.modal-card-wide {
    width: min(860px, 100%);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.icon-button {
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    place-items: center;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
    font-size: 1.35rem;
    line-height: 1;
}

.icon-button:hover {
    color: var(--text);
}

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

.form-stack {
    display: grid;
    gap: 15px;
}

.field {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 750;
}

.field > span {
    display: block;
    margin-bottom: 7px;
}

.field small {
    display: block;
    margin-top: 6px;
    color: #7f8ca8;
    font-size: 0.69rem;
    font-weight: 500;
    line-height: 1.45;
}

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

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

.account-warning,
.payment-explanation {
    padding: 13px;
    color: var(--muted);
    background: rgba(108, 124, 255, 0.07);
    border: 1px solid rgba(108, 124, 255, 0.16);
    border-radius: var(--radius-small);
    font-size: 0.75rem;
    line-height: 1.5;
}

.account-warning strong {
    display: block;
    margin-bottom: 5px;
    color: var(--text);
}

.account-warning p {
    margin-bottom: 0;
}

.modal-open {
    overflow: hidden;
}

.toast {
    position: fixed;
    z-index: 200;
    right: 24px;
    bottom: 24px;
    max-width: min(420px, calc(100% - 48px));
    padding: 13px 16px;
    color: var(--text);
    background: #1d2942;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px);
    transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    border-color: rgba(57, 217, 138, 0.35);
}

.toast.error {
    border-color: rgba(255, 107, 122, 0.4);
}


.download-button {
    gap: 8px;
    text-decoration: none;
}

.download-button svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.device-id-row {
    display: flex;
    max-width: 230px;
    align-items: center;
    gap: 7px;
    margin-top: 5px;
}

.device-id-row code {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.action-danger {
    color: #ffb1ba;
    background: rgba(255, 107, 122, 0.09);
    border-color: rgba(255, 107, 122, 0.22);
}

.action-danger:hover {
    color: #ffd2d7;
    background: rgba(255, 107, 122, 0.16);
}

.payment-actions-column {
    width: 90px;
}

@media (max-width: 1260px) {
    .stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .dashboard-page {
        padding-bottom: 30px;
    }

    .topbar {
        position: static;
        align-items: flex-start;
        padding: 18px 20px;
    }

    .topbar-actions {
        flex-direction: column;
    }

    .dashboard-shell {
        width: min(100% - 24px, 1480px);
        margin-top: 18px;
    }

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

    .stat-card {
        min-height: 132px;
        padding: 16px;
    }

    .panel-heading,
    .analytics-heading,
    .subscribers-heading {
        flex-direction: column;
        align-items: stretch;
        padding: 20px;
    }

    .analytics-controls,
    .table-toolbar {
        grid-template-columns: 1fr;
        flex-direction: column;
    }

    .analytics-controls label {
        min-width: 0;
    }

    .table-toolbar {
        display: grid;
        padding: 0 20px 18px;
    }

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

    .field-full {
        grid-column: auto;
    }

    .modal {
        padding: 10px;
    }

    .modal-card {
        max-height: calc(100vh - 20px);
        padding: 20px;
    }
}

@media (max-width: 470px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-direction: column;
    }

    .topbar-actions,
    .topbar-actions .button {
        width: 100%;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .modal-actions .button {
        width: 100%;
    }
}

.field-hidden {
    display: none !important;
}

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

.onboarding-message {
    min-height: 360px;
    resize: vertical;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.78rem;
    line-height: 1.55;
}

.onboarding-notice {
    padding: 13px;
    color: var(--muted);
    background: rgba(57, 217, 138, 0.07);
    border: 1px solid rgba(57, 217, 138, 0.18);
    border-radius: var(--radius-small);
    font-size: 0.75rem;
    line-height: 1.5;
}

.onboarding-actions {
    flex-wrap: wrap;
}

@media (max-width: 760px) {
    .onboarding-actions {
        flex-direction: column-reverse;
    }

    .onboarding-actions .button {
        width: 100%;
    }
}
