/* ── Reset & Variables ────────────────────────────────────────────────────── */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Premium Concierge Brand Colors */
    --color-primary:       #0A5E4A; /* Mockup Dark Teal */
    --color-primary-dark:  #063D30;
    --color-primary-light: #E6F0EE;
    --color-accent:        #F59E0B;

    /* Surface & Background */
    --color-bg:            #F8FAFC;
    --color-surface:       #FFFFFF;
    --color-surface-2:     #F1F5F9;
    --color-border:        #E2E8F0;

    /* Text */
    --color-text-primary:  #1E293B;
    --color-text-muted:    #64748B;
    --color-text-faint:    #94A3B8;

    /* Chat bubbles */
    --color-bot-bg:        #EEF2F6;
    --color-bot-text:      #1E293B;
    --color-user-bg:       #0A5E4A;
    --color-user-text:     #FFFFFF;
    --color-info-bg:       #F0FDF4;
    --color-info-border:   #BBF7D0;
    --color-error-bg:      #FEF2F2;
    --color-error-border:  #FECACA;
    --color-success-bg:    #F0FDFA;
    --color-success-border:#A7F3D0;

    /* Sizing */
    --header-height:       65px;
    --nav-height:          75px;
    --input-height:        70px;
    --quick-bar-height:    44px;
    --border-radius:       16px;
    --border-radius-sm:    8px;
    --border-radius-pill:  999px;

    /* Font */
    --font-base: -apple-system, BlinkMacSystemFont, 'Segoe UI',
                 Roboto, Oxygen, Ubuntu, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

    /* Transitions */
    --transition: 0.18s ease;
}

/* ── Ghost Mode Override (Dark Theme) ─────────────────────────────────────── */
body.ghost-mode {
    --color-bg:            #0F172A;
    --color-surface:       #1E293B;
    --color-surface-2:     #0F172A;
    --color-border:        #334155;
    --color-text-primary:  #F8FAFC;
    --color-text-muted:    #94A3B8;
    --color-text-faint:    #64748B;
    --color-bot-bg:        #334155;
    --color-bot-text:      #F8FAFC;
    --color-info-bg:       #064E3B;
    --color-info-border:   #047857;
}

/* ── Base ─────────────────────────────────────────────────────────────────── */

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--color-bg);
    color: var(--color-text-primary);
    font-family: var(--font-base);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

/* ── App Shell ────────────────────────────────────────────────────────────── */

#app {
    display: flex;
    flex-direction: column;
    height: 100dvh;             /* dynamic viewport height — handles mobile chrome */
    max-width: 500px;           /* Adjusted to give it a mobile app feel like the mockup */
    margin: 0 auto;
    background: var(--color-bg);
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    position: relative;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
}

/* ── Header ───────────────────────────────────────────────────────────────── */

#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 20px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    z-index: 10;
}

#header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-circle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    overflow: hidden;
    background: #F3E8E2;
}

.avatar-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#header-logo {
    font-size: 22px;
    line-height: 1;
}

#header-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-primary);
}

#header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Ghost Mode Toggle (Original Slider Restored) */
#ghost-mode-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

#ghost-label {
    font-size: 12px;
    color: var(--color-text-muted);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--color-border);
    border-radius: var(--border-radius-pill);
    transition: var(--transition);
    cursor: pointer;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--color-primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

/* Ghost Button */
#ghost-btn {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color var(--transition), transform var(--transition);
    padding: 4px 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ghost-btn:hover  { color: var(--color-primary); }
#ghost-btn:active { transform: scale(0.9); }

body.ghost-active #ghost-btn {
    color: var(--color-primary);
}

/* Balance Pill */
#balance-pill {
    background: var(--color-primary-light);
    color: var(--color-primary);
    padding: 6px 14px;
    border-radius: var(--border-radius-pill);
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    transition: var(--transition);
}

/* ── Views / Chat Window ──────────────────────────────────────────────────── */

.view-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 20px calc(var(--nav-height) + var(--input-height) + 20px);
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

