:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #ece9e2;
  --line: #ddd8ce;
  --ink: #1c1d21;
  --ink-2: #5d5f66;
  --ink-3: #8b8d94;
  --accent: #2550c4;
  --accent-ink: #ffffff;
  --accent-soft: #e3e9fa;
  --mine: #2550c4;
  --mine-ink: #ffffff;
  --theirs: #ffffff;
  --theirs-ink: #1c1d21;
  --read: #8fd0ff;
  --danger: #c2342b;
  --ok: #2f8a4f;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 2px 8px rgba(20, 20, 30, .05);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #23272e;
    --line: #2c3139;
    --ink: #eceef2;
    --ink-2: #a5a9b2;
    --ink-3: #737882;
    --accent: #6d93f2;
    --accent-ink: #0d1324;
    --accent-soft: #1f2a46;
    --mine: #3864d6;
    --mine-ink: #ffffff;
    --theirs: #1f232a;
    --theirs-ink: #eceef2;
    --read: #a9dcff;
    --danger: #ef6a60;
    --ok: #5cc27f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

#app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; background: var(--bg); }
@media (min-width: 760px) {
  body { background: var(--surface-2); }
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
.splash { flex: 1; display: grid; place-items: center; }
.splash img { border-radius: 16px; opacity: .9; }

/* ---------- Κεφαλίδα ---------- */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  min-height: 58px;
  position: relative; z-index: 2;
}
.bar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 0 4px; flex: 1; }
.bar .who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.bar .who-text { min-width: 0; }
.bar .who-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .who-sub { font-size: 12.5px; color: var(--ink-3); }
.bar .who-sub.on { color: var(--ok); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--ink); flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

.netbar {
  background: var(--danger); color: #fff; font-size: 13px; text-align: center; padding: 5px 10px;
}

/* ---------- Avatar ---------- */
.av {
  --c: #6b7280;
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 600; font-size: 16px; letter-spacing: .02em;
  position: relative;
}
.av.sm { width: 36px; height: 36px; font-size: 14px; }
.av .dot {
  position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%;
  background: var(--ok); border: 2px solid var(--bg);
}

