:root {
  color-scheme: light;
  font-family: Inter, 'Segoe UI', system-ui, sans-serif;
  color: #202736;
  background: #f3f5f9;
  --surface: #fff;
  --muted: #5d687a;
  --line: #e1e6ef;
  --accent: #4944be;
  --accent-dark: #373298;
  --accent-light: #eeedff;
  --red: #a12441;
  --red-light: #fdebf0;
  --amber: #855009;
  --amber-light: #fff1d9;
  --green: #226344;
  --green-light: #e6f5ec;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
a { color: var(--accent-dark); }
:focus-visible { outline: 3px solid #6861e8; outline-offset: 2px; }
[hidden] { display: none !important; }
p, h1, h2, h3, dl, dd { margin: 0; }
p, dd { overflow-wrap: anywhere; }
h1 { font-size: clamp(1.4rem, 3vw, 2.1rem); line-height: 1.15; letter-spacing: -.045em; }
h2 { font-size: 1.18rem; letter-spacing: -.025em; }
h3 { font-size: 1rem; }
label { font-weight: 600; }

input:not([type="checkbox"], [type="radio"]), select, textarea {
  width: 100%;
  min-width: 0;
  padding: .7rem .8rem;
  border: 1px solid #bfc8d8;
  border-radius: .65rem;
  background: #fff;
  color: inherit;
  min-height: 44px;
}
textarea { resize: vertical; }
label > :is(input, select, textarea) { margin-top: .32rem; }

.startup { padding: 2rem; color: var(--muted); }
.shell { display: grid; grid-template-rows: auto auto minmax(0, 1fr); height: 100vh; height: 100dvh; }
.topbar {
  display: flex;
  align-items: center;
  gap: .7rem;
  min-width: 0;
  padding: .75rem clamp(.85rem, 2.5vw, 1.75rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand, .top-actions, .row { display: flex; align-items: center; flex-wrap: wrap; gap: .6rem; min-width: 0; }
.top-actions { justify-content: flex-end; margin-left: auto; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: .75rem;
  background: var(--accent);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .015em;
}
.brand-label { font-weight: 750; font-size: 1.06rem; letter-spacing: -.025em; }
.user-pill { color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.user-pill small { display: block; margin-top: .12rem; }
.shell > .alert { grid-row: 2; margin: .35rem .85rem; }

.shell-body { grid-row: 3; display: grid; grid-template-columns: minmax(17rem, 21rem) minmax(0, 1fr); min-height: 0; }
.shell.is-table .shell-body { grid-template-columns: minmax(9rem, 12rem) minmax(0, 1fr); }
.shell.is-table .tabs { display: grid; }
.shell.is-table .tabs button { justify-content: flex-start; }
.sidebar {
  display: flex;
  flex-direction: column;
  gap: .8rem;
  min-width: 0;
  overflow: auto;
  padding: 1rem;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.tabs { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.tabs button, .room-tabs button {
  padding: .52rem .65rem;
  border: 0;
  border-radius: .6rem;
  background: #f2f4f8;
  color: #465167;
  font-size: .88rem;
  font-weight: 650;
  min-height: 36px;
}
.tabs button:is(.selected, .active, [aria-current="page"], [aria-pressed="true"]),
.room-tabs button:is(.selected, .active, [aria-pressed="true"]) { background: var(--accent-light); color: var(--accent-dark); }
.side-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .55rem; }
.list, .stack, .attention-list { display: grid; gap: .55rem; min-width: 0; }
.btn.list-item {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: .55rem;
  text-align: left;
  width: 100%;
  min-height: 48px;
  padding: .75rem;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: .75rem;
  background: var(--surface);
  overflow-wrap: anywhere;
}
.btn.list-item:hover, .btn.list-item.selected { border-color: #b9b6eb; background: #f6f5ff; }
.list-copy { flex: 1 1 auto; min-width: 0; }
.list-copy small { display: block; margin-top: .22rem; font-weight: 450; }
.chat-group .list-copy small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-meta { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: flex-end; gap: .25rem; }
.avatar { display: grid; place-items: center; flex: 0 0 2.25rem; height: 2.25rem; border-radius: .65rem; background: var(--accent-light); color: var(--accent-dark); font-weight: 750; }
.avatar.master { color: var(--green); background: var(--green-light); }
.chat-group { display: grid; gap: .45rem; }
.chat-group h3 { color: var(--muted); font-size: .86rem; margin-block: .3rem; }
.list-item small, .muted, .subtle, .meta, .hint, .message-meta { color: var(--muted); }
.list-item small, .meta, .hint, .message-meta { font-size: .82rem; }
.workspace { min-height: 0; min-width: 0; overflow: auto; }
.workspace:has(> .messages) { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.order-detail, .attention, .overview { width: min(100%, 86rem); margin-inline: auto; padding: clamp(1rem, 2.6vw, 2rem); }
.order-head, .hero, .section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .7rem; margin-bottom: 1.1rem; }
.order-head p, .hero p { color: var(--muted); margin-top: .3rem; }
.order-sections { display: grid; align-items: start; gap: .85rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); gap: .85rem 1rem; }
.facts dt { color: var(--muted); font-size: .82rem; margin-bottom: .2rem; }
.facts dd { font-weight: 600; }
.order-actions, .room-tabs { display: flex; flex-wrap: wrap; gap: .55rem; margin-block: .65rem; }
.card, .hero, .metric, .empty {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: .9rem;
  padding: clamp(.8rem, 1.8vw, 1.15rem);
}
.card h2, .card h3 { margin-bottom: .55rem; }
.card p + p { margin-top: .45rem; }
.hero { padding: clamp(1rem, 2.6vw, 1.7rem); }
.empty { color: var(--muted); line-height: 1.5; }
.workspace > .empty { margin: 1rem; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); gap: .7rem; margin-block: .9rem 1.15rem; }
.metric { text-align: left; color: inherit; }
.metric strong { display: block; color: var(--accent-dark); font-size: 1.55rem; }
.badge, .count {
  display: inline-flex;
  align-items: center;
  align-self: center;
  width: fit-content;
  padding: .16rem .47rem;
  border-radius: 999px;
  font-size: .76rem;
  line-height: 1.35;
  font-weight: 650;
  color: #494a76;
  background: #ececf6;
}
.badge.hot { color: var(--red); background: var(--red-light); }
.badge.warm { color: var(--amber); background: var(--amber-light); }
.badge.ok { color: var(--green); background: var(--green-light); }

.order-table, .orders-table { width: 100%; min-width: 31rem; border-spacing: 0; text-align: left; }
:is(.order-table, .orders-table) :is(th, td) { padding: .7rem; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
:is(.order-table, .orders-table) th { color: var(--muted); font-size: .83rem; }
:is(.order-table, .orders-table) tbody tr:hover { background: #f6f5ff; }
.order-table tr:last-child td { border-bottom: 0; }
.order-table .company-heading th { padding: .5rem .7rem; background: var(--accent-light); color: var(--accent-dark); font-size: .88rem; }
.order-table td small { display: block; font-size: .82rem; color: var(--muted); margin-top: .2rem; }
.order-table td:first-child { min-width: 9rem; }
.table-wrap { overflow: auto; padding: .45rem .6rem; }
.btn.table-order { display: block; text-align: left; border: 0; background: transparent; padding: .15rem .2rem; color: var(--accent-dark); }
.btn.table-order:hover { text-decoration: underline; }
.metric { text-decoration: none; }
.metric:hover { border-color: #b9b6eb; }
.attention-group { display: grid; gap: .45rem; }
.attention-group h2 { margin-bottom: .15rem; }

.room-header { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; border-bottom: 1px solid var(--line); background: var(--surface); padding: .85rem clamp(.85rem, 2vw, 1.45rem); }
.room-header p { color: var(--muted); font-size: .87rem; }
.messages { min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: .62rem; padding: 1rem clamp(.8rem, 2.6vw, 2rem); }
.message, .bubble {
  max-width: min(85%, 37rem);
  width: fit-content;
  padding: .65rem .85rem;
  border: 1px solid var(--line);
  border-radius: .8rem .8rem .8rem .25rem;
  background: var(--surface);
  overflow-wrap: anywhere;
}
.message.mine, .bubble.mine, .message.is-mine { align-self: flex-end; background: var(--accent-light); border-color: #dddbf7; border-radius: .8rem .8rem .25rem .8rem; }
.message :is(p, .message-text), .bubble :is(p, .message-text) { white-space: pre-wrap; line-height: 1.45; }
.message video { display: block; width: min(24rem, 100%); max-height: min(58dvh, 26rem); margin-block: .45rem; border-radius: .5rem; background: #171b23; }
.video-actions:not(:empty) { margin-top: .4rem; }
.video-actions, .upload-status, .video-notice { font-size: .85rem; color: var(--muted); }
.video-notice:not(:empty) { padding: .3rem .85rem .55rem; }
.video-download { display: inline-block; margin-top: .4rem; }
.message-meta { margin-top: .3rem; }
.message-from { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.message-from a { font-size: .85rem; }
.contact-list { list-style: none; margin: 0; padding: 0; }
.contact-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .4rem; }
.contact-list a { display: inline-flex; align-items: center; min-height: 44px; }
.composer { padding: .75rem clamp(.85rem, 2vw, 1.45rem); border-top: 1px solid var(--line); background: var(--surface); }
.composer form, form.composer { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .55rem; }
.composer textarea { flex: 1 1 12rem; min-height: 44px; }
.composer-slot, .closed-room { background: var(--surface); }
.closed-room { padding: .8rem 1.25rem; color: var(--muted); border-top: 1px solid var(--line); }
.send-button { min-width: 44px; min-height: 44px; font-size: 1.2rem; }
.dictation-button { min-height: 44px; }
.dictation-button[aria-pressed="true"] { color: var(--red); background: var(--red-light); border-color: #edbcc8; }
.dictation-status { width: 100%; color: var(--muted); font-size: .83rem; }
.dictation-status:empty { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.message-meta { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.receipt { color: var(--accent-dark); }

.btn, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 39px;
  border-radius: .62rem;
  padding: .45rem .72rem;
  border: 1px solid #c7cddd;
  background: var(--surface);
  color: #273149;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  line-height: 1.25;
}
.btn:hover, .icon-btn:hover { background: #f2f4fa; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.quiet { border-color: transparent; background: #f2f4fa; }
.icon-btn { min-width: 39px; }
.alert { padding: .65rem .82rem; border-radius: .58rem; color: var(--red); background: var(--red-light); overflow-wrap: anywhere; }

.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: min(100%, 28rem); display: grid; gap: 1rem; padding: clamp(1.15rem, 5vw, 2rem); border: 1px solid var(--line); border-radius: 1.15rem; background: var(--surface); box-shadow: 0 1rem 2.5rem #1721490c; }
.auth-card :is(p, small) { color: var(--muted); line-height: 1.45; }
.auth-card form { display: grid; gap: .8rem; }
dialog { width: min(34rem, calc(100% - 1.5rem)); max-height: calc(100dvh - 1.5rem); padding: 1rem; border: 1px solid var(--line); border-radius: .95rem; background: var(--surface); color: inherit; overflow: auto; }
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { background: #1c23456b; }
dialog :is(form, .dialog-content) { display: grid; gap: .7rem; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .9rem; }
.install-help { line-height: 1.45; }
.invite-qr { display: block; width: min(100%, 13rem); height: auto; image-rendering: pixelated; }
.invite-group { display: flex; align-items: center; gap: .5rem; min-height: 40px; }

@media (max-width: 740px) {
  .topbar { flex-wrap: wrap; gap: .35rem .6rem; padding-block: .55rem; }
  .shell-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .shell.is-table .shell-body { grid-template-columns: minmax(0, 1fr); }
  .shell.is-table .tabs { display: flex; }
  .sidebar { border-right: 0; padding: .7rem; }
  .shell:not(.is-detail, .is-overview) .workspace { display: none; }
  .shell.is-detail .sidebar { display: none; }
  .shell.is-overview:not(.is-detail) .shell-body { grid-template-rows: auto minmax(0, 1fr); }
  .shell.is-overview:not(.is-detail) .sidebar { border-bottom: 1px solid var(--line); }
  .shell.is-overview:not(.is-detail) .sidebar > :not(.tabs) { display: none; }
  :is(.btn, .icon-btn, .tabs button, .room-tabs button) { min-height: 44px; }
  .message, .bubble { max-width: 91%; }
}