#chat-window {
    padding-bottom: 8px; /* For backwards compatibility if old HTML is used */
}

/* Thin scrollbar */
.view-container::-webkit-scrollbar { width: 4px; }
.view-container::-webkit-scrollbar-track { background: transparent; }
.view-container::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

#chat-messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 100%;
}

/* ── Message Rows ─────────────────────────────────────────────────────────── */

.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: msgIn 0.18s ease forwards;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.msg-row.bot  { justify-content: flex-start; }
.msg-row.user { justify-content: flex-end; }

/* Bot avatar */
.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-bottom: 2px;
    overflow: hidden;
}

.msg-row.user .msg-avatar { display: none; }

/* ── Bubble Base ──────────────────────────────────────────────────────────── */

.bubble {
    max-width: min(85%, 520px);
    padding: 14px 18px;
    border-radius: var(--border-radius);
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

/* Bot bubble variants */
.bubble.type-text,
.bubble.type-buttons {
    background: var(--color-bot-bg);
    color: var(--color-bot-text);
    border-bottom-left-radius: 4px;
}

.bubble.type-info {
    background: var(--color-info-bg);
    border: 1px solid var(--color-info-border);
    border-bottom-left-radius: 4px;
}

.bubble.type-error {
    background: var(--color-error-bg);
    border: 1px solid var(--color-error-border);
    border-bottom-left-radius: 4px;
}

.bubble.type-success {
    background: var(--color-success-bg);
    border: 1px solid var(--color-success-border);
    border-bottom-left-radius: 4px;
}

/* User bubble */
.bubble.from-user {
    background: var(--color-user-bg);
    color: var(--color-user-text);
    border-bottom-right-radius: 4px;
}

/* Timestamp */
.bubble-time {
    display: block;
    font-size: 11px;
    color: var(--color-text-faint);
    text-align: right;
    margin-top: 6px;
    opacity: 0.8;
}

/* Subtext */
.bubble-subtext {
    display: block;
    font-size: 13.5px;
    color: var(--color-text-muted);
    margin-top: 8px;
    white-space: pre-wrap;
    line-height: 1.5;
}

/* ── Markdown-style formatting inside bubbles ─────────────────────────────── */

.bubble strong  { font-weight: 700; }
.bubble em      { font-style: italic; }
.bubble code    {
    font-family: var(--font-mono);
    font-size: 13px;
    background: rgba(128,128,128,0.15);
    padding: 3px 6px;
    border-radius: 6px;
    user-select: all;      /* tap-to-select on mobile */
    letter-spacing: 0.03em;
}
.bubble a {
    color: #60A5FA;
    text-decoration: underline;
    word-break: break-all;
}

/* ── Inline Buttons (inside bubble) ──────────────────────────────────────── */

.bubble-buttons {
    display: flex;
    flex-direction: column; /* Modified from wrap to match Mockup vertical style */
    gap: 8px;
    margin-top: 12px;
}

.bubble-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-primary);
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-base);
    line-height: 1.4;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bot .bubble-btn { background: var(--color-surface); }

.bubble-btn:hover,
.bubble-btn:focus-visible {
    border-color: var(--color-primary);
    outline: none;
}

.bubble-btn:active {
    transform: scale(0.98);
}

/* Disable buttons once parent message is superseded */
.bubble-btn.used {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

/* ── Typing Indicator ─────────────────────────────────────────────────────── */

#typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--color-bot-bg);
    border-radius: var(--border-radius);
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin-top: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: typingBounce 1.2s ease infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0);    opacity: 0.4; }
    40%           { transform: translateY(-4px); opacity: 1;   }
}

/* ── Quick Bar (Original Restored - Hidden by default if Nav used) ───────── */

#quick-bar {
    display: flex;
    gap: 6px;
    padding: 6px 12px;
    background: var(--color-surface-2);
    border-top: 1px solid var(--color-border);
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
}

#quick-bar::-webkit-scrollbar { display: none; }

