/* ---- Reset & Variables ---- */
:root {
    /* Core Brand Colors */
    --theme-primary: #ef355c;
    --theme-primary-hover: rgba(239, 53, 92, 0.85);
    
    /* Default: DARK MODE Variables */
    --bg-grad-1: #090e17;
    --bg-grad-2: #17253b;
    --panel-bg: rgba(20, 25, 40, 0.6);
    --border-glass: rgba(255, 255, 255, 0.1);
    
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    
    --btn-glass: rgba(255, 255, 255, 0.1);
    --btn-glass-hover: rgba(255, 255, 255, 0.2);
    --btn-text: #ffffff;
    
    --input-bg: rgba(0, 0, 0, 0.25);
    --log-bg: rgba(0, 0, 0, 0.4);
    --log-text: #4ade80;
    
    --chat-header-bg: rgba(255,255,255,0.02);
    --chat-input-area: rgba(0,0,0,0.15);
    --assistant-bubble: rgba(255, 255, 255, 0.08);
    --assistant-text: #e2e8f0;
    
    --ticket-card-bg: rgba(30, 41, 59, 0.85);
    --ticket-card-border: rgba(255,255,255,0.15);
    --ticket-hover-bg: rgba(239, 53, 92, 0.15);
    
    --shadow-heavy: 0 12px 32px 0 rgba(0, 0, 0, 0.4);
    --shadow-light: 0 4px 12px 0 rgba(0, 0, 0, 0.2);
    --boxy-radius: 6px;
}

/* LIGHT MODE Overrides */
[data-theme="light"] {
    --bg-grad-1: #f0f4f8;
    --bg-grad-2: #d9e2ec;
    --panel-bg: rgba(255, 255, 255, 0.7);
    --border-glass: rgba(0, 0, 0, 0.1);
    
    --text-main: #102a43;
    --text-muted: #486581;
    
    --btn-glass: rgba(0, 0, 0, 0.05);
    --btn-glass-hover: rgba(0, 0, 0, 0.1);
    --btn-text: #102a43;
    
    --input-bg: rgba(255, 255, 255, 0.8);
    --log-bg: rgba(255, 255, 255, 0.6);
    --log-text: #047857; 
    
    --chat-header-bg: rgba(0,0,0,0.02);
    --chat-input-area: rgba(255, 255, 255, 0.5);
    --assistant-bubble: rgba(255, 255, 255, 0.9);
    --assistant-text: #102a43;
    
    --ticket-card-bg: rgba(255, 255, 255, 0.95);
    --ticket-card-border: rgba(0,0,0,0.1);
    --ticket-hover-bg: rgba(239, 53, 92, 0.08);
    
    --shadow-heavy: 0 12px 32px 0 rgba(31, 38, 135, 0.15);
    --shadow-light: 0 4px 12px 0 rgba(31, 38, 135, 0.07);
}

