/* ================================
   🌙 ZÁKLADNÍ PROMĚNNÉ A RESET
   ================================ */
:root {
  --bg: #0f172a;         /* pozadí celé stránky */
  --fg: #e5e7eb;         /* hlavní barva textu */
  --muted: #94a3b8;      /* tlumené texty, např. čas zprávy */
  --card: #111827;       /* barva karty s chatem */

  --accent: #2563eb;     /* barva tlačítek */
  --link: #0077cc;
  --link-hover: #004a99;

  --header-min: 40px;    /* výška hlavičky */
  --compose-min: 72px;   /* výška spodního panelu na desktopu */
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

/* ================================
   🧱 ROZLOŽENÍ STRÁNKY A KARTY
   ================================ */
main {
  max-width: 780px;
  margin: 0 auto;
  padding: 12px;
  height: 100dvh;
  height: 100svh;
  height: 100vh;
  display: flex;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.3);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-height: 100%;
  overflow: hidden;
}

/* ================================
   🧭 HLAVIČKA CHATU
   ================================ */
.head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: var(--header-min);
  padding: 2px 4px;
  gap: 8px;
}

.head h1 {
  margin: 0;
  font-weight: 600;
  line-height: 1.2;
  font-size: clamp(14px, 2.8vw, 20px);
}

/* ================================
   💬 SEZNAM ZPRÁV
   ================================ */
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(255,255,255,.03);
}

/* 🟦 Jednotlivá bublina zprávy */
.msg {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.06);
}
.msg small {
  color: var(--muted);
  display: block;
  margin-top: 4px;
  font-size: 11px;
}

/* odkazy, embed, RTL texty */
.msg .embed { margin-top: 8px; }
.msg a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
  transition: color 0.2s ease;
}
.msg a:hover { color: var(--link-hover); }

.msg[dir="rtl"] {
  text-align: right;
  font-family: sans-serif, "Alef", "Rubik", "Assistant", "Heebo",
               system-ui, -apple-system, "Segoe UI", Roboto, Arial;
  font-size: 1.05em;
  line-height: 1.6;
}

/* ================================
   ✏️ SPODNÍ PANEL (COMPOSE)
   ================================ */
.compose {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 0 12px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(17,24,39,0.7), rgba(17,24,39,0.9));
  backdrop-filter: blur(3px);
  min-height: var(--compose-min);
  margin-bottom: 6px;
}
.compose > * { min-width: 0; max-width: 100%; }

/* ✍️ Textové pole */
.compose textarea {
  grid-column: 1 / 2;
  width: 100%;
  resize: none;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(255,255,255,0.05);
  color: #fff;
  font-size: 1em;
  line-height: 1.4;
  min-height: 3em;
  height: 3em;
}

/* === SJEDNOCENÝ STYL TEXTOVÉHO POLE PRO LTR I RTL === */
.compose textarea,
textarea[dir="rtl"] {
  font-family: sans-serif, "Alef", system-ui, -apple-system, "Segoe UI", Roboto, Arial;
  font-size: 1.25em;    /* sjednocená velikost */
  line-height: 1.6;     /* pohodlné čtení */
  direction: inherit;   /* respektuje nastavení dir */
}


/* ⚙️ Ovládací část (RTL/LTR + tlačítko) */
.toggle {
  grid-column: 2 / 3;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
}

/* ================================
   🎨 TLAČÍTKA, ODKAZY A DETAJLY
   ================================ */
button, .btn {
  border: 0;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.toggle input[type="checkbox"] { transform: scale(1.05); }

textarea::placeholder {
  white-space: pre-line;
  opacity: .75;
  font-size: 0.8rem !important;
  line-height: 1.4;
}

/* 🖼️ Obrázky a lightbox */
.thumb img {
  max-width: 240px;
  max-height: 180px;
  border-radius: 8px;
  cursor: zoom-in;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.thumb img:hover { transform: scale(1.02); box-shadow: 0 0 8px rgba(255,255,255,.3); }

.img-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  cursor: zoom-out;
}
.img-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 0 16px rgba(0,0,0,.6);
}

