:root {
    color-scheme: dark;
    --bg: #070a14;
    --card: rgba(18, 24, 43, 0.88);
    --card-strong: rgba(34, 43, 74, 0.9);
    --surface: rgba(255, 255, 255, 0.07);
    --text: #f8fbff;
    --muted: #aeb8d7;
    --line: rgba(255, 255, 255, 0.14);
    --primary: #7865ff;
    --primary-strong: #a995ff;
    --accent: #48d6ff;
    --warning: #ffd166;
    --danger: #ff6b7a;
    --ok: #59d090;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 16% 0%, rgba(120, 101, 255, 0.34), transparent 28rem),
        radial-gradient(circle at 95% 28%, rgba(72, 214, 255, 0.16), transparent 24rem),
        radial-gradient(circle at 50% 100%, rgba(89, 208, 144, 0.12), transparent 30rem),
        linear-gradient(180deg, #0c1020 0%, var(--bg) 55%, #050710 100%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent 72%);
}

.page {
    position: relative;
    width: min(100%, 520px);
    margin: 0 auto;
    padding: 18px;
}

.admin-page {
    width: min(100%, 1280px);
}

.admin-sidebar {
    display: grid;
    gap: 16px;
}

.admin-brand h1 {
    margin-bottom: 0;
    font-size: 30px;
}

.admin-token-box {
    display: grid;
    gap: 10px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.admin-token-box h2 {
    margin-bottom: 0;
    font-size: 16px;
}

.admin-token-box input,
.admin-token-box button {
    min-height: 40px;
    border-radius: 12px;
    font-size: 14px;
}

.admin-pinned {
    display: grid;
    gap: 14px;
    margin-bottom: 14px;
}

.admin-pinned .card {
    margin: 0;
}

.admin-dashboard-card h2,
.admin-announcement-card h2 {
    margin-bottom: 12px;
}

.dashboard-groups {
    display: grid;
    gap: 16px;
    margin-top: 14px;
}

.dashboard-group {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.04);
}

.dashboard-group h3 {
    margin: 0;
    font-size: 18px;
}

.stats-grid.compact {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.dashboard-shortcut {
    width: auto;
    min-width: 120px;
}

.admin-announcement-card {
    display: grid;
    gap: 12px;
}

.admin-announcement-card textarea {
    min-height: 104px;
}

.admin-nav {
    display: grid;
    gap: 10px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.admin-nav-group {
    padding: 10px 10px 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.04);
}

.admin-nav-group summary {
    list-style: none;
    cursor: pointer;
    margin-bottom: 10px;
    color: var(--primary-strong);
    font-weight: 900;
    letter-spacing: 0.03em;
}

.admin-nav-group summary::-webkit-details-marker {
    display: none;
}

.admin-nav-group .admin-nav-item {
    margin-top: 8px;
}

.admin-nav-item {
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.055);
    box-shadow: none;
    text-align: left;
}

.admin-nav-item.active {
    border-color: rgba(72, 214, 255, 0.7);
    background: linear-gradient(135deg, rgba(120, 101, 255, 0.88), rgba(72, 214, 255, 0.72));
}

.admin-content {
    min-width: 0;
}

.admin-section {
    display: none;
}

.admin-section.active {
    display: block;
}

.admin-content > .card,
.admin-pinned > .card {
    border-radius: 24px;
}

.card {
    margin: 14px 0;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 26px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035)), var(--card);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.hero {
    position: relative;
    overflow: hidden;
    padding: 28px 20px;
    border-color: rgba(169, 149, 255, 0.28);
}

.hero::after {
    content: "";
    position: absolute;
    right: -54px;
    top: -54px;
    width: 150px;
    height: 150px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(72, 214, 255, 0.34), transparent 68%);
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--primary-strong);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

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

h1 {
    margin-bottom: 8px;
    font-size: clamp(34px, 10vw, 52px);
    line-height: 1.02;
    letter-spacing: 0.03em;
}

