/* ══════════════════════════════════════════════════════════════════════════════
   SpotLens AI — Flagship Grade Stylesheet
   Adaptive Clinical Theme • Safe Area Aware • Zero External Font Dependencies
   ══════════════════════════════════════════════════════════════════════════════ */

:root {
    --bg: #0B1118;
    --surface: #131C27;
    --surface-2: #1A2636;
    --surface-3: #233348;
    --border: rgba(255, 255, 255, 0.08);
    --border-subtle: rgba(255, 255, 255, 0.04);
    --border-focus: #38BDF8;

    --text: #F1F5F9;
    --text-muted: #94A3B8;
    --text-hint: #64748B;

    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-light: rgba(37, 99, 235, 0.15);

    --accent: #06B6D4;
    --accent-bright: #38BDF8;
    --accent-light: rgba(6, 182, 212, 0.12);

    --success: #10B981;
    --success-light: rgba(16, 185, 129, 0.12);

    --warning: #F59E0B;
    --warning-light: rgba(245, 158, 11, 0.12);

    --error: #F43F5E;
    --error-light: rgba(244, 63, 94, 0.12);

    --stars: #F59E0B;
    --stars-light: rgba(245, 158, 11, 0.15);

    --radius-sm: 8px;
    --radius: 16px;
    --radius-lg: 22px;
    --radius-full: 9999px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.55);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Telegram theme adaptive blend */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: var(--tg-theme-bg-color, #0B1118);
        --surface: var(--tg-theme-secondary-bg-color, #131C27);
        --text: var(--tg-theme-text-color, #F1F5F9);
        --text-hint: var(--tg-theme-hint-color, #64748B);
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    background-color: var(--bg);
    -webkit-text-size-adjust: 100%;
}

body {
    width: 100%;
    margin: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100dvh;
    background: var(--bg);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow-x: clip;
}

#page-container {
    flex: 1 0 auto;
    padding: 16px 16px calc(92px + env(safe-area-inset-bottom, 0px));
    width: 100%;
}

#page-container.chat-page {
    padding: 0 0 calc(64px + env(safe-area-inset-bottom, 0px));
    height: var(--tg-viewport-stable-height, 100dvh);
    max-height: var(--tg-viewport-stable-height, 100dvh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Typography & Headings ── */
h1, h2, h3, h4 {
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

p {
    color: var(--text);
}

a {
    color: var(--accent-bright);
    text-decoration: none;
}

/* ── SVG Icons ── */
.spot-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    vertical-align: middle;
    flex-shrink: 0;
}
.spot-icon-sm { width: 16px; height: 16px; }
.spot-icon-md { width: 22px; height: 22px; }
.spot-icon-lg { width: 28px; height: 28px; }
.spot-icon-xl { width: 36px; height: 36px; }
.spot-icon-hero { width: 48px; height: 48px; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.card-interactive {
    cursor: pointer;
}
.card-interactive:active {
    transform: scale(0.985);
    background: var(--surface-2);
}

.card-glass {
    background: rgba(19, 28, 39, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 20px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    width: 100%;
    user-select: none;
    line-height: 1.2;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #1D4ED8);
    color: #FFFFFF;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.btn-primary:active {
    background: #1D4ED8;
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), #0284C7);
    color: #FFFFFF;
    box-shadow: 0 4px 14px rgba(6, 182, 212, 0.35);
}

.btn-stars {
    background: linear-gradient(135deg, #F59E0B, #D97706);
    color: #FFFFFF;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.btn-outlined {
    background: transparent;
    color: var(--accent-bright);
    border: 1.5px solid rgba(56, 189, 248, 0.35);
}
.btn-outlined:active {
    background: var(--accent-light);
    border-color: var(--accent-bright);
}

.btn-text {
    background: transparent;
    color: var(--text-muted);
    padding: 8px 12px;
}
.btn-text:active {
    color: var(--text);
    background: var(--surface-2);
}

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

/* ── Bottom Navigation Bar ── */
.md-navbar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    max-width: 480px;
    width: 100%;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(19, 28, 39, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    z-index: 100;
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--text-hint);
    cursor: pointer;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    font-family: var(--font);
    min-width: 64px;
}

.nav-btn.active {
    color: var(--accent-bright);
}
.nav-btn.active .spot-icon {
    stroke-width: 2.4;
    filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.45));
}

.nav-btn:active {
    transform: scale(0.92);
}

.nav-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* ── Non-SaMD Clinical Disclaimer Banner ── */
.disclaimer-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(56, 189, 248, 0.25);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.45;
}
.disclaimer-banner .spot-icon {
    color: var(--accent-bright);
    margin-top: 2px;
}

/* ── Hero on Home ── */
.hero {
    text-align: center;
    padding: 12px 0 16px;
}
.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--accent-light);
    border: 1px solid rgba(6, 182, 212, 0.25);
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-bright);
    margin-bottom: 10px;
}
.hero-title {
    font-size: 26px;
    line-height: 1.25;
    font-weight: 800;
    margin-bottom: 6px;
}
.hero-sub {
    font-size: 14px;
    color: var(--text-muted);
}

