/* nooky – Designsystem
   Idee: „nook“ = gemütliche Ecke bei Nacht. Tiefes Indigo, warme Glut (Koralle/Pfirsich),
   Mint für „online“ und „gelesen“. Unbounded für Marke und Überschriften, Figtree für Text.
   Dunkel ist Standard, hell folgt der Systemeinstellung. */

@font-face { font-family: "Unbounded"; font-weight: 500 800; font-display: swap; src: url("fonts/unbounded.woff2") format("woff2"); }
@font-face { font-family: "Figtree";   font-weight: 400 700; font-display: swap; src: url("fonts/figtree.woff2") format("woff2"); }

:root {
  --bg: #12111b;
  --surface: #1b1a27;
  --surface-2: #252336;
  --line: #322f47;
  --fg: #f4f1fa;
  --muted: #a39fbd;
  --ember: #ff6a4d;
  --peach: #ffb38a;
  --glow: linear-gradient(135deg, var(--ember), var(--peach));
  --on-glow: #2a120b;
  --mint: #5ee0b5;
  --tick-read: #6aa8ff;          /* gelesen, auf dunklem Grund */
  --tick-read-on-glow: #1238b5;  /* gelesen, auf der eigenen (Glut-)Blase */
  --tick-sent-on-glow: rgba(42, 18, 11, .45);
  --danger: #ff5c7a;
  --bubble-in: #262438;
  --shadow: 0 18px 50px -24px rgba(0, 0, 0, .7);
  --display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fbf7f3;
    --surface: #ffffff;
    --surface-2: #f3ece6;
    --line: #e8dfd7;
    --fg: #1d1a2b;
    --muted: #6f6a82;
    --ember: #f2553a;
    --peach: #ff9e70;
    --on-glow: #2a120b;
    --mint: #12a37a;
    --tick-read: #1a6ae0;
    --danger: #d9284d;
    --bubble-in: #ffffff;
    --shadow: 0 18px 40px -24px rgba(60, 30, 20, .25);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--peach); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---- Grundgerüst --------------------------------------------------------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; font: 700 1.25rem/1 var(--display); letter-spacing: -.02em; }
.logo svg { width: 30px; height: 30px; }
.topbar .spacer { flex: 1; }
.iconbtn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; color: var(--fg); cursor: pointer; text-decoration: none; position: relative;
}
.iconbtn:hover { background: var(--surface-2); }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn .dot { position: absolute; top: 6px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--glow); color: var(--on-glow); font: 700 11px/18px var(--body); text-align: center; }

.page { width: 100%; max-width: 720px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left)); flex: 1; }
.page.wide { max-width: 1000px; }
h1 { font: 700 1.6rem/1.15 var(--display); letter-spacing: -.03em; margin: 8px 0 18px; text-wrap: balance; }
h2 { font: 700 1.05rem/1.2 var(--display); letter-spacing: -.02em; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 6vh auto 0; }
.card.notice { border-color: var(--peach); }

