/* hermes-bot — from mockup v2 (user-approved). Wide (≥820px) = 3 columns; narrow = phone. */
:root {
  --bg: #0f0f0f; --panel: #171717; --panel2: #1f1f1f; --line: #262626; --text: #ececec; --sub: #9a9a9a;
  --accent: #1680f3; --user: #2a2a2a; --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444; --r: 12px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root { --bg: #fff; --panel: #f5f5f5; --panel2: #ececec; --line: #e5e5e5; --text: #111; --sub: #6b6b6b; --user: #1c1c1c; }
  .msg.user .bubble { color: #fff; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
body { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); font-size: 16px; } /* 16px: no iOS zoom */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.sub { color: var(--sub); font-size: 14px; line-height: 1.5; }
.err { color: var(--bad); font-size: 14px; min-height: 1.4em; margin: 0; }

/* login */
.login { height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center; }
.login-card img { align-self: center; border-radius: 18px; }
.login-card h1 { margin: 4px 0 0; font-size: 24px; }
.login-card input { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.login-card .btn { padding: 12px; font-size: 16px; }

.app { position: fixed; inset: 0; display: flex; overflow: hidden; }
.pane-list, .pane-chat { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); transition: transform .25s ease; }
.app:not(.wide) .pane-chat { transform: translateX(100%); }
.app:not(.wide).in-chat .pane-chat { transform: none; }
.app:not(.wide).in-chat .pane-list { transform: translateX(-25%); }
.app.wide .pane-list { position: relative; width: 320px; flex: none; border-right: 1px solid var(--line); }
.app.wide .pane-chat { position: relative; flex: 1; min-width: 0; }
.app.wide .back { display: none; }
.empty { flex: 1; display: grid; place-items: center; color: var(--sub); }

header { display: flex; align-items: center; gap: 10px; padding: calc(var(--safe-top) + 14px) 16px 12px; border-bottom: 1px solid var(--line); flex: none; }
header h1 { font-size: 20px; margin: 0; flex: 1; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; flex: none; }
.icon-btn:hover { background: var(--panel); }

.avatar { position: relative; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; flex: none; background: var(--panel2); }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar .dot { position: absolute; right: 1px; bottom: 1px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--bg); background: var(--ok); }

