/* styles.css */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #070d19;
    --card-bg: #0d1b2a;
    --card-bg-alt: #1b263b;
    --border: #243b55;
    --input-bg: #0b1325;
    --orange: #f97316;
    --purple: #14b8a6;
    --cyan: #22c55e;
    --text: #e2e8f0;
    --text-dim: #708090;
    --glow: 0 0 40px rgba(20, 184, 166, 0.25);
    --result-bg: linear-gradient(135deg, #0b1325, #1b263b);
    --font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="light"] {
    --bg: #f0f4f8;
    --card-bg: #ffffff;
    --card-bg-alt: #e2e8f0;
    --border: #cbd5e1;
    --input-bg: #f8fafc;
    --text: #0f172a;
    --text-dim: #64748b;
    --glow: 0 4px 20px rgba(13, 27, 42, 0.1);
    --result-bg: linear-gradient(135deg, #f8fafc, #e2e8f0);
}

[data-theme="dark"] {
    --bg: #070d19;
    --card-bg: #0d1b2a;
    --card-bg-alt: #1b263b;
    --border: #243b55;
    --input-bg: #0b1325;
    --text: #e2e8f0;
    --text-dim: #8da2bb;
    --glow: 0 0 40px rgba(20, 184, 166, 0.3);
    --result-bg: linear-gradient(135deg, #0b1325, #1b263b);
}

@keyframes borderColorPulse {
    0%, 100% { border-color: #f97316; }
    33% { border-color: #14b8a6; }
    66% { border-color: #22c55e; }
}

@keyframes chargeGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes pulseRing {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

@keyframes gentlePulse {
    0%, 100% { box-shadow: 0 4px 12px rgba(20, 184, 166, 0.3); }
    50% { box-shadow: 0 6px 24px rgba(249, 115, 22, 0.5), 0 0 0 8px rgba(249, 115, 22, 0.1); }
}

body {
    font-family: var(--font-family);
    background: radial-gradient(800px 600px at 20% -20%, rgba(20, 184, 166, 0.15) 0, transparent 50%),
        radial-gradient(600px 500px at 100% 120%, rgba(34, 197, 94, 0.15) 0, transparent 50%),
        var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    align-items: center;
    padding: 20px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transition: background .3s, color .3s;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.wrap {
    max-width: 480px;
    width: 100%;
    margin: auto;
}

.card {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 24px;
    padding: 28px;
    backdrop-filter: blur(16px);
    box-shadow: var(--glow);
    transition: all .3s;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 10px;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

h1, h2 {
    font-family: var(--font-family);
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(90deg, var(--orange), var(--purple), var(--cyan));
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0;
    animation: chargeGradient 3s ease infinite;
    letter-spacing: -0.02em;
    flex-shrink: 1;
    min-width: 0;
}

.header h2 { font-size: 1.3rem; }

.theme-btn,
.install-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--input-bg);
    border: 2px solid var(--border);
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .3s;
    flex-shrink: 0;
    position: relative;
}

.theme-btn:hover { border-color: var(--purple); transform: scale(1.05); }
.theme-btn:active { transform: scale(.95); }

.install-btn {
    background: linear-gradient(135deg, var(--orange), var(--purple), var(--cyan));
    background-size: 200% 200%;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    animation: chargeGradient 3s ease infinite, gentlePulse 2.5s ease-in-out infinite;
    box-shadow: 0 4px 12px rgba(20, 184, 166, 0.3);
    display: none;
}

.install-btn.visible { display: flex; }

.install-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(20, 184, 166, 0.45);
    animation: chargeGradient 3s ease infinite;
}
.install-btn:active { transform: scale(.9); }

.install-btn::after {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid rgba(249, 115, 22, 0.6);
    animation: pulseRing 2.2s ease-out infinite;
    pointer-events: none;
}

/* ---------- Install Bar ---------- */
.install-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--card-bg);
    border-top: 2px solid var(--border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    z-index: 2500;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 12px 16px;
    display: flex;
    justify-content: center;
}

/* ซ่อนแถบถาวรเมื่อมีคลาส hidden */
.install-bar.hidden {
    display: none !important;
}

.install-bar.visible {
    transform: translateY(0);
}

.install-bar-content {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 480px;
}

.install-bar-icon {
    font-size: 1.8rem;
}

.install-bar-text {
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
}

.install-bar-button {
    width: auto !important;
    padding: 10px 20px;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* ---------- iOS Tip Overlay ---------- */
.ios-tip-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 3000;
    padding-top: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s;
}
.ios-tip-overlay.show {
    opacity: 1;
    pointer-events: auto;
}
.ios-tip-box {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 20px;
    padding: 24px 20px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.ios-tip-box h3 {
    margin-bottom: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}
.ios-tip-box p {
    color: var(--text-dim);
    font-size: .9rem;
    line-height: 1.6;
    margin-bottom: 8px;
}
.ios-tip-box .tip-icon { font-size: 3rem; margin-bottom: 12px; }
.ios-tip-box .tip-highlight {
    display: inline-block;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 6px 14px;
    margin: 4px 2px;
    font-weight: 600;
    color: var(--text);
    font-size: .85rem;
}
.ios-tip-box .tip-arrow { font-size: 1.5rem; color: var(--orange); }

/* ---------- องค์ประกอบเดิม ---------- */
.subtitle {
    color: var(--text-dim);
    font-size: .9rem;
    margin-bottom: 24px;
    font-weight: 400;
}

label {
    display: block;
    color: var(--text-dim);
    font-size: .85rem;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: 0.01em;
}

select, input {
    width: 100%;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 500;
    transition: .2s;
    outline: none;
    font-family: var(--font-family);
}

select:focus, input:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.2);
}

select:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 18px; }

.btn {
    width: 100%;
    padding: 16px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 1.05rem;
    border: 0;
    cursor: pointer;
    transition: .15s;
    position: relative;
    overflow: hidden;
    font-family: var(--font-family);
    letter-spacing: 0.01em;
}

.btn:active { transform: scale(.97); }

.btn-primary {
    background: linear-gradient(90deg, var(--orange), var(--purple), var(--cyan));
    background-size: 200% 200%;
    color: #fff;
    box-shadow: 0 8px 24px rgba(20, 184, 166, 0.3);
    animation: chargeGradient 3s ease infinite;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) rotate(45deg); }
    100% { transform: translateX(100%) rotate(45deg); }
}

