:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e3e5e8;
  --text: #1d1d1f;
  --muted: #6b6f76;
  --accent: #2f6f5e;
  --accent-soft: #e6f0ed;
  --danger: #c4383d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button { font: inherit; cursor: pointer; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; }
.secondary { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); border-radius: 8px; padding: 6px 12px; }
.link { background: none; border: 0; color: var(--accent); padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.login-box input { font: inherit; color: var(--text); padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; }

/* app shell */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; }
.topbar-right { display: flex; gap: 14px; align-items: center; }
.conn { font-size: 12px; color: #7a4b00; background: #fff4e5; padding: 2px 8px; border-radius: 10px; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px 1fr 320px; }
.dialogs { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.chat { min-width: 0; display: flex; flex-direction: column; }
.card { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px 16px; }

/* dialog list */
.dialog-list { list-style: none; margin: 0; padding: 0; }
.dialog-list li { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.dialog-list li:hover { background: #fafafa; }
.dialog-list li.active { background: var(--accent-soft); }
.dl-top { display: flex; justify-content: space-between; gap: 8px; }
.dl-name { font-weight: 600; }
.dialog-list li.unread .dl-name::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 6px; border-radius: 50%; background: var(--danger); vertical-align: middle; }
.dl-preview { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0; }
.dl-meta { color: var(--muted); font-size: 12px; }

/* chat */
.chat-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-title { font-weight: 600; font-size: 15px; }
.chat-head-right { display: flex; gap: 10px; align-items: center; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; flex-direction: column; max-width: 70%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.in .bubble { background: var(--panel); border: 1px solid var(--line); }
.out .bubble { background: var(--accent); color: #fff; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 2px; padding: 0 4px; }
.typing { padding: 2px 16px 6px; color: var(--muted); font-style: italic; font-size: 13px; }
.reply { display: flex; gap: 8px; padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--line); align-items: flex-end; }
.reply textarea { flex: 1; font: inherit; resize: vertical; min-height: 44px; max-height: 200px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.reply-error { padding: 0 16px 8px; background: var(--panel); }

/* visitor card */
.card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 6px; }
.card h3:first-child { margin-top: 0; }
.source-label { font-size: 16px; font-weight: 600; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 4px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.raw { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; color: var(--muted); overflow-wrap: anywhere; white-space: pre-wrap; margin-top: 6px; }
.visit-code { font-size: 22px; font-weight: 600; letter-spacing: .12em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pages { list-style: none; margin: 0; padding: 0; }
.pages li { padding: 4px 0; border-bottom: 1px dashed var(--line); overflow-wrap: anywhere; }
.pages .time { color: var(--muted); font-size: 12px; margin-right: 6px; }
.url { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.card a { color: var(--accent); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 260px 1fr; }
  .card { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: 40vh; }
  .app { height: auto; min-height: 100vh; }
  .chat { min-height: 60vh; }
}

@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  .dialogs { max-height: 35vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .msg { max-width: 88%; }
}
