:root {
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  color: #201b2b;
  background: #f6f5f2;
  font-synthesis: none;
  --ink: #201b2b;
  --muted: #686172;
  --outline: #e6e1e8;
  --surface: #fff;
  --accent: #6037cd;
  --accent-hover: #4c25b0;
  --accent-soft: #f1ebff;
  --success: #167548;
  --success-soft: #e8f6ed;
  --warn: #884916;
  --warn-soft: #fff3df;
  --danger: #a3263b;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; }
h1, h2, p { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .56; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.topbar {
  height: 65px;
  padding: 0 max(24px, calc((100vw - 1360px) / 2));
  border-bottom: 1px solid var(--outline);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand, .top-actions, .bot-indicator { display: flex; align-items: center; }
.brand { font-size: 17px; font-weight: 735; gap: 11px; white-space: nowrap; letter-spacing: -.035em; }
.brand-separator { margin: 0 3px; color: #a897be; font-weight: 450; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 8px); gap: 2px; padding: 7px; border-radius: 9px; background: var(--accent-soft); }
.brand-mark i { width: 8px; height: 8px; border-radius: 50%; background: #7851df; }
.brand-mark i:nth-child(2) { background: #a987f2; }
.brand-mark i:nth-child(3) { background: #c9b5f8; }
.top-actions { gap: 12px; }
.bot-indicator { gap: 8px; white-space: nowrap; font-size: 13px; color: var(--muted); }
.bot-indicator i { width: 8px; height: 8px; border-radius: 50%; background: #a29bab; }
.bot-indicator.is-active i { background: #23945e; box-shadow: 0 0 0 3px var(--success-soft); }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; border: 1px solid transparent; border-radius: 9px; padding: 8px 13px; font-weight: 650; font-size: 13px; line-height: 1.3; white-space: nowrap; transition: background .16s, color .16s, border-color .16s; }
.primary { background: var(--accent); color: white; border-color: var(--accent); }
.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.secondary { background: var(--surface); border-color: var(--outline); color: var(--ink); }
.secondary:hover:not(:disabled), .quietly:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-hover); }
.quietly { color: var(--muted); background: transparent; }

.login { display: grid; place-items: center; min-height: calc(100dvh - 65px); padding: 20px; }
.login-card { width: min(100%, 410px); background: var(--surface); padding: 34px; border: 1px solid var(--outline); border-radius: 20px; box-shadow: 0 18px 54px #39274b0d; display: grid; gap: 12px; }
.login-mark { width: 51px; height: 51px; display: grid; align-content: center; justify-content: center; gap: 4px; background: var(--accent-soft); border-radius: 15px; margin-bottom: 3px; }
.login-mark i { display: block; border-radius: 8px; width: 22px; height: 3px; background: #7b55df; }
.login-mark i:nth-child(2) { width: 15px; }
.login-mark i:nth-child(3) { width: 19px; }
.login-card h1 { margin-bottom: 12px; font-size: 28px; letter-spacing: -.055em; }
.login-card label { font-weight: 620; font-size: 14px; }
.login-card input, .time-row input { min-width: 0; border: 1px solid var(--outline); border-radius: 9px; padding: 11px 12px; color: var(--ink); background: #fcfbfd; }
.login-card .primary { margin-top: 6px; min-height: 43px; }

.app { width: min(100%, 1408px); padding: 28px 24px 24px; margin: 0 auto; height: calc(100dvh - 65px); min-height: 490px; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 18px; }
.workspace-title { display: flex; align-items: center; justify-content: space-between; }
.workspace-title h1 { font-size: clamp(27px, 3.2vw, 38px); line-height: 1.15; letter-spacing: -.065em; }
.refresh-button span { font-size: 16px; line-height: 1; }
.workspace { display: grid; grid-template-columns: minmax(275px, 340px) minmax(0, 1fr); background: var(--surface); border: 1px solid var(--outline); border-radius: 17px; overflow: hidden; min-height: 0; box-shadow: 0 5px 27px #30204008; }
.inbox { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; min-width: 0; border-right: 1px solid var(--outline); }
.inbox-toolbar { display: grid; gap: 13px; padding: 16px 14px 12px; border-bottom: 1px solid #f1edf3; }
.search { display: flex; gap: 10px; align-items: center; padding: 0 12px; border-radius: 10px; background: #f7f5f8; border: 1px solid #ede8f0; }
.search:focus-within { border-color: #9d80ea; }
.search span { width: 12px; height: 12px; position: relative; border: 1.5px solid #7a7185; border-radius: 100%; margin-right: 1px; flex-shrink: 0; }
.search span::after { content: ""; width: 5px; height: 1.5px; position: absolute; bottom: -2px; right: -4px; transform: rotate(46deg); background: #7a7185; border-radius: 1px; }
.search input { padding: 10px 0; width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 14px; }
.search input::placeholder { color: #776f80; }
.filters { display: flex; gap: 5px; }
.filters button { color: var(--muted); border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; font-size: 12px; font-weight: 680; }
.filters button:hover, .filters button[aria-pressed="true"] { color: var(--accent-hover); background: var(--accent-soft); }
.inbox-scroll { overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; padding: 5px; }
.chat-list, .messages { padding: 0; margin: 0; list-style: none; }
.chat-list li + li { margin-top: 2px; }
.chat-row { width: 100%; border: 1px solid transparent; background: transparent; border-radius: 11px; text-align: left; color: var(--ink); display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; padding: 11px 9px; align-items: center; min-height: 68px; }
.chat-row:hover { background: #f9f7fa; }
.chat-row[aria-current="true"] { background: #f2edfd; border-color: #e9dfff; }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 13px; color: #5631a6; background: #ede4fb; font-weight: 760; font-size: 14px; flex: none; letter-spacing: -.04em; }
.avatar[data-tone="1"] { background: #e3ecfb; color: #315995; }
.avatar[data-tone="2"] { background: #e5f1ee; color: #276959; }
.avatar[data-tone="3"] { background: #fbe5e9; color: #973a53; }
.avatar[data-tone="4"] { background: #f7ebd9; color: #86521f; }
.avatar[data-tone="5"] { background: #e8ebfa; color: #4b4c93; }
.chat-row-copy, .chat-row-meta { display: grid; align-content: start; gap: 4px; min-width: 0; }
.chat-row-meta { justify-items: end; align-self: start; padding-top: 2px; gap: 7px; }
.row-name, .row-preview { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row-name { font-size: 14px; font-weight: 720; }
.row-preview, .row-time { color: var(--muted); font-size: 12px; }
.row-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.unread-dot { height: 7px; width: 7px; border-radius: 50%; background: var(--accent); }
.paused-dot { height: 10px; width: 8px; border-left: 3px solid #aa702c; border-right: 3px solid #aa702c; }
.load-more, .older-messages { display: flex; margin: 7px auto 12px; }

.conversation { display: grid; min-height: 0; min-width: 0; background: #fdfcfe; }
.empty-chat { display: grid; place-content: center; justify-items: center; gap: 15px; background: radial-gradient(ellipse at center, #f6f1ff 0, #fdfbff 52%, #fdfcfe 76%); }
.empty-chat h2 { font-size: 22px; letter-spacing: -.035em; }
.empty-mark { position: relative; width: 78px; height: 60px; border: 1px solid #e6dafa; border-radius: 19px 19px 19px 5px; display: flex; gap: 6px; align-items: center; justify-content: center; background: white; box-shadow: 8px 7px 0 #eae2f8; transform: rotate(-7deg); }
.empty-mark i { width: 7px; height: 7px; border-radius: 50%; background: #a88ce9; }
.chat-content { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; min-height: 0; min-width: 0; }
.chat-header { grid-row: 1; display: flex; gap: 11px; align-items: center; padding: 14px 18px; background: var(--surface); border-bottom: 1px solid var(--outline); min-width: 0; }
.chat-avatar { width: 42px; height: 42px; }
.chat-heading { flex: 1; min-width: 0; }
.chat-heading h2 { font-size: 16px; letter-spacing: -.025em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-heading p { margin-top: 3px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.automation-button { min-width: 90px; }
.automation-button.is-paused { color: var(--accent-hover); border-color: #e4daf9; background: var(--accent-soft); }
.back-button { display: none; font-size: 21px; line-height: 1; padding: 5px; min-height: 34px; }
.chat-status { grid-row: 2; margin: 11px 17px 0; border-radius: 9px; padding: 8px 11px; font-size: 13px; line-height: 1.4; background: var(--warn-soft); color: var(--warn); overflow-wrap: anywhere; }
.chat-scroll { grid-row: 3; min-height: 0; overflow-y: auto; scrollbar-width: thin; padding: 15px 20px 18px; overscroll-behavior: contain; }
.messages { display: flex; flex-direction: column; gap: 9px; max-width: 840px; margin: 0 auto; }
.date-break { color: var(--muted); font-size: 12px; text-align: center; align-self: center; background: #f3eff7; padding: 4px 10px; border-radius: 999px; margin: 4px 0 2px; }
.message { max-width: min(88%, 540px); align-self: flex-start; border: 1px solid #ece6f0; background: var(--surface); padding: 9px 11px 7px; border-radius: 12px 12px 12px 3px; }
.message.out { align-self: flex-end; border-color: #e7dcfc; background: #efe7fd; border-radius: 12px 12px 3px 12px; }
.message.system { align-self: center; max-width: 90%; border-color: transparent; background: #f4f1f6; border-radius: 11px; color: var(--muted); }
.message p { font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.message time { display: block; margin-top: 3px; text-align: right; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.composer { grid-row: 4; background: var(--surface); border-top: 1px solid var(--outline); padding: 12px 16px; min-width: 0; }
.composer textarea { display: block; width: 100%; min-height: 60px; max-height: 180px; padding: 10px 12px; resize: vertical; border: 1px solid var(--outline); border-radius: 11px; color: var(--ink); line-height: 1.4; background: #fbfafc; }
.composer textarea::placeholder { color: #756e7d; }
.composer textarea:focus { background: white; }
.composer-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 8px; }
.composer-actions > span { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.draft-button { margin-right: auto; }
.draft-button span { color: var(--accent); }
.send-button { min-height: 36px; }
.send-button span { font-size: 15px; }

.inline-state { display: grid; justify-items: center; gap: 9px; color: var(--muted); text-align: center; font-size: 13px; line-height: 1.35; padding: 14px; }
.inline-state:empty { display: none; }
.form-error { font-size: 13px; color: var(--danger); line-height: 1.35; overflow-wrap: anywhere; margin-top: 5px; }
.settings-dialog { color: var(--ink); width: min(440px, calc(100% - 24px)); border: 1px solid var(--outline); border-radius: 17px; padding: 22px; box-shadow: 0 14px 65px #21133229; }
.settings-dialog::backdrop { background: #241a34a0; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
.dialog-heading h2 { font-size: 23px; letter-spacing: -.045em; }
.close-button { padding: 4px 10px; min-height: 33px; font-size: 21px; line-height: 1; }
.settings-bot-state { font-size: 13px; color: var(--muted); margin-bottom: 13px; }
.settings-dialog fieldset { margin: 0; padding: 13px; border: 1px solid var(--outline); border-radius: 11px; }
.settings-dialog legend { padding: 0 4px; font-weight: 650; font-size: 14px; }
.timezone-label { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.time-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 7px; font-size: 14px; }
.time-row input { width: 120px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.toast { position: fixed; z-index: 5; right: 18px; bottom: 16px; max-width: min(400px, calc(100% - 36px)); padding: 11px 14px; border-radius: 10px; font-size: 14px; background: #272032; color: white; box-shadow: 0 5px 22px #23163128; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

@media (max-width: 740px) {
  .topbar { height: 55px; padding: 0 12px; gap: 7px; }
  .brand { font-size: 15px; gap: 7px; }
  .brand-mark { padding: 5px; }
  .top-actions { gap: 4px; }
  .top-actions .button { padding: 6px 8px; min-height: 33px; }
  .bot-indicator { display: none; }
  .app { height: calc(100dvh - 55px); min-height: 400px; padding: 12px 9px 8px; gap: 10px; }
  .login { min-height: calc(100dvh - 55px); }
  .workspace { grid-template-columns: minmax(0, 1fr); border-radius: 12px; }
  .inbox { border-right: 0; }
  .conversation { display: none; }
  .workspace.chat-open .inbox { display: none; }
  .workspace.chat-open .conversation { display: grid; }
  .workspace-title h1 { font-size: 25px; }
  .refresh-button { min-height: 34px; }
  .chat-header { padding: 9px 8px; gap: 7px; }
  .chat-avatar { width: 34px; height: 34px; border-radius: 10px; }
  .automation-button { font-size: 11px; padding: 6px 8px; min-width: 0; }
  .back-button { display: inline-flex; }
  .chat-scroll { padding: 9px; }
  .composer { padding: 8px; }
}

@media (max-width: 380px) {
  .brand { letter-spacing: -.055em; }
  .brand-separator { margin: 0; }
  .sign-out { font-size: 12px; }
  .composer-actions > span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
