html, body { height: 100%; }
body { font-size: 14px; overflow: hidden; }

/* Sign in / setup */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border-radius: var(--radius-l); padding: 32px 28px; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 22px; }
.auth-card h1 { font-size: 24px; font-weight: 600; margin-bottom: 4px; }
.auth-card .lede { color: var(--ink-2); margin-bottom: 20px; }
.auth-card .btn { width: 100%; min-height: 40px; margin-top: 4px; }
.auth-card .btn-quiet { margin-top: 8px; }
#setupBanner { flex: none; }
.qr { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; margin: 10px 0 14px; }
.qr svg { width: 200px; height: 200px; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; }
.qr .secret { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; letter-spacing: .06em; word-break: break-all; background: var(--surface-2); padding: 8px 10px; border-radius: var(--radius-s); }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-s); margin: 10px 0; }
.consent-list { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 14px; font-size: 13px; }
.consent-item { padding: 8px 10px; border: 1px solid var(--line-2); border-radius: var(--radius-s); background: var(--surface-2); }
.consent-item .q { color: var(--ink-2); font-style: italic; margin-top: 4px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); flex: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Ccircle cx='32' cy='32' r='17.5' fill='%23fff'/%3E%3Cpath d='M24.2 32.4l5.6 5.4 10.2-11.4' fill='none' stroke='%230071e3' stroke-width='4.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-size: cover; }
.brand-wordmark { height: 36px; width: auto; display: block; }

/* Shell */
.shell { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  flex: none; height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: rgba(255, 255, 255, .82); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line-2);
}
.topbar .brand { margin-right: 8px; }
.spacer { flex: 1; }
.ws-state { font-size: 12px; color: var(--ink-3); display: inline-flex; align-items: center; gap: 6px; }
.ws-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.ws-state.on::before { background: var(--good); }
.ws-state.off::before { background: var(--bad); }
.me { display: flex; align-items: center; gap: 4px; }
.me-name { font-weight: 500; margin-right: 6px; }
.body { flex: 1; min-height: 0; display: flex; }

/* Sidebar */
.sidebar { width: 350px; flex: none; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line-2); min-height: 0; }
.account-bar { padding: 12px 12px 0; }
.account-bar select { font-weight: 600; font-size: 15px; min-height: 42px; background-color: var(--surface-2); border-color: transparent; }
.account-bar select:hover { background-color: var(--line-2); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 12px 10px; }
.filters input[type="search"] { grid-column: 1 / -1; min-height: 34px; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); font-size: 13px; text-decoration: underline; }
.history-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 14px; }
.history-item { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: var(--radius-s); background: var(--surface-2); font-size: 13px; }
.history-item:hover { background: var(--accent-soft); }
.history-item .preview { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.access-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 12px; max-height: 320px; overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); }
.no-access { padding: 28px 18px; color: var(--ink-2); text-align: center; line-height: 1.5; }
.seg { grid-column: 1 / -1; display: flex; background: var(--line-2); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 6px 0; font-weight: 500; color: var(--ink-2); border-radius: 8px; transition: background .15s ease; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.filters select { min-height: 34px; padding: 4px 8px; font-size: 13px; }
.conv-list { flex: 1; overflow-y: auto; border-top: 1px solid var(--line-2); padding: 6px; }
.conv-empty { padding: 28px 18px; color: var(--ink-3); text-align: center; line-height: 1.5; }
.conv-item {
  display: flex; gap: 10px; width: 100%; text-align: left; padding: 11px 12px;
  border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); margin-bottom: 2px;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--accent-soft); }