/* ── Tips Banner (3 step macro capture) ── */
.capture-tips {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}
.tip-item {
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 8px;
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.tip-item .tip-num {
    font-size: 10px;
    font-weight: 700;
    color: var(--accent-bright);
    background: var(--surface-2);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Impulse Single Promo Card ── */
.single-promo {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.14), rgba(37, 99, 235, 0.08));
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(6, 182, 212, 0.1);
    transition: transform 0.15s ease;
}
.single-promo:active {
    transform: scale(0.985);
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.22), rgba(37, 99, 235, 0.14));
}
.single-promo-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.single-promo-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(56, 189, 248, 0.2);
    color: var(--accent-bright);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.single-promo-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}
.single-promo-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 1px;
}
.single-promo-arrow {
    color: var(--text-hint);
}

/* ── Photo Area ── */
.photo-area {
    width: 100%;
    margin-bottom: 14px;
}
.photo-placeholder {
    width: 100%;
    min-height: 240px;
    background: var(--surface-2);
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
    text-align: center;
}
.photo-placeholder:active {
    background: var(--surface-3);
    border-color: var(--accent-bright);
}
.photo-placeholder .ph-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--surface);
    color: var(--accent-bright);
    display: flex;
    align-items: center;
    justify-content: center;
}
.photo-placeholder .ph-title {
    font-size: 16px;
    font-weight: 600;
}
.photo-placeholder .ph-hint {
    font-size: 12px;
    color: var(--text-hint);
}

.photo-preview {
    width: 100%;
    max-height: 340px;
    object-fit: cover;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    display: block;
    cursor: pointer;
}

/* ── Form Inputs ── */
.field-group {
    margin-bottom: 12px;
}
.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.field-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s ease;
}
.field-input:focus {
    border-color: var(--accent-bright);
}
select.field-input {
    appearance: auto;
}
textarea.field-input {
    resize: vertical;
    min-height: 70px;
}

/* ── Result Badges & Status ── */
.result-header {
    text-align: center;
    padding: 20px 16px;
}
.condition-label {
    font-size: 26px;
    font-weight: 800;
    color: var(--accent-bright);
    letter-spacing: -0.01em;
}
.confidence-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 700;
    margin-top: 8px;
}
.conf-high {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.conf-medium {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
}
.conf-low {
    background: var(--error-light);
    color: var(--error);
    border: 1px solid rgba(244, 63, 94, 0.3);
}

.urgency-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 700;
}
.urgency-high {
    background: rgba(244, 63, 94, 0.15);
    color: var(--error);
    border: 1px solid rgba(244, 63, 94, 0.35);
}
.urgency-medium {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.35);
}
.urgency-low {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.35);
}

