/* Realms of Elynia -tukiportaali. Antiikin-Rooma-henki: pergamentti, pronssi,
   kulta, laakeri. Itsenäinen (ei ulkoisia fontteja). Ei emojeita. */

:root {
  --sand: #EAE0C9;
  --parchment: #F5EEDD;
  --parchment-deep: #ECE1C6;
  --bronze: #8C6B2F;
  --bronze-dark: #6B4F1F;
  --gold: #C9A24B;
  --laurel: #4A5D33;
  --crimson: #7A2020;
  --night: #241C12;
  --ink: #2E2416;
  --muted: #7A6C4E;
  --line: rgba(107, 79, 31, 0.28);
  --line-soft: rgba(107, 79, 31, 0.16);
  --shadow: 0 2px 12px rgba(36, 28, 18, 0.14);
  --serif: Georgia, 'Times New Roman', 'Palatino Linotype', serif;
  --display: 'Trajan Pro', 'Optima', Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 700px at 50% -10%, rgba(201, 162, 75, 0.12), transparent 60%),
    linear-gradient(180deg, #F7F1E1 0%, #EFE6CF 100%);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app-root { height: 100%; }

button { font-family: inherit; cursor: pointer; }
a { color: var(--bronze-dark); }

/* Otsakkeen "kaiverrettu" tyyli */
.display {
  font-family: var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--bronze-dark);
}

/* ---------- Kirjautuminen ---------- */
.login-wrap {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--parchment);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 34px 30px 28px;
  text-align: center;
}
.crest {
  width: 58px; height: 58px;
  margin: 0 auto 14px;
  display: block;
}
.login-card h1 {
  font-family: var(--display);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 18px;
  color: var(--bronze-dark);
  margin: 0 0 2px;
}
.login-card .tagline {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
  margin: 0 0 22px;
}
.field { text-align: left; margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type="password"], input[type="text"], textarea {
  width: 100%;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink);
  background: #FBF7EC;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  outline: none;
}
input:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 75, 0.18);
}

.btn {
  display: inline-block;
  border: 1px solid var(--bronze-dark);
  background: linear-gradient(180deg, #B98B3C, #8C6B2F);
  color: #FBF3DF;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent;
  color: var(--bronze-dark);
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn-ghost:hover { background: rgba(201, 162, 75, 0.10); }

.error-msg {
  color: var(--crimson);
  font-size: 13px;
  min-height: 18px;
  margin: 6px 0 0;
}

/* ---------- Portaalin runko ---------- */
.shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: linear-gradient(180deg, #2C2314, #241C12);
  color: var(--sand);
  border-bottom: 3px solid var(--gold);
}
.topbar .brand {
  font-family: var(--display);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 15px;
  color: #EBD9A6;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar .brand svg { width: 26px; height: 26px; }
.topbar .spacer { flex: 1; }
.topbar .addr {
  font-style: italic;
  color: #C9B98E;
  font-size: 13px;
}
.topbar .btn-ghost {
  color: #EBD9A6;
  border-color: rgba(201, 162, 75, 0.4);
}
.topbar .btn-ghost:hover { background: rgba(201, 162, 75, 0.14); }

.main {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 0;
}

/* ---------- Säielista ---------- */
.list-pane {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #F2E9D4, #EFE5CD);
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}
.list-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.tab {
  flex: 1;
  text-align: center;
  padding: 7px 8px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
}
.tab.active {
  color: var(--bronze-dark);
  background: var(--parchment);
  border-color: var(--line);
  box-shadow: var(--shadow);
}
.tab .badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 5px;
  padding: 0 5px;
  font-size: 11px;
  line-height: 17px;
  color: #FBF3DF;
  background: var(--crimson);
  border-radius: 9px;
}
.thread-list { overflow-y: auto; padding: 6px; min-height: 0; }
.thread-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 11px 12px;
  margin-bottom: 3px;
}
.thread-item:hover { background: rgba(201, 162, 75, 0.10); }
.thread-item.active {
  background: var(--parchment);
  border-color: var(--line);
  box-shadow: var(--shadow);
}
.thread-item .ti-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.thread-item .ti-from {
  font-weight: bold;
  color: var(--ink);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.thread-item.unread .ti-from::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 2px rgba(201, 162, 75, 0.25);
  vertical-align: middle;
}
.thread-item .ti-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.thread-item .ti-subj {
  color: var(--ink);
  font-size: 13px;
  margin: 2px 0 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-item .ti-preview {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.empty {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 40px 20px;
}

/* ---------- Keskustelunäkymä ---------- */
.conv-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  background:
    radial-gradient(900px 500px at 100% 0%, rgba(201, 162, 75, 0.06), transparent 55%),
    var(--parchment);
}
.conv-head {
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}
.conv-head .ch-main { min-width: 0; flex: 1; }
.conv-head h2 {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  margin: 0 0 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-head .ch-from { color: var(--muted); font-size: 13px; }
.conv-body { overflow-y: auto; padding: 20px 22px; min-height: 0; }

.msg {
  max-width: 82%;
  margin-bottom: 16px;
  padding: 13px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14.5px;
  line-height: 1.6;
}
.msg .msg-meta {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
  opacity: 0.75;
}
.msg.in {
  background: #FBF7EC;
  border: 1px solid var(--line-soft);
  color: var(--ink);
}
.msg.out {
  background: linear-gradient(180deg, #F0E4C4, #E9DBB6);
  border: 1px solid var(--line);
  color: var(--night);
  margin-left: auto;
}
.msg.out .msg-meta { color: var(--bronze-dark); }

/* ---------- Vastauskenttä ---------- */
.composer {
  border-top: 1px solid var(--line);
  padding: 12px 22px 16px;
  background: linear-gradient(180deg, #F3EAD3, #EEE3C9);
}
.composer textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  line-height: 1.55;
}
.composer .composer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}
.composer .hint { color: var(--muted); font-size: 12px; font-style: italic; flex: 1; }

/* Tyhjä keskustelunäkymä */
.conv-empty {
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 40px;
}
.conv-empty svg { width: 84px; height: 84px; opacity: 0.5; margin-bottom: 14px; }

/* Ilmoitus (toast) */
.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: var(--night);
  color: var(--sand);
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--gold);
  box-shadow: var(--shadow);
  font-size: 13px;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
.toast.err { border-color: var(--crimson); }

.spin {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid rgba(251, 243, 223, 0.4);
  border-top-color: #FBF3DF;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Mobiili ---------- */
@media (max-width: 760px) {
  .main { grid-template-columns: 1fr; }
  .list-pane { display: none; }
  .main.show-list .list-pane { display: grid; }
  .main.show-list .conv-pane { display: none; }
  .msg { max-width: 92%; }
  .back-btn { display: inline-flex; }
}
.back-btn { display: none; align-items: center; gap: 6px; }