/* ---- Formulare ----------------------------------------------------------- */
label { display: block; margin-bottom: 14px; font-size: .875rem; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--fg); }
input[type=text], input[type=password], input[type=search], textarea {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
}
input:focus, textarea:focus { outline: none; border-color: var(--peach); box-shadow: 0 0 0 3px color-mix(in srgb, var(--peach) 25%, transparent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 99px; border: 0; cursor: pointer; text-decoration: none;
  background: var(--glow); color: var(--on-glow); font-weight: 700;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.block { width: 100%; }
form.inline { display: inline; margin: 0; }
.err { color: var(--danger); }
.ok  { color: var(--mint); }
.flash { padding: 12px 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.grid label { margin: 0; }
.pw code { font-size: 1.4rem; color: var(--peach); user-select: all; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }

/* ---- Avatare ------------------------------------------------------------- */
.avatar {
  --s: 48px; width: var(--s); height: var(--s); flex: none; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden; position: relative;
  background: var(--glow); color: var(--on-glow); font: 700 calc(var(--s) * .38)/1 var(--display);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.s { --s: 38px; }
.avatar.l { --s: 132px; }
.avatar-wrap { position: relative; flex: none; }
.online-dot { position: absolute; right: 1px; bottom: 1px; width: 13px; height: 13px; border-radius: 50%; background: var(--mint); border: 2.5px solid var(--bg); }

/* ---- Chat-Liste ---------------------------------------------------------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 14px; padding: 12px 10px; margin: 0 -10px;
  border-radius: 18px; text-decoration: none; color: inherit; background: none; border: 0; width: calc(100% + 20px); text-align: left; cursor: pointer;
}
.row:hover { background: var(--surface); }
.row .main { flex: 1; min-width: 0; }
.row .top { display: flex; align-items: baseline; gap: 8px; }
.row .name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .time { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .time.unread { color: var(--peach); font-weight: 700; }
.row .bottom { display: flex; align-items: center; gap: 8px; }
.row .preview { flex: 1; min-width: 0; color: var(--muted); font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .preview .tick { color: var(--muted); display: inline-block; vertical-align: -1px; }
.row .preview .tick svg { width: 17px; height: 11px; stroke-width: 2.4; }
.row .preview .tick.read { color: var(--tick-read); }
.badge-count { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 99px; background: var(--glow); color: var(--on-glow); font: 700 12px/22px var(--body); text-align: center; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 96px; height: 96px; margin-bottom: 8px; }
.empty h2 { color: var(--fg); }
.fab {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 20px; display: grid; place-items: center;
  background: var(--glow); color: var(--on-glow); box-shadow: var(--shadow); text-decoration: none;
}
.fab svg { width: 26px; height: 26px; }
.search { margin: 0 0 12px; }
.search input { margin: 0; }

/* ---- Chat-Ansicht -------------------------------------------------------- */
body.chat-view { overflow: hidden; }
.chat { height: 100dvh; display: flex; flex-direction: column; }
.chat .topbar { gap: 10px; }
.chat .who { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; flex: 1; }
.chat .who .txt { min-width: 0; }
.chat .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat .who small { display: block; color: var(--muted); font-size: .78rem; }
.chat .who small.on { color: var(--mint); }

.stream {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 3px;
}
.stream-inner { width: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; margin: 14px 0 8px; padding: 4px 12px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 600; }
.older { align-self: center; margin-bottom: 8px; }

.msg { max-width: min(78%, 520px); display: flex; flex-direction: column; position: relative; }
.msg.in  { align-self: flex-start; }
.msg.out { align-self: flex-end; }
.msg + .msg.in, .msg + .msg.out { margin-top: 0; }
.msg.in + .msg.out, .msg.out + .msg.in { margin-top: 8px; }
.bubble {
  padding: 8px 12px 6px; border-radius: 20px; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
  cursor: pointer; -webkit-user-select: text; user-select: text;
}
.msg.in  .bubble { background: var(--bubble-in); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.out .bubble { background: var(--glow); color: var(--on-glow); border-bottom-right-radius: 6px; }
.bubble .meta { display: flex; justify-content: flex-end; align-items: center; gap: 5px; font-size: .72rem; opacity: .75; margin-top: 2px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg.out .bubble .meta { opacity: 1; color: rgba(42, 18, 11, .7); }
.tick svg { width: 19px; height: 12px; display: block; stroke-width: 2.6; }
.msg.out .tick { color: var(--tick-sent-on-glow); }
.msg.out .tick.read { color: var(--tick-read-on-glow); }
.msg.in .tick { display: none; }
.bubble.photo { padding: 4px; }
.bubble.photo img { display: block; border-radius: 16px; max-height: 360px; width: auto; height: auto; background: var(--surface-2); }
.bubble.photo .cap { padding: 6px 8px 0; }
.bubble.photo .meta { padding: 0 8px 2px; }
.bubble.deleted { font-style: italic; opacity: .65; background: transparent !important; border: 1px dashed var(--line) !important; color: var(--muted) !important; }
.msg.pending .bubble { opacity: .6; }

.composer {
  border-top: 1px solid var(--line); background: var(--bg);
  padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.composer form { max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  margin: 0; resize: none; max-height: 160px; min-height: 46px; line-height: 1.35; border-radius: 22px; padding: 12px 16px;
  background: var(--surface);
}
/* keine Scrollleiste/Pfeile im Eingabefeld, solange der Text reinpasst */
.composer textarea { overflow-y: hidden; scrollbar-width: thin; }
.composer textarea::-webkit-scrollbar { width: 6px; }
.composer textarea::-webkit-scrollbar-button { display: none; height: 0; }
.composer textarea::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
.composer .send { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; background: var(--glow); color: var(--on-glow); display: grid; place-items: center; cursor: pointer; }
.composer .send svg, .composer .attach svg { width: 22px; height: 22px; }
.composer .attach { width: 46px; height: 46px; flex: none; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--muted); margin: 0; }
.composer .attach:hover { background: var(--surface); color: var(--fg); }
.composer .attach input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.preview-strip { max-width: 760px; margin: 0 auto 8px; display: flex; align-items: center; gap: 10px; }
.preview-strip img { height: 64px; width: auto; border-radius: 12px; }
.composer-note { max-width: 760px; margin: 0 auto 6px; font-size: .85rem; }

/* Menü und Foto-Ansicht */
dialog { border: 0; padding: 0; background: transparent; color: var(--fg); max-width: 100vw; max-height: 100vh; }
dialog::backdrop { background: rgba(8, 7, 14, .6); backdrop-filter: blur(4px); }
.sheet { width: min(360px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 8px; box-shadow: var(--shadow); }
.sheet button { display: flex; width: 100%; align-items: center; gap: 12px; padding: 14px 14px; border: 0; background: none; border-radius: 14px; cursor: pointer; text-align: left; }
.sheet button:hover { background: var(--surface-2); }
.sheet button svg, .btn svg { width: 20px; height: 20px; flex: none; }
.sheet button.danger { color: var(--danger); }
.sheet .hint { padding: 6px 14px 10px; color: var(--muted); font-size: .8rem; }
.viewer { width: 100vw; height: 100dvh; display: grid; place-items: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 12px; }
.viewer .close { position: fixed; top: max(12px, env(safe-area-inset-top)); right: 12px; background: rgba(0,0,0,.5); color: #fff; }

/* ---- Profil -------------------------------------------------------------- */
.profile-head { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 8px 0 18px; }
.profile-head h1 { margin: 6px 0 0; }
.profile-head .handle { color: var(--muted); }
.avatar-edit { position: relative; }
.avatar-edit .cam { position: absolute; right: 0; bottom: 4px; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 3px solid var(--bg); cursor: pointer; color: var(--fg); }
.avatar-edit .cam svg { width: 20px; height: 20px; }
.avatar-edit input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.field-row { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; border-top: 1px solid var(--line); }
.field-row:first-child { border-top: 0; }
.field-row svg { width: 22px; height: 22px; color: var(--muted); flex: none; margin-top: 2px; }
.field-row .f { flex: 1; min-width: 0; }
.field-row .k { font-size: .8rem; color: var(--muted); }
.field-row .v { overflow-wrap: anywhere; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.chip { padding: 7px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-size: .875rem; }
.chip:hover { border-color: var(--peach); }
.counter { float: right; font-variant-numeric: tabular-nums; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- Admin-Tabelle ------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.actions form { display: inline-block; margin: 0 4px 4px 0; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; background: var(--surface-2); }
.badge.ok { color: var(--mint); background: color-mix(in srgb, var(--mint) 14%, transparent); }
.badge.bad { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.badge.admin { color: var(--peach); background: color-mix(in srgb, var(--peach) 16%, transparent); }
@media (max-width: 640px) {
  thead { display: none; }
  tr, td { display: block; }
  td { border: 0; padding: 3px 0; }
  tr { border-bottom: 1px solid var(--line); padding: 10px 0; }
}

/* ---- Login / Sperrseite -------------------------------------------------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: min(420px, 100%); margin: 0; }
.auth .brand-big { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth .brand-big svg { width: 72px; height: 72px; }
.auth .brand-big span { font: 700 1.8rem/1 var(--display); letter-spacing: -.03em; }

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