/* ── Premium Extended Sections & Teaser ── */
.premium-card {
    border-left: 3px solid var(--accent);
}
.premium-badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--accent-light);
    border: 1px solid rgba(6, 182, 212, 0.3);
    border-radius: var(--radius-full);
    color: var(--accent-bright);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.blur-teaser-wrap {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    margin: 10px 0 16px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.blur-teaser-row {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
}
.blur-teaser-text {
    font-size: 13px;
    filter: blur(5px);
    user-select: none;
    pointer-events: none;
    color: var(--text-muted);
}
.blur-teaser-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(rgba(11, 17, 24, 0.4), rgba(11, 17, 24, 0.85));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: #FFFFFF;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}

/* ── History List ── */
.history-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}
.history-item:active {
    transform: scale(0.985);
    background: var(--surface-2);
}
.history-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 10px;
    margin-right: 12px;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--border-subtle);
}
.history-info {
    flex: 1 1 auto;
    min-width: 0;
}
.history-label {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-date {
    font-size: 12px;
    color: var(--text-hint);
    margin-top: 2px;
}
.history-arrow {
    color: var(--text-hint);
    margin-left: 8px;
    flex-shrink: 0;
}

/* ── Plan Cards ── */
.plan-card {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    background: var(--surface);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}
.plan-card.selected {
    border-color: var(--accent-bright);
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.08), rgba(37, 99, 235, 0.04));
    box-shadow: 0 0 0 1px var(--accent-bright);
}
.plan-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}
.plan-name {
    font-size: 18px;
    font-weight: 700;
}
.plan-price-wrap {
    text-align: right;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 12px;
}
.plan-price-usd {
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
}
.plan-price-stars {
    font-size: 13px;
    font-weight: 600;
    color: var(--stars);
}
.plan-features {
    list-style: none;
    margin-top: 10px;
}
.plan-features li {
    padding: 3px 0;
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}
.plan-features li .spot-icon {
    color: var(--success);
}

/* ── Chat Page ── */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.chat-thread-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    background: var(--surface-2);
    border-radius: var(--radius-full);
    font-size: 12px;
    color: var(--text-muted);
}
.chat-list {
    flex: 1 1 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}
.chat-bubble {
    max-width: 82%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    position: relative;
}
.chat-bubble-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary), #1D4ED8);
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}
.chat-bubble-assistant {
    align-self: flex-start;
    background: var(--surface-2);
    color: var(--text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-subtle);
}
.chat-input-row {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.chat-input {
    flex: 1;
    padding: 12px 16px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
}
.chat-input:focus {
    border-color: var(--accent-bright);
}
.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    padding: 0;
    flex-shrink: 0;
}

/* ── Modals & Overlays ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}
.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 20px;
    text-align: center;
    max-width: 360px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalPop {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    max-width: 480px;
    width: 100%;
    background: var(--surface);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    border-top: 1px solid var(--border);
    padding: 20px 20px max(24px, env(safe-area-inset-bottom, 0px));
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    animation: sheetSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes sheetSlide {
    from { transform: translate(-50%, 100%); }
    to { transform: translate(-50%, 0); }
}

/* ── Spinner & Skeleton ── */
.spinner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 17, 24, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.spinner {
    width: 44px;
    height: 44px;
    border: 3.5px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent-bright);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.spinner-text {
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
}

.toast {
    position: fixed;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    z-index: 1500;
    box-shadow: var(--shadow);
    animation: toastIn 0.25s ease;
    white-space: nowrap;
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
}
@keyframes toastIn {
    from { opacity: 0; transform: translate(-50%, 16px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Utility Classes ── */
.text-center { text-align: center; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { display: flex; flex-direction: column; gap: 8px; }
.gap-12 { display: flex; flex-direction: column; gap: 12px; }
.flex-row { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.space-between { justify-content: space-between; }
.hidden { display: none !important; }
