:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --green: #10b981;
    --green-light: #ecfdf5;
    --red: #ef4444;
    --red-light: #fef2f2;
    --amber: #f59e0b;
    --amber-light: #fffbeb;
    --text: #0f172a;
    --text-secondary: #64748b;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --border: #e2e8f0;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
    --transition: 200ms ease;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }

body {
    margin: 0;
    font-family: "Inter", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
.hidden { display: none !important; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    font-family: inherit;
}

.btn:hover { border-color: #cbd5e1; background: var(--bg); }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: 0 4px 14px rgba(99,102,241,.25);
}

.btn-danger {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}

.btn-danger:hover { background: #dc2626; border-color: #dc2626; }

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover { color: var(--text); background: var(--bg); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }

.btn.is-loading {
    pointer-events: none;
    opacity: .6;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    background: #334155;
    box-shadow: var(--shadow-md);
    animation: toastIn .25s ease;
    max-width: 360px;
}

.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
.toast.warn { background: var(--amber); color: var(--text); }

@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ── Auth ── */
.auth-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 50%, #ecfdf5 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 40px 32px 32px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    text-align: center;
}

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

.auth-logo {
    width: 56px;
    height: 56px;
    background: var(--primary);
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 800;
    font-size: 24px;
    margin: 0 auto 16px;
}

.auth-brand h1 {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 700;
}

.auth-brand p {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-tabs {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 24px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: var(--bg);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.auth-tab.is-active {
    background: var(--bg-card);
    color: var(--primary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-form input {
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

.auth-form input:focus { border-color: var(--primary); }

.auth-form .btn { margin-top: 4px; }

.auth-back {
    display: inline-block;
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

.auth-back:hover { color: var(--primary); }

/* ── App Shell (Top Nav Layout) ── */
.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(255,255,255,.88);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.app-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    height: 56px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 28px;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    text-decoration: none;
    flex-shrink: 0;
}

.app-logo {
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 7px;
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 800;
    font-size: 14px;
}

.app-tabs {
    display: flex;
    gap: 2px;
    flex: 1;
}

.app-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.app-tab svg { width: 16px; height: 16px; }

.app-tab:hover { color: var(--text); background: var(--bg); }

.app-tab.is-active {
    color: var(--primary);
    background: var(--primary-light);
    font-weight: 600;
}

.app-user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.app-user-info {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Main Content ── */
.app-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.view { display: none; }
.view.is-active { display: block; }

.view-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.view-head h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

/* ── Cards ── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.card h4 {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-secondary);
}

.card strong {
    display: block;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.card small {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ── Panel ── */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.panel-head {
    margin-bottom: 14px;
}

.panel-head h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

/* ── Redeem row ── */
.redeem-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.redeem-row input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    outline: none;
}

.redeem-row input:focus { border-color: var(--primary); }

/* ── Key create row ── */
.key-create-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.key-create-row input {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    min-width: 0;
}

.key-create-row input:first-child { flex: 2; }
.key-create-row input:nth-child(2) { flex: 1; min-width: 120px; }
.key-create-row input:focus { border-color: var(--primary); }

/* ── Tables ── */
.table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

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

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

th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    background: var(--bg);
    text-transform: uppercase;
    letter-spacing: .04em;
}

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

.empty-row td {
    text-align: center;
    padding: 32px;
    color: var(--text-secondary);
}

/* ── Copy wrap ── */
.copy-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 240px;
}

.copy-wrap code {
    font-family: "JetBrains Mono", "Consolas", monospace;
    font-size: 12px;
    background: var(--bg);
    padding: 3px 8px;
    border-radius: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    max-width: 180px;
}

.copy-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    display: inline-grid;
    place-items: center;
    transition: all var(--transition);
}

.copy-btn:hover { color: var(--primary); background: var(--primary-light); }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.badge-green { background: var(--green-light); color: #047857; }
.badge-red { background: var(--red-light); color: #b91c1c; }
.badge-amber { background: var(--amber-light); color: #92400e; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ── Guide ── */
.guide-info {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.guide-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 8px;
}

.guide-copy-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.guide-copy-row code {
    font-family: "JetBrains Mono", "Consolas", monospace;
    font-size: 13px;
    background: var(--bg);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.guide-field select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: "JetBrains Mono", "Consolas", monospace;
    background: var(--bg-card);
    outline: none;
    cursor: pointer;
}

.guide-field select:focus { border-color: var(--primary); }

/* ── Guide Tabs ── */
.guide-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 6px 6px 0;
}

.guide-tab {
    padding: 10px 18px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.guide-tab:hover { color: var(--text); }

.guide-tab.is-active {
    color: var(--primary);
    background: var(--bg);
}

/* ── Guide Panel ── */
.guide-panel {
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 24px;
}

.guide-panel.is-active { display: block; }

.guide-panel h3 {
    margin: 0 0 6px;
    font-size: 17px;
    font-weight: 700;
}

.guide-panel .guide-desc {
    margin: 0 0 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.guide-step {
    margin-bottom: 24px;
}

.guide-step h4 {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.guide-step-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
}

.guide-step p {
    margin: 0 0 10px;
    font-size: 13px;
    color: var(--text-secondary);
    padding-left: 30px;
}

.code-block {
    position: relative;
    margin: 0 0 4px;
    background: #1e293b;
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    font-family: "JetBrains Mono", "Consolas", monospace;
    font-size: 13px;
    line-height: 1.7;
    color: #e2e8f0;
    overflow-x: auto;
    white-space: pre;
}

.code-block .code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,.1);
    border: none;
    border-radius: 6px;
    padding: 6px 8px;
    cursor: pointer;
    color: #94a3b8;
    transition: all var(--transition);
    display: inline-grid;
    place-items: center;
}

.code-block .code-copy-btn:hover { background: rgba(255,255,255,.2); color: #fff; }

.guide-note {
    margin: 16px 0 0;
    padding: 12px 16px;
    border-left: 3px solid var(--primary);
    background: var(--primary-light);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 13px;
    color: var(--text);
}

.guide-note strong { font-weight: 600; }
.guide-note ul { line-height: 1.8; }
.guide-note a { color: var(--primary); text-decoration: underline; }
.guide-note a:hover { color: var(--primary-hover); }

.guide-section-title {
    margin: 28px 0 16px;
    padding: 10px 16px;
    background: linear-gradient(90deg, var(--primary-light), transparent);
    border-left: 3px solid var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.guide-section-title:first-of-type { margin-top: 20px; }

/* ── Action buttons in table ── */
.action-btns {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

/* ── Modal ── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 24px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.4);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow: auto;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }

.json-box {
    margin: 0;
    padding: 20px;
    font-family: "JetBrains Mono", "Consolas", monospace;
    font-size: 12px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ── Custom confirm/prompt dialogs ── */
.dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    background: rgba(0,0,0,.4);
    backdrop-filter: blur(4px);
    padding: 24px;
}

.dialog-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 28px 24px 20px;
    max-width: 380px;
    width: 100%;
    text-align: center;
}

.dialog-card p {
    margin: 0 0 20px;
    font-size: 14px;
    font-weight: 500;
}

.dialog-card input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    margin-bottom: 16px;
}

.dialog-card input:focus { border-color: var(--primary); }

.dialog-btns {
    display: flex;
    gap: 8px;
    justify-content: center;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .app-header-inner { padding: 0 12px; gap: 12px; }

    .app-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .app-tabs::-webkit-scrollbar { display: none; }

    .app-main { padding: 16px; }

    .guide-info { grid-template-columns: 1fr; }

    .key-create-row { flex-direction: column; }
    .key-create-row input { width: 100%; }

    .redeem-row { flex-direction: column; }
    .redeem-row input { width: 100%; }

    .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card strong { font-size: 20px; }

    .app-user-info { display: none; }
}

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

/* ── Announcements ── */
.announcements-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.empty-announcements {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.announcement-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    transition: border-color 0.2s;
}

.announcement-card.is-unread {
    border-left: 3px solid var(--primary);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.03), transparent);
}

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

.announcement-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.announcement-header time {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.ann-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    display: inline-block;
    flex-shrink: 0;
}

.announcement-body {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.ann-read-btn {
    font-size: 12px;
}

.ann-read-label {
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0.6;
}

.unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    margin-left: 4px;
}

.unread-badge.hidden {
    display: none;
}