.conv-item .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--line); }
.conv-item .dot.online { background: var(--good); }
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.conv-top, .conv-bottom { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.conv-top .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item.unread .name, .conv-item.unread .preview { font-weight: 600; color: var(--ink); }
.conv-top .time { font-size: 12px; color: var(--ink-3); flex: none; }
.conv-bottom .preview { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; display: inline-grid; place-items: center; }
.conv-tags { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.client-tag { --tag: var(--accent); display: inline-block; padding: 2px 9px; border-radius: 999px; background: color-mix(in srgb, var(--tag) 12%, white); color: var(--tag); font-weight: 600; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-weight: 500; font-size: 12px; white-space: nowrap; }
.step-tag.done { background: var(--good-soft); color: var(--good); }
.step-tag.waiting { background: var(--warn-soft); color: var(--warn); }
.conv-tags .state { color: var(--warn); }

/* Conversation pane */
.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--paper); }
.pane-empty { flex: 1; display: grid; place-items: center; color: var(--ink-3); text-align: center; padding: 24px; line-height: 1.6; }
.pane-empty strong { color: var(--ink-2); font-weight: 500; }
.pane-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pane-body { flex: 1; min-height: 0; display: flex; }
.pane-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.journey-panel { display: none; width: 320px; flex: none; overflow-y: auto; background: var(--surface); border-left: 1px solid var(--line-2); padding: 12px 12px 20px; }
@media (min-width: 1180px) { .journey-panel { display: block; } }
.jp-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 4px 2px 10px; }
.jp-head h3 { font-size: 15px; font-weight: 600; }
.jp-head .small { color: var(--ink-3); }
.jp-track { height: 5px; border-radius: 3px; background: var(--line-2); overflow: hidden; margin: 0 2px 12px; }
.jp-fill { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.jp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.jp-step { display: grid; grid-template-columns: 26px 1fr; gap: 10px; padding: 8px 8px; border-radius: 10px; }
.jp-step.current { background: var(--accent-soft); }
.jp-step.off { opacity: .55; }
.jp-num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); }
.jp-num.done { background: var(--good); color: #fff; }
.jp-num.current { background: var(--accent); color: #fff; }
.jp-num svg { width: 14px; height: 14px; }
.jp-title { font-weight: 500; font-size: 14px; line-height: 1.3; }
.jp-state { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.jp-state.waiting { color: var(--warn); font-weight: 500; }
.jp-data { font-size: 12px; color: var(--ink-2); margin-top: 4px; line-height: 1.4; }
.jp-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.jp-actions .btn { min-height: 26px; padding: 0 9px; font-size: 12px; }
.msg.card { max-width: 480px; }
.msg.card.mine { align-self: flex-end; }
.step-list { display: flex; flex-direction: column; gap: 10px; }
.step-edit { border: 1px solid var(--line-2); border-radius: 12px; padding: 12px 14px; background: var(--surface); }
.step-edit summary { cursor: pointer; font-weight: 500; display: flex; align-items: center; gap: 10px; list-style: none; }
.step-edit summary::-webkit-details-marker { display: none; }
.step-edit .step-pos { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 12px; color: var(--ink-2); flex: none; }
.step-edit .field { margin-bottom: 10px; }
.step-edit form { margin-top: 12px; }
.step-edit .step-tools { margin-left: auto; display: flex; gap: 4px; }
.pane-head { flex: none; display: flex; align-items: center; gap: 12px; padding: 10px 18px; background: rgba(255, 255, 255, .85); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.who { flex: 1; min-width: 200px; }
.who h2 { font-size: 17px; font-weight: 600; line-height: 1.2; }
.who-meta { display: flex; align-items: center; gap: 10px; margin-top: 3px; font-size: 13px; flex-wrap: wrap; }
.presence { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-3); font-size: 12px; }
.presence::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.presence.online { color: var(--good); }
.presence.online::before { background: var(--good); }
.pane-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pane-actions select { width: auto; min-height: 34px; padding: 4px 28px 4px 10px; font-size: 13px; }
.pane-actions .btn { min-height: 34px; font-size: 13px; }
.alert { padding: 8px 18px; font-size: 13px; background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid #f3dfb5; }
.alert.bad { background: var(--bad-soft); color: var(--bad); border-color: #f5c9c9; }

.thread { flex: 1; overflow-y: auto; padding: 16px 22px 10px; }
.thread .messages { display: flex; flex-direction: column; gap: 8px; max-width: 900px; }
.load-more { align-self: center; margin-bottom: 10px; }
.typing-row { margin-top: 6px; }
.typing-row .typing { background: #e9e9eb; border-radius: 20px; border-bottom-left-radius: 6px; }
.msg-meta .seen { color: var(--accent); font-weight: 500; }
.msg.mine .msg-meta { justify-content: flex-end; }
.msg.note { align-self: flex-end; align-items: flex-end; }

/* Composer */
.composer { flex: none; background: var(--surface); border-top: 1px solid var(--line-2); padding: 8px 18px 12px; }
.composer.note-mode { background: #fff9ec; }
.composer-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.composer-tools .check { font-size: 13px; color: var(--ink-2); }
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 44px; max-height: 200px; resize: none; padding: 11px 16px; line-height: 1.4; border-radius: 22px; font-size: 15px; }
.composer.note-mode textarea { border-color: #e4c07a; background: #fffdf7; }
.composer-row .btn-primary { min-height: 44px; padding: 0 20px; }
.composer.note-mode .btn-primary { background: var(--warn); border-color: var(--warn); }
.tpl-wrap { position: relative; }
.tpl-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 20; width: min(440px, 80vw); max-height: 320px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px;
}
.tpl-menu input { margin-bottom: 6px; min-height: 34px; }
.tpl-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: var(--radius-s); }
.tpl-item:hover { background: var(--surface-2); }
.tpl-item .t { font-weight: 500; display: block; }
.tpl-item .b { display: block; font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-empty { padding: 10px; font-size: 13px; color: var(--ink-3); }
.pending { display: flex; align-items: center; gap: 10px; padding: 6px 8px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface-2); font-size: 13px; max-width: 480px; }
.pending-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }
.pending-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Link modal */
.link-box { display: flex; gap: 8px; align-items: center; margin: 6px 0 14px; }
.link-box input { font-size: 13px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; margin: 10px 0 16px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.danger-zone { border-top: 1px solid var(--line-2); padding-top: 14px; margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; }

/* Settings */
.tabs { display: flex; gap: 2px; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 7px 12px; color: var(--ink-2); font-weight: 500; border-radius: 8px; white-space: nowrap; }
.tabs button.on { color: var(--ink); background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table th { text-align: left; font-weight: 500; color: var(--ink-3); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 8px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn { margin-left: 4px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--ink-2); font-weight: 500; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.off { background: var(--bad-soft); color: var(--bad); }
.subform { background: var(--surface-2); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.subform h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.swatch { width: 38px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); }

.back-btn { display: none; }
@media (max-width: 860px) {
  .sidebar { width: 100%; }
  .shell.has-active .sidebar { display: none; }
  .shell:not(.has-active) .pane { display: none; }
  .shell.has-active .back-btn { display: inline-flex; }
  .me-name { display: none; }
  .shell.has-active #newChatBtn, .shell.has-active #notifBtn { display: none; }
  .topbar { padding: 0 8px; gap: 6px; }
  .topbar .brand-name { display: none; }          /* the mark alone is enough on a phone */
  .topbar .ws-state { font-size: 0; gap: 0; }     /* dot only */
  .topbar .btn { padding-left: 9px; padding-right: 9px; white-space: nowrap; }
  #setupBanner { font-size: 12px; padding: 6px 10px; }
  .pane-head { padding: 8px 12px; }
  .thread { padding: 12px; }
  .composer { padding: 8px 10px 10px; }
  .composer-tools .small { display: none; }
}