* {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

body {
    background: linear-gradient(135deg, var(--bg-grad-1) 0%, var(--bg-grad-2) 100%);
    color: var(--text-main);
    margin: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ---- Layout Grid ---- */
.kiosk-layout {
    width: 95vw;
    max-width: 1400px;
    height: 92vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.grid-container {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    height: 100%;
    overflow: hidden;
    min-height: 0; /* CRITICAL FIX: Forces grid children to respect height bounds */
}

/* ---- Glass & Boxy Utilities ---- */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--boxy-radius);
    box-shadow: var(--shadow-heavy);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.boxy-btn {
    border: none;
    border-radius: var(--boxy-radius);
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
    background: var(--btn-glass);
    color: var(--btn-text);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.boxy-btn:hover { background: var(--btn-glass-hover); }
.boxy-btn:active { transform: translateY(1px); }
.boxy-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.primary { background: var(--theme-primary); color: #fff; }
.primary:hover:not(:disabled) {
    background: var(--theme-primary-hover);
    box-shadow: 0 0 10px var(--theme-primary-hover);
    color: #fff;
}

.danger { background: rgba(220, 53, 69, 0.8); color: #fff;}
.danger:hover:not(:disabled) { background: rgba(220, 53, 69, 1); }

.boxy-shadow { box-shadow: var(--shadow-light); }

.input-boxy {
    background: var(--input-bg);
    border: 1px solid var(--border-glass);
    border-radius: var(--boxy-radius);
    padding: 12px;
    color: var(--text-main);
    width: 100%;
    outline: none;
}
.input-boxy:focus { border-color: var(--theme-primary); }
.input-boxy:disabled { opacity: 0.5; }
.input-boxy option { color: initial; background: initial; } 

/* ---- Header & Controls ---- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
}
.topbar h1 { margin: 0; font-size: 1.2rem; font-weight: 600; letter-spacing: 1px;}
.status { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pill {
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--btn-glass);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    white-space: nowrap;
}
.pill.on { background: rgba(40, 167, 69, 0.2); border-color: #28a745; color: #10b981; font-weight: bold; }
.pill.err { background: rgba(220, 53, 69, 0.2); border-color: #dc3545; color: #ef4444; font-weight: bold; }

.controls-panel {
    min-height: 0; /* CRITICAL FIX for scrolling */
    overflow-y: auto;
}
.controls-panel h2 {
    margin-top: 0; margin-bottom: 20px; font-size: 1.1rem;
    border-bottom: 1px solid var(--border-glass); padding-bottom: 10px;
}
label { display: block; margin-bottom: 15px; font-size: 0.85rem; color: var(--text-muted); }
label input, label select { margin-top: 5px; }

.btn-row { display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap; }
.btn-row button { flex: 1; }

.logs-container {
    display: flex;
    flex-direction: column;
    min-height: 150px; /* Gives logs a base height */
}
.logs-container h3 { font-size: 0.9rem; margin: 0 0 10px 0; color: var(--text-muted); }
#logs {
    flex-grow: 1;
    background: var(--log-bg);
    border: 1px solid var(--border-glass);
    border-radius: var(--boxy-radius);
    padding: 10px;
    font-size: 0.75rem;
    color: var(--log-text);
    overflow-y: auto;
    margin: 0;
    white-space: pre-wrap;
}
.spacer { flex-grow: 1; min-height: 20px; }

/* ---- Centered Chat UI ---- */
.chat-panel {
    display: flex;
    flex-direction: column;
    padding: 0; 
    min-height: 0; /* CRITICAL FIX: Forces the panel to respect grid boundaries */
    overflow: hidden; /* Contains the scrollable child */
}
.chat-header {
    padding: 15px 25px;
    border-bottom: 1px solid var(--border-glass);
    background: var(--chat-header-bg);
}
.chat-header h2 { margin: 0; font-size: 1.1rem; }

.chat {
    flex: 1;
    overflow-y: auto;
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 20px;
    background: var(--chat-input-area);
    border-top: 1px solid var(--border-glass);
}
.chat-input-area input { flex: 1; }
.chat-input-area button { padding: 0 25px; font-size: 1rem; }

/* ---- Chat Bubbles ---- */
.bubble {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: var(--boxy-radius);
    font-size: 1rem;
    line-height: 1.4;
    box-shadow: var(--shadow-light);
    word-wrap: break-word;
}
.bubble.user {
    align-self: flex-end;
    background: var(--theme-primary);
    color: white;
    border-bottom-right-radius: 0;
}
.bubble.assistant {
    align-self: flex-start;
    background: var(--assistant-bubble);
    border: 1px solid var(--border-glass);
    color: var(--assistant-text);
    border-bottom-left-radius: 0;
}
.bubble.rich-card-wrapper {
    background: transparent;
    box-shadow: none;
    border: none;
    padding: 0;
    width: 100%;
    max-width: 600px;
}
.bubble.rich-card-wrapper.options-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ---- In-Chat Tickets & QR Cards ---- */
.ticket-card {
    background: var(--ticket-card-bg);
    border: 1px solid var(--ticket-card-border);
    padding: 18px;
    border-radius: var(--boxy-radius);
    color: var(--text-main);
}
.selectable-card {
    cursor: pointer;
    text-align: left;
    border-left: 4px solid transparent;
}
.selectable-card:hover {
    background: var(--ticket-hover-bg);
    border-left: 4px solid var(--theme-primary);
    transform: translateX(4px);
}
.tags-wrapper { margin-bottom: 8px; }
.tag {
    font-size: 0.65rem;
    padding: 4px 6px;
    border-radius: 3px;
    font-weight: bold;
    margin-right: 6px;
    display: inline-block;
}
.tag-cheap { background: #15803d; color: white; }
.tag-early { background: #0369a1; color: white; }
.tag-fast { background: #6d28d9; color: white; }
.price-highlight { color: var(--theme-primary); font-weight: bold; font-size: 1.1rem; }
.ticket-details { margin-top: 8px; font-size: 0.85rem; line-height: 1.4; color: var(--text-muted); }

/* Booking & Success */
.booking-card, .success-card { text-align: center; border-top: 4px solid var(--theme-primary); }
.success-card { border-top-color: #10b981; }
.booking-title { margin: 0 0 10px 0; color: var(--theme-primary); }
.success-title { margin: 0 0 10px 0; color: #10b981; }
.booking-amount strong { font-size: 1.6rem; color: var(--text-main); }
.qr-text { margin: 15px 0 8px 0; font-size: 0.9rem; color: var(--text-muted); }
.qr-image { width: 100%; max-width: 180px; border-radius: var(--boxy-radius); padding: 6px; background: white; }

/* Chat Buttons */
.chat-action-btn { display: inline-block; margin-top: 12px; margin-right: 8px; text-decoration: none; text-align: center; }
.success-btn { background: #10b981; color: white; }
.success-btn:hover { background: #059669; }

/* Thinking Animation */
.thinking-bubble { display: flex; align-items: center; gap: 4px; padding: 16px 20px; }
.dot-pulse {
    width: 6px; height: 6px; background: var(--text-muted); border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out both;
}
.dot-pulse:nth-child(1) { animation-delay: -0.32s; }
.dot-pulse:nth-child(2) { animation-delay: -0.16s; }
@keyframes pulse { 0%, 80%, 100% { transform: scale(0); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }



/* ---- Modern In-Chat Ticket Tags ---- */
.tags-wrapper { 
    margin-bottom: 10px; 
    display: flex;
    flex-wrap: wrap;
}

.tag {
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: var(--boxy-radius); /* Keeps the boxy 6px look */
    font-weight: 700;
    margin-right: 8px;
    margin-bottom: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px; /* Adds perfect spacing between the emoji and the text */
    letter-spacing: 0.5px;
    border: 1px solid transparent;
    box-shadow: var(--shadow-light);
    backdrop-filter: blur(4px);
}

/* Default (Dark Mode) Tag Colors */
.tag-cheap { 
    background: rgba(16, 185, 129, 0.15); /* Soft transparent Emerald */
    color: #34d399; /* Bright Emerald text */
    border-color: rgba(16, 185, 129, 0.3);
}
.tag-early { 
    background: rgba(14, 165, 233, 0.15); /* Soft transparent Sky Blue */
    color: #38bdf8; /* Bright Sky Blue text */
    border-color: rgba(14, 165, 233, 0.3);
}
.tag-fast { 
    background: rgba(139, 92, 246, 0.15); /* Soft transparent Violet */
    color: #a78bfa; /* Bright Violet text */
    border-color: rgba(139, 92, 246, 0.3);
}

/* Light Mode Overrides for Tags */
[data-theme="light"] .tag-cheap {
    background: rgba(16, 185, 129, 0.1); 
    color: #059669; /* Darker Emerald for readability on light bg */
    border-color: rgba(16, 185, 129, 0.4);
}
[data-theme="light"] .tag-early {
    background: rgba(14, 165, 233, 0.1); 
    color: #0284c7; /* Darker Sky Blue */
    border-color: rgba(14, 165, 233, 0.4);
}
[data-theme="light"] .tag-fast {
    background: rgba(139, 92, 246, 0.1); 
    color: #7c3aed; /* Darker Violet */
    border-color: rgba(139, 92, 246, 0.4);
}

/* =========================================
   MOBILE RESPONSIVENESS
========================================= */
@media (max-width: 850px) {
    body {
        align-items: flex-start; /* Prevent clipping at top on scroll */
        padding: 15px 10px;
    }
    
    .kiosk-layout {
        width: 100%;
        height: auto; 
        min-height: 100vh; /* Allow it to grow naturally */
    }

    .grid-container {
        grid-template-columns: 1fr; /* Switch to a single column */
        height: auto; /* Let it expand based on content */
        overflow: visible; /* Let the body handle the main scrolling */
    }

    /* Stack panels gracefully */
    .chat-panel {
        min-height: 60vh; /* Ensure the chat always has a good chunk of space */
    }
    
    .controls-panel {
        max-height: none; 
        overflow-y: visible;
    }

    /* Adjust header for tight spaces */
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    #theme-toggle {
        margin-bottom: 10px;
    }

    /* Adjust chat inputs for mobile */
    .chat-input-area {
        flex-wrap: wrap;
        padding: 15px;
    }
    
    .chat-input-area button {
        width: 100%; /* Full width send button on tiny screens */
        padding: 15px;
    }




}