:root {
  --ink: #182d34;
  --muted: #536873;
  --canvas: #f4f6f5;
  --paper: #fff;
  --rule: #d5deda;
  --brand: #ab252c;
  --brand-dark: #8e1720;
  --forest: #14614c;
  --mint: #e2f1e9;
  color: var(--ink);
  font: 16px/1.5 "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--canvas);
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { letter-spacing: -.035em; line-height: 1.17; }
h1 { font-size: clamp(1.9rem, 4vw, 2.55rem); }
h2 { font-size: 1.17rem; }
h3 { font-size: 1.02rem; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 3px solid #0079b1; outline-offset: 3px; }
label { display: block; font-weight: 650; font-size: .86rem; }
input, select, textarea {
  display: block; width: 100%; min-width: 0; margin: 5px 0 0;
  border: 1px solid #a9b8b6; border-radius: 8px; padding: .58rem .72rem;
  color: var(--ink); background: #fff;
}
textarea { resize: vertical; }
button { border: 0; color: inherit; }
button.primary, button.secondary {
  border: 1px solid transparent; border-radius: 8px; min-height: 42px;
  font-size: .9rem; font-weight: 650; padding: .56rem 1rem; line-height: 1.3;
}
button.primary { background: var(--brand); color: #fff; }
button.primary:hover:enabled { background: var(--brand-dark); }
button.secondary { background: #fff; border-color: #b7c6c2; }
button.secondary:hover:enabled, .thread:hover { background: #f2f6f3; }
button.small { padding: .38rem .64rem; min-height: 34px; font-size: .82rem; }
button.plain { background: none; color: var(--muted); text-decoration: underline; padding: .4rem; }
.muted { color: var(--muted); font-size: .84rem; }
.loading { padding: 2rem; }
.brand { display: flex; align-items: center; gap: .65rem; font-size: 1.05rem; letter-spacing: -.035em; }
.mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; color: #fff; background: var(--brand); font: bold italic 25px/1 Georgia, serif; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.login-card { width: min(410px, 100%); background: var(--paper); border: 1px solid var(--rule); border-radius: 18px; box-shadow: 0 14px 50px #213a3510; padding: clamp(23px, 5vw, 36px); }
.login-card h1 { font-size: 1.9rem; margin: 2rem 0 1.35rem; }
.login-card label:not(:first-child), dialog label { margin-top: 1rem; }
.login-card .primary, dialog form > .primary { margin-top: 1.3rem; width: 100%; }
.workspace { min-height: 100vh; display: grid; grid-template-columns: 218px minmax(0, 1fr); }
.sidebar { display: flex; flex-direction: column; background: #182d34; color: #fff; padding: 28px 16px; }
.sidebar .brand { margin: 0 3px 38px; }
.sidebar .mark { background: #f6d8d6; color: #8c1820; }
.sidebar nav { display: flex; flex-direction: column; gap: .35rem; }
.sidebar nav button { background: transparent; color: #d5e0de; border-radius: 7px; padding: .7rem 1rem; text-align: left; font-weight: 600; }
.sidebar nav button[aria-current=page] { color: #fff; background: #35494c; box-shadow: inset 3px 0 0 #f4aaa5; }
.sidebar nav button:hover { background: #304349; }
.account { margin-top: auto; display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; padding: 1.25rem .3rem 0; font-size: .8rem; color: #cbd8d5; overflow-wrap: anywhere; }
.account button { color: #fff; background: transparent; text-decoration: underline; text-underline-offset: .18rem; }
.main { width: min(1250px, 100%); margin: 0 auto; padding: clamp(22px, 3.6vw, 58px); }
.heading, .toolbar, .section-head, .device-heading, .dialog-head, .reply-actions, .call-row, .card-head, .pair-box { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }
.heading { margin-bottom: 1.5rem; align-items: end; flex-wrap: wrap; }
.heading h1 { margin-bottom: .25rem; }
.toolbar { align-items: end; }
.compact { color: var(--muted); font-size: .77rem; }
.compact select { max-width: 290px; font-size: .88rem; }
.panel, .device-card, .pair-box { border: 1px solid var(--rule); background: #fff; border-radius: 13px; }
.panel { overflow: hidden; }
.notice { background: #e5f2eb; color: #204a3e; border-radius: 7px; margin: 0 0 1rem; padding: .7rem .95rem; font-size: .9rem; }
.notice.error { background: #fbebe7; color: #853020; }
.login-card .notice, dialog .notice { margin-top: 1rem; }
.section-head { min-height: 71px; padding: 15px 18px; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.inbox { display: grid; grid-template-columns: minmax(200px, 34%) minmax(0, 1fr); min-height: 440px; }
.thread-column { min-width: 0; border-right: 1px solid var(--rule); }
.thread-list { max-height: 72vh; overflow: auto; }
.thread { display: block; width: 100%; min-height: 74px; padding: .85rem 1rem; text-align: left; background: white; border: 0; border-bottom: 1px solid var(--rule); border-left: 3px solid transparent; }
.thread.active { background: #edf5f0; border-left-color: var(--forest); }
.thread strong, .thread .preview { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { color: var(--muted); margin: .15rem 0; font-size: .9rem; }
.thread-meta, .bubble-meta { color: var(--muted); font-size: .76rem; }
.conversation { min-width: 0; display: grid; }
#thread-detail { display: flex; flex-direction: column; min-width: 0; min-height: 410px; }
.conversation-head { min-height: 71px; display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--rule); overflow-wrap: anywhere; }
#back { display: none; }
.bubbles { flex: 1; max-height: 54vh; min-height: 170px; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 13px; }
.bubble { max-width: 88%; align-self: flex-start; }
.bubble.out { align-self: flex-end; }
.bubble p { white-space: pre-wrap; overflow-wrap: anywhere; background: #f0f2f2; padding: 9px 13px; border-radius: 12px 12px 12px 2px; }
.bubble.out p { background: var(--mint); border-radius: 12px 12px 2px 12px; }
.bubble-meta { margin: 2px 2px 0; }
.bubble.out .bubble-meta { text-align: right; }
.reply-form { background: #f8faf9; border-top: 1px solid var(--rule); padding: 14px 18px; }
.reply-actions { margin-top: .58rem; }
.reply-actions button { white-space: nowrap; }
.empty { color: var(--muted); display: grid; align-content: center; padding: 28px 20px; font-size: .9rem; }
.call-row { padding: 16px 20px; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.call-row:last-child { border: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.meta-line { margin-top: .2rem; color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.device-heading { margin-bottom: .85rem; }
.device-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(285px, 100%), 1fr)); gap: 1rem; }
.device-card { padding: 18px; min-width: 0; }
.card-head { flex-wrap: wrap; }
.card-head h3 { overflow-wrap: anywhere; }
.badge { color: #175941; background: #dff1e7; border-radius: 100px; font-size: .76rem; font-weight: 650; padding: 3px 9px; }
.badge.wait { color: #774314; background: #f9ebce; }
.badge.off { color: #525d61; background: #e9eded; }
dl { margin: 14px 0; }
dl > div { display: flex; align-items: start; justify-content: space-between; gap: 8px; border-top: 1px solid var(--rule); padding: .45rem 0; font-size: .83rem; }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.pair-box { align-items: start; padding: 16px 20px; margin: 0 0 1rem; border-color: #a8c4b6; }
.code { font: 650 clamp(1.4rem, 4vw, 2rem)/1.4 ui-monospace, monospace; letter-spacing: .09em; overflow-wrap: anywhere; user-select: all; }
.history-tools { padding-top: 12px; }
dialog { width: min(450px, calc(100% - 26px)); max-height: 90vh; border: 1px solid var(--rule); border-radius: 14px; padding: 22px; color: var(--ink); }
dialog::backdrop { background: #15252788; }
.skip-link { position: absolute; transform: translateY(-200%); z-index: 5; background: white; color: var(--ink); padding: .5rem; }
.skip-link:focus { transform: none; }
@media (max-width: 920px) {
  .workspace { display: block; }
  .sidebar { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 15px 20px 0; }
  .sidebar .brand { margin: 0; }
  .sidebar nav { grid-column: 1 / -1; grid-row: 2; flex-direction: row; }
  .sidebar nav button { padding: .5rem 1rem .7rem; border-radius: 5px 5px 0 0; }
  .sidebar nav button[aria-current=page] { box-shadow: inset 0 -3px 0 #f4aaa5; }
  .account { margin: 0; padding: 0; align-self: center; }
}
@media (max-width: 650px) {
  .sidebar { padding: 10px 12px 0; gap: 8px; }
  .sidebar nav button { flex: 1; text-align: center; padding: .65rem .25rem; }
  .sidebar .brand { font-size: .94rem; }
  .account span { display: none; }
  .main { padding: 18px 12px; }
  .heading { margin-bottom: 12px; gap: 8px; }
  .heading h1 { font-size: 1.75rem; }
  .toolbar { gap: 6px; }
  .compact select { max-width: 180px; }
  .inbox { display: block; min-height: 0; }
  .thread-column { border-right: none; }
  .conversation, .inbox.focus-thread .thread-column { display: none; }
  .inbox.focus-thread .conversation { display: grid; }
  #thread-detail { min-height: 330px; }
  .bubbles { max-height: 48vh; }
  #back { display: inline-block; }
  .conversation-head, .reply-form, .call-row { padding: 12px 14px; }
  .section-head { min-height: 55px; padding: 10px 14px; }
  .reply-actions { align-items: end; }
}
