:root {
    --ink: #29222b;
    --muted: #736b75;
    --primary: #8b315b;
    --primary-dark: #68203f;
    --primary-soft: #f6e9ef;
    --accent: #f4d983;
    --accent-soft: #fff7d8;
    --surface: #ffffff;
    --surface-2: #faf7f9;
    --background: #f4eff2;
    --line: #e8dce3;
    --success: #267454;
    --success-soft: #e7f7ef;
    --danger: #b53a42;
    --danger-soft: #fff0f1;
    --warning: #9a671d;
    --warning-soft: #fff7df;
    --shadow: 0 18px 50px rgba(58, 31, 45, 0.10);
    --radius: 18px;
    --sidebar-width: 252px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--background);
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
    color: var(--ink);
    background: var(--background);
}

body.modal-open {
    overflow: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

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

button,
a,
input,
select,
textarea {
    -webkit-tap-highlight-color: transparent;
}

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    color: #fff;
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.14), transparent 34%),
        linear-gradient(180deg, #722348 0%, #4c1732 100%);
    box-shadow: 18px 0 42px rgba(73, 24, 49, 0.16);
    transition: width 0.22s ease, transform 0.22s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 78px;
    padding: 14px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 44px;
    height: 44px;
    border-radius: 15px;
    color: #6c2145;
    font-size: 21px;
    font-weight: 900;
    background: linear-gradient(145deg, #fff3b9, #f0d270);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.15);
}

.sidebar-brand-text {
    min-width: 0;
}

.sidebar-brand-text strong,
.sidebar-brand-text small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-brand-text strong {
    font-size: 16px;
}

.sidebar-brand-text small {
    margin-top: 3px;
    color: rgba(255, 255, 255, 0.68);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 14px 10px 24px;
}

.nav-section-title {
    padding: 15px 12px 7px;
    color: rgba(255, 255, 255, 0.48);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.1em;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 46px;
    margin: 4px 0;
    padding: 10px 12px;
    border-radius: 13px;
    color: rgba(255, 255, 255, 0.82);
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav-item:hover,
.nav-item.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.13);
}

.nav-item:hover {
    transform: translateX(2px);
}

.nav-icon {
    display: grid;
    place-items: center;
    flex: 0 0 26px;
    font-size: 18px;
}

.nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
}

.sidebar-footer {
    padding: 13px 14px 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.11);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    display: grid;
    place-items: center;
    flex: 0 0 38px;
    height: 38px;
    overflow: hidden;
    border-radius: 50%;
    color: var(--primary-dark);
    font-weight: 900;
    background: #f9e7ef;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sidebar-user-info {
    min-width: 0;
}

.sidebar-user-info strong,
.sidebar-user-info small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-info small {
    margin-top: 2px;
    color: rgba(255, 255, 255, 0.62);
}

.main-area {
    min-height: 100vh;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.22s ease;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    padding: 10px 24px;
    border-bottom: 1px solid rgba(226, 214, 221, 0.9);
    background: rgba(250, 247, 249, 0.90);
    backdrop-filter: blur(16px);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 13px;
    color: var(--ink);
    background: #fff;
    cursor: pointer;
}

.icon-btn:hover {
    border-color: #d4bdca;
    background: var(--primary-soft);
}

