:root {
  color-scheme: light;
  --ink: #17352d;
  --muted: #597068;
  --brand: #0b684f;
  --brand-dark: #08533e;
  --surface: #fff;
  --canvas: #f3f6f3;
  --wash: #edf6f0;
  --line: #d9e4dd;
  --error: #a02e36;
  --shadow: 0 9px 28px rgba(20, 49, 38, .07);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; }
p, h1, h2, h3 { margin: 0; }
a { color: var(--brand); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .6; }
button, input, select, textarea, a { outline-offset: 3px; }
:focus-visible { outline: 2px solid var(--brand); }
h1 { font-size: clamp(1.65rem, 3vw, 2.25rem); line-height: 1.18; letter-spacing: -.045em; }
h2 { font-size: 1.13rem; letter-spacing: -.018em; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); font-size: .9rem; line-height: 1.5; }
.small { font-size: .82rem; }
.strong { font-weight: 700; }
.button {
  border: 1px solid transparent; border-radius: .65rem; padding: .59rem .8rem;
  min-height: 2.55rem; display: inline-flex; align-items: center; justify-content: center;
  gap: .35rem; text-decoration: none; font-weight: 650; font-size: .88rem;
  text-align: center; line-height: 1.2;
}
.button.primary { background: var(--brand); color: white; }
.button.primary:hover { background: var(--brand-dark); }
.button.secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.button.secondary:hover, .button.quiet:hover { background: var(--wash); }
.button.quiet { color: var(--muted); background: transparent; }
.button.danger { color: var(--error); background: #fff5f4; border-color: #eed4d3; }
.icon-button { padding: .35rem .65rem; font-size: 1.3rem; color: var(--ink); background: var(--wash); }
label { display: grid; gap: .33rem; font-weight: 640; font-size: .88rem; min-width: 0; }
input:not([type=checkbox]), select, textarea {
  border: 1px solid var(--line); border-radius: .62rem; background: white; color: var(--ink);
  width: 100%; min-width: 0; padding: .57rem .66rem; min-height: 2.52rem;
}
textarea { resize: vertical; line-height: 1.5; min-height: 5rem; }
input[type=checkbox] { accent-color: var(--brand); width: 1rem; height: 1rem; }
.checkbox { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
fieldset { border: 1px solid var(--line); border-radius: .7rem; padding: .75rem; margin: 0; min-width: 0; }
legend { padding: 0 .3rem; font-size: .86rem; font-weight: 650; }
.form-stack { display: grid; gap: .88rem; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.form-message { font-size: .87rem; line-height: 1.45; }
.form-message:empty { display: none; }
.error { color: var(--error); }
.brand { display: inline-flex; align-items: center; gap: .58rem; color: var(--ink); text-decoration: none; font-size: 1.02rem; font-weight: 750; letter-spacing: -.035em; white-space: nowrap; }
.brand b { color: var(--brand); }
.brand-mark { display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: .66rem; background: var(--brand); flex: 0 0 auto; }
.brand-mark::before { content: ""; width: .95rem; height: .95rem; border: 1.75px solid white; border-radius: 50%; grid-area: 1 / 1; }
.brand-mark::after { content: ""; width: .28rem; height: .34rem; border: solid white; border-width: 0 0 1.7px 1.7px; transform: translate(.08rem, -.08rem); grid-area: 1 / 1; }

.login-page {
  display: grid; place-items: center; padding: 1.35rem;
  background: radial-gradient(ellipse at 30% 12%, #e1f0e4, transparent 65%), var(--canvas);
}
.login-card {
  display: grid; gap: .9rem; width: min(100%, 27rem); padding: clamp(1.45rem, 5vw, 2.4rem);
  background: white; border: 1px solid var(--line); border-radius: 1.25rem; box-shadow: var(--shadow);
}
.login-card .brand { justify-self: start; margin-bottom: .7rem; }
.login-card h1 { font-size: 1.86rem; }
.login-card .form-stack { padding-top: .35rem; }

.layout { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh;
  background: #fcfdfb; border-right: 1px solid var(--line); padding: 1.3rem .95rem;
}
.sidebar > .brand { margin: .1rem .4rem 1.42rem; }
.workspace-name { display: flex; align-items: center; gap: .65rem; border: 1px solid var(--line); border-radius: .8rem; padding: .62rem; overflow-wrap: anywhere; }
.workspace-avatar, .chat-avatar {
  display: inline-grid; place-items: center; flex: 0 0 auto; width: 2.25rem; height: 2.25rem; border-radius: .72rem;
  background: #dfefe4; color: var(--brand); font-weight: 750;
}
.workspace-name strong { line-height: 1.18; font-size: .9rem; }
.workspace-name small { display: block; color: var(--muted); font-size: .74rem; margin-top: .17rem; }
.navigation { display: grid; gap: .25rem; margin-top: 1.2rem; }
.navigation button {
  display: flex; align-items: center; gap: .55rem; min-height: 2.55rem; padding: .45rem .66rem; border: 0;
  border-radius: .65rem; background: transparent; color: var(--muted); font-weight: 640; font-size: .88rem; text-align: left;
}
.navigation button span { font-size: 1rem; width: 1.12rem; text-align: center; }
.navigation button:hover, .navigation button.selected { background: #e4f0e6; color: var(--brand-dark); }
.count { font-size: .72rem; border-radius: 1rem; padding: .08rem .4rem; background: var(--brand); color: white; margin-left: auto; white-space: nowrap; }
.sidebar-bottom { display: grid; gap: .5rem; margin-top: auto; border-top: 1px solid var(--line); padding: .7rem .2rem 0; justify-items: start; }
.user-line { display: flex; align-items: center; justify-content: space-between; gap: .55rem; width: 100%; min-width: 0; font-size: .84rem; }
.user-line > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { display: inline-flex; align-items: center; gap: .35rem; background: #edf1ef; color: #536660; border-radius: 2rem; padding: .26rem .57rem; font-size: .75rem; font-weight: 650; white-space: nowrap; }
.status-pill::before { content: ""; border-radius: 50%; width: .42rem; height: .42rem; background: currentColor; }
.status-pill.good { background: #e4f4e8; color: #216446; }
.status-pill.wait { background: #fff0d8; color: #855412; }
.status-pill.off { background: #f1ece9; color: #775344; }
.workspace { width: 100%; max-width: 105rem; margin: 0 auto; padding: 1.65rem min(3vw, 2.3rem); min-width: 0; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.12rem; }
.page-heading p { margin-top: .35rem; }
.heading-actions { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.page { min-width: 0; }
.notice { display: block; padding: .65rem .82rem; border: 1px solid #e9d9b9; border-radius: .66rem; background: #fff9e9; color: #684b25; font-size: .84rem; line-height: 1.45; margin-bottom: .68rem; }
.notice.good { background: var(--wash); border-color: var(--line); color: var(--ink); }
.notice.error { background: #fff3f2; border-color: #eecfca; color: var(--error); }
.panel-card { background: white; border: 1px solid var(--line); border-radius: .95rem; box-shadow: var(--shadow); min-width: 0; }
.card-content { padding: 1rem; }
.card-content h2 { margin-bottom: .5rem; }
.empty { color: var(--muted); padding: 1.6rem 1rem; text-align: center; font-size: .9rem; line-height: 1.55; }
.toolbar { display: flex; gap: .55rem; align-items: center; padding: .68rem .8rem; border-bottom: 1px solid var(--line); }
.toolbar label { flex: 1 1 auto; }
.toolbar input { font-size: .85rem; }
.spaced { display: grid; gap: .8rem; }
.row { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .65rem; }
.align-start { align-items: flex-start; }

.inbox { display: grid; grid-template-columns: minmax(14.5rem, 30%) minmax(0, 1fr); height: clamp(30rem, calc(100dvh - 9.2rem), 65rem); overflow: hidden; }
.inbox-list { border-right: 1px solid var(--line); display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; }
.chat-list { overflow: auto; padding: .2rem 0; }
.chat-item { display: flex; gap: .64rem; align-items: center; text-align: left; width: 100%; min-width: 0; background: white; color: var(--ink); border: 0; border-bottom: 1px solid #edf2ee; padding: .72rem .75rem; min-height: 4.12rem; }
.chat-item:hover, .chat-item.active { background: #eaf4eb; }
.chat-avatar { border-radius: 50%; }
.chat-label, .clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-label { display: block; font-weight: 690; font-size: .9rem; }
.chat-item-main { min-width: 0; flex: 1 1 auto; display: grid; gap: .23rem; }
.chat-item-end { display: grid; gap: .2rem; justify-items: end; }
.thread { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.thread-header { padding: .7rem .9rem; border-bottom: 1px solid var(--line); min-height: 3.55rem; }
.thread-header h2 { overflow-wrap: anywhere; }
.notice-stack { padding: .35rem .65rem 0; max-height: 9rem; overflow: auto; }
.notice-stack:empty { display: none; }
.notice-stack .notice { margin-bottom: .35rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.messages { overflow: auto; background: #f6f9f5; padding: .62rem .86rem; display: flex; flex-direction: column; gap: .55rem; min-width: 0; }
.bubble {
  max-width: min(88%, 34rem); background: white; border: 1px solid #e0e9e2; border-radius: .83rem .83rem .83rem .2rem;
  padding: .55rem .67rem; align-self: flex-start; overflow-wrap: anywhere; box-shadow: 0 2px 7px #193b2f09;
}
.bubble.outgoing { align-self: flex-end; background: #e1f1e5; border-radius: .83rem .83rem .2rem .83rem; }
.bubble-body { white-space: pre-wrap; font-size: .9rem; line-height: 1.48; }
.bubble-meta { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .32rem; font-size: .7rem; color: var(--muted); margin-top: .34rem; }
.bubble audio { display: block; width: min(15rem, 100%); min-width: min(10rem, 100%); height: 2.5rem; }
.composer { display: flex; align-items: flex-end; gap: .55rem; padding: .68rem .85rem; border-top: 1px solid var(--line); }
.composer textarea { min-height: 2.6rem; max-height: 8rem; flex: 1 1 auto; resize: none; }
.composer .button { flex: 0 0 auto; }
.composer-note { padding: .65rem .85rem; color: var(--muted); border-top: 1px solid var(--line); font-size: .86rem; }
.mobile-back { display: none; }
.load-more { align-self: center; margin: .45rem .55rem; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .86rem; }
th { background: #f7f9f7; color: var(--muted); font-weight: 650; font-size: .78rem; }
th, td { padding: .66rem .75rem; vertical-align: middle; }
tbody tr { border-top: 1px solid #e7eee9; }
tbody tr:hover { background: #fbfcfa; }
.cell-summary { display: grid; gap: .17rem; min-width: 7.5rem; overflow-wrap: anywhere; }
.cell-actions { text-align: right; }
.cell-actions > .row { justify-content: flex-end; }
.tag { display: inline-block; border-radius: 1rem; background: var(--wash); color: var(--brand-dark); padding: .22rem .49rem; font-size: .75rem; font-weight: 650; }
.tag.neutral { background: #edf1ee; color: var(--muted); }
.tag.danger { color: var(--error); background: #fff0ed; }
.tag.warning { color: #795015; background: #fff0d6; }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .68rem; margin-bottom: .8rem; }
.metric { padding: .82rem; }
.metric strong { display: block; font-size: 1.6rem; letter-spacing: -.04em; margin-bottom: .2rem; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; align-items: start; }
.day-list { display: flex; flex-wrap: wrap; gap: .65rem; }
.qr { display: grid; justify-items: start; gap: .45rem; margin-top: .65rem; }
.qr img { width: min(12rem, 100%); height: auto; border: 1px solid var(--line); border-radius: .65rem; }
.admin-top {
  display: flex; justify-content: space-between; align-items: center; gap: .7rem; padding: .85rem min(4vw, 2.1rem);
  background: white; border-bottom: 1px solid var(--line);
}
.admin-top .user-line { width: auto; }
.admin-page { width: min(68rem, 100%); padding: 1.55rem min(3vw, 1.7rem); margin: auto; }
.control-card { display: flex; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap; padding: 1rem; margin-bottom: .75rem; }
.control-card h2 { margin-bottom: .3rem; }

.dialog { width: min(39rem, calc(100% - 1.15rem)); max-height: 92dvh; border: 1px solid var(--line); border-radius: .95rem; color: var(--ink); padding: 0; box-shadow: 0 18px 58px #193e3440; }
.dialog::backdrop { background: #192e2755; }
.dialog-header { background: white; position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: .65rem; padding: .7rem .95rem; border-bottom: 1px solid var(--line); }
.dialog-body { padding: .95rem; }
#dialog > .form-message { padding: .15rem .95rem .95rem; }
.dialog-body .form-stack + .form-stack, .divider { border-top: 1px solid var(--line); padding-top: .82rem; }
.toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 5; border-radius: .7rem; background: var(--ink); color: white; padding: .7rem .85rem; max-width: min(25rem, calc(100vw - 2rem)); font-size: .9rem; box-shadow: var(--shadow); }
.toast.error { background: var(--error); color: white; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 12.25rem minmax(0, 1fr); }
  .sidebar { padding-inline: .65rem; }
  .workspace { padding-inline: .85rem; }
  .inbox { grid-template-columns: minmax(11.5rem, 34%) minmax(0, 1fr); }
  .chat-item { padding-inline: .52rem; gap: .4rem; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .layout { display: block; }
  .sidebar { position: static; height: auto; padding: .64rem .67rem .16rem; border-right: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .28rem; }
  .sidebar > .brand { margin: 0; }
  .workspace-name { display: none; }
  .sidebar-bottom { grid-column: 2; grid-row: 1; border: 0; margin: 0; padding: 0; display: flex; align-items: center; gap: .32rem; }
  .sidebar-bottom .user-line > span { display: none; }
  .sidebar-bottom .button { padding: .35rem .36rem; }
  .sidebar-bottom .status-pill { font-size: .68rem; }
  .navigation { grid-column: 1 / -1; display: flex; overflow: auto; gap: .16rem; margin: .15rem 0 0; }
  .navigation button { flex: 0 0 auto; white-space: nowrap; font-size: .79rem; padding: .32rem .52rem; gap: .32rem; }
  .navigation button span { display: none; }
  .workspace { padding: .75rem .55rem; }
  .page-heading { align-items: flex-start; gap: .48rem; margin-bottom: .65rem; }
  .page-heading .button { min-height: 2.35rem; font-size: .78rem; padding-inline: .55rem; }
  .page-heading .muted { font-size: .82rem; }
  .heading-actions { gap: .35rem; }
  .inbox { display: block; height: clamp(25rem, calc(100dvh - 11rem), 65rem); }
  .inbox-list, .thread { height: 100%; border: 0; }
  .inbox:not(.show-thread) .thread, .inbox.show-thread .inbox-list { display: none; }
  .mobile-back { display: inline-flex; }
  .toolbar, .thread-header, .composer { padding-inline: .54rem; }
  .messages { padding-inline: .53rem; }
  .bubble { max-width: 92%; }
  .cards { gap: .34rem; }
  .metric { padding: .48rem; }
  .metric strong { font-size: 1.24rem; }
  .metric .muted { font-size: .75rem; }
  .table-wrap table { min-width: 30rem; }
  th, td { padding-inline: .55rem; }
}
@media (max-width: 400px) {
  .form-row { grid-template-columns: 1fr; }
  .brand { font-size: .9rem; }
}
