:root {
  --paper: #f3eee5; --paper-2: #ebe4d6; --card: #fbf8f2; --ink: #211b17; --ink-2: #6b6058; --line: #d9d0bf;
  --accent: #c8452c; --accent-ink: #fff8f0; --shadow: 0 1px 2px rgba(60,40,20,.06), 0 8px 24px rgba(60,40,20,.08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #17130f; --paper-2: #1f1913; --card: #261f18; --ink: #f1e9dc; --ink-2: #a39583; --line: #3a3026;
    --accent: #e8664a; --accent-ink: #1a110c; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35); }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font: 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .35; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2'/><feColorMatrix values='0 0 0 0 .4  0 0 0 0 .3  0 0 0 0 .2  0 0 0 .12 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"); }
@media (prefers-color-scheme: dark) { body::before { opacity: .2; mix-blend-mode: screen; } }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#app { height: 100%; position: relative; }

/* welcome */
.welcome { min-height: 100%; display: grid; place-items: center; padding: 32px 20px; text-align: center; }
.welcome .stage { max-width: 440px; }
.welcome h1 { font: 500 clamp(2.4rem, 8vw, 3.6rem)/1.05 var(--serif); letter-spacing: -.02em; margin: 28px 0 12px; }
.welcome h1 em { color: var(--accent); font-style: italic; }
.welcome p { color: var(--ink-2); margin: 0 0 28px; font-size: 1.05rem; }
.btn { background: var(--ink); color: var(--paper); border: 0; border-radius: 999px; padding: 14px 28px; font-weight: 600; letter-spacing: .01em; transition: transform .15s, box-shadow .15s; box-shadow: var(--shadow); }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.err { color: var(--accent); min-height: 1.5em; margin-top: 16px; font-size: .95rem; }
.orb-big { width: 168px; height: 168px; margin: 0 auto; animation: float 9s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(4deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* shell */
.shell { display: grid; grid-template-columns: 300px 1fr; height: 100%; position: relative; z-index: 1; }
.side { background: var(--paper-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { padding: 26px 22px 14px; font: 500 1.6rem/1 var(--serif); letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }
.brand small { display: block; font: 400 .8rem var(--sans); color: var(--ink-2); letter-spacing: 0; margin-top: 6px; }
.agents { flex: 1; overflow-y: auto; padding: 6px 10px; }
.agent-item { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: none; border: 0; padding: 12px; border-radius: 16px; transition: background .15s; }
.agent-item:hover { background: color-mix(in srgb, var(--card) 70%, transparent); }
.agent-item[aria-current="true"] { background: var(--card); box-shadow: var(--shadow); }
.agent-item .nm { font: 500 1.15rem var(--serif); line-height: 1.2; }
.agent-item .ds { font-size: .82rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.agent-item .dot { margin-left: auto; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.me { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); padding: 14px 18px calc(14px + env(safe-area-inset-bottom)); transition: background .15s; }
.me:hover, .me[aria-current="true"] { background: color-mix(in srgb, var(--card) 70%, transparent); }
.me .who { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.me .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me small { color: var(--ink-2); font-size: .78rem; }
.avatar { object-fit: cover; background: var(--line); }
.orb { flex: none; display: block; border-radius: 50%; }

.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.head { display: flex; align-items: center; gap: 14px; padding: 16px 28px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 85%, transparent); backdrop-filter: blur(8px); }
.head h2 { margin: 0; font: 500 1.5rem/1.1 var(--serif); }
.head p { margin: 2px 0 0; color: var(--ink-2); font-size: .85rem; }
.back { display: none; background: none; border: 0; font-size: 1.6rem; padding: 0 6px 4px 0; }
.log { flex: 1; overflow-y: auto; padding: 28px clamp(16px, 6vw, 80px); display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.empty { margin: auto; text-align: center; color: var(--ink-2); font: italic 1.2rem var(--serif); max-width: 360px; }
.msg { max-width: min(640px, 86%); padding: 12px 18px; border-radius: 22px; box-shadow: var(--shadow); animation: rise .25s ease-out; overflow-wrap: anywhere; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg.agent { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; font-family: var(--serif); font-size: 1.08rem; align-self: flex-start; }
.msg.user { background: var(--ink); color: var(--paper); border-bottom-right-radius: 6px; align-self: flex-end; }
.msg p { margin: 0 0 .6em; } .msg p:last-of-type { margin-bottom: 0; }
.msg code { font: .88em ui-monospace, Menlo, monospace; background: color-mix(in srgb, currentColor 12%, transparent); padding: 1px 6px; border-radius: 6px; }
.msg pre { background: color-mix(in srgb, currentColor 10%, transparent); padding: 12px; border-radius: 12px; overflow-x: auto; margin: .5em 0; }
.msg pre code { background: none; padding: 0; }
.msg a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.msg time { user-select: none; -webkit-user-select: none; display: block; font: .7rem var(--sans); opacity: .55; margin-top: 6px; }
.typing { align-self: flex-start; display: flex; gap: 5px; padding: 14px 18px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-2); animation: bob 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 40% { transform: translateY(-5px); opacity: .5; } }

.composer { display: flex; align-items: flex-end; gap: 10px; padding: 14px clamp(14px, 4vw, 60px) calc(18px + env(safe-area-inset-bottom)); }
.composer textarea { flex: 1; resize: none; max-height: 180px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 24px; padding: 14px 20px; font: inherit; box-shadow: var(--shadow); }
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.send { width: 50px; height: 50px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 1.3rem; box-shadow: var(--shadow); flex: none; }
.send:disabled { opacity: .4; }

/* profile */
.profile { flex: 1; overflow-y: auto; padding: 28px clamp(16px, 5vw, 60px) 48px; }
.profile-in { max-width: 600px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.identity { display: flex; align-items: center; gap: 22px; }
.avatar-btn { position: relative; width: 112px; height: 112px; padding: 0; border: 0; background: none; border-radius: 50%; overflow: hidden; flex: none; box-shadow: var(--shadow); }
.avatar-btn .cam { position: absolute; inset: auto 0 0 0; padding: 6px 0 8px; font-size: .75rem; font-weight: 600; text-align: center; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.55)); opacity: 0; transition: opacity .15s; }
.avatar-btn:hover .cam, .avatar-btn:focus-visible .cam { opacity: 1; }
@media (hover: none) { .avatar-btn .cam { opacity: 1; } }
h3.big { font: 500 1.9rem/1.1 var(--serif); margin: 0 0 8px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; font-size: .9rem; }
.link:hover { color: var(--ink); }
.link.danger:hover { color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 20px 22px; box-shadow: var(--shadow); }
.card h3 { font: 500 1.25rem var(--serif); margin: 0 0 2px; }
.hint { margin: 0 0 14px; color: var(--ink-2); font-size: .88rem; }
.emails { list-style: none; margin: 0 0 14px; padding: 0; }
.emails li { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.emails li:first-child { border-top: 0; }
.emails .addr { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.badge { font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; background: var(--accent); color: var(--accent-ink); padding: 3px 10px; border-radius: 999px; }
.empty-line { color: var(--ink-2); font-style: italic; margin: 0 0 14px; }
.inline { display: flex; gap: 10px; }
.inline input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 999px; padding: 11px 18px; font: inherit; }
.inline input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.btn.small { padding: 10px 22px; box-shadow: none; }
.phone-saved { color: var(--ink-2); font-size: .88rem; min-height: 1.2em; margin-top: 8px; }
.card .err { margin-top: 10px; min-height: 0; }
.signout { justify-self: center; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side, .main { grid-area: 1 / 1; }
  .shell[data-view="chat"] .side, .shell[data-view="profile"] .side { display: none; }
  .shell[data-view="list"] .main { display: none; }
  .identity { flex-direction: column; text-align: center; }
  .row-actions { justify-content: center; }
  .back { display: block; }
  .head { padding: 12px 16px; }
}

/* attachments */
.dock { position: relative; }
.composer { align-items: flex-end; }
.attach-wrap { position: relative; flex: none; }
.attach { width: 50px; height: 50px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 1.7rem; line-height: 1; box-shadow: var(--shadow); }
.attach[aria-expanded="true"] { background: var(--ink); color: var(--paper); }
.menu { position: absolute; bottom: 60px; left: 0; min-width: 240px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow), 0 12px 40px rgba(0,0,0,.15); padding: 6px; z-index: 5; }
.menu[hidden], .tray[hidden] { display: none; }
.mi { display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: 0; background: none; padding: 10px 14px; border-radius: 12px; text-align: left; }
.mi:hover, .mi:focus-visible { background: var(--paper-2); }
.mi small { color: var(--ink-2); }
.tray { display: flex; gap: 10px; overflow-x: auto; padding: 4px clamp(14px, 4vw, 60px) 0; }
.chip { position: relative; display: flex; align-items: center; gap: 10px; flex: none; max-width: 240px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 6px 34px 6px 6px; overflow: hidden; box-shadow: var(--shadow); }
.chip img { width: 44px; height: 44px; object-fit: cover; border-radius: 10px; }
.chip.error { border-color: var(--accent); }
.chip .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); transition: width .15s; }
.chip .x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--paper-2); line-height: 1; font-size: 1.1rem; }
.ico { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; background: var(--paper-2); color: var(--ink-2); font: 700 .7rem var(--sans); letter-spacing: .04em; }
.fn { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.fn .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.fn small { color: var(--ink-2); font: .75rem var(--sans); }
.main.drop::after { content: "Drop to attach"; position: absolute; inset: 8px; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 24px; background: color-mix(in srgb, var(--paper) 80%, transparent); font: italic 1.6rem var(--serif); z-index: 6; pointer-events: none; }
.main { position: relative; }
.atts { display: flex; flex-direction: column; gap: 8px; margin: 2px 0 4px; }
.msg > .atts:first-child { margin-top: 0; }
.pics { display: grid; gap: 4px; grid-template-columns: 1fr; }
.pics.n2, .pics.n4 { grid-template-columns: 1fr 1fr; }
.pics.n3 { grid-template-columns: 1fr 1fr; }
.pic { padding: 0; border: 0; background: var(--paper-2); border-radius: 14px; overflow: hidden; display: block; }
.pic img { display: block; width: 100%; max-height: 320px; object-fit: cover; }
.pics.n1 .pic img { max-height: 420px; object-fit: contain; }
.file { display: flex; align-items: center; gap: 10px; text-decoration: none; background: color-mix(in srgb, currentColor 9%, transparent); border-radius: 14px; padding: 8px 12px 8px 8px; font-family: var(--sans); }
.msg .file .fn small { color: inherit; opacity: .65; }
.msg .file .ico { background: color-mix(in srgb, currentColor 14%, transparent); color: inherit; }
.lightbox { position: fixed; inset: 0; z-index: 20; background: rgba(10,8,6,.88); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 16px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: calc(100% - 64px); border-radius: 12px; }
.lb-bar { display: flex; gap: 12px; align-items: center; color: #fff; }
.lb-bar span { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .75; }
.lb-bar a, .lb-bar button { color: #fff; background: rgba(255,255,255,.14); border: 0; border-radius: 999px; padding: 8px 18px; text-decoration: none; }
.lb-bar .btn { background: var(--accent); color: var(--accent-ink); }

.head-av{position:relative;display:inline-flex;flex:none}
.head-pic{border:0;background:none;padding:0;border-radius:50%;cursor:pointer;line-height:0}
.head-pic:hover,.head-pic:focus-visible{outline:2px solid var(--accent,#7a8fd6);outline-offset:2px}
.head-rm{position:absolute;top:-6px;right:-6px;width:20px;height:20px;border-radius:50%;border:0;background:rgba(0,0,0,.6);color:#fff;font-size:14px;line-height:20px;padding:0;cursor:pointer;opacity:0;transition:opacity .15s}
.head-av:hover .head-rm,.head-rm:focus-visible{opacity:1}
@media (hover:none){.head-rm{opacity:1}}
img.orb.avatar{object-fit:cover;border-radius:50%}

/* voice */
.mic { min-width: 50px; height: 50px; padding: 0 16px; gap: 7px; grid-auto-flow: column; border-radius: 25px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; font: 600 .95rem var(--sans); cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); display: grid; place-items: center; box-shadow: var(--shadow); flex: none; }
.mic:hover { background: var(--paper-2); }
.mic.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 22%, transparent); } }
.recbar { display: flex; align-items: center; gap: 10px; margin: 6px clamp(14px, 4vw, 60px) 0; padding: 10px 16px; background: var(--card); border: 1px solid var(--accent); border-radius: 18px; font: .95rem var(--sans); box-shadow: var(--shadow); }
.recbar[hidden] { display: none; }
.rdot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }
.rt { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.rc { margin-left: auto; border: 0; background: var(--paper-2); color: var(--ink); border-radius: 999px; padding: 6px 14px; font: inherit; }
.voice { display: flex; align-items: center; gap: 10px; min-width: min(240px, 70vw); font-family: var(--sans); }
.play { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); position: relative; }
.play::before { content: ""; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px; background: currentColor; clip-path: polygon(22% 8%, 94% 50%, 22% 92%); }
.play.playing::before { clip-path: polygon(14% 8%, 38% 8%, 38% 92%, 14% 92%, 14% 8%, 62% 8%, 86% 8%, 86% 92%, 62% 92%, 62% 8%); }
.seek { flex: 1; min-width: 60px; height: 4px; -webkit-appearance: none; appearance: none; border-radius: 4px; background: linear-gradient(to right, var(--accent) var(--p, 0%), color-mix(in srgb, currentColor 22%, transparent) var(--p, 0%)); }
.seek::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 0; }
.seek::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 0; }
.tm { font-size: .8rem; font-variant-numeric: tabular-nums; opacity: .75; min-width: 2.6em; text-align: right; }
.chip.vchip { max-width: 300px; }
.chip.vchip .voice { min-width: 190px; }
.chip.vchip .cs { color: var(--ink-2); font: .75rem var(--sans); }

/* editing a sent message */
.msg time .edit { background: none; border: 0; color: inherit; opacity: 0; cursor: pointer; font-size: .95rem; padding: 0 0 0 8px; transition: opacity .15s; }
.msg.user:hover time .edit, .msg time .edit:focus-visible { opacity: .8; }
@media (hover: none) { .msg time .edit { opacity: .6; } }
.msg.editor { width: min(640px, 86%); display: flex; flex-direction: column; gap: 8px; }
.msg.editor textarea { width: 100%; box-sizing: border-box; resize: none; background: color-mix(in srgb, var(--paper) 10%, transparent); color: inherit; border: 1px solid color-mix(in srgb, var(--paper) 35%, transparent); border-radius: 12px; padding: 8px 12px; font: inherit; line-height: 1.4; outline: none; }
.msg.editor textarea:focus { border-color: var(--accent); }
.msg.editor .ea { display: flex; gap: 8px; justify-content: flex-end; }
.msg.editor .ea button { font: .85rem var(--sans); border-radius: 999px; padding: 6px 14px; cursor: pointer; border: 1px solid color-mix(in srgb, var(--paper) 35%, transparent); background: none; color: inherit; }
.msg.editor .ea .ok { background: var(--accent); border-color: var(--accent); color: #fff; }
.msg.editor .ea .ok:disabled { opacity: .5; }
.msg.editor .err { color: #ffb4a6; min-height: 0; }
.msg.editor .err:empty { display: none; } .msg time .edit svg { vertical-align: -2px; }

.mic .ml { white-space: nowrap; }
.recbar .rh { color: var(--ink-2); font-size: .85rem; flex: 1; }
.recbar.cancelling { border-color: #c0392b; }
.recbar.cancelling .rh { color: #c0392b; }
@media (max-width: 420px) { .composer { gap: 6px; } .composer textarea { min-width: 0; padding: 14px 14px; } .mic { padding: 0 12px; } }
.msg time .speak { background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 6px 4px 6px 10px; margin: -6px 0 -6px 4px; vertical-align: middle; }
.msg time .speak:hover, .msg time .speak:focus-visible, .msg time .speak.playing { opacity: 1; }
.msg time .speak svg { vertical-align: -3px; }
.msg time .speak.loading { animation: speakpulse 1s ease-in-out infinite; }
@keyframes speakpulse { 50% { opacity: .25; } }
.voice-set { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.voice-set select { flex: 1 1 180px; font: inherit; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.check { display: block; font-size: .95rem; margin: 6px 0 12px; }
.check input { margin-right: 6px; transform: scale(1.15); }
.msg time .speak .spk-err { font: .7rem var(--sans); margin-left: 4px; color: #b3402a; }

.lang { flex: none; margin-left: auto; height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); color: var(--ink-2); font: 600 .8rem var(--sans); cursor: pointer; white-space: nowrap; }
.lang:hover { background: var(--paper-2); color: var(--ink); }
.send.queued { animation: qpulse 1s ease-in-out infinite; }
@keyframes qpulse { 50% { opacity: .55; } }
.msg .trn { display: block; color: var(--ink-2); font-size: .8rem; margin-top: 4px; }