h2 {
    margin-bottom: 14px;
    font-size: 20px;
}

.subtitle {
    margin-bottom: 0;
    color: var(--muted);
}

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

.tab {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.065);
    color: var(--text);
    font-weight: 800;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.tab:hover {
    transform: translateY(-1px);
    border-color: rgba(169, 149, 255, 0.5);
}

.tab.active {
    border-color: rgba(72, 214, 255, 0.72);
    background: linear-gradient(135deg, var(--primary), #4bb8ff);
    box-shadow: 0 12px 26px rgba(75, 184, 255, 0.2);
}

.room-card {
    border-color: rgba(72, 214, 255, 0.18);
}

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

.room-list.empty {
    display: block;
    color: var(--muted);
    text-align: center;
    padding: 28px 0;
}

.room-item {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    padding: 12px 10px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(72, 214, 255, 0.12), rgba(255, 255, 255, 0.055));
    cursor: pointer;
    user-select: text;
    -webkit-user-select: text;
    -webkit-touch-callout: default;
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.room-item:hover {
    transform: translateY(-1px);
    border-color: rgba(72, 214, 255, 0.48);
}

.room-item.selected {
    border-color: rgba(255, 209, 102, 0.88);
    background:
        linear-gradient(180deg, rgba(255, 209, 102, 0.2), rgba(72, 214, 255, 0.1));
    box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.12);
}

.room-number {
    min-width: 0;
    cursor: text;
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-align: center;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    user-select: text;
    -webkit-user-select: text;
    -webkit-touch-callout: default;
}

label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

input, select, textarea, button {
    width: 100%;
    min-height: 46px;
    border-radius: 14px;
    font: inherit;
}

input, select, textarea {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.09);
    color: var(--text);
    padding: 0 14px;
    font-size: 16px;
    outline: none;
}

textarea {
    min-height: 120px;
    padding: 12px 14px;
    resize: vertical;
    line-height: 1.5;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(72, 214, 255, 0.14);
}

select option {
    background: #1b213a;
}

input[type="checkbox"] {
    width: 18px;
    min-height: 18px;
    accent-color: var(--primary);
}

button {
    border: 0;
    background: linear-gradient(135deg, var(--primary), #4bb8ff);
    color: white;
    cursor: pointer;
    font-weight: 800;
    box-shadow: 0 12px 26px rgba(93, 156, 255, 0.18);
    transition: transform 0.16s ease, filter 0.16s ease;
}

button:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

button:active {
    transform: translateY(0);
}

button.secondary {
    background: var(--card-strong);
    border: 1px solid var(--line);
}

button.danger {
    background: linear-gradient(135deg, #d9415d, #ff6b7a);
}

.notice-card {
    position: relative;
    overflow: hidden;
    border-color: rgba(255, 209, 102, 0.34);
    background:
        linear-gradient(135deg, rgba(255, 209, 102, 0.14), rgba(72, 214, 255, 0.055)),
        var(--card);
}

.notice-card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 18px;
    bottom: 18px;
    width: 4px;
    border-radius: 999px;
    background: var(--warning);
}

.notice-title {
    margin-bottom: 10px;
    color: var(--warning);
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 0.08em;
}

.notice-body {
    color: #f6e7b1;
    line-height: 1.55;
}

.notice-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding-left: 20px;
    color: #f6e7b1;
    line-height: 1.55;
}

.notice-empty,
.form-hint {
    color: var(--muted);
    line-height: 1.55;
}

.selected-room-box {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px dashed rgba(255, 255, 255, 0.18);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.055);
    color: var(--muted);
}

.selected-room-box.selected {
    border-style: solid;
    border-color: rgba(255, 209, 102, 0.5);
    background: rgba(255, 209, 102, 0.12);
    color: #ffe3a0;
}

.selected-room-box strong {
    color: #fff;
    font-size: 20px;
    letter-spacing: 0.08em;
}

