/* ============================================================
 *  TUULILASIKORJAAMO — CHATBOT TYYLIT
 *  iOS-tyylinen widget. Värit ja koot määritellään :root-osassa.
 *  Vaihda brändiväri muuttamalla --ios-blue (tai lisää uusi muuttuja).
 * ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&family=Orbitron:wght@400;700;900&display=swap');

:root {
  --ios-blue:      #007aff;
  --ios-green:     #34c759;
  --ios-orange:    #ff9500;
  --ios-red:       #ff3b30;
  --ios-indigo:    #5856d6;
  --sci-fi-cyan:   #00f3ff;
  --sci-fi-purp:   #bc00ff;
  --modern-white:  #ffffff;
  --modern-text:   #1c1c1e;

  /* Fontistackit kootusti tähän — käytetään muuttujina että fallback toimii
     myös adblocker-selaimissa (Brave, Vivaldi, jne.) jotka voivat blokata
     Google Fontsin. Jos Montserrat/Orbitron eivät lataudu, järjestelmäfontit
     ottavat paikan automaattisesti ilman layout-rikkoa. */
  --font-body:    'Montserrat', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-display: 'Orbitron',   Impact, 'Arial Black', 'Helvetica Neue', system-ui, sans-serif;
}

/* ── LAUNCHER ── */
#sm-launcher-wrapper {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 999999;
  font-family: var(--font-body);
}

#sm-shout {
  position: absolute;
  top: -42px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ios-blue);
  color: white;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 6px 14px;
  border-radius: 20px;
  box-shadow: 0 4px 15px rgba(0, 122, 255, 0.3);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* Piilota kupla kun chat-ikkuna on auki — kaikissa kokoluokissa.
   :has-selektoria tuetaan kaikissa moderneissa selaimissa (2023+). */
body:has(#sm-window.sm-open) #sm-shout {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
}

/* Vanha mobiilin launcher-piilotus poistettu — launcher morfautuu nyt
   X-napiksi (Option C), joten se on hyödyllinen myös mobiilissa. */

#sm-launcher {
  width: 100px;
  height: auto;
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: block;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: none;
  transition: transform 0.25s ease;
}

#sm-launcher:focus { outline: none; }
#sm-launcher:hover  { transform: scale(1.06); }
#sm-launcher:active { transform: scale(0.95); }

#sm-launcher img {
  width: 100%;
  height: auto;
  display: block;
  background: transparent;
  border: none;
  pointer-events: none;
  user-select: none;
}

/* ── IPHONE FRAME ── */
#sm-window {
  position: fixed;
  bottom: 110px;
  right: 30px;
  width: 360px;
  height: 720px;
  max-width: 90vw;
  max-height: 85vh;
  background: #000;
  border: 12px solid #1c1c1c;
  border-radius: 50px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.4);
  z-index: 999998;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(30px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-family: var(--font-body);
}

#sm-window.sm-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── BOOT-NÄYTÖN SCI-FI ANIMAATIO ── */
#boot-screen {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: #000;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.5s;
  overflow: hidden;
}
#boot-screen.active { visibility: visible; opacity: 1; }

.boot-bg {
  position: absolute;
  top: 0; left: 0; width: 200%; height: 200%;
  background-image:
    linear-gradient(rgba(0, 243, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 243, 255, 0.05) 1px, transparent 1px);
  background-size: 20px 20px;
  transform: translate(-25%, -25%) rotate(15deg);
  animation: bg-move 10s linear infinite;
  opacity: 0;
}
#boot-screen.active .boot-bg { opacity: 1; }

.boot-logo-container {
  position: relative;
  overflow: hidden;
  padding: 10px;
  margin-bottom: 20px;
}

.boot-logo {
  font-family: var(--font-display);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-shadow: 0 0 10px var(--sci-fi-cyan);
  transform: translateY(100%);
  opacity: 0;
  text-align: center;
  padding: 0 12px;
  max-width: 100%;
  white-space: nowrap;
}
#boot-screen.active .boot-logo {
  animation:
    text-reveal 0.6s 0.3s ease-out forwards,
    mega-glitch 2s infinite;
}

.boot-status {
  font-family: var(--font-body);
  color: rgba(255,255,255,0.7);
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 10px;
  opacity: 0;
}
#boot-screen.active .boot-status { animation: status-fade 1s 1.2s ease-out forwards; }