.page-content {
    width: min(1520px, 100%);
    margin: 0 auto;
    padding: 26px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.page-title h1 {
    margin: 0;
    font-size: clamp(24px, 3vw, 34px);
    line-height: 1.25;
}

.page-title p {
    margin: 8px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.card {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 10px 34px rgba(61, 33, 47, 0.06);
}

.card + .card {
    margin-top: 18px;
}

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

.card-title {
    margin: 0;
    font-size: 18px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    min-height: 126px;
    padding: 19px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: linear-gradient(145deg, #fff, #fbf8fa);
}

.stat-label {
    color: var(--muted);
    font-weight: 700;
}

.stat-value {
    margin-top: 12px;
    font-size: 31px;
    font-weight: 900;
    letter-spacing: -0.02em;
}

.stat-note {
    margin-top: 5px;
    color: var(--muted);
    font-size: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 42px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 12px;
    white-space: nowrap;
    color: var(--ink);
    font-weight: 800;
    line-height: 1.2;
    background: #fff;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.58;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    color: #fff;
    background: linear-gradient(145deg, var(--primary), var(--primary-dark));
    box-shadow: 0 10px 24px rgba(108, 33, 69, 0.18);
}

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

.btn-soft {
    color: var(--primary-dark);
    border-color: #ead5df;
    background: var(--primary-soft);
}

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

.btn-warning {
    color: #704712;
    border-color: #efd58b;
    background: var(--warning-soft);
}

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

.btn-sm {
    min-height: 34px;
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 13px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.toolbar-grow {
    flex: 1 1 260px;
}

.field,
.form-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field label,
.form-field label {
    font-weight: 800;
}

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

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

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

.field-full {
    grid-column: 1 / -1;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="datetime-local"],
select,
textarea,
.input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #d9ccd4;
    border-radius: 12px;
    color: var(--ink);
    background: #fff;
    outline: none;
}

textarea {
    min-height: 112px;
    resize: vertical;
    line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus,
.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(139, 49, 91, 0.10);
}

.help-text {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.checkbox-row,
.switch-row {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 42px;
}

.checkbox-row input,
.switch-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.date-wrap {
    display: flex;
    gap: 7px;
}

.date-wrap input[type="text"] {
    flex: 1;
}

.date-button {
    flex: 0 0 44px;
}

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

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

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

th {
    color: #5f5260;
    font-size: 12px;
    letter-spacing: 0.03em;
    background: #faf7f9;
}

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

tbody tr[data-editable="1"] {
    cursor: pointer;
}

tbody tr[data-editable="1"]:hover {
    background: #fdf9fb;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

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

.badge-success {
    color: #1d6b4c;
    background: var(--success-soft);
}

.badge-warning {
    color: #875a17;
    background: var(--warning-soft);
}

.badge-danger {
    color: #9a2932;
    background: var(--danger-soft);
}

.badge-muted {
    color: #675d68;
    background: #eee8ec;
}

.badge-primary {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.empty-state {
    padding: 42px 18px;
    text-align: center;
    color: var(--muted);
}

.empty-state strong {
    display: block;
    margin-bottom: 8px;
    color: var(--ink);
    font-size: 18px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(36, 22, 30, 0.56);
    backdrop-filter: blur(4px);
}

.modal-backdrop.open {
    display: flex;
}

.modal-dialog {
    display: flex;
    flex-direction: column;
    width: min(760px, 100%);
    max-height: min(90vh, 980px);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 22px;
    background: #fff;
    box-shadow: 0 32px 90px rgba(31, 17, 24, 0.34);
    overflow: hidden;
}

.modal-lg {
    width: min(1080px, 100%);
}

.modal-xl {
    width: min(1360px, 100%);
}

.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    background: #fff;
}

.modal-header {
    border-bottom: 1px solid var(--line);
}

.modal-footer {
    justify-content: flex-end;
    border-top: 1px solid var(--line);
}

.modal-title {
    margin: 0;
    font-size: 20px;
}

.modal-body {
    overflow-y: auto;
    padding: 20px;
}

.modal-close {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 12px;
    background: #f4eef1;
    cursor: pointer;
}

.toast-container {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 3000;
    display: grid;
    gap: 10px;
    width: min(390px, calc(100% - 36px));
}

.toast {
    padding: 14px 16px;
    border-radius: 15px;
    color: #fff;
    line-height: 1.5;
    box-shadow: 0 18px 42px rgba(37, 20, 29, 0.24);
    animation: toast-in 0.2s ease;
}

.toast-success {
    background: #247152;
}

.toast-error {
    background: #ad343d;
}

.toast-info {
    background: #5f466b;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
}

.confirm-dialog {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(33, 19, 27, 0.6);
}

.confirm-box {
    width: min(480px, 100%);
    padding: 24px;
    border-radius: 20px;
    background: #fff;
    box-shadow: var(--shadow);
}

.confirm-box h3 {
    margin: 0 0 10px;
}

.confirm-box p {
    margin: 0 0 18px;
    color: var(--muted);
    line-height: 1.65;
}

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.auth-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 22px;
    background:
        radial-gradient(circle at 15% 10%, rgba(139, 49, 91, 0.16), transparent 34%),
        radial-gradient(circle at 90% 90%, rgba(244, 217, 131, 0.18), transparent 30%),
        linear-gradient(135deg, #fbf8fa 0%, #f2ebef 100%);
}

.auth-card {
    width: min(470px, 100%);
    padding: 30px;
    border: 1px solid var(--line);
    border-radius: 26px;
    text-align: center;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 28px 80px rgba(61, 29, 46, 0.14);
}

.auth-card .brand-mark {
    width: 62px;
    height: 62px;
    margin: 0 auto 18px;
    font-size: 28px;
}

.auth-card h1 {
    margin: 0;
    font-size: 27px;
}

.auth-card > p {
    margin: 10px 0 22px;
    color: var(--muted);
    line-height: 1.65;
}

.line-button {
    width: 100%;
    min-height: 52px;
    color: #fff;
    background: #06c755;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 22px 0;
    color: #9a9098;
    font-size: 12px;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}

.login-form {
    display: grid;
    gap: 13px;
    text-align: left;
}

.login-form .btn {
    width: 100%;
}

.ticket-grid {
    display: grid;
    grid-template-columns: repeat(10, max-content);
    gap: 11px 2ch;
    align-items: center;
    overflow-x: auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
}

.ticket-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 5px 9px;
    border: 1px solid #e4d8df;
    border-radius: 9px;
    white-space: nowrap;
    font-family: "Consolas", "Courier New", monospace;
    font-weight: 800;
    background: #fff;
}

.ticket-number.redeemed {
    border-color: #ead27c;
    background: #fff3b8;
    box-shadow: inset 0 0 0 1px rgba(169, 113, 24, 0.08);
}

.redeem-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
    gap: 18px;
}

.redeem-entry {
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: linear-gradient(145deg, #fff, #fcf9fb);
}

.redeem-number {
    min-height: 68px !important;
    font-family: "Consolas", monospace !important;
    font-size: clamp(26px, 5vw, 42px) !important;
    font-weight: 900 !important;
    letter-spacing: 0.08em;
    text-align: center;
}

.redeem-result {
    display: none;
    margin-top: 16px;
    padding: 18px;
    border-radius: 16px;
    line-height: 1.65;
}

.redeem-result.show {
    display: block;
}

.redeem-result.success {
    color: #155f43;
    border: 1px solid #b6e2cf;
    background: #ecfaf4;
}

.redeem-result.error {
    color: #8c2630;
    border: 1px solid #efb9be;
    background: #fff0f1;
}

.redeem-history {
    display: grid;
    gap: 9px;
    max-height: 520px;
    overflow-y: auto;
}

.history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 12px 13px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: #fff;
}

.history-number {
    font-family: "Consolas", monospace;
    font-weight: 900;
}

.history-meta {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.venue-selector-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    max-height: 360px;
    overflow-y: auto;
    padding: 4px;
}

.venue-option {
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.venue-option-head {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 10px;
}

.batch-row {
    position: relative;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: #fbf8fa;
}

.batch-row + .batch-row {
    margin-top: 12px;
}

.batch-remove {
    position: absolute;
    top: 10px;
    right: 10px;
}

.quick-links {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.quick-link {
    display: block;
    min-height: 116px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
}

.quick-link:hover {
    border-color: #d7bdcb;
    box-shadow: 0 12px 30px rgba(72, 37, 55, 0.08);
}

.quick-link strong {
    display: block;
    margin-bottom: 7px;
    font-size: 17px;
}

.quick-link span {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
}

.notice {
    padding: 14px 16px;
    border-radius: 14px;
    line-height: 1.6;
}

.notice-info {
    color: #5b4863;
    border: 1px solid #dfd1e5;
    background: #f8f1fb;
}

.notice-warning {
    color: #7e5517;
    border: 1px solid #ecd38b;
    background: #fff8e1;
}

.notice-danger {
    color: #8d2730;
    border: 1px solid #efb9be;
    background: #fff0f1;
}

@media (max-width: 1180px) {
    .stat-grid,
    .quick-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .form-grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ticket-grid {
        grid-template-columns: repeat(5, max-content);
    }
}

@media (max-width: 920px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-area {
        margin-left: 0;
    }

    .topbar {
        padding: 10px 14px;
    }

    .page-content {
        padding: 18px 14px 28px;
    }

    .page-header {
        flex-direction: column;
    }

    .page-actions {
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 3px;
    }

    .redeem-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 680px) {
    .stat-grid,
    .quick-links,
    .form-grid,
    .form-grid-3,
    .form-grid-4,
    .venue-selector-grid {
        grid-template-columns: 1fr;
    }

    .field-full {
        grid-column: auto;
    }

    .card {
        padding: 16px;
        border-radius: 16px;
    }

    .modal-backdrop {
        padding: 0;
        align-items: stretch;
    }

    .modal-dialog,
    .modal-lg,
    .modal-xl {
        width: 100%;
        max-height: 100vh;
        border: 0;
        border-radius: 0;
    }

    .modal-body {
        padding: 16px;
    }

    .ticket-grid {
        grid-template-columns: repeat(3, max-content);
    }

    .auth-card {
        padding: 24px 18px;
        border-radius: 20px;
    }

    .topbar-right .topbar-user-name {
        display: none;
    }
}

/* 連續消號：新資料由下方推入，舊資料自然往上移動。 */
.history-new {
    opacity: 0;
    transform: translateY(18px);
}

.history-new.history-push-in {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 180ms ease, transform 220ms ease;
}

.recent-redeem-card {
    min-width: 0;
}

@media (max-width: 680px) {
    .recent-redeem-card {
        padding: 12px;
        border-radius: 14px;
        background: #fcfafb;
    }

    .recent-redeem-card .card-header {
        margin-bottom: 6px;
    }

    .recent-redeem-card .card-title {
        font-size: 15px;
    }

    .recent-hint,
    .history-previous {
        display: none;
    }

    .redeem-history {
        max-height: 178px;
        gap: 6px;
    }

    .history-item {
        padding: 8px 10px;
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.78);
        box-shadow: none;
    }

    .history-number {
        font-size: 14px;
    }

    .history-meta {
        font-size: 10px;
    }
}