.search { margin: 10px 12px 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; width: calc(100% - 24px); }
.list { flex: 1; overflow-y: auto; padding: 4px 0 calc(var(--safe-bottom) + 90px); -webkit-overflow-scrolling: touch; }
.app.wide .list { padding-bottom: 12px; }
.section-label { font-size: 12px; color: var(--sub); padding: 12px 16px 4px; }
.row { position: relative; display: flex; gap: 12px; align-items: center; padding: 10px 8px 10px 16px; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.row:hover, .row.active { background: var(--panel); }
.row .open { position: absolute; inset: 0; }
.row .main, .row .avatar { pointer-events: none; }
.row .main { flex: 1; min-width: 0; }
.row .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 12px; color: var(--sub); flex: none; }
.row .last { font-size: 14px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row .more { position: relative; z-index: 1; width: 32px; height: 32px; border-radius: 50%; color: var(--sub); flex: none; }
.row .more:hover { background: var(--panel2); color: var(--text); }
.pin { font-size: 11px; margin-left: 4px; }
.fab { position: absolute; right: 20px; bottom: calc(var(--safe-bottom) + 24px); background: var(--accent); color: #fff; border-radius: 28px; padding: 14px 20px; font-weight: 600; box-shadow: 0 6px 20px rgba(22,128,243,.35); }
.app.wide .fab { position: static; margin: 10px 12px 14px; border-radius: 10px; padding: 10px; box-shadow: none; }

.menu { position: absolute; z-index: 30; min-width: 160px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 8px; font-size: 15px; }
.menu button:hover { background: var(--panel); }
.menu .danger { color: var(--bad); }

/* floating capsule */
.chat-top { position: absolute; z-index: 5; left: 0; right: 0; top: 0; height: calc(var(--safe-top) + 64px); pointer-events: none;
  background: linear-gradient(var(--bg) 55%, transparent); }
.capsule { position: absolute; left: 50%; top: calc(var(--safe-top) + 12px); transform: translateX(-50%); pointer-events: auto; max-width: calc(100% - 120px);
  display: flex; align-items: center; gap: 8px; padding: 5px 14px 5px 5px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.capsule:hover { border-color: var(--accent); }
.capsule b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.capsule .avatar { width: 28px; height: 28px; font-size: 15px; }
.dot-run { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite; flex: none; }
.chat-top .back { position: absolute; left: 8px; top: calc(var(--safe-top) + 10px); pointer-events: auto; background: var(--panel2); border: 1px solid var(--line); }

.msgs { flex: 1; overflow-y: auto; padding: calc(var(--safe-top) + 72px) 16px 16px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.app.wide .msgs { padding: 72px max(24px, calc((100% - 760px) / 2)) 24px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: min(480px, 82%); padding: 10px 14px; border-radius: var(--r); line-height: 1.6; font-size: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); }
.msg.bot .bubble { padding-left: 0; max-width: 100%; }
.bubble code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.bubble pre { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-x: auto; white-space: pre; font-size: 13px; margin: 6px 0; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--accent); }
.meta { font-size: 12px; color: var(--sub); margin-top: 4px; }
.status { align-self: center; font-size: 12px; color: var(--sub); background: var(--panel); border-radius: 999px; padding: 4px 12px; max-width: 92%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.warn { color: var(--warn); }
.status.bad { color: var(--bad); white-space: normal; }
.card { border: 1px solid var(--line); background: var(--panel); border-radius: var(--r); padding: 14px; max-width: min(480px, 92%); }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; max-height: 200px; overflow: auto; margin: 0 0 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); font-size: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }
.typing { color: var(--sub); }
.typing i { animation: blink 1s infinite; font-style: normal; }
@keyframes blink { 50% { opacity: .2; } }
.conn { text-align: center; font-size: 12px; color: var(--warn); padding: 4px; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px calc(var(--safe-bottom) + 10px); border-top: 1px solid var(--line); flex: none; background: var(--bg); }
.app.wide .composer { padding: 12px max(24px, calc((100% - 760px) / 2)) 18px; border-top: 0; }
.composer textarea { flex: 1; resize: none; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; max-height: 160px; line-height: 1.4; }
.send { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 18px; flex: none; }
.send.stop { background: var(--panel2); color: var(--text); border: 1px solid var(--line); font-size: 14px; }

/* sheet: phone = bottom sheet; wide = third column */
.scrim { position: absolute; inset: 0; z-index: 20; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet { position: absolute; z-index: 21; left: 0; right: 0; bottom: 0; background: var(--panel); border-radius: 20px 20px 0 0; padding: 8px 20px calc(var(--safe-bottom) + 24px);
  transform: translateY(100%); transition: transform .25s ease; max-height: 86%; overflow-y: auto; }
.sheet.open { transform: none; }
.app.wide .scrim { display: none; }
.app.wide .sheet { position: relative; flex: none; width: 0; padding: 0; max-height: none; border-radius: 0; transform: none;
  overflow: hidden; transition: width .25s ease; border-left: 1px solid transparent; }
.app.wide .sheet.open { width: 360px; border-left-color: var(--line); }
.app.wide .sheet-inner { width: 360px; height: 100%; overflow-y: auto; padding: 16px 20px 24px; }
.app.wide .grab { display: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet .close { position: absolute; right: 12px; top: 12px; z-index: 1; }
.sheet-h { font-size: 18px; margin: 6px 0 12px; }
.profile { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 18px 0 14px; }
.avatar-edit { position: relative; border-radius: 50%; }
.avatar-edit .avatar { width: 88px; height: 88px; font-size: 42px; }
.avatar-edit .pen { position: absolute; right: 0; bottom: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; display: grid; place-items: center; opacity: 0; transition: opacity .15s; }
.avatar-edit:hover .pen, .avatar-edit:focus-visible .pen { opacity: 1; }
@media (hover: none) { .avatar-edit .pen { opacity: 1; } }
.name-edit { font-size: 20px; font-weight: 700; text-align: center; background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; width: 100%; max-width: 280px; }
.name-edit:hover { border-color: var(--line); }
.name-edit:focus { border-color: var(--accent); background: var(--bg); outline: none; }
.chip { font-size: 12px; color: var(--sub); }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.tabs button { padding: 6px 14px; border-radius: 999px; font-size: 14px; color: var(--sub); }
.tabs button[aria-selected=true] { background: var(--panel2); color: var(--text); }
.sec-title { font-size: 13px; color: var(--sub); margin: 6px 0 8px; }
.task { display: flex; align-items: center; gap: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.task .t { flex: 1; min-width: 0; }
.task .t b { display: block; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.task .t span { font-size: 13px; color: var(--sub); }
.task.off .t { opacity: .5; }
.toggle { position: relative; width: 44px; height: 26px; flex: none; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.toggle span { position: absolute; inset: 0; border-radius: 13px; background: #555; transition: background .2s; pointer-events: none; }
.toggle span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(18px); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle input:disabled + span { opacity: .5; }
.field { border-top: 1px solid var(--line); padding: 12px 0; }
.field label, .field .lbl { display: block; font-size: 12px; color: var(--sub); margin-bottom: 6px; }
.field textarea { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical; min-height: 64px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; }
.switch-row > label:first-child { margin: 0; font-size: 15px; color: var(--text); }
.note { font-size: 12px; color: var(--sub); text-align: center; margin: 8px 0 0; }
.device { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; font-size: 13px; }
.device span { color: var(--sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .btn { flex: none; padding: 6px 10px; font-size: 13px; }

.dlg-scrim { position: absolute; inset: 0; z-index: 40; background: rgba(0,0,0,.55); }
.dialog { position: absolute; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(340px, calc(100% - 40px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.dialog h2 { font-size: 17px; margin: 0 0 12px; }
.dialog p { color: var(--sub); font-size: 14px; line-height: 1.5; margin: 0 0 14px; }
.dialog input[type=text] { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 14px; }
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 12px; }
.emoji-grid button { font-size: 24px; aspect-ratio: 1; border-radius: 10px; background: var(--bg); border: 2px solid transparent; }
.emoji-grid button[aria-pressed=true] { border-color: var(--accent); }
.upload { display: block; text-align: center; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; font-size: 14px; color: var(--sub); cursor: pointer; margin-bottom: 14px; }
.upload input { display: none; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(var(--safe-bottom) + 90px); transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90%; text-align: center; }
.toast.show { opacity: 1; }
