:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel2: #202c33;
  --line: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-dim: #025c4c;
  --danger: #f15c6d;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--panel); padding: 32px; border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 12px; width: 280px; border: 1px solid var(--line);
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }
.login-card input {
  padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text);
}
.login-card button {
  padding: 11px; border: none; border-radius: 8px; background: var(--accent); color: #04231d; font-weight: 600;
}
.err { color: var(--danger); font-size: 13px; margin: 0; text-align: center; }

/* Shell */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar .spacer { flex: 1; }
.conn { font-size: 12px; color: var(--muted); }
.conn.ok::before { content: "● "; color: var(--accent); }
.conn.bad::before { content: "● "; color: var(--danger); }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); padding: 6px 10px; border-radius: 8px; }

.tabs { display: flex; gap: 4px; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 49px; z-index: 4; }
.tab { background: transparent; color: var(--muted); border: none; padding: 8px 12px; border-radius: 8px; font-weight: 500; }
.tab.active { color: var(--text); background: var(--panel2); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; font-size: 11px; line-height: 18px; text-align: center; background: var(--accent); color: #04231d; border-radius: 9px; }
.badge:empty { display: none; }

main { max-width: 760px; margin: 0 auto; padding: 12px; }
.panel { display: none; }
.panel.active { display: block; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card .text { margin: 8px 0; white-space: pre-wrap; word-break: break-word; }
.card .actions { display: flex; gap: 8px; }
.btn { padding: 7px 14px; border-radius: 8px; border: none; font-weight: 600; }
.btn.approve { background: var(--accent); color: #04231d; }
.btn.discard { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Chat list */
.chat-row { display: flex; align-items: center; gap: 12px; padding: 11px 8px; border-bottom: 1px solid var(--line); cursor: pointer; }
.chat-row:hover { background: var(--panel2); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-dim); display: grid; place-items: center; font-weight: 600; color: var(--text); flex-shrink: 0; }
.chat-main { flex: 1; min-width: 0; }
.chat-name { font-weight: 500; }
.chat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 11px; color: var(--muted); }
.unread { background: var(--accent); color: #04231d; border-radius: 9px; font-size: 11px; min-width: 18px; text-align: center; padding: 0 5px; }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 6px; background: var(--panel2); color: var(--muted); }

/* Overlay (chat detail) */
.overlay { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; z-index: 20; }
.overlay.hidden { display: none; }
.overlay-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 78%; padding: 7px 11px; border-radius: 8px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.in { background: var(--panel2); align-self: flex-start; }
.msg.out { background: var(--accent-dim); align-self: flex-end; }
.msg img { max-width: 220px; border-radius: 6px; display: block; }
.msg .ts { font-size: 10px; color: var(--muted); margin-top: 3px; }
.compose { display: flex; gap: 8px; padding: 10px; background: var(--panel); border-top: 1px solid var(--line); }
.compose input { flex: 1; padding: 10px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); }
.compose button { padding: 10px 16px; border: none; border-radius: 20px; background: var(--accent); color: #04231d; font-weight: 600; }
.scheduled-badge { font-size: 11px; color: var(--accent); }

/* Cockpit */
.sec { font-size: 13px; color: var(--muted); margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.agent-note { background: var(--accent-dim); color: var(--text); padding: 10px 12px; border-radius: var(--radius); margin-bottom: 10px; font-size: 14px; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.draft-text { width: 100%; min-height: 64px; resize: vertical; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; margin: 8px 0; }
.ctx { font-size: 13px; color: var(--muted); border-left: 3px solid var(--line); padding: 4px 0 4px 10px; margin: 6px 0; font-style: italic; }
select[data-reltype] { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: inherit; }

/* Tiers */
.tier-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 8px; vertical-align: middle; flex-shrink: 0; cursor: pointer; border: 2px solid transparent; }
.tier-dot.t1 { background: #f15c6d; } .tier-dot.t2 { background: #e8b04b; } .tier-dot.t3 { background: #5b9bd5; }
.tier-dot.tnone { background: transparent; border-color: var(--line); }
.chatbar { display: flex; align-items: center; gap: 8px; padding: 4px 2px 10px; }
.tiers { display: flex; gap: 6px; }
.tierbtn { background: var(--panel2); color: var(--muted); border: 1px solid var(--line); padding: 5px 12px; border-radius: 8px; font-size: 13px; }
.tierbtn.on { background: var(--accent); color: #04231d; border-color: var(--accent); font-weight: 600; }

/* Profil */
.profile-body { flex: 1; overflow-y: auto; padding: 12px; max-width: 760px; margin: 0 auto; width: 100%; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.prow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 4px 0; }
.phead { font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.plist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 5px; }
.plist li { font-size: 14px; }
.mini { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 1px 7px; font-size: 12px; cursor: pointer; }
.mini.add { margin-left: auto; }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2a3942; color: var(--text); padding: 11px 18px; border-radius: 22px; font-size: 14px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 90vw; text-align: center; }
.toast.hidden { display: none; }

/* Schreibstil pro Person (Profil-Overlay) */
.styleedit {
  width: 100%; margin: 8px 0 6px; padding: 9px 10px; resize: vertical;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font: inherit; font-size: 13px;
}

/* Chat-Layout: links Nachrichten, rechts Profil-Spalte */
.chat-body { flex: 1; display: flex; min-height: 0; position: relative; }
.chat-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-profile {
  width: 340px; flex-shrink: 0; border-left: 1px solid var(--line);
  background: var(--bg); display: flex; flex-direction: column; min-height: 0;
}
.chat-profile .profile-body { max-width: none; margin: 0; }
.cp-head { display: none; }
.cp-name { font-weight: 600; font-size: 16px; margin: 2px 2px 10px; }
#profileBtn { display: none; } /* Desktop: Spalte ist immer sichtbar */

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  /* Profil-Spalte: ausgeblendet, slidet per 👤 über den Chat */
  #profileBtn { display: inline-block; }
  .chat-profile {
    position: absolute; inset: 0; width: auto; border-left: none; z-index: 6;
    transform: translateX(100%); transition: transform .22s ease;
  }
  .chat-profile.open { transform: translateX(0); }
  .cp-head {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    background: var(--panel); border-bottom: 1px solid var(--line);
  }
  .cp-name { display: none; } /* Name steht mobil im cp-head */
}

@media (max-width: 600px) {
  .topbar { padding: 8px 10px; gap: 6px; }
  .ghost { padding: 6px 8px; font-size: 13px; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 8px 10px; white-space: nowrap; }
  main { padding: 10px 8px; }
  .msg { max-width: 88%; }
  .msg img { max-width: 180px; }
  .card { padding: 10px 12px; }
  .card .actions { flex-wrap: wrap; }
  .prow { flex-wrap: wrap; }
  .tiers { flex-wrap: wrap; }
  .chatbar { flex-wrap: wrap; }
  .overlay-head { padding: 8px 10px; gap: 6px; }
  .overlay-head strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
}

/* iOS zoomt bei Inputs < 16px beim Fokussieren — deshalb fix 16px */
.compose input, .login-card input, .draft-text, .styleedit { font-size: 16px; }
