/* ══════════════════════════════════════
   THEME VARIABLES
   ══════════════════════════════════════ */
:root {
    --font-scale: 1;
}

[data-theme="dark"] {
    --bg-deep: #07090f;
    --bg-surface: #0d1117;
    --bg-card: #131a24;
    --accent: #d4a853;
    --accent-dark: #b8852e;
    --accent-soft: rgba(212, 168, 83, 0.15);
    --accent-border: rgba(212, 168, 83, 0.2);
    --accent-hover: rgba(212, 168, 83, 0.12);
    --accent-glow: rgba(212, 168, 83, 0.3);
    --text-primary: #e8eaf0;
    --text-secondary: #8b92a5;
    --text-muted: #555d73;
    --border: rgba(255,255,255,0.06);
    --header-bg: rgba(7, 9, 15, 0.6);
    --chat-header-bg: rgba(255,255,255,0.01);
    --input-bg: rgba(255,255,255,0.01);
    --shadow-heavy: rgba(0,0,0,0.5);
    --shadow-glow: rgba(212, 168, 83, 0.15);
    --scrollbar-thumb: rgba(255,255,255,0.08);
    --user-bubble-bg: linear-gradient(135deg, rgba(212,168,83,0.15), rgba(212,168,83,0.08));
    --status-color: #4ade80;
}

[data-theme="light"] {
    --bg-deep: #e8eef6;
    --bg-surface: #f0f4f9;
    --bg-card: #ffffff;
    --accent: #9a6e1e;
    --accent-dark: #7d5816;
    --accent-soft: rgba(154, 110, 30, 0.1);
    --accent-border: rgba(154, 110, 30, 0.25);
    --accent-hover: rgba(154, 110, 30, 0.15);
    --accent-glow: rgba(154, 110, 30, 0.15);
    --text-primary: #1a2233;
    --text-secondary: #4a5568;
    --text-muted: #8899aa;
    --border: rgba(0,0,0,0.08);
    --header-bg: rgba(232, 238, 246, 0.75);
    --chat-header-bg: rgba(0,0,0,0.02);
    --input-bg: rgba(0,0,0,0.02);
    --shadow-heavy: rgba(0,0,0,0.08);
    --shadow-glow: rgba(154, 110, 30, 0.08);
    --scrollbar-thumb: rgba(0,0,0,0.1);
    --user-bubble-bg: linear-gradient(135deg, rgba(154,110,30,0.12), rgba(154,110,30,0.06));
    --status-color: #22a65a;
}

/* ══════════════════════════════════════
   BASE
   ══════════════════════════════════════ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }

body {
    font-family: 'DM Sans', sans-serif;
    font-size: calc(1rem * var(--font-scale));
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;            /* Dynamic viewport height — huomioi mobiilinavigaation */
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
    transition: background 0.5s, color 0.4s;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ══════════════════════════════════════
   DARK — STARFIELD
   ══════════════════════════════════════ */
.starfield {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    transition: opacity 0.6s;
}
[data-theme="light"] .starfield { opacity: 0; }

.star {
    position: absolute;
    width: 2px; height: 2px;
    background: #fff;
    border-radius: 50%;
    animation: twinkle var(--dur) ease-in-out infinite alternate;
}
@keyframes twinkle {
    0% { opacity: 0.1; transform: scale(0.8); }
    100% { opacity: var(--peak); transform: scale(1.2); }
}

.glow-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(100px);
    pointer-events: none;
    z-index: 0;
    transition: opacity 0.6s;
}
.glow-orb.gold {
    width: 500px; height: 500px;
    background: radial-gradient(circle, rgba(212,168,83,0.08), transparent 70%);
    top: -10%; right: -5%;
    animation: orbFloat 20s ease-in-out infinite alternate;
}
.glow-orb.blue {
    width: 400px; height: 400px;
    background: radial-gradient(circle, rgba(74,142,255,0.06), transparent 70%);
    bottom: -5%; left: -5%;
    animation: orbFloat 25s ease-in-out infinite alternate-reverse;
}
[data-theme="light"] .glow-orb { opacity: 0; }
@keyframes orbFloat {
    0% { transform: translate(0, 0); }
    100% { transform: translate(30px, -40px); }
}

/* ══════════════════════════════════════
   LIGHT — SKY & CLOUDS
   ══════════════════════════════════════ */
.sky-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.6s;
    background: linear-gradient(180deg, #b5d4f1 0%, #d6e6f5 35%, #e8eff7 70%, #f0f4f9 100%);
}
[data-theme="light"] .sky-bg { opacity: 1; }

