:root {
    --bg: #eef3f7;
    --surface: #ffffff;
    --surface-soft: #f7fafc;
    --ink: #102033;
    --muted: #607086;
    --line: #d7e1ea;
    --primary: #2457d6;
    --primary-dark: #173a8f;
    --success: #168456;
    --danger: #c93535;
    --warning: #b06a11;
    --teal: #0f766e;
    --amber: #c98218;
    --shadow: 0 24px 70px rgba(22, 34, 51, .14);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(36, 87, 214, .10), transparent 34%),
        linear-gradient(180deg, #f7fafc 0%, var(--bg) 48%, #e8eef4 100%);
    color: var(--ink);
    padding: 32px;
}

.app-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    display: grid;
    gap: 20px;
}

.hidden {
    display: none !important;
}

.auth-shell {
    width: min(1040px, 100%);
    min-height: 640px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(300px, .92fr) minmax(380px, 1.08fr);
    overflow: hidden;
    border: 1px solid rgba(215, 225, 234, .95);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-brand {
    position: relative;
    min-height: 100%;
    padding: 42px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 36px;
    color: #fff;
    background:
        linear-gradient(140deg, rgba(16, 32, 51, .98), rgba(23, 58, 143, .94)),
        linear-gradient(45deg, rgba(15, 118, 110, .65), transparent);
}

.auth-brand::after {
    content: "";
    position: absolute;
    inset: auto -80px -110px auto;
    width: 260px;
    height: 260px;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 50%;
}

.brand-mark {
    width: 190px;
    height: 118px;
    align-self: center;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: #fff;
    padding: 14px;
    overflow: hidden;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .20);
}

.brand-mark img {
    width: 150px;
    height: auto;
    max-height: 72px;
    object-fit: contain;
    display: block;
}

.eyebrow {
    display: inline-block;
    margin: 28px 0 10px;
    color: #a9f0df;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
}

.auth-brand h1 {
    max-width: 360px;
    font-size: 42px;
    line-height: 1.05;
    margin: 0;
}

.auth-brand p {
    max-width: 390px;
    color: rgba(255, 255, 255, .78);
    font-size: 15px;
    line-height: 1.55;
}

.brand-metrics {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 12px;
}

.brand-metrics div {
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 10px;
    background: rgba(255, 255, 255, .08);
}

.brand-metrics strong,
.brand-metrics span {
    display: block;
}

.brand-metrics span {
    margin-top: 3px;
    color: rgba(255, 255, 255, .70);
    font-size: 13px;
}

.auth-card {
    padding: 42px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.auth-card-header {
    margin-bottom: 22px;
}

.auth-card-header h2 {
    margin-top: 14px;
    font-size: 28px;
}

.panel,
.page-panel {
    background: rgba(255, 255, 255, .96);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 18px 44px rgba(22, 34, 51, .08);
    padding: 28px;
}

.app-nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, .82);
    box-shadow: 0 14px 34px rgba(22, 34, 51, .07);
}

.app-nav button {
    min-height: 46px;
    border-radius: 10px;
    background: transparent;
    color: #40566f;
    box-shadow: none;
}

.app-nav button:hover,
.app-nav button.is-active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 10px 22px rgba(36, 87, 214, .22);
}

.session-bar {
    background:
        linear-gradient(135deg, rgba(16, 32, 51, .98), rgba(29, 63, 117, .96)),
        linear-gradient(90deg, rgba(15, 118, 110, .55), transparent);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 14px;
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    box-shadow: 0 16px 36px rgba(16, 32, 51, .18);
}

.session-bar strong {
    display: block;
    font-size: 16px;
    margin-bottom: 3px;
}

.session-bar span {
    display: inline-block;
    color: #d9e6f2;
    font-size: 13px;
    margin: 4px 14px 0 0;
}

.auth-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 22px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-soft);
}

.auth-tabs button {
    width: 100%;
    min-height: 40px;
    padding: 10px 8px;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
}

.auth-tabs button:hover,
.auth-tabs button:focus,
.auth-tabs button.is-active {
    background: #fff;
    color: var(--primary-dark);
    box-shadow: 0 8px 20px rgba(16, 32, 51, .08);
}

body.needs-auth .generator-panel,
body.needs-auth .master-panel,
body.needs-auth .admin-panel,
body.needs-auth .search-panel {
    display: none;
}

body:not(.is-admin) .admin-panel {
    display: none;
}

.header,
.section-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 22px;
}

