/* SchönChat by Xschon — UI */
:root {
  --gold: #c9a84c; --gold-light: #e8cb7a; --gold-dark: #9a7a2e;
  --bg: #080808; --bg-2: #111111; --bg-3: #1a1a1a; --bg-4: #242424;
  --text: #f0ece4; --muted: #8a8070; --muted-2: #5e574b; --border: #2a2a2a;
  --red: #c0392b; --green: #3fb27f;
  --bubble-me: #2b2414; --bubble-me-border: #4a3d1c; --bubble-them: #1b1b1b;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --list-w: 380px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: 'Lato', 'Helvetica Neue', Arial, sans-serif;
  font-weight: 400; line-height: 1.45; overflow: hidden; overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: var(--gold); text-decoration: none; }
img { display: block; max-width: 100%; }
.hidden { display: none !important; }
.serif { font-family: 'Playfair Display', Georgia, serif; }

/* ── App frame ───────────────────────────────────────────────────────── */
#app { height: 100dvh; display: flex; flex-direction: column; position: relative; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.view[hidden] { display: none; }

.topbar {
  display: flex; align-items: center; gap: .75rem; padding: calc(var(--sat) + .6rem) .9rem .6rem;
  background: rgba(8,8,8,.96); border-bottom: 1px solid var(--border); min-height: calc(56px + var(--sat));
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); flex: 0 0 auto;
}
.topbar h1 { font-family: 'Playfair Display', serif; font-weight: 600; font-size: 1.2rem; letter-spacing: .02em; color: var(--gold); }
.topbar h1 small { display: block; font-family: 'Lato', sans-serif; font-weight: 300; font-size: .62rem; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); flex: 0 0 auto; position: relative;
}
.icon-btn:hover { background: var(--bg-3); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.gold { color: var(--gold); }
.badge-dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--gold); color: #000; font-size: .62rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.avatar {
  width: 48px; height: 48px; border-radius: 50%; background: var(--bg-3) center/cover no-repeat; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; font-family: 'Playfair Display', serif; color: var(--gold); font-size: 1.15rem;
  border: 1px solid var(--border); overflow: hidden; position: relative;
}
.avatar.sm { width: 38px; height: 38px; font-size: .95rem; }
.avatar .online { position: absolute; right: 1px; bottom: 1px; width: 11px; height: 11px; border-radius: 50%; background: var(--green); border: 2px solid var(--bg); }

/* ── Auth ────────────────────────────────────────────────────────────── */
.auth-wrap { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: calc(var(--sat) + 2rem) 1.25rem calc(var(--sab) + 2rem); }
.auth-box { width: 100%; max-width: 400px; }
.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo img { height: 44px; margin: 0 auto .9rem; }
.auth-logo h1 { font-family: 'Playfair Display', serif; font-weight: 600; font-size: 1.6rem; color: var(--gold); }
.auth-logo p { color: var(--muted); font-size: .72rem; letter-spacing: .25em; text-transform: uppercase; margin-top: .25rem; }
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .9rem; }
.field label { font-size: .7rem; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; }
.field input, .field select, .field textarea {
  background: var(--bg-2); border: 1px solid var(--border); color: var(--text); padding: .8rem .95rem; font-size: .95rem;
  outline: none; width: 100%; border-radius: 6px; -webkit-appearance: none; appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--gold); }