.btn-ghost {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-dim);
    margin-top: 10px;
    transition: all .3s;
    font-weight: 600;
}

.btn-ghost:hover {
    border-color: var(--purple);
    color: var(--purple);
}

.btn-download {
    background: linear-gradient(90deg, #10b981, #06b6d4);
    background-size: 200% 200%;
    color: #fff;
    font-weight: 600;
    font-size: .85rem;
    padding: 10px 20px;
    border-radius: 10px;
    border: 0;
    cursor: pointer;
    animation: chargeGradient 3s ease infinite;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all .2s;
}

.btn-download:hover { transform: scale(1.05); box-shadow: 0 4px 16px #10b98140; }
.btn-download:active { transform: scale(.95); }

.mode-switch {
    position: relative;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 4px;
    display: flex;
    margin-bottom: 24px;
}

.mode-btn {
    flex: 1;
    padding: 12px;
    border: 0;
    background: transparent;
    color: var(--text-dim);
    font-weight: 600;
    font-size: 1rem;
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    z-index: 2;
    transition: color .3s;
    font-family: var(--font-family);
}

.mode-btn.active { color: #fff; }

.mode-slider {
    position: absolute;
    top: 4px; left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background: linear-gradient(90deg, var(--orange), var(--purple), var(--cyan));
    background-size: 200% 200%;
    border-radius: 12px;
    transition: left .4s cubic-bezier(.4, 0, .2, 1);
    box-shadow: 0 4px 12px rgba(20, 184, 166, 0.3);
    animation: chargeGradient 3s ease infinite;
}

.mode-switch[data-mode="stop"] .mode-slider { left: calc(50% + 0px); }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.car-box {
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.08), rgba(20, 184, 166, 0.08), rgba(34, 197, 94, 0.08));
    border: 2px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    margin-bottom: 24px;
    transition: all .3s;
}

.car-title { color: var(--text-dim); font-size: .85rem; margin-bottom: 4px; font-weight: 500; }
.car-name { font-size: 1.2rem; font-weight: 700; margin-bottom: 6px; }
.car-rate { color: var(--purple); font-size: 1.1rem; font-weight: 600; }

.agreement-box {
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
    font-size: .85rem;
    line-height: 1.6;
    color: var(--text-dim);
    font-weight: 400;
}

.agreement-box h3 { color: var(--text); margin-bottom: 8px; font-size: 1rem; font-weight: 700; }

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.checkbox-group input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--orange); }
.checkbox-group label { margin-bottom: 0; cursor: pointer; font-weight: 500; }