p {
    margin-top: 7px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.badge {
    flex: 0 0 auto;
    border: 1px solid #c8d7e6;
    border-radius: 999px;
    background: #fff;
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 800;
    padding: 8px 12px;
}

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

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

label {
    display: block;
    margin-bottom: 7px;
    font-size: 12px;
    font-weight: 800;
    color: #26374c;
}

input,
select {
    width: 100%;
    min-height: 46px;
    padding: 12px 13px;
    border: 1px solid #c8d4e0;
    border-radius: 9px;
    font-size: 15px;
    background: #fbfdff;
    color: var(--ink);
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

input:focus,
select:focus {
    border-color: var(--primary);
    background: #fff;
    outline: 3px solid rgba(36, 87, 214, .14);
}

button {
    min-height: 44px;
    border: none;
    border-radius: 9px;
    padding: 12px 18px;
    font-weight: 800;
    cursor: pointer;
    background: var(--success);
    color: #fff;
    box-shadow: 0 10px 22px rgba(22, 132, 86, .20);
}

button:hover {
    filter: brightness(.97);
}

.secondary {
    background: var(--primary);
    box-shadow: 0 10px 22px rgba(36, 87, 214, .20);
}

.danger-button {
    background: var(--danger);
    box-shadow: 0 10px 22px rgba(201, 53, 53, .18);
}

.actions,
.search-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.filter-bar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 220px;
    gap: 14px;
    margin: 0 0 18px;
    padding: 14px;
    border: 1px solid #e1e9f1;
    border-radius: 12px;
    background: var(--surface-soft);
}

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

.metric-card {
    min-height: 108px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    border: 1px solid #dbe7f2;
    border-radius: 14px;
    background: linear-gradient(180deg, #fff, #f6fafc);
    color: var(--ink);
    box-shadow: 0 14px 32px rgba(22, 34, 51, .08);
    text-align: left;
}

.metric-card:hover {
    filter: none;
    border-color: #b8cce0;
    transform: translateY(-1px);
}

.metric-card span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.metric-card strong {
    color: var(--primary-dark);
    font-size: 24px;
    line-height: 1.1;
}

body.is-admin .reseller-only {
    display: none;
}

.auth-form .actions button {
    width: 100%;
}

.inline-actions {
    display: flex;
    gap: 8px;
    min-width: 330px;
}

.credit-input {
    max-width: 112px;
}

.align-end {
    align-items: end;
}

.status {
    min-height: 22px;
    margin-top: 16px;
    font-weight: 800;
    font-size: 13px;
}

.status.ok {
    color: var(--success);
}

.status.warn {
    color: var(--warning);
}

.status.error {
    color: var(--danger);
}

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

.decoded-value {
    min-height: 46px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface-soft);
    color: var(--ink);
    font-family: Consolas, "Courier New", monospace;
    font-size: 16px;
    font-weight: 800;
}

.result {
    margin-top: 18px;
    padding: 18px;
    border: 1px solid #cfe0ef;
    border-radius: 12px;
    background: linear-gradient(180deg, #fbfdff, #f4f8fb);
}

.license {
    width: 100%;
    font-family: Consolas, "Courier New", monospace;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--ink);
    word-break: break-all;
}

.hint {
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
}

.table-wrap {
    width: 100%;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1040px;
}

th,
td {
    padding: 13px 14px;
    border-bottom: 1px solid #e8eef4;
    text-align: left;
    font-size: 14px;
}

th {
    background: #f7fafc;
    color: #354a62;
    font-size: 12px;
    font-weight: 900;
}

td {
    font-family: Consolas, "Courier New", monospace;
}

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

.empty {
    text-align: center;
    color: var(--muted);
    font-family: Arial, Helvetica, sans-serif;
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    color: var(--muted);
    font-size: 14px;
}

.pagination-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pagination-actions button {
    min-height: 38px;
    padding: 9px 14px;
}

.pagination-actions button:disabled {
    cursor: not-allowed;
    filter: grayscale(.2);
    opacity: .55;
}

@media (max-width: 860px) {
    body {
        padding: 18px;
    }

    .auth-shell {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .auth-brand {
        min-height: 270px;
        padding: 30px;
    }

    .brand-mark {
        width: 160px;
        height: 96px;
    }

    .brand-mark img {
        width: 128px;
        max-height: 60px;
    }

    .auth-brand h1 {
        font-size: 34px;
    }

    .brand-metrics {
        display: none;
    }

    .auth-card,
    .panel {
        padding: 24px;
    }

    .header,
    .section-title {
        display: block;
    }

    .badge {
        display: inline-block;
        margin-top: 12px;
    }
}

@media (max-width: 620px) {
    body {
        padding: 12px;
    }

    .auth-tabs,
    .app-nav,
    .filter-bar,
    .dashboard-cards,
    .form-grid,
    .decoded-grid {
        grid-template-columns: 1fr;
    }

    .wide {
        grid-column: auto;
    }

    .actions,
    .search-row,
    .inline-actions,
    .pagination-bar,
    .pagination-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .session-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .license {
        font-size: 18px;
    }
}