/* Yksittäiset kirjaimet viimeisessä boot-viestissä — pomppivat esiin */
.boot-letter {
  display: inline-block;
  opacity: 0;
  animation: boot-letter-in 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes boot-letter-in {
  0%   { opacity: 0; transform: translateY(14px) scale(0.6); filter: blur(2px); }
  60%  { opacity: 1; transform: translateY(-2px) scale(1.1); filter: blur(0); }
  100% { opacity: 1; transform: translateY(0)    scale(1); }
}

.boot-loader {
  width: 180px;
  height: 3px;
  background: rgba(255,255,255,0.05);
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  opacity: 0;
}
#boot-screen.active .boot-loader { animation: status-fade 0.5s 1.5s ease-out forwards; }

.boot-loader::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, var(--sci-fi-cyan), transparent);
  animation: load-fast 2s 1.5s ease-out forwards;
}

/* ── KEYFRAMES ── */
@keyframes bg-move      { 0% { transform: translate(-25%, -25%) rotate(15deg); } 100% { transform: translate(-20%, -20%) rotate(15deg); } }
@keyframes text-reveal  { 0% { transform: translateY(100%); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }
@keyframes status-fade  { 0% { opacity: 0; transform: translateY(5px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes load-fast    { 0% { left: -100%; } 50% { left: 0%; } 100% { left: 100%; } }

@keyframes mega-glitch {
  0%   { transform: translate(0); text-shadow: 0 0 10px var(--sci-fi-cyan); }
  10%  { transform: translate(-3px, 3px); text-shadow: 3px 0 red, -3px 0 blue; color: #eee; }
  12%  { transform: translate(3px, -3px); text-shadow: -3px 0 var(--sci-fi-purp), 3px 0 green; }
  14%  { transform: translate(0); text-shadow: 0 0 20px var(--sci-fi-cyan); color: #fff; }
  18%  { transform: translate(-1px, 1px); scale: 1.02; }
  20%  { transform: translate(1px, -1px); scale: 1; opacity: 0.8; }
  22%  { transform: translate(0); opacity: 1; }
  80%  { transform: translate(0); }
  82%  { transform: translate(5px, 0); color: #ccc; }
  84%  { transform: translate(-5px, 0); color: #fff; }
  86%  { transform: translate(0); }
  100% { transform: translate(0); }
}

/* ── STATUS BAR & DYNAMIC ISLAND ── */
.status-bar {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 25px;
  color: white;
  font-size: 13px;
  font-weight: 600;
  z-index: 300;
}

/* ── LAUNCHER MORFAUTUU X-NAPIKSI KUN IKKUNA ON AUKI ──
   Korvaa aikaisemman piilotuksen: nyt nappi pysyy näkyvissä toisena
   sulkukeinona ja vaihtaa visuaalisen ilmeensä pyöreäksi sulje-napiksi. */
#sm-launcher {
  position: relative;
}
body:has(#sm-window.sm-open) #sm-launcher {
  width: 56px !important;
  height: 56px !important;
  background: #1c1c1e;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0,0,0,0.3);
  transition: width 0.3s ease, height 0.3s ease, background 0.3s ease, border-radius 0.3s ease;
  pointer-events: all;
  opacity: 1;
  transform: scale(1);
}
body:has(#sm-window.sm-open) #sm-launcher img {
  opacity: 0;
  transition: opacity 0.15s ease;
}
body:has(#sm-window.sm-open) #sm-launcher::after {
  content: '×';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  color: #fff;
  font-size: 36px;
  font-weight: 200;
  line-height: 1;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.dynamic-island {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 110px;
  max-width: 75%;
  height: 28px;
  padding: 0 16px;
  background: black;
  border-radius: 20px;
  z-index: 301;
  display: flex;
  justify-content: center;
  align-items: center;
  color: rgba(255, 255, 255, 0.9);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── KOTINÄKYMÄ ── */
#view-home {
  flex: 1;
  background: linear-gradient(160deg, #0f0c29, #302b63, #24243e);
  padding: 60px 20px 20px;
  display: flex;
  flex-direction: column;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px 15px;
}

.section-title {
  grid-column: span 4;
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 5px;
  margin-top: 15px;
}

.app-icon-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  transition: transform 0.2s;
}

.app-icon {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  margin-bottom: 6px;
  position: relative;
}

.app-icon-wrapper:active { transform: scale(0.9); }
.app-icon-wrapper:active .app-icon::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: 14px;
  border: 2px solid var(--sci-fi-cyan);
  animation: icon-ping 0.4s ease-out forwards;
}

@keyframes icon-ping { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }

.label {
  color: white;
  font-size: 10px;
  font-weight: 500;
  text-align: center;
  line-height: 1.3;
  min-height: 26px;       /* 2 riviä → ruudukko pysyy linjassa */
  word-break: break-word;
}

.bg-blue   { background: linear-gradient(180deg, #5ac8fa, #007aff); }
.bg-green  { background: linear-gradient(180deg, #5ae485, #34c759); }
.bg-orange { background: linear-gradient(180deg, #ffb347, #ff9500); }
.bg-indigo { background: linear-gradient(180deg, #a2a2ff, #5856d6); }
.bg-red    { background: linear-gradient(180deg, #ff7a73, #ff3b30); }
.bg-white  { background: #ffffff; }

/* ── ETUSIVUN VARAA AIKA -CTA ──
   Kontti: .home-cta (otsikko + alaotsikko + napit)
   Napit:  .home-cta-btn (yksi tai useampi rinnakkain)
*/
.home-cta {
  margin: 8px 14px 8px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  text-align: center;
  color: #fff;
  font-family: inherit;
}

.home-cta .cta-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.home-cta .cta-foot {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 2px;
  margin-bottom: 10px;
}

.cta-actions {
  display: flex;
  gap: 8px;
}

.home-cta-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  border-radius: 12px;
  text-decoration: none;
  color: #fff;
  font-family: inherit;
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
  min-height: 56px;
}
.home-cta-btn:hover  { transform: translateY(-1px); filter: brightness(1.08); }
.home-cta-btn:active { transform: translateY(0) scale(0.97); }

.home-cta-btn .cta-btn-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.home-cta-btn .cta-btn-icon  { font-size: 16px; }
.home-cta-btn .cta-btn-label {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.home-cta-btn .cta-btn-sub {
  font-size: 11px;
  opacity: 0.95;
  margin-top: 2px;
  font-weight: 600;
}

/* Toimintotyypin värit */
.cta-call  { background: linear-gradient(135deg, #00c853, #009e42); box-shadow: 0 4px 14px rgba(0,200,83,0.35); }
.cta-email { background: linear-gradient(135deg, #5ac8fa, #007aff); box-shadow: 0 4px 14px rgba(0,122,255,0.35); }
.cta-url   { background: linear-gradient(135deg, #ffb347, #ff9500); box-shadow: 0 4px 14px rgba(255,149,0,0.35); }

/* ── CHAT-NÄKYMÄ ── */
#view-chat {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: var(--modern-white);
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  z-index: 200;
}
#view-chat.active { transform: translateY(0); }

/* Chat-header on nyt pelkkä tilanvaraaja status-barille (back-btn siirtynyt
   footeriin). Pidetään päälläkin pieni semitransparenttinen blur-tausta,
   joka istuu iOS-tunnelmaan. */
.chat-header {
  padding: 50px 20px 0;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  flex-shrink: 0;
}

/* Takaisin-nappi sijaitsee nyt chat-footerissa (alalaita), ei enää headerissa */
.back-btn {
  background: rgba(0, 122, 255, 0.08);
  border: none;
  color: var(--ios-blue);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border-radius: 12px;
  font-family: inherit;
}
.back-btn:hover  { background: rgba(0, 122, 255, 0.14); }
.back-btn:active { transform: scale(0.96); }

/* ── CHAT-FOOTER ──
   Alalaidan toimintoalue: takaisin-painike vasemmalla + home-bar keskellä.
   Koko footer on klikattavissa (id="chat-close"), joten vahingossa-osumat
   homen lähellä kelpaavat myös. */
.chat-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 10px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0,0,0,0.06);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
}
.chat-footer .home-bar {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* D: Laajennettu kosketusalue — näkymätön ::before lisää ~10–16 px ympärille
   joten mobiilissa on helpompi osua nappiin vahingoittamatta visuaalia. */
/* Laajennettu kosketusalue takaisin-napille — toimii myös footerissa,
   helpottaa osumista mobiilissa (näkymätön ::before extends hit zone). */
.back-btn { position: relative; }
.back-btn::before {
  content: '';
  position: absolute;
  top: -8px;
  right: -12px;
  bottom: -8px;
  left: -12px;
}

.chat-header-title {
  font-weight: 700;
  font-size: 12px;
  color: var(--modern-text);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  max-width: 60%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#chat-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.msg       { padding: 12px 16px; border-radius: 18px; font-size: 14px; max-width: 85%; }
.msg-bot   { background: #e9e9eb; color: black; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg-user  { background: var(--ios-blue); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }

/* ── VALINTAPAINIKKEET (haarautuva keskustelu) ──
   Renderöityy bot-puolelle (vasemmalla) vastauksen alle. Klikkaus
   avaa seuraavan vastauksen ja painikkeet katoavat. */
.msg-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: flex-start;
  max-width: 85%;
  animation: msgIn 0.3s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.choice-btn {
  background: white;
  border: 1.5px solid var(--ios-blue);
  color: var(--ios-blue);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 18px;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  display: inline-block;
  transition: background 0.15s, color 0.15s, box-shadow 0.2s, transform 0.1s;
}
.choice-btn:hover  { background: var(--ios-blue); color: white; }
.choice-btn:active { transform: scale(0.97); }

/* Primary-tyyli: suora toiminto (tel/mailto/https), erottuu täytetyllä taustalla */
.choice-btn.primary {
  background: linear-gradient(135deg, var(--ios-blue), #0062cc);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(0, 122, 255, 0.35);
  font-weight: 700;
}
.choice-btn.primary:hover {
  box-shadow: 0 6px 20px rgba(0, 122, 255, 0.5);
  transform: translateY(-1px);
}
.choice-btn.primary:active { transform: translateY(0) scale(0.97); }

/* ── HOME INDICATOR ── */
.home-bar-area {
  width: 100%;
  padding: 10px 0;
  cursor: pointer;
  display: flex;
  justify-content: center;
}
.home-bar      { height: 5px; width: 120px; background: rgba(255,255,255,0.3); border-radius: 10px; }
.home-bar-dark { background: rgba(0,0,0,0.2); }

/* ════════════════════════════════════════════════════════════
   RESPONSIIVISUUS — mobiili (≤ 480 px)
   Chat-ikkuna lähes täysruutu, pienempi launcher, tiiviimpi padding.
═══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {

  /* Launcher pienempi ja lähemmäs reunaa */
  #sm-launcher-wrapper {
    bottom: 16px;
    right: 16px;
  }
  #sm-launcher { width: 78px; }

  /* Kupla pienempi */
  #sm-shout {
    font-size: 11px;
    padding: 5px 11px;
    top: -34px;
    letter-spacing: 0.3px;
  }

  /* Chat-ikkuna lähes täysruutu */
  #sm-window {
    bottom: 16px;
    top: 16px;
    right: 8px;
    left: 8px;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    border-width: 6px;
    border-radius: 28px;
  }

  /* Tiiviimpi sisältö */
  #view-home {
    padding: 50px 16px 16px;
  }
  .app-grid { gap: 16px 12px; }

  .status-bar {
    height: 32px;
    font-size: 12px;
    padding: 0 18px;
  }
  .dynamic-island {
    top: 6px;
    height: 24px;
    font-size: 9px;
  }

  .chat-header {
    padding: 38px 16px 0;
  }
  /* Mobiilissa back-btn isompi — 44+ px tap target. */
  .back-btn {
    padding: 10px 14px;
    font-size: 15px;
  }
  /* Footer hieman tilavampi mobiilissa, helpompi osua. */
  .chat-footer {
    padding: 10px 16px 12px;
  }
  #chat-content {
    padding: 16px;
    gap: 12px;
  }

  /* Boot-näyttö pienempi logo */
  .boot-logo {
    font-size: 18px;
    letter-spacing: 1.5px;
  }

  /* CTA-mainos tiiviimpi */
  .home-cta { margin: 6px 10px 6px; padding: 10px 12px; }
  .home-cta-btn { min-height: 50px; padding: 8px 6px; }
  .home-cta-btn .cta-btn-label { font-size: 13px; }
  .home-cta-btn .cta-btn-sub   { font-size: 10px; }
}

/* Hyvin lyhyt korkeus (esim. landscape-puhelin): pienennä korkeutta vielä */
@media (max-height: 600px) {
  #sm-window {
    bottom: 12px;
    top: 12px;
    height: auto;
    max-height: none;
  }
}
