:root {
    --bg-dark: #09090e;
    --bg-card: rgba(255, 255, 255, 0.03);
    --border-light: rgba(255, 255, 255, 0.08);
    
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.15);
    
    --visitor-color: #10b981;
    --visitor-glow: rgba(16, 185, 129, 0.15);
    --visitor-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    
    --meeting-color: #f59e0b;
    --meeting-glow: rgba(245, 158, 11, 0.15);
    --meeting-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    
    --text-main: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --success: #10b981;
    --error: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: radial-gradient(circle at 50% 0%, #1e1b4b 0%, var(--bg-dark) 70%);
    color: var(--text-main);
    font-family: 'Noto Sans TC', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
}

#app-container {
    width: 100%;
    max-width: 480px;
    min-height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Toast Notifications */
#toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    padding: 12px 24px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--border-light);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
    pointer-events: none;
}
#toast.toast-show {
    opacity: 1;
    transform: translateX(-50%) translateY(10px);
}
#toast.error {
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(20, 10, 10, 0.95);
    color: #fca5a5;
}
#toast.success {
    border-color: rgba(16, 185, 129, 0.4);
    background: rgba(10, 20, 15, 0.95);
    color: #a7f3d0;
}

/* View Panels */
.view-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.hidden {
    display: none !important;
}

/* Glassmorphism Panel Base */
.glass-panel {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-light);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
}

/* 1. Login Panel View */
#login-view {
    justify-content: center;
    align-items: center;
}

.login-card {
    width: 100%;
    padding: 32px 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

.brand-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo-symbol {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px var(--primary-glow);
}

.logo-symbol span {
    font-size: 2.2rem;
    color: #fff;
}

.brand-header h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #fff, var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper span {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    font-size: 1.2rem;
}

.input-wrapper input {
    width: 100%;
    padding: 14px 16px 14px 44px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    color: #fff;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
    background: rgba(0, 0, 0, 0.3);
}

.btn-submit {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 20px -10px rgba(99, 102, 241, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px -10px rgba(99, 102, 241, 0.7);
}

.btn-submit:active {
    transform: translateY(0);
}

.login-footer {
    text-align: center;
    margin-top: 24px;
}

.login-footer p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Spinner */
.spinner-hidden {
    display: none;
}
.spinner-show {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 2. Dashboard Panel View */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px -15px rgba(0, 0, 0, 0.3);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.user-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.user-info span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: block;
}

.icon-btn-logout {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn-logout:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

/* Tab controls */
.tabs-container {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 4px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.tab-btn span {
    font-size: 1.15rem;
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Card Deck Grid */
.cards-deck {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.deck-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.deck-placeholder span {
    font-size: 3rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.deck-placeholder p {
    font-size: 0.95rem;
    font-weight: 500;
}

.deck-placeholder .subtext {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
    max-width: 280px;
}

.pulse-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--primary-glow);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
    margin-bottom: 16px;
}

.cards-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Wallet Card Style */
.wallet-card {
    position: relative;
    border-radius: 20px;
    padding: 20px;
    border: 1px solid var(--border-light);
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.wallet-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.02;
    z-index: 0;
    pointer-events: none;
}

.wallet-card:hover {
    transform: translateY(-3px) scale(1.01);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
}

.wallet-card.card-visitor {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(5, 150, 105, 0.02) 100%);
    border-color: rgba(16, 185, 129, 0.2);
}
.wallet-card.card-visitor:hover {
    border-color: rgba(16, 185, 129, 0.4);
    box-shadow: 0 12px 30px var(--visitor-glow);
}

.wallet-card.card-meeting {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.08) 0%, rgba(217, 119, 6, 0.02) 100%);
    border-color: rgba(245, 158, 11, 0.2);
}
.wallet-card.card-meeting:hover {
    border-color: rgba(245, 158, 11, 0.4);
    box-shadow: 0 12px 30px var(--meeting-glow);
}

.wallet-card.card-history {
    opacity: 0.65;
    background: rgba(255, 255, 255, 0.01) !important;
    border-color: var(--border-light) !important;
    box-shadow: none !important;
    transform: none !important;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    position: relative;
    z-index: 1;
}

.badge {
    padding: 4px 10px;
    border-radius: 8px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.card-visitor .badge {
    background: var(--visitor-glow);
    color: var(--visitor-color);
}

.card-meeting .badge {
    background: var(--meeting-glow);
    color: var(--meeting-color);
}

.card-history .badge {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
}

.card-arrow {
    color: var(--text-muted);
    font-size: 1.2rem;
    transition: transform 0.2s ease;
}

.wallet-card:hover .card-arrow {
    transform: translateX(4px);
    color: var(--text-main);
}

.card-body {
    position: relative;
    z-index: 1;
}

.card-body h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-main);
}

.card-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 12px;
}

.meta-field {
    display: flex;
    align-items: center;
    gap: 6px;
}

.meta-field span {
    font-size: 1.05rem;
    color: var(--text-muted);
}

/* 3. Ticket Details Modal Bottom Sheet */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* Mobile Bottom Sheet */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-sheet {
    width: 100%;
    max-width: 480px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: 0 -20px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-overlay.show .modal-sheet {
    transform: translateY(0);
}

.sheet-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 16px 4px;
    position: relative;
}

.drag-bar {
    width: 40px;
    height: 4px;
    background: var(--text-muted);
    opacity: 0.3;
    border-radius: 2px;
    margin-bottom: 8px;
}

.btn-close {
    position: absolute;
    right: 20px;
    top: 10px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.8rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.sheet-content {
    padding: 0 24px 32px;
    overflow-y: auto;
    flex: 1;
}

.ticket-header {
    text-align: center;
    margin-bottom: 24px;
}

.ticket-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 8px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

#details-modal.visitor-pass .ticket-badge {
    background: var(--visitor-glow);
    color: var(--visitor-color);
}

