:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #647084;
    --line: #dfe5ee;
    --primary: #1769e0;
    --primary-dark: #0f54b8;
    --success-bg: #e8f7ef;
    --success-text: #17663a;
    --error-bg: #fff0f0;
    --error-text: #a52727;
    --shadow: 0 18px 50px rgba(23, 32, 51, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: var(--primary);
    text-decoration: none;
}

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

.store-page {
    min-height: 100vh;
    background:
        linear-gradient(120deg, rgba(23, 105, 224, .12), transparent 38%),
        linear-gradient(240deg, rgba(17, 150, 126, .11), transparent 35%),
        var(--bg);
}

.store-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 16px;
}

.redeem-panel,
.login-panel,
.admin-form,
.generated-box,
.table-wrap,
.result-box {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.redeem-panel {
    width: min(760px, 100%);
    padding: 32px;
}

.announcement-bar {
    margin-bottom: 20px;
    border: 1px solid #f0d58a;
    border-radius: 6px;
    padding: 12px 14px;
    background: #fff8df;
    color: #6d5208;
    font-weight: 700;
    line-height: 1.55;
    word-break: break-word;
}

.brand-row h1,
.login-panel h1,
.page-head h1 {
    margin: 0;
    line-height: 1.18;
    letter-spacing: 0;
}

.brand-row p,
.page-head p {
    color: var(--muted);
    margin: 8px 0 0;
}

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

.form-grid {
    margin-top: 24px;
}

label span {
    display: block;
    margin-bottom: 8px;
    color: #364258;
    font-weight: 650;
}

.field-help {
    display: block;
    margin-top: 7px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 11px 12px;
    background: #fff;
    color: var(--text);
}

textarea {
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    outline: 2px solid rgba(23, 105, 224, .18);
    border-color: var(--primary);
}

.primary-button,
.danger-button,
.download-button,
.primary-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    padding: 0 18px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.danger-button {
    background: #b4232a;
}

.danger-button:hover {
    background: #8f1d22;
    color: #fff;
}

.danger-button:disabled {
    background: #d9dee8;
    color: #6b7484;
    cursor: not-allowed;
}

.primary-button:hover,
.download-button:hover,
.primary-link:hover {
    background: var(--primary-dark);
    color: #fff;
}

.ghost-button,
.ghost-link,
.text-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0 14px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
}

.compact-button {
    min-height: 30px;
    padding: 0 10px;
    font-size: 13px;
}

.text-button {
    width: 100%;
    color: #fff;
    background: rgba(255,255,255,.08);
    border-color: rgba(255,255,255,.18);
}

.alert {
    margin: 16px 0;
    border-radius: 6px;
    padding: 12px 14px;
    font-weight: 650;
}

.alert.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.alert.error {
    background: var(--error-bg);
    color: var(--error-text);
}

.result-box {
    margin-top: 24px;
    padding: 22px;
}

.result-head,
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.eyebrow {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.result-head h2 {
    margin: 0;
    font-size: 22px;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 18px 0;
}

.meta-grid div,
.stats-row div {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
    background: #fbfcfe;
}

.meta-grid dt,
.stats-row span {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 13px;
}

.meta-grid dd,
.stats-row strong {
    margin: 0;
    font-weight: 750;
    word-break: break-word;
}

.delivery-list {
    display: grid;
    gap: 10px;
}

pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
    background: #0f1726;
    color: #edf3ff;
}

.download-button {
    margin-top: 16px;
}

.result-actions,
.button-row,
.section-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.result-actions {
    flex-wrap: wrap;
    margin: 2px 0 10px;
}

.result-actions .download-button {
    margin-top: 0;
}

.hint {
    margin: 0 0 16px;
    color: var(--muted);
    font-size: 14px;
}

.result-textarea {
    display: block;
    margin-top: 16px;
}

.delivery-item {
    display: grid;
    gap: 8px;
}

.delivery-item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

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

.login-panel {
    width: min(420px, 100%);
    padding: 28px;
}

.admin-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
}

.admin-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 24px 18px;
    background: #182238;
    color: #fff;
}

.admin-logo {
    color: #fff;
    font-size: 20px;
    font-weight: 800;
}

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

.admin-sidebar nav a {
    border-radius: 6px;
    padding: 10px 12px;
    color: #d7deed;
}

.admin-sidebar nav a:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.admin-sidebar nav a.active {
    background: rgba(255,255,255,.14);
    color: #fff;
}

.admin-sidebar form {
    margin-top: auto;
}

.admin-main {
    padding: 28px;
    min-width: 0;
}

.page-head {
    margin-bottom: 18px;
}

.admin-form {
    padding: 20px;
    margin-bottom: 20px;
}

.inline-form {
    grid-template-columns: minmax(220px, 1fr) 160px 160px auto;
    align-items: end;
}

.delete-code-form {
    grid-template-columns: minmax(220px, 1fr) 160px auto minmax(180px, 1fr);
}

.form-note {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.settings-form {
    max-width: 920px;
}

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

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-row input {
    width: auto;
}

.checkbox-row span {
    margin: 0;
}

.table-wrap {
    overflow-x: auto;
}

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

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 13px 14px;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f8fafc;
    color: #46536a;
    font-size: 13px;
}

td small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
}

.actions {
    white-space: nowrap;
}

.actions a + a,
.actions a + form,
.actions form + a,
.actions form + form {
    margin-left: 10px;
}

.action-form {
    display: inline-flex;
    margin: 0;
}

.danger-link {
    border: 0;
    padding: 0;
    background: transparent;
    color: #a52727;
    cursor: pointer;
}

.danger-link:hover {
    color: #7f1d1d;
    text-decoration: underline;
}

.empty {
    color: var(--muted);
    text-align: center;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 160px));
    gap: 12px;
    margin-bottom: 18px;
}

.generated-box {
    padding: 18px;
    margin-bottom: 18px;
}

.generated-box h2 {
    margin: 0 0 12px;
}

.section-head {
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-head h2,
.section-head p {
    margin: 0;
}

.section-head p {
    margin-top: 4px;
    color: var(--muted);
    font-size: 14px;
}

.button-row {
    flex-wrap: wrap;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 0 9px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.status-on,
.status-available,
.status-unused {
    background: #e8f7ef;
    color: #17663a;
}

.status-used,
.status-delivered {
    background: #e9f1ff;
    color: #174ea6;
}

.status-off {
    background: #eef1f5;
    color: #536074;
}

.admin-meta {
    margin-bottom: 18px;
}

@media (max-width: 820px) {
    .admin-page {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        position: static;
        height: auto;
    }

    .admin-sidebar nav {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .inline-form,
    .delete-code-form,
    .meta-grid,
    .form-two {
        grid-template-columns: 1fr;
    }

    .page-head,
    .result-head,
    .section-head {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 560px) {
    .redeem-panel,
    .login-panel {
        padding: 22px;
    }

    .admin-main {
        padding: 18px;
    }

    .admin-sidebar nav {
        grid-template-columns: 1fr;
    }
}