.selected-room-box button {
    width: auto;
    min-width: 88px;
    min-height: 36px;
    box-shadow: none;
}

.action-card,
.query-card,
.redeem-card {
    border-color: rgba(169, 149, 255, 0.26);
}

.action-card {
    display: grid;
    gap: 18px;
}

.action-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.055);
}

.action-tab {
    min-height: 42px;
    border-radius: 14px;
    background: transparent;
    box-shadow: none;
    color: var(--muted);
}

.action-tab.active {
    background: linear-gradient(135deg, var(--primary), #4bb8ff);
    color: #fff;
    box-shadow: 0 10px 22px rgba(75, 184, 255, 0.18);
}

.action-tab-panel {
    display: none;
}

.action-tab-panel.active {
    display: grid;
    gap: 18px;
}

.agent-panel {
    display: grid;
    gap: 12px;
}

.agent-status-box {
    display: grid;
    gap: 10px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.055);
    color: var(--muted);
}

.agent-status-box div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.agent-status-box strong {
    color: #fff;
    text-align: right;
}

.agent-status-box.muted {
    display: block;
    text-align: center;
    color: var(--muted);
}

.agent-status-message {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--muted);
    line-height: 1.45;
}

.agent-status-message.success {
    border-color: rgba(89, 208, 144, 0.45);
    color: var(--ok);
}

.agent-status-message.error {
    border-color: rgba(255, 107, 122, 0.45);
    color: var(--danger);
}

.warning-text {
    margin: 0;
    color: var(--warning);
}

.hidden {
    display: none !important;
}

.query-panel {
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.query-panel input,
.redeem-panel input,
.query-card input,
.redeem-card input {
    margin-bottom: 12px;
}

.inline-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.inline-form button {
    min-width: 96px;
}

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

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.section-subtabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.section-subtab {
    width: auto;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.055);
    color: var(--text);
    box-shadow: none;
}

.section-subtab.active {
    border-color: rgba(72, 214, 255, 0.72);
    background: linear-gradient(135deg, var(--primary), #4bb8ff);
}

.section-subpanel {
    display: none;
}

.section-subpanel.active {
    display: block;
}

.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.section-head h2 {
    margin-bottom: 0;
}

.section-head button {
    width: auto;
    min-width: 90px;
}

.generated-codes {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.bulk-copy-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(124, 92, 255, 0.14);
    color: var(--muted);
}

.bulk-copy-bar button {
    width: auto;
    min-width: 120px;
    min-height: 38px;
}

.code-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    word-break: break-all;
}

.code-row button {
    min-width: 72px;
    min-height: 38px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}

.stat-card {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.06);
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.stat-card strong {
    display: block;
    margin-top: 6px;
    font-size: 28px;
}

.low-stock-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding: 12px 14px;
    border: 1px solid rgba(255, 209, 102, 0.35);
    border-radius: 16px;
    background: rgba(255, 209, 102, 0.12);
    color: #ffd166;
}

.low-stock-bar strong {
    margin-right: 8px;
}

.low-stock-bar span {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.table-wrap {
    overflow-x: auto;
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
}

.script-delete,
.script-offline-delete {
    width: auto;
    min-width: 78px;
    min-height: 34px;
    padding: 0 12px;
}

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

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

.pager button {
    width: auto;
    min-width: 88px;
}

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

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

th, td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

td {
    font-size: 14px;
}

.status-ok {
    color: var(--ok);
    font-weight: 700;
}

.status-pending {
    color: #ffd166;
    font-weight: 700;
}

.status-used {
    color: var(--danger);
    font-weight: 700;
}

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

.modal.hidden {
    display: none;
}

.modal-panel {
    width: min(100%, 410px);
    padding: 24px;
    border: 1px solid rgba(169, 149, 255, 0.24);
    border-radius: 24px;
    background: linear-gradient(180deg, #1a213c, #12182b);
    box-shadow: var(--shadow);
}

.modal-panel button {
    margin-top: 16px;
}

.result-room {
    display: grid;
    gap: 10px;
    margin-top: 8px;
}

.result-tip {
    margin: 0;
    padding: 10px 12px;
    border: 1px solid rgba(255, 209, 102, 0.28);
    border-radius: 14px;
    background: rgba(255, 209, 102, 0.1);
    color: #ffe3a0;
    line-height: 1.5;
}

.result-room div {
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.075);
}

.result-room strong {
    display: block;
    margin-top: 5px;
    font-size: 26px;
    letter-spacing: 0.08em;
    user-select: text;
    -webkit-user-select: text;
    -webkit-touch-callout: default;
}

.success-result strong {
    font-size: 36px;
    color: #ffffff;
}

.result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
}