#details-modal.meeting-pass .ticket-badge {
    background: var(--meeting-glow);
    color: var(--meeting-color);
}

.ticket-header h2 {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-main);
}

.ticket-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* QR Box */
.qr-box-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 28px;
}

.qr-container {
    background: #fff;
    padding: 16px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    display: inline-block;
    margin-bottom: 12px;
}

.qr-container img {
    display: block;
}

.qr-status-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--success);
    font-weight: 500;
}

.qr-status-label .success-icon {
    font-size: 1.15rem;
}

/* Ticket Parameters */
.ticket-meta-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-light);
    border-radius: 18px;
    padding: 16px;
    margin-bottom: 28px;
}

.meta-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
    padding-bottom: 10px;
}

.meta-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.meta-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.meta-val {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    text-align: right;
}

/* Apple/Google Wallet buttons style */
.wallet-actions-wrapper {
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 24px;
}

.wallet-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 16px;
}

.wallet-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.wallet-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px;
    border-radius: 14px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.25s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.wallet-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.wallet-btn:active {
    transform: translateY(0);
}

.apple-btn {
    background: #000;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.google-btn {
    background: #1a73e8;
    color: #fff;
}

.wallet-icon {
    width: 20px;
    height: 20px;
}

/* Responsive Desktop styles */
@media (min-width: 480px) {
    body {
        padding: 40px 0;
    }
    
    #app-container {
        border-radius: 32px;
        border: 1px solid var(--border-light);
        min-height: auto;
        height: 820px;
        box-shadow: none;
        overflow: hidden;
        background: radial-gradient(circle at 50% 0%, #1e1b4b 0%, var(--bg-dark) 100%);
    }
    
    .view-panel {
        overflow-y: auto;
    }
    
    .modal-overlay {
        position: absolute;
        border-radius: 32px;
        align-items: center; /* Centered modal on desktop */
    }
    
    .modal-sheet {
        border-radius: 28px;
        width: 90%;
        max-height: 85%;
        transform: scale(0.9) translateY(20px);
        opacity: 0;
        transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    
    .modal-overlay.show .modal-sheet {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
    
    .sheet-header .drag-bar {
        display: none;
    }
}

/* ───────── Top controls: theme toggle + language selector ───────── */
.top-controls {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 1100;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ctrl-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border-light);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
    font-size: 1.05rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.2s ease;
    padding: 0;
}
.ctrl-btn:hover { background: rgba(255, 255, 255, 0.12); }
.lang-select { position: relative; }
.lang-menu {
    position: absolute;
    top: 46px;
    right: 0;
    min-width: 140px;
    background: var(--bg-dark);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    padding: 6px;
    display: none;
    flex-direction: column;
    box-shadow: 0 10px 30px -8px rgba(0, 0, 0, 0.5);
}
.lang-menu.open { display: flex; }
.lang-menu button {
    background: none;
    border: none;
    color: var(--text-main);
    text-align: left;
    padding: 9px 12px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 8px;
}
.lang-menu button:hover { background: rgba(255, 255, 255, 0.08); }
.lang-menu button.active { color: var(--visitor-color); font-weight: 600; }

/* ───────── Light mode ───────── */
body.light-mode {
    --bg-dark: #eef1f6;
    --bg-card: rgba(255, 255, 255, 0.75);
    --border-light: rgba(0, 0, 0, 0.1);
    --text-main: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
}
body.light-mode {
    background: radial-gradient(circle at 50% 0%, #dbe4ff 0%, var(--bg-dark) 70%);
}
body.light-mode .glass-panel {
    background: rgba(255, 255, 255, 0.78);
}
body.light-mode .brand-header h1 {
    background: linear-gradient(to right, #1e293b, #6366f1);
    -webkit-background-clip: text;
    background-clip: text;
}
body.light-mode .input-wrapper input {
    background: rgba(0, 0, 0, 0.04);
    color: #1e293b;
}
body.light-mode .input-wrapper input:focus {
    background: rgba(0, 0, 0, 0.06);
}
body.light-mode .ctrl-btn {
    background: rgba(0, 0, 0, 0.05);
}
body.light-mode .ctrl-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}
body.light-mode #toast {
    background: rgba(255, 255, 255, 0.95);
    color: #1e293b;
}
/* 桌面外框（手機面板）改成淺色，修正深紫底 */
body.light-mode #app-container {
    background: radial-gradient(circle at 50% 0%, #e6ecfb 0%, #f4f6fb 100%);
    border-color: rgba(0, 0, 0, 0.08);
}
/* 分頁列 */
body.light-mode .tabs-container {
    background: rgba(0, 0, 0, 0.05);
}
body.light-mode .tab-btn.active {
    background: #ffffff;
    color: #1e293b;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
/* 卡片 */
body.light-mode .wallet-card.card-history {
    background: rgba(255, 255, 255, 0.7) !important;
}
body.light-mode .avatar {
    background: rgba(0, 0, 0, 0.04);
}
/* 彈窗內的資訊區 */
body.light-mode .ticket-meta-grid {
    background: rgba(0, 0, 0, 0.04);
}
body.light-mode .card-history .badge {
    background: rgba(0, 0, 0, 0.05);
}
/* 彈窗：背板與遮罩都調淺 */
body.light-mode .modal-sheet {
    background: #ffffff;
}
body.light-mode .modal-overlay {
    background: rgba(15, 23, 42, 0.25);
}
body.light-mode .ticket-meta-grid {
    background: rgba(0, 0, 0, 0.03);
}
body.light-mode .sheet-content .btn-close,
body.light-mode .icon-btn-logout {
    color: var(--text-secondary);
}