/* RTL styl pro textarea */
textarea[dir="rtl"] {
  font-family: sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial;
  font-size: 1.25em;
  direction: rtl;
}

/* ================================
   📱 RESPONSIVITA
   ================================ */

/* 🖥️ Desktop: 2× vyšší compose */
@media (min-width: 769px) {
  :root { --compose-min: 144px; }
  .compose { min-height: var(--compose-min); }
  .compose textarea { min-height: 6em; height: 6em; }
  .toggle { flex-wrap: nowrap; }
}

/* 📲 Mobilní režim (do 768 px) */
@media (max-width: 768px) {
  main {
    height: 100svh;
    display: flex;
    justify-content: center;
    align-items: stretch;
    overflow: hidden; /* scroll jen v .messages */
  }

  .card {
    width: 100%;
    height: 94svh;   /* rezerva pro lišty */
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px;
    max-height: calc(90% - var(--header-min) - var(--compose-min) - 10%);
  }

  .compose {
    position: relative;
    margin: 0;
    padding: 8px 10px;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto; /* textarea + toggle */
    gap: 6px;
  }

  .compose textarea {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
  }

  .toggle {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
  }

  #dirIndicator,
  .toggle label {
    font-size: 0.8em;
    opacity: 0.8;
  }

  .toggle button {
    flex: 1;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.9em;
  }

  body { font-size: 0.95em; }
  .head h1 { font-size: clamp(12px, 2.5vw, 18px); }
  button { padding: 8px 10px; }
}

/* 📏 Extra úzké telefony ≤400px
   -> Textarea vyplní compose na výšku */
@media (max-width: 400px) {
  .compose {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    align-items: stretch;
    gap: 4px;
    padding: 0 6px 4px;
    margin: 0;
    min-height: unset;
    height: auto;
  }

  .compose textarea {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    height: 100%;
    min-height: 108px; /* komfortní výška */
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    font-size: 1em;
    line-height: 1.4;
    resize: none;
  }

  .toggle {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    margin: 0;
  }

  /* zmenšené RTL/LTR prvky */
  .toggle label { display: none; }
  .toggle input[type="checkbox"] { transform: scale(0.9); margin: 0 4px; }
  #dirIndicator { font-size: .85em; opacity: .75; }

  .toggle button {
    flex: 1;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: .9em;
  }
}

/* === AUTH STRÁNKY (login, registrace, reset hesla) === */
.auth {
  max-width: 420px;
  margin: 8vh auto;
  padding: 16px 14px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,.3);
}

/* Nadpisy a odstavce uvnitř auth */
.auth h1 {
  margin: 0 0 12px 0;
  font-size: clamp(18px, 3.2vw, 22px);
  font-weight: 600;
}
.auth p { color: var(--muted); margin: 6px 0 12px; }

/* Chybové a informační hlášky */
.auth .error { color: #fca5a5; margin-bottom: 8px; }
.auth .info  { color: #93c5fd; margin-bottom: 8px; }

/* Form vstupy už máš globálně – jen jemné zpříjemnění rozestupů */
.auth label { display:block; margin: 10px 0 6px; color: var(--muted); }

.auth .row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.auth button {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
}

/* Odkazy (např. „Zapomenuté heslo?“) */
.auth a {
  color: var(--link);
  text-decoration: none;
}
.auth a:hover { text-decoration: underline; }

/* Mobil: ať je stránka scrolovatelná i bez chat layoutu */
@media (max-width: 768px) {
  /* Pokud je na stránce jen .auth a ne chat, povol scroll hlavnímu kontejneru */
  main:has(.auth) {
    height: auto;
    overflow: auto;
    padding: 12px;
  }
  .auth { margin: 6vh auto; padding: 14px 12px; }
}