.btn { width: 100%; padding: .9rem; background: var(--gold); color: #000; border-radius: 6px; font-size: .95rem; font-weight: 700; letter-spacing: .04em; transition: background .2s, opacity .2s; }
.btn:hover { background: var(--gold-light); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 400; }
.btn.ghost:hover { border-color: var(--gold); color: var(--gold); }
.btn.danger { background: transparent; color: var(--red); border: 1px solid #4a1c17; font-weight: 400; }
.auth-links { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1rem; font-size: .82rem; color: var(--muted); }
.auth-links button { color: var(--gold); }
.msg-err { background: #2a1512; border: 1px solid #4a1c17; color: #e78b7d; padding: .7rem .9rem; border-radius: 6px; font-size: .85rem; margin-bottom: .9rem; }
.msg-ok { background: #13261d; border: 1px solid #1e4a34; color: #8ad8b2; padding: .7rem .9rem; border-radius: 6px; font-size: .85rem; margin-bottom: .9rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-size: .82rem; color: var(--muted); margin: .25rem 0 1rem; }
.check input { width: 18px; height: 18px; accent-color: var(--gold); margin-top: 1px; flex: 0 0 auto; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-bottom: .9rem; }
.seg button { flex: 1; padding: .7rem; color: var(--muted); font-size: .85rem; }
.seg button.on { background: var(--bg-3); color: var(--gold); }
.legal-note { font-size: .72rem; color: var(--muted-2); text-align: center; margin-top: 1.25rem; line-height: 1.5; }

/* ── Conversation list ───────────────────────────────────────────────── */
.search { padding: .5rem .9rem; border-bottom: 1px solid var(--border); background: var(--bg); }
.search input { width: 100%; background: var(--bg-2); border: 1px solid var(--border); border-radius: 20px; padding: .55rem 1rem; font-size: .9rem; outline: none; }
.search input:focus { border-color: var(--gold); }
.conv-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--sab); }
.conv { display: flex; gap: .85rem; align-items: center; padding: .8rem .9rem; border-bottom: 1px solid #161616; cursor: pointer; width: 100%; text-align: left; }
.conv:hover, .conv.active { background: var(--bg-2); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.conv-name { font-weight: 700; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: .7rem; color: var(--muted); flex: 0 0 auto; }
.conv-time.unread { color: var(--gold); }
.conv-bottom { display: flex; justify-content: space-between; gap: .5rem; align-items: center; margin-top: .15rem; }
.conv-preview { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: .35rem; align-items: center; }
.conv-preview svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; flex: 0 0 auto; }
.conv-preview .ticks { color: var(--muted); }
.conv-preview .ticks.read { color: var(--gold); }
.conv-sub { font-size: .7rem; color: var(--muted-2); }
.unread-pill { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--gold); color: #000; font-size: .7rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1.5rem; font-size: .9rem; line-height: 1.6; }
.empty strong { color: var(--gold); font-weight: 400; }
.empty svg { width: 48px; height: 48px; stroke: var(--muted-2); fill: none; stroke-width: 1.2; margin: 0 auto 1rem; }

/* ── Thread ──────────────────────────────────────────────────────────── */
.thread-head { cursor: pointer; flex: 1; min-width: 0; }
.thread-head .name { font-weight: 700; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-head .status { font-size: .72rem; color: var(--muted); }
.thread-head .status.on { color: var(--green); }
.messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 1rem .8rem .5rem; display: flex; flex-direction: column; gap: .2rem;
  background: radial-gradient(ellipse at top, rgba(201,168,76,.05), transparent 60%), var(--bg);
}
.day-sep { align-self: center; font-size: .68rem; color: var(--muted); background: var(--bg-2); border: 1px solid var(--border); padding: .2rem .7rem; border-radius: 12px; margin: .6rem 0; letter-spacing: .05em; }
.sys { align-self: center; font-size: .75rem; color: var(--muted); background: #1a1810; border: 1px solid #332c18; padding: .5rem .9rem; border-radius: 10px; margin: .5rem 0; text-align: center; max-width: 85%; line-height: 1.5; }
.bubble {
  max-width: min(78%, 520px); padding: .5rem .7rem .35rem; border-radius: 14px; position: relative; font-size: .95rem; word-wrap: break-word; overflow-wrap: anywhere;
  background: var(--bubble-them); border: 1px solid #242424; align-self: flex-start; border-bottom-left-radius: 4px; user-select: text;
}
.bubble.me { background: var(--bubble-me); border-color: var(--bubble-me-border); align-self: flex-end; border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.bubble.cont { margin-top: -.05rem; }
.bubble .txt { white-space: pre-wrap; }
.bubble .txt a { text-decoration: underline; }
.bubble .meta { display: flex; justify-content: flex-end; align-items: center; gap: .3rem; margin-top: .15rem; font-size: .66rem; color: var(--muted); }
.bubble .ticks { font-size: .8rem; letter-spacing: -.25em; color: var(--muted); padding-right: .25em; }
.bubble .ticks.read { color: var(--gold); }
.bubble.deleted .txt { color: var(--muted); font-style: italic; font-size: .85rem; }
.bubble .tr { margin-top: .4rem; padding-top: .4rem; border-top: 1px dashed #3a3220; color: var(--gold-light); font-size: .9rem; white-space: pre-wrap; }
.bubble .tr small { display: block; color: var(--muted); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; margin-bottom: .15rem; }
.bubble .tr-btn { font-size: .7rem; color: var(--gold); margin-top: .2rem; letter-spacing: .04em; }
.bubble img.photo { border-radius: 10px; max-height: 360px; min-width: 120px; min-height: 80px; object-fit: cover; cursor: zoom-in; background: var(--bg-3); margin: -.15rem -.3rem .3rem; width: calc(100% + .6rem); }
.bubble.media { padding-top: .35rem; max-width: min(78%, 340px); }
.audio { display: flex; align-items: center; gap: .6rem; min-width: 210px; padding: .2rem 0 .1rem; }
.audio button { width: 36px; height: 36px; border-radius: 50%; background: var(--gold); color: #000; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.audio button svg { width: 16px; height: 16px; fill: currentColor; }
.audio .bar { flex: 1; height: 4px; background: #3a3a3a; border-radius: 2px; position: relative; cursor: pointer; }
.audio .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--gold); border-radius: 2px; width: 0; }
.audio .t { font-size: .7rem; color: var(--muted); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.typing { align-self: flex-start; font-size: .75rem; color: var(--muted); padding: .2rem .6rem; }
.scroll-down { position: absolute; right: 1rem; bottom: calc(84px + var(--sab)); width: 40px; height: 40px; border-radius: 50%; background: var(--bg-3); border: 1px solid var(--border); color: var(--gold); display: none; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0,0,0,.5); }
.scroll-down.show { display: flex; }
.scroll-down svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }

.composer { display: flex; align-items: flex-end; gap: .4rem; padding: .5rem .6rem calc(.5rem + var(--sab)); border-top: 1px solid var(--border); background: var(--bg); flex: 0 0 auto; }
.composer textarea { flex: 1; background: var(--bg-2); border: 1px solid var(--border); border-radius: 20px; padding: .6rem 1rem; max-height: 140px; min-height: 42px; resize: none; outline: none; font-size: .95rem; line-height: 1.4; }
.composer textarea:focus { border-color: var(--gold); }
.composer .send { background: var(--gold); color: #000; }
.composer .send:hover { background: var(--gold-light); }
.composer .send svg { stroke: #000; }
.composer .rec { background: var(--red); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(192,57,43,.5);} 50% { box-shadow: 0 0 0 10px rgba(192,57,43,0);} }
.rec-bar { flex: 1; display: flex; align-items: center; gap: .7rem; background: var(--bg-2); border: 1px solid #4a1c17; border-radius: 20px; padding: .55rem 1rem; min-height: 42px; }
.rec-bar .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.rec-bar .time { font-variant-numeric: tabular-nums; }
.rec-bar .cancel { margin-left: auto; color: var(--muted); font-size: .8rem; }
.blocked-bar { padding: .9rem 1rem calc(.9rem + var(--sab)); border-top: 1px solid var(--border); text-align: center; color: var(--muted); font-size: .85rem; }
.blocked-bar button { color: var(--gold); margin-left: .4rem; }

/* ── Menus / sheets / toasts ─────────────────────────────────────────── */
.menu { position: absolute; top: calc(var(--sat) + 54px); right: .6rem; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; min-width: 220px; z-index: 30; box-shadow: 0 10px 30px rgba(0,0,0,.6); overflow: hidden; }
.menu button { display: block; width: 100%; text-align: left; padding: .8rem 1rem; font-size: .9rem; }
.menu button:hover { background: var(--bg-3); }
.menu button.danger { color: #e78b7d; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; background: var(--bg-2); border: 1px solid var(--border); border-bottom: 0; border-radius: 16px 16px 0 0; padding: 1rem 1rem calc(1rem + var(--sab)); max-height: 85dvh; overflow: auto; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h3 { font-family: 'Playfair Display', serif; font-weight: 500; color: var(--gold); margin-bottom: .75rem; font-size: 1.05rem; }
.sheet p { color: var(--muted); font-size: .85rem; margin-bottom: .9rem; line-height: 1.55; }
.sheet .opt { display: block; width: 100%; text-align: left; padding: .85rem .9rem; border-radius: 8px; font-size: .92rem; }
.sheet .opt:hover { background: var(--bg-3); }
.sheet .opt.danger { color: #e78b7d; }
.sheet .row { display: flex; gap: .6rem; margin-top: .75rem; }
.sheet .row .btn { flex: 1; }
.sheet .preview { max-height: 50dvh; border-radius: 10px; margin: 0 auto .75rem; object-fit: contain; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--sab)); transform: translateX(-50%); background: var(--bg-3); color: var(--text); border: 1px solid var(--border); padding: .65rem 1rem; border-radius: 10px; font-size: .85rem; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.5); max-width: 92vw; text-align: center; animation: up .2s; }
.toast.err { border-color: #4a1c17; color: #e78b7d; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.95); z-index: 70; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lightbox button { position: absolute; top: calc(var(--sat) + .6rem); right: .6rem; color: #fff; font-size: 1.6rem; width: 44px; height: 44px; }
.install { display: flex; gap: .75rem; align-items: center; padding: .7rem .9rem; background: linear-gradient(90deg, #1a160c, var(--bg-2)); border-bottom: 1px solid #3a3220; font-size: .82rem; }
.install img { width: 36px; height: 36px; border-radius: 8px; }
.install b { color: var(--gold); font-weight: 700; display: block; }
.install .btn { width: auto; padding: .45rem .8rem; font-size: .78rem; margin-left: auto; }
.install .x { color: var(--muted); padding: .25rem .4rem; }

/* ── Settings ────────────────────────────────────────────────────────── */
.settings { flex: 1; overflow-y: auto; padding: 1rem .9rem calc(2rem + var(--sab)); }
.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.card h2 { font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); margin-bottom: .8rem; font-weight: 400; }
.card .me { display: flex; align-items: center; gap: .9rem; }
.card .me .n { font-weight: 700; font-size: 1.05rem; }
.card .me .e { color: var(--muted); font-size: .8rem; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 0; border-top: 1px solid #1c1c1c; font-size: .92rem; }
.toggle:first-of-type { border-top: 0; }
.toggle small { display: block; color: var(--muted); font-size: .74rem; margin-top: .1rem; }
.switch { width: 46px; height: 26px; border-radius: 13px; background: #3a3a3a; position: relative; flex: 0 0 auto; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch.on { background: var(--gold); }
.switch.on::after { left: 23px; }
.linkbox { display: flex; gap: .5rem; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; margin-top: .5rem; }
.linkbox code { flex: 1; font-size: .78rem; color: var(--gold-light); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbox button { color: var(--gold); font-size: .78rem; padding: .3rem .4rem; }
.linkbox .nolv { color: var(--muted); font-size: .72rem; }
.card .btn + .btn { margin-top: .6rem; }
.version { text-align: center; color: var(--muted-2); font-size: .7rem; margin-top: 1rem; }

/* ── Desktop: two panes ──────────────────────────────────────────────── */
@media (min-width: 900px) {
  #app { max-width: 1400px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  #viewList { width: var(--list-w); right: auto; border-right: 1px solid var(--border); }
  #viewThread, #viewSettings { left: var(--list-w); }
  #viewThread .back { display: none; }
  .bubble { max-width: min(70%, 620px); }
  .desk-empty { display: flex; }
}
.desk-empty { display: none; position: absolute; inset: 0; left: var(--list-w); align-items: center; justify-content: center; flex-direction: column; color: var(--muted); gap: .6rem; text-align: center; padding: 2rem; }
.desk-empty img { height: 44px; opacity: .8; }
.desk-empty h2 { font-family: 'Playfair Display', serif; font-weight: 500; color: var(--gold); font-size: 1.4rem; }
.desk-empty p { font-size: .85rem; max-width: 380px; line-height: 1.6; }
@media (max-width: 899px) { .desk-empty { display: none !important; } }

/* ── Suspended ───────────────────────────────────────────────────────── */
.suspended { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 2rem; gap: .75rem; color: var(--muted); }
.suspended h2 { color: #e78b7d; font-family: 'Playfair Display', serif; font-weight: 500; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
