/* Beskeder – iOS-agtig stil som Noter. Lys og mørk følger systemet. */
:root {
  --bg: #f2f2f7; --panel: #ffffff; --text: #1c1c1e; --muted: #8e8e93; --line: rgba(60, 60, 67, .18);
  --accent: #2f6fde; --accent-soft: #e4edfc; --bubble: #ffffff; --chat-bg: #f2f2f7; --note: #fff6d6; --note-text: #5c4600;
  --danger: #e5484d; --badge: #2f6fde; --shadow: 0 1px 1px rgba(0, 0, 0, .06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --panel: #1c1c1e; --text: #f2f2f7; --muted: #8e8e93; --line: rgba(84, 84, 88, .55);
    --accent: #5b93f5; --accent-soft: #1d2a44; --bubble: #26262a; --chat-bg: #000000; --note: #3a3220; --note-text: #f4dc95;
    --badge: #3b7af0; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 17px; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow: hidden; }
[hidden] { display: none !important; }
a { color: var(--accent); }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .85em; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; word-break: break-all; }
button { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; }

.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.splash img { width: 96px; height: 96px; border-radius: 22px; }

/* Login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto; }
.login-card { background: var(--panel); border-radius: 20px; padding: 32px 24px; width: 100%; max-width: 380px; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .08); }
.login-icon { width: 80px; height: 80px; border-radius: 18px; }
.login-card h1 { margin: 12px 0 4px; font-size: 26px; }
.login-text { color: var(--muted); font-size: 15px; line-height: 1.4; }
.login-card input { width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); margin-bottom: 12px; }
.login-error { color: var(--danger); font-size: 15px; min-height: 1.2em; margin: 10px 0 0; }

.btn-primary, .btn-secondary, .btn-danger { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; cursor: pointer; width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--accent-soft); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn-primary:disabled { opacity: .5; }
.btn-link { background: none; border: 0; color: var(--accent); margin-top: 12px; cursor: pointer; }

/* Ramme: liste + chat. Smal skærm viser én ad gangen. */
.app { position: fixed; inset: 0; display: flex; }
.pane { display: flex; flex-direction: column; min-width: 0; height: 100%; background: var(--panel); }
.pane-list { width: 100%; }
.pane-chat { width: 100%; background: var(--chat-bg); }
.app[data-view="list"] .pane-chat { display: none; }
.app[data-view="chat"] .pane-list { display: none; }
@media (min-width: 900px) {
  .pane-list { width: 340px; flex: none; border-right: 1px solid var(--line); }
  .app .pane-chat, .app .pane-list { display: flex !important; }
  .pane-chat { flex: 1; }
  .back-btn { display: none !important; }
}

.bar { display: flex; align-items: center; height: calc(52px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0; flex: none; background: color-mix(in srgb, var(--panel) 85%, transparent); backdrop-filter: blur(20px); border-bottom: 1px solid var(--line); position: relative; z-index: 2; }
.bar-side { flex: 1; display: flex; align-items: center; min-width: 0; }
.bar-side.right { justify-content: flex-end; }
.bar-title { font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.icon-btn { background: none; border: 0; color: var(--accent); padding: 8px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--accent-soft); }
.back-btn { display: flex; align-items: center; gap: 2px; text-decoration: none; color: var(--accent); padding: 6px 4px; }
.text-btn { text-decoration: none; font-weight: 600; padding: 8px; }
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: env(safe-area-inset-bottom); }
.large-title { font-size: 32px; margin: 8px 16px 8px; }
.empty { color: var(--muted); padding: 16px; text-align: center; line-height: 1.5; }