.cloud {
    position: absolute;
    background: rgba(255,255,255,0.85);
    border-radius: 50%;
}
.cloud::before, .cloud::after {
    content: '';
    position: absolute;
    background: rgba(255,255,255,0.85);
    border-radius: 50%;
}

.cloud-1 {
    width: 200px; height: 55px;
    top: 6%; left: -5%;
    animation: cloudDrift 65s linear infinite;
    opacity: 0.7;
}
.cloud-1::before { width: 100px; height: 75px; top: -40px; left: 35px; }
.cloud-1::after { width: 120px; height: 65px; top: -28px; left: 85px; }

.cloud-2 {
    width: 280px; height: 65px;
    top: 15%; left: -18%;
    animation: cloudDrift 85s linear infinite;
    animation-delay: -25s;
    opacity: 0.6;
}
.cloud-2::before { width: 140px; height: 90px; top: -50px; left: 55px; }
.cloud-2::after { width: 110px; height: 60px; top: -22px; left: 155px; }

.cloud-3 {
    width: 150px; height: 40px;
    top: 35%; left: -8%;
    animation: cloudDrift 72s linear infinite;
    animation-delay: -45s;
    opacity: 0.45;
}
.cloud-3::before { width: 80px; height: 55px; top: -30px; left: 22px; }
.cloud-3::after { width: 85px; height: 45px; top: -18px; left: 68px; }

.cloud-4 {
    width: 240px; height: 50px;
    top: 58%; left: -14%;
    animation: cloudDrift 95s linear infinite;
    animation-delay: -60s;
    opacity: 0.35;
}
.cloud-4::before { width: 120px; height: 70px; top: -42px; left: 45px; }
.cloud-4::after { width: 95px; height: 52px; top: -18px; left: 130px; }

.cloud-5 {
    width: 170px; height: 42px;
    top: 78%; left: -10%;
    animation: cloudDrift 78s linear infinite;
    animation-delay: -35s;
    opacity: 0.3;
}
.cloud-5::before { width: 85px; height: 58px; top: -34px; left: 28px; }
.cloud-5::after { width: 95px; height: 48px; top: -20px; left: 78px; }

@keyframes cloudDrift {
    from { transform: translateX(0); }
    to { transform: translateX(calc(100vw + 350px)); }
}