.quick-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    border-radius: var(--border-radius-pill);
    padding: 4px 12px;
    font-size: 12.5px;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition);
    font-family: var(--font-base);
    flex-shrink: 0;
}

.quick-btn:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary);
    color: white;
}

/* ── Services View (Mockup Styling) ───────────────────────────────────────── */

.services-hero { text-align: center; margin-bottom: 30px; }
.services-hero .hero-img { width: 100%; border-radius: 20px; margin-bottom: 20px; object-fit: cover; height: 420px; }
.services-hero h1 { font-size: 28px; color: var(--color-primary); margin-bottom: 10px; }
.hero-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 20px; padding: 24px; text-align: left; }
.hero-card h3 { font-size: 11px; letter-spacing: 1px; color: var(--color-text-muted); margin-bottom: 8px; }
.hero-card h2 { font-size: 18px; margin-bottom: 12px; }
.hero-card p { font-size: 14px; color: var(--color-text-muted); }

.services-list h4 { margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; }
.service-item { display: flex; gap: 16px; background: var(--color-surface); padding: 16px; border-radius: 16px; border: 1px solid var(--color-border); margin-bottom: 12px; align-items: center; }
.service-item .icon-box { width: 48px; height: 48px; background: var(--color-primary-light); color: var(--color-primary); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.service-item.disabled { opacity: 0.6; filter: grayscale(1); }
.badge { font-size: 10px; font-weight: 800; padding: 3px 8px; border-radius: 6px; }
.badge.active { background: #E0E7FF; color: #4338CA; }
.badge.live { background: #DCFCE7; color: #166534; }
.badge.soon { background: #F1F5F9; color: #475569; }

/* ── Wallet View (Mockup Styling) ─────────────────────────────────────────── */

.wallet-card { background: var(--color-primary); color: white; padding: 40px 20px; border-radius: 24px; text-align: center; margin-bottom: 30px; box-shadow: 0 10px 25px rgba(10, 94, 74, 0.2); }
.wallet-card p { font-size: 13px; opacity: 0.8; letter-spacing: 1px; }
.wallet-card h1 { font-size: 46px; margin: 10px 0 24px; font-weight: 700; }
.btn-topup { background: rgba(255,255,255,0.2); color: white; border: none; padding: 14px 28px; border-radius: var(--border-radius-pill); font-weight: 600; font-size: 15px; cursor: pointer; transition: background var(--transition); }
.btn-topup:hover { background: rgba(255,255,255,0.3); }

.wallet-section h4 { margin-bottom: 16px; }
.tx-row { display: flex; justify-content: space-between; padding: 16px 0; border-bottom: 1px solid var(--color-border); align-items: center; }
.tx-row strong { font-size: 15px; }
.tx-row small { color: var(--color-text-muted); font-size: 13px; }

/* ── History View (Mockup Styling) ────────────────────────────────────────── */

.history-header { margin-bottom: 24px; }
.history-header h2 { font-size: 24px; margin-bottom: 8px; }
.history-header p { color: var(--color-text-muted); font-size: 14px; }
.history-card { background: var(--color-surface); padding: 18px; border-radius: 16px; margin-bottom: 12px; border: 1px solid var(--color-border); }
.history-card.ghost { border: 1px dashed var(--color-primary); opacity: 0.7; }
.history-card .status { font-size: 11px; padding: 4px 8px; border-radius: 6px; font-weight: bold; }
.history-card .status.completed { background: #DCFCE7; color: #166534; }
.history-card .status.active { background: #FEF08A; color: #854D0E; }
.history-card .status.refunded { background: #F1F5F9; color: #475569; }

/* ── Input Area ───────────────────────────────────────────────────────────── */

#input-area {
    position: absolute;
    bottom: var(--nav-height);
    width: 100%;
    padding: 10px 20px;
    background: var(--color-bg);
    z-index: 5;
}

#input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 30px;
    padding: 8px 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    transition: border-color var(--transition);
}

#input-wrap:focus-within {
    border-color: var(--color-primary);
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--color-text-primary);
    font-family: var(--font-base);
    font-size: 16px; /* MOBILE ZOOM FIX: Must be 16px to prevent iOS Safari zoom */
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    scrollbar-width: none;
    padding: 6px 0;
}

#chat-input::placeholder { color: var(--color-text-faint); }

#voice-btn,
#send-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: 18px;
    padding: 8px;
    line-height: 1;
    transition: color var(--transition), transform var(--transition);
    flex-shrink: 0;
    border-radius: 6px;
}

#voice-btn:hover  { color: var(--color-accent); }

#send-btn {
    color: white; 
    background: var(--color-primary); 
    border-radius: 50%; 
    width: 38px; 
    height: 38px; 
    margin-left: 8px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
}

#send-btn:active  { transform: scale(0.9); }
#send-btn:disabled { opacity: 0.3; cursor: default; pointer-events: none; }

/* Voice status bar (Original Restored) */
#voice-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 0;
    font-size: 12px;
}

