:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", sans-serif;
  color: #30241f;
  background: #f8f3ec;
  --navy: #493629;
  --gold: #eab755;
  --muted: #736457;
  --border: #e4d8c9;
  --paper: #fffcf7;
  --selected: #fbe6b9;
  --hover: #f5ebda;
  --gutter: clamp(14px, 3vw, 40px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
.startup-logo {
  position: fixed; z-index: 10; inset: 0; display: flex; align-items: center; justify-content: center;
  gap: 10px; background: #30241f; color: #fff8ec; pointer-events: none;
  font-size: clamp(22px, 4vw, 34px); animation: astra-reveal 950ms ease both;
}
.startup-logo span { color: #f2c66a; font-size: 1.55em; animation: astra-star 740ms cubic-bezier(.2,.8,.4,1) both; }
@keyframes astra-star {
  from { transform: scale(.45) rotate(-35deg); opacity: 0; }
  70% { transform: scale(1.15) rotate(7deg); opacity: 1; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes astra-reveal {
  0%, 63% { opacity: 1; visibility: visible; }
  100% { opacity: 0; visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) { .startup-logo { display: none; } }
.auth-body { min-height: 100dvh; background: radial-gradient(ellipse at 50% 0, #f1d6ab 0, #f8f3ec 55%); }
.auth-layout { min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.auth-box {
  width: min(100%, 420px); padding: clamp(20px, 5vw, 34px); border: 1px solid var(--border);
  border-radius: 17px; background: var(--paper); box-shadow: 0 14px 45px #49362918;
}
.auth-brand { display: flex; align-items: center; gap: 7px; font-size: 18px; margin-bottom: 17px; }
.auth-box h1 { font-size: 25px; }
.auth-tabs { display: flex; gap: 6px; margin: 14px 0; }
.auth-tabs .ghost[aria-pressed="true"] { background: var(--selected); border-color: #e8c37e; }
.auth-form { display: grid; gap: 12px; }
.auth-form label { display: grid; gap: 5px; font-size: 14px; font-weight: 600; }
.auth-form input { width: 100%; padding: 9px; background: white; color: inherit; border: 1px solid var(--border); border-radius: 8px; }
.auth-form .primary { min-height: 38px; }
#auth-note { font-size: 12px; color: var(--muted); }
#profile-logout { margin-left: auto; }
.connect-accounts { display: inline-flex; justify-self: start; align-items: center; flex-wrap: wrap; min-height: 38px; gap: 8px; background: var(--selected); }
#connect-icons { display: flex; gap: 4px; }
#connect-icons .channel-icon { width: 21px; height: 21px; flex-basis: 21px; border-radius: 5px; }
#connect-icons svg { width: 14px; height: 14px; }
button, textarea, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:enabled, a { cursor: pointer; }
:focus-visible { outline: 2px solid #3565a3; outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(26px, 3vw, 39px); letter-spacing: -.045em; }
h2 { font-size: 19px; letter-spacing: -.02em; }
.top, .account, .brand, .person, .list-title, .chat-head, .input-row { display: flex; align-items: center; }
.top { gap: clamp(10px, 2vw, 30px); padding: 9px var(--gutter); min-height: 60px;
  background: #30241f; color: #fffbf4; }
.brand, .account, .person, .list-title { gap: 12px; }
.mark, .avatar {
  display: grid; place-items: center; flex: 0 0 auto; width: 42px; height: 42px;
  border-radius: 50%; font-weight: 700; background: #f0dfc5; color: var(--navy);
}
.mark { width: 28px; height: 28px; background: transparent; color: #f2c66a; font-size: 29px; }
.brand strong { font-size: 19px; white-space: nowrap; }
small { display: block; margin-top: 3px; color: var(--muted); }
.unread { padding: 1px 5px; border-radius: 12px; font-weight: 700; font-size: 11px; }
.agent { font-size: 14px; font-weight: 650; }
.account { min-width: 0; margin-left: auto; gap: 8px; }
.profile-avatar { width: 34px; height: 34px; overflow: hidden; }
.profile-avatar > * { grid-area: 1 / 1; }
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-button { display: flex; align-items: center; gap: 7px; padding: 2px; border: 0;
  border-radius: 9px; background: transparent; color: inherit; }
.profile-button:hover { background: #493a30; }
.profile-caret { color: #f2c66a; }
body.profile-view { overflow: auto; }
.profile-view .top, .profile-view main > :not(#profile-page) { display: none; }
.profile-view main { max-width: none; }
.settings-content { display: grid; gap: 16px; max-width: 780px; margin: 0 auto; padding: 16px var(--gutter) 32px; }
.settings-card { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 12px; }
.settings-card h2 { font-size: 16px; }
.settings-card label { display: grid; gap: 5px; font-size: 13px; }
.settings-card input, .settings-card select { min-width: 0; width: 100%; padding: 7px 9px; border: 1px solid var(--border);
  border-radius: 7px; background: #fff; color: inherit; font: inherit; }
.settings-card .primary { justify-self: start; }
.settings-avatar-row { display: flex; align-items: center; gap: 10px; }
.settings-avatar { width: 52px; height: 52px; position: relative; overflow: hidden; }
.settings-avatar > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.account-setting { display: grid; gap: 7px; border-top: 1px solid var(--border); padding-top: 10px; }
.account-setting-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.account-setting-head button { margin-left: auto; }
.account-setting-head > span, .settings-result { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.account-setting-head > .account-connected { color: #226b3f; }
.account-list { display: grid; gap: 5px; }
.account-list > .account-setting-head { padding: 4px 0; }
.account-setting-head > .account-row-label { min-width: 0; flex: 1 1 120px; }
.account-setting-head .account-controls { display: flex; flex-wrap: wrap; gap: 5px; }
.account-setting details summary { cursor: pointer; font-size: 14px; font-weight: 650; }
.account-setting ol { margin: 9px 0; padding-left: 20px; font-size: 13px; line-height: 1.5; }
.account-form { display: grid; gap: 8px; max-width: 340px; }
.settings-result:empty { display: none; }
.tools { display: flex; gap: 5px; margin-left: auto; }
.top .tools + .account { margin-left: 0; }
.utility { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; }
.utility svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.device-status { color: var(--muted); font-size: 13px; padding: 8px var(--gutter) 0; }
.device-status:empty { display: none; }
.channels { display: grid; grid-template-columns: minmax(230px, 310px) 1fr; align-items: center;
  gap: 20px; padding: 10px var(--gutter); border-bottom: 1px solid var(--border); }
.channels:has(.search-box[hidden]) { grid-template-columns: 1fr; }
.search-box { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--paper); }
.search-box:focus-within { outline: 2px solid #9b6b25; }
.search-box svg { flex: 0 0 16px; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.search-box input { flex: 1; min-width: 0; width: 100%; background: none; border: 0; outline: none; color: inherit; }
.top .ghost { color: #fff8eb; background: transparent; border-color: transparent; }
.top .ghost:hover { background: #493a30; }
body.client-view { overflow: auto; }
.client-view .top, .client-view main > :not(#client-page):not(#merge-dialog) { display: none; }
.client-view main { max-width: none; }
.client-page { min-height: 100dvh; background: var(--paper); }
.client-page-head {
  display: flex; align-items: center; gap: 10px; min-height: 56px;
  padding: 8px var(--gutter); background: #30241f; color: #fffbf4;
}
.client-page-head h1 { font-size: 19px; letter-spacing: -.02em; }
.client-page-head .ghost { color: inherit; }
.client-page-head .ghost:hover { background: #493a30; }
.clients-panel {
  display: grid; grid-template-columns: minmax(240px, 310px) minmax(0, 1fr);
  min-height: calc(100dvh - 56px); background: var(--paper);
}
.clients-sidebar { border-right: 1px solid var(--border); }
.clients-sidebar > .list-title { justify-content: space-between; padding: 17px; border-bottom: 1px solid var(--border); }
.client-list { max-height: calc(100dvh - 235px); overflow: auto; }
.client-form { display: grid; align-content: start; gap: 12px; padding: 20px; }
.client-form input:not([type="checkbox"]), select {
  width: 100%; min-height: 36px; padding: 6px 9px; color: inherit; font: inherit;
  border: 1px solid var(--border); border-radius: 9px; background: #fff;
}
#client-identities { max-height: 38vh; overflow: auto; }
.client-actions, .chat-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.channel-icon.message-source { width: 15px; height: 15px; flex-basis: 15px; border-radius: 4px; }
.channel-icon.message-source svg { width: 11px; height: 11px; }
.channel-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.channel { position: relative; display: flex; align-items: center; gap: 7px; padding: 4px 12px;
  min-height: 36px; border: 1px solid var(--border); border-radius: 20px; background: var(--paper); }
.channel strong { font-size: 13px; font-weight: 600; }
.channel-filter { text-align: left; color: inherit; }
.channel-filter:hover, .channel-filter[aria-pressed="true"] { background: var(--selected); border-color: #e8c37e; }
.channel-online { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: #25854d; }
.channel-unread {
  position: absolute; top: -5px; right: -2px; min-width: 18px; height: 18px; padding-inline: 3px;
  line-height: 18px; border-radius: 18px; text-align: center; background: #8e520c; color: white;
  font-size: 10px; font-weight: 750; font-variant-numeric: tabular-nums;
}
.client-list-tools { display: grid; gap: 9px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
#merge-hint { color: var(--muted); font-size: 12px; }
.client-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.client-fields label { display: grid; gap: 5px; font-size: 14px; font-weight: 650; }
.client-list-tools input, .contact-section input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; color: inherit; }
.contact-section { display: grid; gap: 10px; min-width: 0; border-top: 1px solid var(--border); padding-top: 12px; }
.contact-section h3 { margin: 0; font-size: 16px; }
.contact-entry { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.contact-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.contact-entry .message-source { width: 24px; height: 24px; flex-basis: 24px; }
.contact-entry .message-source svg { width: 15px; height: 15px; }
.pagination { display: flex; gap: 8px; padding: 8px 14px; }
.pagination:has(button:not([hidden])) { border-top: 1px solid var(--border); }
.pagination:not(:has(button:not([hidden]))) { display: none; }
.client-card[draggable="true"] { cursor: grab; }
.client-card.drop-target { outline: 2px solid var(--navy); outline-offset: -3px; background: #e3eafa; }
.client-status { grid-column: 1 / -1; padding: 10px 16px; color: var(--muted); }
.client-status:empty { display: none; }
.merge-dialog { width: min(440px, calc(100% - 32px)); border: 1px solid var(--border); border-radius: 16px; color: inherit; padding: 22px; }
.merge-dialog::backdrop { background: #152a4470; }
.merge-dialog form { display: grid; gap: 16px; }
.channel-icon { width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; border-radius: 10px; color: white; }
.channel-icon svg { width: 22px; height: 22px; fill: currentColor; }
.tg-icon { background: #168bcb; }
.max-icon { background: linear-gradient(145deg,#447bff,#5927e9 75%); }
.mail-icon { background: #ecf1fd; color: #2b5ba7; }
.mail-icon svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.wa-icon { background: #168447; }
main { max-width: 1600px; margin: auto; }
.channel > .channel-icon { width: 23px; height: 23px; flex-basis: 23px; border-radius: 7px; }
.channel > .channel-icon svg { width: 16px; height: 16px; }
.workspace {
  display: grid; grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  min-height: 490px; height: calc(100dvh - 118px); border-bottom: 1px solid var(--border);
  background: var(--paper); overflow: hidden;
}
.inbox, .chat { display: flex; flex-direction: column; min-height: 0; }
.inbox { border-right: 1px solid var(--border); }
.list-head { display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.list-head select { flex: 1; min-width: 0; width: auto; font-size: 12px; min-height: 32px; padding: 4px 6px; }
textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 11px; padding: 10px 12px;
  color: inherit; background: #fff;
}
.ghost, .primary {
  display: inline-block; text-decoration: none; border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 10px; color: var(--navy); background: #fff; font-size: 13px; font-weight: 650;
}
.ghost:hover, .ghost[aria-pressed="true"] { background: var(--hover); }
.threads, .log { overflow: auto; }
.thread {
  display: flex; align-items: center; gap: 9px; text-align: left; width: 100%;
  border: 0; border-bottom: 1px solid var(--border); padding: 8px 10px; color: inherit; background: transparent;
}
.thread:hover { background: var(--hover); }
.thread[aria-current="true"] { background: var(--selected); }
.thread .avatar { width: 32px; height: 32px; font-size: 12px; }
.thread-text { flex: 1; min-width: 0; }
.thread-text strong, .thread-text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-text strong { font-size: 14px; }
.thread-text small { font-size: 12px; margin-top: 2px; }
.thread-meta { display: grid; gap: 3px; justify-items: end; flex: 0 0 auto; }
.thread-meta time { color: var(--muted); font-size: 11px; }
.unread { background: var(--navy); color: #fff; }
.conversation, .chat { height: 100%; min-height: 0; }
.chat-head { justify-content: space-between; gap: 8px; padding: 7px 14px; border-bottom: 1px solid var(--border); }
.chat-head .person { gap: 8px; min-width: 0; }
.chat-head .avatar { width: 34px; height: 34px; font-size: 12px; }
.chat-head h2 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .chat-actions { gap: 4px; flex-wrap: nowrap; }
#chat-back { display: none; }
.mail-topics { padding: 5px 14px; border-bottom: 1px solid var(--border); }
.mail-topics select { width: min(100%, 310px); min-height: 31px; font-size: 13px; }
.icon-action {
  position: relative; display: inline-grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px;
  padding: 0; background: transparent; border-color: transparent;
}
.icon-action > svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#telegram .external-mark { position: absolute; width: 10px; height: 10px; top: 1px; right: 1px; }
.identity-icons { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.identity-tooltip { display: inline-grid; position: relative; flex: 0 0 auto; padding: 2px; }
.identity-tooltip::after {
  content: attr(data-tooltip); position: absolute; z-index: 3; top: calc(100% + 5px); left: 0;
  width: max-content; max-width: min(180px, 62vw); padding: 5px 8px; border-radius: 6px;
  background: #30241f; color: #fffbf4; font-size: 12px; overflow-wrap: anywhere;
  pointer-events: none; opacity: 0; transition: opacity 110ms;
}
.identity-tooltip:hover::after, .identity-tooltip:focus::after { opacity: 1; }
.account .identity-tooltip::after { left: auto; right: 0; }
.log { flex: 1; min-height: 0; background: #faf5ed; padding: 12px clamp(10px, 2vw, 28px); }
#messages { display: flex; flex-direction: column; gap: 7px; }
#older { display: block; margin: 0 auto 14px; }
.bubble {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; column-gap: 9px;
  max-width: min(92%, 710px); align-self: flex-start; padding: 7px 10px; background: var(--paper);
  border: 1px solid var(--border); border-radius: 11px;
  font-size: 14px; line-height: 1.35;
}
.bubble > .message-source { margin-top: 2px; }
.bubble > .tg-icon, .identity-tooltip .tg-icon { background: #e6edf0; color: #42677d; }
.bubble > .mail-icon, .identity-tooltip .mail-icon { background: #ece7df; color: #736653; }
.bubble-body { min-width: 0; }
.bubble-text { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.attachments { display: grid; gap: 5px; min-width: 0; }
.bubble-text + .attachments { margin-top: 6px; }
.attachment { display: grid; gap: 4px; min-width: 0; color: inherit; text-decoration: none; }
.attachment-photo {
  display: block; width: auto; max-width: min(100%, 360px); height: auto; max-height: 320px;
  object-fit: contain; object-position: left center; border-radius: 7px;
}
.attachment-info {
  display: flex; width: fit-content; max-width: 100%; align-items: center; gap: 5px;
  border-radius: 7px; padding: 5px 7px; background: #f1e8da; font-size: 12px; overflow-wrap: anywhere;
}
.attachment:hover .attachment-info { background: #ebd8b9; }
.attachment-info svg { flex: 0 0 15px; width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.attachment-unavailable { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.bubble.out { align-self: flex-end; background: #fae8c4; border-color: #f0d8a8; }
.bubble time { align-self: end; text-align: right; font-size: 10px; white-space: nowrap; color: var(--muted); }
.composer { padding: 8px 16px; border-top: 1px solid var(--border); }
.input-row {
  gap: 4px; align-items: flex-end; padding: 3px; border: 1px solid var(--border); border-radius: 13px;
}
.input-row:focus-within { border-color: #b88c49; }
.input-row textarea {
  flex: 1; min-width: 0; min-height: 38px; max-height: 136px; field-sizing: content;
  border: 0; padding: 8px 9px; resize: none; line-height: 22px; outline: none;
}
.send-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 2px; }
.reply-picker { position: relative; }
.reply-picker summary {
  display: flex; align-items: center; gap: 2px; height: 38px; padding: 0 6px; cursor: pointer;
  list-style: none; border-radius: 8px; color: var(--muted);
}
.reply-picker summary::-webkit-details-marker { display: none; }
.reply-picker summary:hover, .reply-picker[open] summary { background: var(--hover); }
.reply-picker summary > svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.reply-picker[open] summary > svg { transform: rotate(180deg); }
#reply-icon, .reply-warning { display: grid; place-items: center; width: 20px; height: 20px; }
#reply-icon .message-source { width: 20px; height: 20px; background: transparent; }
#reply-icon .tg-icon { color: #168bcb; }
#reply-icon .message-source svg { width: 17px; height: 17px; }
.reply-warning { color: #ad2536; font-weight: 800; font-size: 19px; line-height: 1; }
.reply-menu {
  position: absolute; z-index: 2; bottom: calc(100% + 8px); right: -38px;
  width: min(284px, calc(100vw - 54px)); max-height: 220px; overflow: auto;
  padding: 4px; border: 1px solid var(--border); border-radius: 12px; background: #fff;
  box-shadow: 0 8px 20px #152a4424;
}
.reply-option {
  display: flex; width: 100%; align-items: flex-start; gap: 8px; padding: 7px 8px;
  border: 0; border-radius: 8px; background: #fff; color: inherit; text-align: left; font-size: 13px;
}
.reply-option:hover, .reply-option[aria-pressed="true"] { background: var(--hover); }
.reply-option .message-source { margin-top: 2px; }
.reply-option-details { min-width: 0; overflow-wrap: anywhere; }
.reply-option-details small { margin-top: 1px; }
.reply-option-details .reply-unavailable { color: #9b3644; }
#send {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0;
  border-radius: 9px; color: #30241f; background: var(--gold);
}
#send:disabled { color: #846e53; background: #f2e6d4; }
#send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.primary { background: var(--navy); color: white; padding-inline: 16px; }
.primary:disabled { opacity: .5; }
.error { color: #a62132; font-size: 13px; }
.error:empty { display: none; }
.error { margin-top: 7px; }
.empty { color: var(--muted); padding: 20px; font-size: 14px; }
.conversation > .empty { display: grid; height: 100%; place-items: center; }
@media (max-width: 700px) {
  .top { flex-wrap: wrap; gap: 7px 10px; }
  .tools { margin-left: auto; }
  .utility { font-size: 0; padding: 5px; }
  .account .agent { max-width: 95px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .account #agent-handle { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); min-height: 0; height: calc(100dvh - 148px); }
  .workspace .conversation { display: none; }
  .inbox .thread { min-height: 58px; padding: 8px 13px; }
  .mobile-chat { overflow: hidden; }
  .mobile-chat .top, .mobile-chat .channels, .mobile-chat .workspace .inbox,
  .mobile-chat #device-status { display: none; }
  .mobile-chat .workspace {
    position: fixed; inset: 0; width: 100%; height: 100dvh; border: 0;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-chat .workspace .conversation { display: block; }
  #chat-back { display: inline-grid; }
  .clients-panel { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .client-list { max-height: 35dvh; }
  .clients-sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .client-fields { grid-template-columns: minmax(0,1fr); }
  .inbox { border-right: 0; border-bottom: 1px solid var(--border); }
  .chat-head, .composer { padding-inline: 9px; }
  .channels { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .channel-grid { gap: 5px; }
  .channel { padding: 3px 6px; gap: 4px; min-height: 32px; }
  .channel strong { font-size: 11px; }
  .channel > .channel-icon { width: 19px; height: 19px; flex-basis: 19px; }
  .channel > .channel-icon svg { width: 14px; height: 14px; }
  .brand strong { font-size: 16px; }
  .account { gap: 7px; }
  .profile-avatar { width: 26px; height: 26px; }
  .agent { font-size: 12px; }
  .chat-actions #simulate { max-width: 94px; padding: 4px 6px; font-size: 11px; }
}