/* Emneliste */
.topic-list { list-style: none; margin: 0; padding: 0; }
.topic { display: flex; gap: 12px; align-items: flex-start; padding: 10px 16px; text-decoration: none; color: inherit; position: relative; }
.topic::after { content: ""; position: absolute; left: 72px; right: 0; bottom: 0; border-bottom: 1px solid var(--line); }
.topic[aria-current="true"] { background: var(--accent-soft); }
.topic-avatar { width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 19px; }
.topic-main { flex: 1; min-width: 0; }
.topic-top { display: flex; gap: 8px; align-items: baseline; }
.topic-name { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.topic-name svg { width: 15px; height: 15px; color: var(--muted); flex: none; }
.topic-time { color: var(--muted); font-size: 14px; flex: none; }
.topic-bottom { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.topic-last { color: var(--muted); font-size: 15px; flex: 1; min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
.badge { background: var(--badge); color: #fff; border-radius: 11px; min-width: 22px; height: 22px; padding: 0 7px; font-size: 13px; font-weight: 600; display: grid; place-items: center; flex: none; }
.topic.muted .badge { background: var(--muted); }

/* Chat */
.chat-none { flex: 1; display: grid; place-items: center; color: var(--muted); }
.pane-chat:not(.has-topic) .chat-scroll, .pane-chat:not(.has-topic) .bar { display: none; }
.pane-chat.has-topic .chat-none { display: none; }
.chat { display: flex; flex-direction: column; gap: 6px; padding: 12px 12px 20px; max-width: 760px; margin: 0 auto; }
.chat-older { text-align: center; color: var(--muted); font-size: 14px; padding: 10px; }
.day { align-self: center; color: var(--muted); font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.msg { align-self: flex-start; max-width: min(88%, 560px); display: flex; flex-direction: column; gap: 4px; }
.bubble { background: var(--bubble); border-radius: 18px; border-bottom-left-radius: 6px; padding: 8px 12px 6px; box-shadow: var(--shadow); cursor: pointer; user-select: text; -webkit-user-select: text; }
.bubble:active { filter: brightness(.96); }
.msg.flash .bubble { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: var(--accent-soft); } }
.msg-title { font-weight: 600; margin-bottom: 2px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.35; }
.msg-meta { display: flex; justify-content: flex-end; gap: 6px; color: var(--muted); font-size: 12px; margin-top: 3px; }
.msg-img { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin: 4px 0; cursor: zoom-in; background: var(--line); }
.msg-imgfail { color: var(--muted); font-style: italic; font-size: 14px; }
.note { background: var(--note); color: var(--note-text); border-radius: 12px; padding: 6px 10px; font-size: 15px; display: flex; gap: 6px; cursor: pointer; white-space: pre-wrap; overflow-wrap: anywhere; margin-left: 10px; }
.note svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }

/* Søg og indstillinger */
.overlay { position: fixed; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column; }
.overlay > .scroll { max-width: 760px; width: 100%; margin: 0 auto; }
.search-box { display: flex; align-items: center; gap: 8px; margin: 10px auto; padding: 8px 12px; border-radius: 12px; background: var(--panel); width: calc(100% - 32px); max-width: 728px; color: var(--muted); }
.search-box svg { width: 18px; height: 18px; }
.search-box input { flex: 1; border: 0; background: none; font: inherit; color: var(--text); outline: none; }
.search-results { list-style: none; margin: 0; padding: 0 16px; }
.hit { display: block; background: var(--panel); border-radius: 14px; padding: 10px 14px; margin-bottom: 8px; text-decoration: none; color: inherit; }
.hit-top { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.hit-top b { color: var(--accent); }
.hit-text { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.hit .note { margin: 6px 0 0; }

.settings { padding: 0 16px 24px; }
.group-title { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; margin: 22px 4px 6px; }
.card { background: var(--panel); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card-text { margin: 0; line-height: 1.4; font-size: 15px; }
.sender-list { list-style: none; margin: 0; padding: 0; }
.sender { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.sender-info { flex: 1; min-width: 0; }
.sender-info small { color: var(--muted); display: block; font-size: 13px; }
.sender button { background: none; border: 0; color: var(--danger); cursor: pointer; padding: 6px; }
.sender-form { display: flex; gap: 8px; }
.sender-form input { flex: 1; min-width: 0; font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.sender-form .btn-primary { width: auto; }
.new-token { background: var(--accent-soft); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.new-token p { margin: 0; font-size: 15px; }
.new-token code { background: var(--panel); padding: 8px; font-size: 13px; user-select: all; }

/* Ark (menuer og noteeditor) */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 520px; border-radius: 16px 16px 0 0; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); max-height: 85vh; overflow: auto; animation: up .18s ease-out; }
@media (min-width: 600px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 16px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-title { text-align: center; color: var(--muted); font-size: 13px; padding: 4px 8px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-list { background: var(--panel); border-radius: 12px; overflow: hidden; }
.sheet-list button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 14px 16px; cursor: pointer; border-bottom: 1px solid var(--line); }
.sheet-list button:last-child { border-bottom: 0; }
.sheet-list button.danger { color: var(--danger); }
.sheet-cancel { margin-top: 8px; background: var(--panel); border: 0; border-radius: 12px; padding: 14px; width: 100%; font-weight: 600; color: var(--accent); cursor: pointer; }
.sheet textarea, .sheet input[type="text"] { width: 100%; font: inherit; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); resize: vertical; }
.sheet textarea { min-height: 140px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 10px; }
.sheet-quote { font-size: 14px; color: var(--muted); margin: 0 4px 10px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }

.lightbox { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .9); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; background: rgba(30, 30, 30, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; max-width: calc(100% - 32px); }