#voice-indicator { color: #F87171; }

#voice-stop {
    background: none;
    border: 1px solid #F87171;
    color: #F87171;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
}

/* ── Bottom Navigation (New Feature) ──────────────────────────────────────── */

#bottom-nav {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: var(--nav-height);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 10;
}

.nav-btn {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--color-text-muted);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    width: 64px;
    padding: 6px 0;
    transition: color var(--transition);
    line-height: 1;
}

.nav-btn.active {
    color: var(--color-primary);
    font-weight: 700;
}

.nav-btn i {
    font-size: 20px;
    display: block;
    transition: transform var(--transition);
}

.nav-btn span {
    display: block;
    font-size: 10.5px;
    line-height: 1;
}

.nav-btn.active i { transform: translateY(-2px); }

/* ── Utility Classes ──────────────────────────────────────────────────────── */

.hidden { display: none !important; }

/* Visually hidden but accessible */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
}

/* ── Date Dividers (Original Restored) ────────────────────────────────────── */

.date-divider {
    text-align: center;
    font-size: 11px;
    color: var(--color-text-faint);
    padding: 8px 0 4px;
    user-select: none;
}

/* ── Ghost Mode Active State (Original Restored + Appended Theme) ─────────── */

body.ghost-active #header-name::after {
    content: ' 👻';
    font-size: 13px;
}

body.ghost-active #balance-pill {
    opacity: 0.4;
    filter: blur(3px);
    pointer-events: none;
}

/* ── Scrolled-to-bottom Indicator (Original Restored) ────────────────────── */

#scroll-to-bottom {
    position: absolute;
    bottom: calc(var(--input-height) + var(--nav-height) + 12px);
    right: 16px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    transition: opacity var(--transition), transform var(--transition);
    z-index: 5;
}

#scroll-to-bottom.hidden { opacity: 0; pointer-events: none; }

/* ── Modals (New Feature for Ghost Mode Popup) ───────────────────────────── */

.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center; z-index: 100;
    animation: fadeIn 0.2s;
}
@keyframes fadeIn { from {opacity: 0} to {opacity: 1} }

.modal-content {
    background: var(--color-surface); padding: 28px; border-radius: 20px;
    width: 85%; max-width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.modal-content h3 { color: var(--color-text-primary); margin-bottom: 12px; font-size: 20px;}
.modal-content p { color: var(--color-text-muted); font-size: 14.5px; line-height: 1.5;}
.modal-content ul { margin: 16px 0 24px 20px; color: var(--color-text-muted); font-size: 14px; line-height: 1.6;}
.modal-content li { margin-bottom: 8px; }

#ghost-ack-btn {
    background: var(--color-primary); color: white; border: none; padding: 14px 20px;
    border-radius: 12px; width: 100%; font-size: 16px; font-weight: 600; cursor: pointer;
}

/* ── Responsive (Original Restored) ───────────────────────────────────────── */

@media (max-width: 480px) {
    .bubble { max-width: 88%; font-size: 14px; }
    #header-name { font-size: 16px; }
    #ghost-label { display: none; }
    .bubble-btn { font-size: 13.5px; padding: 10px 14px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}