/* ══════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════ */
.page-wrapper {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ══════════════════════════════════════
   HEADER
   ══════════════════════════════════════ */
header {
    padding: 0.85rem 2rem;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    background: var(--header-bg);
    position: sticky;
    top: 0;
    z-index: 10;
    transition: background 0.5s, border-color 0.4s;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.logo-img {
    width: 400px;
    max-width: 90%;
    height: auto;
    aspect-ratio: 819 / 438;       /* Lukitsee kuvasuhteen — Safari-tuki */
    object-fit: contain;            /* Estää venymisen */
    -webkit-object-fit: contain;
    transition: opacity 0.4s ease;
}

/*
 * Safari-yhteensopiva teeman mukainen logon vaihto:
 * Käytetään position + opacity + visibility -tekniikkaa
 * display:none/block -vaihdon sijaan, koska Safari
 * ei laske kuvasuhteita oikein piilotetuille kuville.
 */
.logo-area .logo {
    display: inline-flex;
    justify-content: center;
    position: relative;
}

.logo-dark, .logo-light {
    /* Molemmat logot samassa tilassa, päällekkäin */
}

.logo-dark {
    opacity: 1;
    visibility: visible;
}

.logo-light {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;                   /* Perii kontainerin leveyden */
    opacity: 0;
    visibility: hidden;
}

[data-theme="light"] .logo-dark {
    opacity: 0;
    visibility: hidden;
}

[data-theme="light"] .logo-light {
    opacity: 1;
    visibility: visible;
}

/* Logo area — centered above hero */
.logo-area {
    text-align: center;
    padding-top: 3rem;
    padding-bottom: 0.5rem;
    animation: fadeUp 0.6s ease-out both;
    width: 100%;
}

.logo-area .logo-img {
    width: 400px;
}

.header-badge {
    font-size: calc(0.7rem * var(--font-scale));
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 100px;
    transition: color 0.4s, border-color 0.4s;
}

/* ══════════════════════════════════════
   ACCESSIBILITY TOOLBAR
   ══════════════════════════════════════ */
.a11y-toolbar {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

.a11y-btn {
    width: 32px; height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(0.75rem * var(--font-scale));
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    transition: all 0.2s;
    padding: 0;
    line-height: 1;
}

.a11y-btn:hover {
    border-color: var(--accent-border);
    color: var(--accent);
    background: var(--accent-soft);
}

.a11y-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.a11y-btn svg { width: 16px; height: 16px; }

.a11y-divider {
    width: 1px; height: 20px;
    background: var(--border);
    margin: 0 0.15rem;
}

/* ══════════════════════════════════════
   MAIN
   ══════════════════════════════════════ */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ══════════════════════════════════════
   HERO
   ══════════════════════════════════════ */
.hero {
    text-align: center;
    padding: 1.5rem 0 2rem;
    max-width: 600px;
    animation: fadeUp 0.8s ease-out both;
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.hero h1 {
    font-family: 'Playfair Display', serif;
    font-size: clamp(calc(1.6rem * var(--font-scale)), 4vw, calc(2.4rem * var(--font-scale)));
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: 0.75rem;
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    color: var(--text-secondary);
    font-size: calc(0.95rem * var(--font-scale));
    line-height: 1.6;
    max-width: 480px;
    margin: 0 auto;
    transition: color 0.4s;
}

/* ══════════════════════════════════════
   CHAT
   ══════════════════════════════════════ */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 2rem;
    min-height: 420px;
    max-height: 60vh;
    max-width: 700px;
    width: 100%;
    animation: fadeUp 0.8s 0.2s ease-out both;
    box-shadow:
        0 0 0 1px rgba(255,255,255,0.03),
        0 20px 60px -15px var(--shadow-heavy),
        0 0 80px -20px var(--shadow-glow);
    transition: background 0.5s, border-color 0.4s, box-shadow 0.4s;
}

.chat-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--chat-header-bg);
    transition: background 0.4s, border-color 0.4s;
}

.agent-avatar {
    width: 34px; height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(0.85rem * var(--font-scale));
    box-shadow: 0 0 20px var(--accent-glow);
    color: #fff;
}

.agent-info .agent-name {
    font-weight: 600;
    font-size: calc(0.85rem * var(--font-scale));
    color: var(--text-primary);
    transition: color 0.4s;
}

.agent-info .agent-status {
    font-size: calc(0.7rem * var(--font-scale));
    color: var(--status-color);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.agent-info .agent-status::before {
    content: '';
    width: 6px; height: 6px;
    background: var(--status-color);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Messages ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

.message {
    display: flex;
    gap: 0.65rem;
    max-width: 85%;
    animation: msgIn 0.35s ease-out both;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.agent { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
    width: 28px; height: 28px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(0.7rem * var(--font-scale));
    margin-top: 2px;
}
.message.agent .msg-avatar {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
}
.message.user .msg-avatar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.msg-bubble {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: calc(0.875rem * var(--font-scale));
    line-height: 1.6;
    transition: background 0.4s, border-color 0.4s, color 0.4s;
}
.message.agent .msg-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

/* ── Markdown-muotoilut viestikuplissa ── */
.msg-bubble strong { font-weight: 700; }
.msg-bubble em { font-style: italic; }

.msg-bubble code {
    font-family: 'SFMono-Regular', 'Menlo', monospace;
    font-size: 0.85em;
    background: rgba(128,128,128,0.15);
    padding: 0.15em 0.4em;
    border-radius: 4px;
}

.msg-bubble pre {
    margin: 0.5em 0;
    padding: 0.75em;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    overflow-x: auto;
}

[data-theme="light"] .msg-bubble pre {
    background: rgba(0,0,0,0.05);
}

.msg-bubble pre code {
    background: none;
    padding: 0;
    font-size: 0.82em;
}

.msg-bubble ul {
    margin: 0.4em 0;
    padding-left: 1.3em;
}

.msg-bubble li {
    margin-bottom: 0.2em;
}

.msg-bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.msg-bubble a:hover {
    opacity: 0.8;
}
.message.user .msg-bubble {
    background: var(--user-bubble-bg);
    border: 1px solid var(--accent-border);
    color: var(--text-primary);
    border-bottom-right-radius: 4px;
}

/* ── Typing indicator ── */
.typing-indicator {
    display: none;
    gap: 4px;
    padding: 0.75rem 1rem;
    align-items: center;
}
.typing-indicator.visible { display: flex; }

.typing-dot {
    width: 6px; height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input ── */
.chat-input-area {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--input-bg);
    transition: background 0.4s, border-color 0.4s;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.4s;
}
.input-wrapper:focus-within {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: calc(0.875rem * var(--font-scale));
    outline: none;
    line-height: 1.5;
}
.chat-input::placeholder { color: var(--text-muted); }

.send-btn {
    width: 36px; height: 36px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.2s;
}
.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--accent-glow);
}
.send-btn:active { transform: scale(0.95); }
.send-btn svg { width: 16px; height: 16px; }
.send-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ══════════════════════════════════════
   FOOTER
   ══════════════════════════════════════ */
footer {
    text-align: center;
    padding: 1.25rem;
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
    color: var(--text-muted);
    font-size: calc(0.7rem * var(--font-scale));
    letter-spacing: 0.04em;
    border-top: 1px solid var(--border);
    transition: color 0.4s, border-color 0.4s;
}

/* ══════════════════════════════════════
   QUICK ACTIONS
   ══════════════════════════════════════ */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.quick-btn {
    font-family: 'DM Sans', sans-serif;
    font-size: calc(0.78rem * var(--font-scale));
    padding: 0.45rem 0.85rem;
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    color: var(--accent);
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.quick-btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
}
.quick-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ══════════════════════════════════════
   SCROLLBAR
   ══════════════════════════════════════ */
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 2px;
}

/* ══════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════ */

/* Tablet */
@media (max-width: 768px) {
    .logo-area .logo-img { width: 300px; }
    .hero p { max-width: 100%; }
}

/* Mobile */
@media (max-width: 600px) {
    header { padding: 0.75rem 1rem; }

    .header-badge { display: none; }

    .header-inner { justify-content: flex-end; }

    .a11y-toolbar {
        position: static;
        transform: none;
    }

    .a11y-btn {
        width: 36px; height: 36px;  /* Isompi touch target */
    }

    .logo-area {
        padding-top: 1.5rem;
        padding-bottom: 0.25rem;
    }

    .logo-area .logo-img { width: 90%; }

    .hero {
        padding: 0.75rem 0 1.25rem;
    }

    .hero h1 {
        font-size: calc(1.4rem * var(--font-scale));
    }

    .chat-container {
        min-height: 300px;
        max-height: none;          /* Ei max-height rajoitusta */
        flex: 1;                   /* Täytä käytettävissä oleva tila */
        border-radius: 12px;
        margin-bottom: 1rem;
    }

    .chat-messages {
        padding: 1rem;
        gap: 0.75rem;
    }

    .message {
        max-width: 92%;            /* Leveämmät kuplat mobiililla */
    }

    .msg-bubble {
        padding: 0.65rem 0.85rem;
    }

    /* iOS zoomaus-esto: fontti vähintään 16px */
    .chat-input {
        font-size: max(16px, calc(0.875rem * var(--font-scale)));
    }

    .input-wrapper {
        padding: 0.4rem 0.4rem 0.4rem 0.75rem;
    }

    .send-btn {
        width: 40px; height: 40px; /* Isompi touch target */
    }

    /* Pikapainikkeet: salli rivitys */
    .quick-actions {
        gap: 0.4rem;
    }

    .quick-btn {
        white-space: normal;       /* Salli rivitys kapealla näytöllä */
        text-align: center;
        padding: 0.5rem 0.75rem;   /* Isompi touch target */
        font-size: calc(0.75rem * var(--font-scale));
    }

    main {
        padding: 0 1rem;
    }

    footer {
        padding: 1rem;
    }
}

/* Erittäin kapea näyttö */
@media (max-width: 360px) {
    .logo-area .logo-img { width: 90%; }

    .hero h1 {
        font-size: calc(1.2rem * var(--font-scale));
    }

    .hero p {
        font-size: calc(0.85rem * var(--font-scale));
    }

    .a11y-btn {
        width: 32px; height: 32px;
    }
}

/* Matalat näytöt / näppäimistö auki */
@media (max-height: 600px) {
    .logo-area { padding-top: 1rem; }
    .logo-area .logo-img { width: 200px; }
    .hero { padding: 0.5rem 0 0.75rem; }
    .hero p { display: none; }     /* Piilota kuvaus kun tila on vähissä */
    .chat-container { min-height: 200px; }
}

/* ══════════════════════════════════════
   SKIP LINK
   ══════════════════════════════════════ */
.skip-link {
    position: absolute;
    top: -100%; left: 0;
    background: var(--accent);
    color: #fff;
    padding: 0.75rem 1.5rem;
    z-index: 100;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 8px 0;
}
.skip-link:focus { top: 0; }