.success-result button {
    margin-top: 4px;
}

@media (min-width: 900px) {
    .admin-page {
        display: grid;
        grid-template-columns: 250px minmax(0, 1fr);
        gap: 18px;
        align-items: start;
        padding: 24px;
    }

    .admin-sidebar {
        position: sticky;
        top: 18px;
        margin: 0;
    }

    .admin-content .card {
        margin-top: 0;
    }

    .admin-pinned {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .admin-dashboard-card .stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .user-page {
        width: min(100%, 1180px);
        display: grid;
        grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.75fr);
        gap: 18px;
        align-items: start;
        padding: 28px;
    }

    .user-page .notice-card {
        grid-column: 1 / -1;
        margin-bottom: 0;
    }

    .user-page .room-card,
    .user-page .action-card {
        margin-top: 0;
    }

    .user-page .room-card {
        min-height: 560px;
    }

    .room-section-head {
        margin-bottom: 16px;
    }

    .room-total {
        color: var(--muted);
        white-space: nowrap;
    }

    .room-total strong {
        color: var(--accent);
        font-size: 22px;
    }

    .user-page .tabs {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .user-page .room-list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .user-page .action-card {
        position: sticky;
        top: 18px;
    }
}

@media (min-width: 1200px) {
    .user-page .room-list {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .page {
        padding: 10px;
    }

    .card {
        border-radius: 20px;
        padding: 15px;
    }

    .admin-sidebar {
        gap: 12px;
    }

    .admin-nav {
        display: flex;
        overflow-x: auto;
        padding-bottom: 4px;
        scrollbar-width: thin;
    }

    .admin-nav-item {
        width: auto;
        min-width: 112px;
        text-align: center;
        white-space: nowrap;
    }

    .form-grid, .inline-form, .bulk-copy-bar, .filter-bar, .stats-grid {
        grid-template-columns: 1fr;
    }

    .user-page .tabs,
    .user-page .room-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .user-page .room-item {
        min-height: 48px;
        padding: 10px 8px;
    }

    .user-page .room-number {
        font-size: 16px;
        letter-spacing: 0.05em;
    }

    /* 手机端标题栏：只留“房间列表 + 一键复制”，左对齐同排，底部留出间距 */
    .room-section-head {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
        gap: 12px;
        margin-bottom: 14px;
    }

    .room-section-head h2 {
        flex: 0 0 auto;
    }

    /* 手机上隐藏“当前可用X个”提示，避免标题栏拥挤 */
    .room-section-head .room-total {
        display: none;
    }

    /* 复制按钮紧跟标题左对齐，不贴下方类型框，留出高度 */
    .room-section-head #copyRoomNumbers {
        width: auto;
        min-width: 0;
        flex: 0 0 auto;
        padding: 8px 16px;
        min-height: 34px;
        font-size: 13px;
    }

    .inline-form button,
    .bulk-copy-bar button,
    .filter-bar button {
        width: 100%;
    }

    .section-head:not(.room-section-head) button {
        width: 100%;
    }

    .section-head:not(.room-section-head),
    .pager {
        align-items: stretch;
        flex-direction: column;
    }

    .pager-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}