/* ---------- Λίστα συνομιλιών ---------- */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.list { list-style: none; margin: 0; padding: 4px 0 calc(16px + var(--safe-b)); }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; cursor: pointer;
  text-decoration: none; color: inherit;
}
.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: -10px; }
.row:last-child .row-main { border-bottom: 0; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { font-size: 12.5px; color: var(--ink-3); flex: none; }
.row-bot { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.row-prev { flex: 1; color: var(--ink-2); font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .row-time { color: var(--accent); font-weight: 600; }
.row.unread .row-prev { color: var(--ink); }
.badge {
  min-width: 21px; height: 21px; padding: 0 6px; border-radius: 11px;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700;
  display: grid; place-items: center; flex: none;
}
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 18px 16px 6px; margin: 0; font-weight: 600; }

.empty { text-align: center; padding: 56px 28px; color: var(--ink-2); }
.empty h2 { color: var(--ink); font-size: 18px; margin: 0 0 6px; }

.fab {
  position: absolute; right: 18px; bottom: calc(18px + var(--safe-b));
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 14px rgba(37, 80, 196, .35);
  display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 26px; height: 26px; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

.install {
  margin: 10px 12px 2px; padding: 12px 14px; border-radius: 14px;
  background: var(--accent-soft); display: flex; gap: 12px; align-items: center; font-size: 14.5px;
}
.install b { display: block; }
.install .grow { flex: 1; }

/* ---------- Συνομιλία ---------- */
.msgs { padding: 8px 10px 10px; display: flex; flex-direction: column; }
.day {
  align-self: center; margin: 12px 0 8px; padding: 3px 10px; border-radius: 10px;
  background: var(--surface-2); color: var(--ink-2); font-size: 12.5px; font-weight: 600;
}
.more-btn { align-self: center; margin: 6px 0; }
.msg { display: flex; flex-direction: column; max-width: 82%; margin-top: 6px; align-self: flex-start; }
.msg.cont { margin-top: 2px; }
.msg.mine { align-self: flex-end; }
.msg .sender { font-size: 12.5px; font-weight: 600; color: var(--c, var(--ink-2)); margin: 0 0 2px 12px; }
.bubble {
  background: var(--theirs); color: var(--theirs-ink);
  padding: 7px 11px 6px; border-radius: var(--radius); box-shadow: var(--shadow);
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  font-size: 15.5px; line-height: 1.38;
}
.msg:not(.mine) .bubble { border-top-left-radius: 6px; }
.msg:not(.mine).cont .bubble { border-top-left-radius: var(--radius); border-bottom-left-radius: 6px; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-ink); border-top-right-radius: 6px; box-shadow: none; }
.msg.mine.cont .bubble { border-top-right-radius: var(--radius); border-bottom-right-radius: 6px; }
.msg.mine .bubble a { color: inherit; }
.meta {
  float: right; margin: 6px 0 -4px 10px; font-size: 11px; line-height: 1; opacity: .7;
  display: inline-flex; align-items: center; gap: 3px; user-select: none;
}
.msg.mine .meta { opacity: .85; }
.tick svg { width: 16px; height: 11px; display: block; }
.msg.read .tick { color: var(--read); }
.msg.pending .bubble { opacity: .75; }
.msg.failed .bubble { background: var(--danger); }
.msg .fail { font-size: 12px; color: var(--danger); margin: 3px 6px 0 0; text-align: right; cursor: pointer; }

.newpill {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(76px + var(--safe-b));
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 16px;
  padding: 7px 14px; font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow); cursor: pointer;
}

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-b));
  border-top: 1px solid var(--line); background: var(--bg);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 22px; padding: 10px 16px; max-height: 140px; min-height: 44px;
  line-height: 1.35; outline: none; font-size: 16px;
}
.composer textarea:focus { border-color: var(--accent); }
.send {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer;
  transition: transform .12s, opacity .12s;
}
.send:disabled { opacity: .35; }
.send:not(:disabled):active { transform: scale(.92); }
.send svg { width: 22px; height: 22px; }

/* ---------- Φόρμες / κάρτες ---------- */
.pad { padding: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin: 0 12px 14px;
}
.card h2 { font-size: 17px; margin: 0 0 4px; }
.form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; color: var(--ink-2); font-weight: 500; }
.form input {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; font-size: 16px; color: var(--ink);
  outline: none;
}
.form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-err { color: var(--danger); font-size: 14.5px; margin: 8px 0 0; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 16px;
  font-weight: 600; cursor: pointer; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; padding: 13px 16px; }
.btn.sm { padding: 6px 11px; font-size: 13.5px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

.link-box {
  margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all;
}
.kv { list-style: none; padding: 0; margin: 0; }
.kv li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.kv li:last-child { border-bottom: 0; }
.kv .grow { flex: 1; min-width: 0; }
.kv .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv .s { font-size: 13px; color: var(--ink-3); }
.tag { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 8px; background: var(--surface-2); color: var(--ink-2); }
.tag.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.tag.warn { background: var(--accent-soft); color: var(--accent); }

/* ---------- Σελίδες εκτός εφαρμογής ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 26px; letter-spacing: -.02em; margin: 22px 0 6px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; }
.brand img { border-radius: 12px; }

/* ---------- Οδηγός εγκατάστασης ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 520px; border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(22px + var(--safe-b)); animation: up .22s ease-out;
}
.sheet h2 { margin: 0 0 12px; font-size: 19px; }
.sheet ol { padding-left: 20px; margin: 0 0 18px; }
.sheet li { margin: 8px 0; }
.sheet .ico { display: inline-block; vertical-align: -4px; width: 20px; height: 20px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14.5px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