.qr-section {
    text-align: center;
    margin-top: 24px;
    padding: 20px;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 16px;
}

.qr-section h3 { color: var(--text); margin-bottom: 16px; font-size: 1rem; font-weight: 700; }

.qr-code {
    background: white;
    padding: 16px;
    border-radius: 16px;
    display: inline-block;
    margin-bottom: 16px;
    position: relative;
    line-height: 0;
    max-width: 280px;
}

.qr-code img { display: block; width: 100%; height: auto; max-width: 250px; }

.qr-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 12px;
}

.support-info { color: var(--text-dim); font-size: .9rem; margin-top: 12px; font-weight: 400; }
.support-info a { color: var(--purple); text-decoration: none; font-weight: 500; }
.support-info a:hover { text-decoration: underline; }

.support-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
    padding: 12px;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    color: var(--text-dim);
    font-weight: 600;
    font-size: .9rem;
    transition: all .3s;
    user-select: none;
}

.support-toggle:hover { border-color: var(--purple); color: var(--purple); }
.support-toggle .arrow { transition: transform .3s; font-size: .8rem; }
.support-toggle.open .arrow { transform: rotate(180deg); }

.support-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height .5s cubic-bezier(.4, 0, .2, 1), opacity .4s, margin .4s;
    opacity: 0;
    margin-top: 0;
}

.support-content.open {
    max-height: 800px;
    opacity: 1;
    margin-top: 16px;
}

.result-container {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height .5s cubic-bezier(.4, 0, .2, 1), opacity .4s, margin .4s;
    margin-top: 0;
}

.result-container.has-result {
    max-height: 500px;
    opacity: 1;
    margin-top: 20px;
}

.result-card {
    background: var(--result-bg);
    border: 2px solid #14b8a6;
    border-radius: 20px;
    padding: 24px 20px;
    text-align: center;
    animation: borderColorPulse 3s ease-in-out infinite;
    position: relative;
    overflow: hidden;
}

.result-card > * { position: relative; z-index: 2; }

.result-secondary { color: var(--text-dim); font-size: .9rem; margin-bottom: 2px; font-weight: 500; }
.result-secondary.bottom { margin-top: 8px; margin-bottom: 0; }

.result-time-small { font-size: 1.1rem; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; }
.result-time-small.bottom { margin-top: 8px; margin-bottom: 0; }

.result-main-label { color: var(--text-dim); font-size: .85rem; margin-bottom: 6px; font-weight: 500; }

.result-time-main {
    font-size: 3rem;
    font-weight: 800;
    background: linear-gradient(90deg, var(--orange), var(--purple), var(--cyan));
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
}

.result-divider {
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--orange), var(--purple), var(--cyan), transparent);
    background-size: 200% 200%;
    margin: 16px 0;
    opacity: 0.8;
}

.result-duration { color: var(--purple); font-size: 1.1rem; font-weight: 600; }

.result-badge {
    display: inline-block;
    background: linear-gradient(90deg, rgba(249, 115, 22, 0.15), rgba(20, 184, 166, 0.15), rgba(34, 197, 94, 0.15));
    padding: 6px 16px;
    border-radius: 20px;
    font-size: .8rem;
    color: var(--orange);
    font-weight: 600;
    margin-top: 6px;
}

.hidden { display: none !important; }

.foot { text-align: center; color: var(--text-dim); font-size: .8rem; margin-top: 20px; font-weight: 400; }
.version-info { text-align: center; color: var(--text-dim); font-size: .75rem; margin-top: 8px; opacity: 0.7; font-weight: 400; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: linear-gradient(90deg, #10b981, #06b6d4);
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 600;
    font-size: .9rem;
    z-index: 2000;
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.25);
    font-family: var(--font-family);
    text-align: center;
    max-width: 90vw;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.hidden {
    display: none !important;
}

/* Support Modal Overlay */
#supportModal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
#supportModal.hidden { display: none; }

.support-modal-content {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 24px;
    padding: 28px;
    max-width: 420px;
    width: 90%;
    text-align: center;
}

/* Rate preview box in onboard */
#ratePreview {
    margin: 16px 0;
    padding: 14px;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 14px;
}
#ratePreview.hidden { display: none; }

/* ปุ่มปิดในแถบติดตั้ง */
.install-bar-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 6px;
    margin-left: 4px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}

.install-bar-close:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.1);
}