/* Keyhub: shared, self-contained customer and admin presentation. */
:root {
    color-scheme: dark;
    --page: #090a0c;
    --surface: #121418;
    --surface-raised: #191c22;
    --field: #0c0e12;
    --border: #282c34;
    --text: #f4f5f7;
    --muted: #9ba1ae;
    --quiet: #737d8e;
    --accent: #ff5a5f;
    --radius: 18px;
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 280px; scroll-padding-top: 100px; }
body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--page);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.55;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button, input, select, textarea { min-width: 0; }
button:disabled { cursor: wait; opacity: .6; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
svg { flex-shrink: 0; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: clamp(28px, 4vw, 38px); font-weight: 750; letter-spacing: -.045em; }
h2 { font-size: 19px; font-weight: 650; letter-spacing: -.025em; }
h3 { font-size: 18px; font-weight: 650; letter-spacing: -.015em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.hidden { display: none !important; }
.flex { display: flex; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
    position: fixed; top: 12px; left: 12px; z-index: 110;
    transform: translateY(-180%); padding: 12px 18px;
    background: var(--text); color: var(--page); border-radius: 10px;
}
.skip-link:focus { transform: translateY(0); }

/* Header */
.site-header {
    position: sticky; top: 0; z-index: 40;
    background: rgba(9, 10, 12, .94);
    border-bottom: 1px solid #20232a;
    backdrop-filter: blur(16px);
}
.nav-inner {
    max-width: 1160px; min-height: 76px; margin: 0 auto;
    padding: 14px 32px; display: flex; align-items: center;
    justify-content: space-between; gap: 20px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
    display: grid; place-items: center; width: 34px; height: 34px;
    color: var(--accent); background: #ff5a5f0e; border: 1px solid #ff5a5f2b;
    border-radius: 10px;
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-name { font-size: 23px; font-weight: 800; letter-spacing: -.065em; }
.brand-name span { color: var(--muted); }
.nav-user { display: flex; align-items: center; justify-content: flex-end; gap: 16px; min-width: 0; }
.nav-profile { display: flex; align-items: center; gap: 9px; min-width: 0; }
.user-avatar { width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 50%; background: var(--surface-raised); }
.user-name { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: #d2d6df; }
.nav-button { min-height: 40px; padding: 9px 14px; font-size: 12px; white-space: nowrap; }
.logout-button { padding: 8px 0 8px 8px; border: 0; background: none; color: var(--muted); font-size: 12px; min-height: 44px; }
.logout-button:hover { color: var(--text); }
.admin-tag { font-size: 11px; padding: 4px 8px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; }

/* Shared layout */
.site-main { width: 100%; max-width: 1104px; margin: 0 auto; padding: 44px 32px 64px; flex: 1; }
.page-view { min-width: 0; width: 100%; display: grid; gap: 30px; }
.page-heading { padding: 0 0 2px; }
.eyebrow { color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .17em; text-transform: uppercase; margin-bottom: 11px; }
#portal-view .page-heading .eyebrow { font-size: 13px; }
.page-heading > p:last-child { color: var(--muted); font-size: 14px; margin-top: 10px; }
.surface { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel { padding: 26px; }
.panel-heading { margin-bottom: 22px; }
.panel-heading p, .section-heading p { font-size: 13px; color: var(--muted); margin-top: 7px; }
.section-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.section-icon { width: 40px; height: 40px; border-radius: 12px; background: #ff5a5f0d; color: var(--accent); display: grid; place-items: center; flex-shrink: 0; }
.section-icon svg { width: 19px; height: 19px; }
.subscriptions-section { min-width: 0; }
.subscriptions-section > .panel-heading { margin-bottom: 16px; }
.subscription-list { display: grid; gap: 16px; min-width: 0; }
.section-divider { border: 0; border-top: 1px solid var(--border); margin: 26px 0; }
.site-footer { max-width: 1104px; margin: auto auto 0; width: 100%; padding: 22px 32px; color: var(--quiet); font-size: 12px; display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid #20232a; }
.site-footer .footer-brand { color: var(--muted); font-weight: 600; }

/* Sign in */
.auth-view {
    position: relative; max-width: 440px; margin: clamp(24px, 7vh, 72px) auto 30px;
    text-align: center; padding: 36px;
    background: linear-gradient(155deg, #18191e, #111216 65%);
    box-shadow: 0 24px 80px #00000025;
}
.auth-icon { width: 62px; height: 62px; display: grid; place-items: center; margin: 0 auto 25px; color: var(--accent); border: 1px solid #ff5a5f38; border-radius: 18px; background: #ff5a5f0d; }
.auth-icon svg { width: 28px; height: 28px; }
.auth-view h1 { font-size: 28px; letter-spacing: -.045em; }
.auth-description { font-size: 14px; color: var(--muted); margin: 13px auto 27px; max-width: 310px; }
.auth-footnote { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--quiet); font-size: 12px; }

/* Controls */
.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    min-height: 46px; padding: 11px 18px; border: 1px solid transparent;
    border-radius: 10px; font-size: 13px; line-height: 1.35; font-weight: 650;
    text-align: center; color: var(--text);
    transition: background-color .16s, border-color .16s, opacity .16s;
}
.button svg { width: 18px; height: 18px; }
.button-accent { background: linear-gradient(110deg, #ff4b2b, #ff416c); color: white; }
.button-accent:hover { opacity: .9; }
.button-secondary { background: var(--surface-raised); border-color: #30353f; }
.button-secondary:hover { background: #232730; border-color: #454c59; }
.button-discord { background: #5865f2; color: white; width: 100%; min-height: 50px; }
.button-discord:hover { background: #4b57d6; }
.button-discord svg { width: 21px; height: 21px; }
.button-danger { background: #ff5a5f10; border-color: #ff5a5f40; color: #ff9396; }
.button-danger:hover { background: #ff5a5f1c; }
.button-small { font-size: 12px; min-height: 44px; padding: 9px 12px; }
.button-block { width: 100%; }
.button-link { display: inline-flex; align-items: center; justify-content: center; background: none; border: 0; padding: 8px 0; color: var(--muted); font-size: 12px; min-height: 44px; }
.button-link:hover { color: var(--accent); }
.form-field { display: grid; gap: 7px; min-width: 0; margin-bottom: 15px; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: #bfc5d0; }
.field-input {
    width: 100%; min-height: 46px; padding: 12px 14px;
    border: 1px solid #30353e; border-radius: 10px;
    background: var(--field); color: var(--text); font-size: 14px;
    transition: border-color .16s, box-shadow .16s;
}
.field-input::placeholder { color: #788293; opacity: 1; }
.field-input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px #ff5a5f15; }
.field-input[readonly] { color: #a6b0c0; }
textarea.field-input { display: block; resize: vertical; line-height: 1.6; min-height: 120px; }
select.field-input { padding-right: 28px; text-overflow: ellipsis; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.redeem-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px; gap: 12px; margin-top: 8px; }
#licenseKey { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .035em; text-transform: uppercase; }
#redeemStatus { font-size: 13px; margin-top: 12px; overflow-wrap: anywhere; }
#redeemStatus:empty { display: none; }
.form-actions { display: grid; gap: 10px; margin-top: 15px; }
.form-actions-horizontal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.output-field { margin-top: 14px; }
.generated-output { min-height: 108px !important; }

/* Subscription cards */
.subscription-card { padding: 24px; }
.subscription-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 20px; }
.subscription-title { min-width: 0; }
.subscription-title h3 { overflow-wrap: anywhere; }
.key-code { display: block; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; letter-spacing: .015em; color: var(--muted); margin-top: 8px; overflow-wrap: anywhere; }
.subscription-meta { display: grid; gap: 7px; flex-shrink: 0; justify-items: end; font-size: 11px; color: var(--muted); }
.status-badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 6px; font-size: 10px; font-weight: 650; padding: 4px 8px; letter-spacing: .03em; background: #ffffff05; border: 1px solid #ffffff0b; white-space: nowrap; }
.status-badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.device-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.device-field { min-width: 0; display: grid; gap: 8px; }
.device-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 650; letter-spacing: .075em; text-transform: uppercase; }
.device-label svg { width: 14px; height: 14px; }
.link-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; min-width: 0; }
.link-input { min-height: 44px; height: 44px; padding: 10px; font-size: 11px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; cursor: copy; }
.subscription-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; }
.card-actions { display: flex; gap: 8px; }
.card-actions .button { min-height: 44px; }
[id^="msg-"] { margin-top: 12px; font-size: 12px; overflow-wrap: anywhere; }
[id^="msg-"]:empty { display: none; }
.empty-state { padding: 38px 22px; text-align: center; border-style: dashed; }
.empty-state svg { width: 26px; height: 26px; color: var(--quiet); margin: 0 auto 14px; }
.empty-state h3 { font-size: 15px; }
.empty-state p { font-size: 13px; color: var(--muted); margin: 8px auto 0; max-width: 300px; }

/* Administration */
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stat-card { padding: 23px; }
.stat-label { font-size: 10px; color: var(--muted); font-weight: 650; letter-spacing: .07em; text-transform: uppercase; }
.stat-value { font-size: 34px; font-weight: 700; letter-spacing: -.04em; margin-top: 12px; line-height: 1.15; }
.stat-meta { font-size: 11px; color: var(--quiet); margin-top: 8px; overflow-wrap: anywhere; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.admin-grid > .panel { height: 100%; }
.table-panel { padding: 26px; }
.table-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.table-counts { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--muted); }
.table-counts strong { color: var(--text); font-weight: 650; }
.table-scroll { overflow-x: auto; width: 100%; max-width: 100%; overscroll-behavior-x: contain; }
.data-table { border-collapse: collapse; width: 100%; text-align: left; min-width: 620px; font-size: 12px; }
.data-table th { color: var(--quiet); font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: .045em; padding: 0 14px 14px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 16px 14px; border-bottom: 1px solid #22262e; color: #bfc5d0; vertical-align: middle; }
.data-table th:first-child, .data-table td:first-child { padding-left: 0; }
.data-table th:last-child, .data-table td:last-child { padding-right: 0; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #ffffff02; }
.cell-primary { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.cell-meta { color: var(--quiet); font-size: 11px; margin-top: 4px; overflow-wrap: anywhere; }
.cell-mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
.cell-truncate { max-width: 220px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cell-action { text-align: right; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; z-index: 100; align-items: center; justify-content: center;
    padding: 20px; background: #000000b3; backdrop-filter: blur(8px);
}
.modal-card { width: 100%; max-width: 440px; padding: 28px; max-height: calc(100dvh - 40px); overflow-y: auto; }
.modal-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: #ff5a5f10; color: var(--accent); margin-bottom: 20px; }
.modal-icon svg { width: 22px; height: 22px; }
.modal-card h2 { font-size: 21px; margin-bottom: 12px; }
.modal-card p { font-size: 13px; color: var(--muted); }
.modal-warning { padding: 14px; background: #ff5a5f08; border: 1px solid #ff5a5f21; color: #ffadb0 !important; border-radius: 10px; margin-top: 14px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1.7fr; gap: 10px; margin-top: 24px; }

/* Color hooks retained for the existing status and rendering code. */
.text-green-400, .text-green-500, .text-emerald-400 { color: #75dcb0 !important; }
.text-red-400, .text-red-500, .text-rose-400, .text-rose-500 { color: #ff959c !important; }
.text-yellow-400, .text-yellow-500 { color: #e9c77b !important; }
.text-blue-400, .text-indigo-400 { color: #a0b7ef !important; }
.text-gray-500, .text-zinc-500 { color: var(--quiet); }
.text-white { color: var(--text); }
.font-bold { font-weight: 650; }

@media (min-width: 700px) {
    .nav-user .nav-button { min-height: 40px; }
}

@media (max-width: 800px) {
    .device-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .device-field { grid-template-columns: 78px minmax(0, 1fr); gap: 10px; align-items: center; }
    .link-input { font-size: 13px; }
}

@media (max-width: 699px) {
    html { scroll-padding-top: 140px; }
    .nav-inner { padding: 12px 20px; min-height: 64px; flex-wrap: wrap; gap: 10px; }
    .nav-user { width: 100%; padding-top: 10px; border-top: 1px solid #20232a; gap: 10px; }
    .nav-profile { flex: 1; order: -1; }
    .user-name { max-width: 160px; }
    .nav-user .nav-button { font-size: 11px; min-height: 44px; padding: 8px 10px; }
    .site-main { padding: 28px 20px 44px; }
    .page-view { gap: 24px; }
    .panel, .table-panel { padding: 22px; }
    .admin-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
    .stats-grid { gap: 12px; }
    .stat-card { padding: 18px; }
    .stat-value { font-size: 30px; }
    .table-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
    .field-input { font-size: 16px; }
    .site-footer { padding: 20px; font-size: 11px; }
    .auth-view { padding: 30px 26px; margin-top: 30px; }
}

@media (max-width: 559px) {
    h1 { font-size: 29px; }
    h2 { font-size: 18px; }
    .site-main { padding: 26px 16px 36px; }
    .nav-inner { padding-left: 16px; padding-right: 16px; }
    .nav-user { gap: 8px; }
    .user-name { max-width: 100px; }
    .panel, .table-panel, .subscription-card { padding: 20px; }
    .section-heading { align-items: flex-start; gap: 10px; }
    .section-heading p { font-size: 12px; }
    .section-icon { width: 36px; height: 36px; border-radius: 10px; }
    .redeem-row { grid-template-columns: minmax(0, 1fr); gap: 10px; }
    .redeem-row .button { min-height: 48px; }
    .subscription-header { flex-direction: column; gap: 12px; margin-bottom: 18px; padding-bottom: 18px; }
    .subscription-meta { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 10px; }
    .device-field { grid-template-columns: 64px minmax(0, 1fr); gap: 6px; }
    .device-label { font-size: 9px; gap: 4px; letter-spacing: .04em; }
    .device-label svg { width: 13px; height: 13px; }
    .link-input { font-size: 16px; padding: 9px 8px; }
    .link-row { gap: 5px; }
    .link-row .button { padding: 9px 10px; font-size: 11px; }
    .subscription-footer { flex-direction: column; align-items: stretch; gap: 7px; margin-top: 18px; }
    .card-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .replacement-trigger { justify-content: center; padding: 9px; }
    .stats-grid { grid-template-columns: minmax(0, 1fr); }
    .stat-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 18px 20px; }
    .stat-label { grid-column: 1; grid-row: 1; }
    .stat-value { grid-column: 2; grid-row: 1 / 3; font-size: 29px; margin-top: 0; }
    .stat-meta { grid-column: 1; grid-row: 2; margin-top: 0; }
    .form-actions-horizontal { grid-template-columns: minmax(0, 1fr); }
    .site-footer { padding: 18px 16px; flex-wrap: wrap; }
    .modal-overlay { padding: 16px; }
    .modal-card { padding: 24px; max-height: calc(100dvh - 32px); }
    .modal-actions { grid-template-columns: minmax(0, 1fr); }
    .modal-actions .button-accent { order: -1; }

    /* A record becomes a labeled card instead of forcing the whole page wide. */
    .data-table { display: block; min-width: 0; }
    .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
    .data-table tbody { display: grid; gap: 12px; }
    .data-table tr { display: block; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--field); }
    .data-table td, .data-table td:first-child, .data-table td:last-child {
        display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 8px;
        border: 0; padding: 8px 0; text-align: left; min-width: 0;
        white-space: normal; overflow-wrap: anywhere; max-width: none;
    }
    .data-table td::before { content: attr(data-label); font-size: 10px; color: var(--quiet); font-weight: 600; }
    .data-table td > * { min-width: 0; }
    .cell-truncate { white-space: normal; }
    .cell-action .button { justify-self: start; }
}

@media (max-width: 359px) {
    .brand-name { font-size: 21px; }
    .user-name { max-width: 75px; }
    .panel, .table-panel, .subscription-card { padding: 16px; }
    .auth-view { padding: 28px 20px; }
    .auth-view h1 { font-size: 25px; }
    .form-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .device-field { grid-template-columns: minmax(0, 1fr); gap: 6px; }
    .device-label { font-size: 10px; }
    .data-table td { grid-template-columns: 72px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
