:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --sidebar: #0b1220;
  --sidebar-soft: #151f31;
  --text: #17202e;
  --muted: #667085;
  --border: #e4e8ee;
  --primary: #087a65;
  --primary-dark: #056653;
  --primary-soft: #e9f7f3;
  --success: #18a06a;
  --warning: #b7791f;
  --danger: #d14343;
  --purple: #7656d6;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .035);
  --shadow: 0 14px 38px rgba(16, 24, 40, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 84% -10%, rgba(8, 122, 101, .09), transparent 30rem),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.ui-icon, .nav-icon { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 24px 0 18px;
  color: #fff;
  background: var(--sidebar);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { display: block; width: 126px; height: auto; }
.brand-divider { width: 1px; height: 25px; background: rgba(255,255,255,.16); }
.brand p { margin: 0; color: #9ba8bc; font-size: 11px; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.current-user {
  max-width: 260px;
  overflow: hidden;
  color: #cbd4e1;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-button { color: #dce4ee; background: rgba(255,255,255,.08); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.on { color: #42e3a8; background: rgba(19, 164, 112, .14); border-color: rgba(66, 227, 168, .2); }
.badge.off { color: #ff9f9f; background: rgba(209, 67, 67, .13); border-color: rgba(255, 159, 159, .18); }
.badge.qr { color: #ffd27d; background: rgba(183, 121, 31, .16); border-color: rgba(255, 210, 125, .18); }

nav#tabs {
  position: sticky;
  top: 72px;
  align-self: start;
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: calc(100vh - 72px);
  padding: 22px 14px;
  overflow-y: auto;
  background: var(--sidebar);
}
.nav-section {
  margin: 15px 12px 5px;
  color: #6f7e93;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.nav-section:first-child { margin-top: 0; }
nav#tabs button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 0;
  border-radius: 11px;
  color: #aeb9c9;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: color .16s ease, background .16s ease, transform .16s ease;
}
nav#tabs button:hover { color: #fff; background: rgba(255,255,255,.055); transform: translateX(2px); }
nav#tabs button.active { color: #fff; background: var(--sidebar-soft); border-left: 3px solid #20c997; padding-left: 8px; }
.nav-icon { width: 19px; height: 19px; flex: 0 0 19px; color: #7d8ca2; }
nav#tabs button.active .nav-icon { color: #35d0a4; }
.tab-count {
  min-width: 20px;
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 999px;
  color: #fff;
  background: var(--danger);
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}

main {
  grid-column: 2;
  grid-row: 2;
  width: 100%;
  max-width: 1460px;
  margin: 0 auto;
  padding: 30px clamp(20px, 3vw, 44px) 72px;
}
.tab { display: none; animation: tab-in .2s ease both; }
.tab.active { display: block; }
@keyframes tab-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin: 0 0 22px; }
.page-heading h2 { margin: 3px 0 5px; color: #111827; font-size: clamp(24px, 2.2vw, 32px); line-height: 1.15; letter-spacing: -.035em; }
.page-heading p { max-width: 650px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.eyebrow { color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.compact-heading { margin-bottom: 18px; }

.card, .item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card { padding: 22px; margin-bottom: 16px; transition: border-color .18s ease, box-shadow .18s ease; }
.card.center { text-align: center; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; line-height: 1.45; }
.error { min-height: 18px; color: var(--danger); font-size: 12px; }
.warn { margin: 12px 0; padding: 11px 13px; border: 1px solid #f2d69c; border-radius: 11px; color: #835817; background: #fffbeb; font-size: 13px; }
.ok { color: var(--success); font-size: 13px; font-weight: 650; }
hr { height: 1px; margin: 20px 0; border: 0; background: var(--border); }

button {
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  transition: background .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
button:hover { background: var(--primary-dark); box-shadow: none; transform: translateY(-1px); }
button:active { box-shadow: none; transform: translateY(0); }
button:disabled { opacity: .55; cursor: wait; transform: none; }
button.secondary { color: #344054; background: #fff; border-color: #d7dde5; }
button.secondary:hover { background: #f8fafb; border-color: #bfc8d4; box-shadow: var(--shadow-sm); }
button.danger { color: #c52e2e; background: #fff; border-color: #f0b9b9; }
button.danger:hover { background: #fff4f4; border-color: #e98f8f; box-shadow: none; }
button.small { min-height: 32px; padding: 6px 10px; border-radius: 8px; font-size: 11px; }
.icon-button { display: inline-grid; place-items: center; width: 34px; padding: 0; }
.icon-button .ui-icon { width: 17px; height: 17px; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(31, 181, 145, .22);
  outline-offset: 2px;
}
.field-help { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; font-weight: 500; line-height: 1.45; }

input[type=text], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], textarea, select {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
  padding: 9px 11px;
  border: 1px solid #d7dde5;
  border-radius: 10px;
  color: var(--text);
  background: #fff;
  font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 86px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #98a2b3; }
input:hover, textarea:hover, select:hover { border-color: #bdc6d2; }
input:focus, textarea:focus, select:focus { border-color: #087a65; box-shadow: none; outline: 2px solid #9fd6ca; outline-offset: 1px; }
label { display: block; margin-bottom: 14px; color: #344054; font-size: 12px; font-weight: 650; }
label.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 550; }
label.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
.row { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.row.compact { gap: 10px; }
.row.compact > label { flex: 1; min-width: 130px; }
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 18px; }
.grid-form .full, .grid-form > div { grid-column: 1 / -1; }

.settings-group { margin: 6px 0 20px; padding: 17px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); }
.settings-group legend { padding: 0 8px; color: var(--primary); font-size: 12px; font-weight: 800; }
.settings-group p { margin: 6px 0 10px; }
.secret-input { display: flex; align-items: center; gap: 8px; }
.secret-input input { flex: 1; }
.secret-input button { flex: 0 0 auto; margin-top: 6px; }

/* connection */
.connection-layout { display: grid; grid-template-columns: minmax(0, 1.16fr) minmax(340px, .84fr); gap: 18px; align-items: stretch; }
.connection-layout > .card { margin: 0; }
.connection-hero { display: flex; flex-direction: column; align-items: center; min-height: 470px; justify-content: center; padding: clamp(28px, 5vw, 60px); background: linear-gradient(155deg, #fff 54%, #f1faf7); }
.connection-orb { display: grid; place-items: center; width: 66px; height: 66px; margin-bottom: 18px; border-radius: 22px; color: #fff; background: var(--primary); box-shadow: none; font-size: 34px; }
.connection-orb .ui-icon { width: 28px; height: 28px; stroke-width: 1.65; }
#conn-status-text { max-width: 660px; margin-bottom: 8px; color: #263241; font-size: 17px; font-weight: 750; line-height: 1.5; }
#conn-user { margin: 6px 0 14px; }
.qr-frame { margin: 18px auto 10px; padding: 13px; border: 1px solid var(--border); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.qr-frame:has(.hidden) { display: none; }
#qr-img { display: block; width: min(280px, 68vw); height: auto; border-radius: 10px; }
.status-kicker { margin-bottom: 6px; color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.sync-card { display: flex; flex-direction: column; min-height: 470px; padding: clamp(24px, 3.3vw, 38px); }
.sync-card h3 { margin: 7px 0 8px; font-size: 22px; letter-spacing: -.025em; }
.sync-card > p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.sync-flow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 24px 0; }
.sync-flow > div { position: relative; display: flex; flex-direction: column; min-width: 0; padding: 12px 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); }
.sync-flow > div:not(:last-child)::after { content: ""; position: absolute; z-index: 2; top: 24px; right: -9px; width: 9px; border-top: 1px dashed #b7c1ce; }
.sync-flow span { display: grid; place-items: center; width: 23px; height: 23px; margin-bottom: 8px; border-radius: 8px; color: #fff; background: var(--primary); font-size: 10px; font-weight: 800; }
.sync-flow b { overflow: hidden; font-size: 11px; text-overflow: ellipsis; }
.sync-flow small { margin-top: 3px; color: var(--muted); font-size: 9px; line-height: 1.3; }
.sync-option { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 14px; padding: 13px; border: 1px solid #cce7df; border-radius: 12px; background: #f2faf8; cursor: pointer; }
.sync-option input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--primary); }
.sync-option span { display: flex; flex-direction: column; }
.sync-option b { font-size: 12px; }
.sync-option small { margin-top: 3px; color: var(--muted); font-size: 9px; font-weight: 500; line-height: 1.4; }
.sync-card > button { width: 100%; }
.sync-status { margin-top: 14px; padding: 13px; border-radius: 12px; background: #f7f9fa; }
.sync-status.complete { color: #087454; background: #edf9f5; }
.sync-status.error { color: #9f3030; background: #fff4f4; }
.sync-status p { min-height: 34px; margin: 9px 0; color: inherit; font-size: 10px; line-height: 1.5; }
.sync-progress { height: 5px; overflow: hidden; border-radius: 999px; background: #e1e7eb; }
.sync-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--primary); transition: width .3s ease; }
.sync-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.sync-metrics span { padding: 7px 5px; border-radius: 8px; color: var(--muted); background: rgba(255,255,255,.75); font-size: 8px; text-align: center; }
.sync-metrics b { display: block; margin-bottom: 2px; color: var(--text); font-size: 13px; }
.sync-privacy { display: flex; align-items: center; gap: 6px; margin-top: auto !important; padding-top: 16px; color: #718095 !important; font-size: 9px !important; }
.sync-privacy .ui-icon { width: 14px; height: 14px; color: var(--primary); }

/* conversations */
.chat-layout { display: grid; grid-template-columns: minmax(260px, 330px) minmax(0, 1fr); gap: 16px; min-height: 0; }
.contacts-panel { display: flex; flex-direction: column; min-height: 0; padding: 13px; overflow: hidden; }
.search-box { position: relative; display: flex; align-items: center; margin: 0 0 10px; color: #7b8798; }
.search-box > .ui-icon { position: absolute; left: 13px; z-index: 1; width: 16px; height: 16px; }
.search-box input { height: 42px; margin: 0; padding-left: 38px; border-color: transparent; background: #f3f5f7; }
#contact-list { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; scrollbar-width: thin; }
.contact-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 62px; padding: 10px 11px; border-radius: 12px; cursor: pointer; transition: background .15s, transform .12s, filter .12s; }
.contact-item:hover { background: #f5f7f8; }
.contact-item.unread { padding-left: 8px; border-left: 3px solid #f59e0b; background: #fff7ed; }
.contact-item.unread:hover { background: #ffedd5; }
.contact-item.unread .cname { color: #7c3f00; font-weight: 800; }
.contact-item.active { padding-left: 8px; border-left: 3px solid var(--primary); background: var(--primary-soft); box-shadow: none; }
.contact-item.selected { background: #e7f7f2; box-shadow: inset 0 0 0 1px #a9dacf; }
.contact-main { display: flex; align-items: center; gap: 9px; min-width: 0; }
.contact-main > div { min-width: 0; }
.contact-item .cname { max-width: 190px; overflow: hidden; color: #263241; font-size: 13px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.contact-item .cjid { margin-top: 3px; color: #8a96a8; font-size: 10px; }
.context-menu { position: fixed; z-index: 180; width: 244px; padding: 7px; overflow: hidden; border: 1px solid rgba(215,221,229,.9); border-radius: 18px; background: rgba(255,255,255,.96); box-shadow: 0 20px 55px rgba(11,18,32,.2); backdrop-filter: blur(18px); animation: force-menu-in .14s ease both; transform-origin: top left; }
.context-preview { display: flex; align-items: center; gap: 10px; min-height: 58px; margin-bottom: 5px; padding: 9px 10px 12px; border-bottom: 1px solid var(--border); }
.context-preview-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border-radius: 11px; color: var(--primary); background: var(--primary-soft); }
.context-preview-icon .ui-icon { width: 17px; height: 17px; }
.context-preview div { min-width: 0; }
.context-preview b, .context-preview small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.context-preview b { color: var(--text); font-size: 12px; }
.context-preview small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.context-menu button { display: block; width: 100%; min-height: 38px; padding: 8px 11px; border: 0; border-radius: 9px; color: #344054; background: transparent; font-size: 12px; text-align: left; }
.context-menu button:hover, .context-menu button:focus-visible { color: var(--primary); background: var(--primary-soft); box-shadow: none; transform: none; }
.context-menu button.context-menu-danger { color: #b42318; }
.context-menu button.context-menu-danger:hover, .context-menu button.context-menu-danger:focus-visible { color: #9f1c14; background: #fff1f0; }
@keyframes force-menu-in { from { opacity: 0; transform: scale(.94) translateY(-3px); } to { opacity: 1; transform: none; } }
.pressing { transform: scale(.985); filter: brightness(.98); }
.selection-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; padding: 10px 12px; border: 1px solid #bfe2d9; border-radius: 12px; color: #155f51; background: #eff9f6; }
.selection-toolbar > span { font-size: 11px; white-space: nowrap; }
.selection-toolbar > div { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.selection-toolbar.compact { align-items: stretch; flex-direction: column; }
.selection-toolbar.compact > div { justify-content: stretch; }
.selection-toolbar.compact button { flex: 1; padding-inline: 7px; }
.selection-check { display: none; place-items: center; width: 20px; height: 20px; flex: 0 0 20px; border: 1.5px solid #aab4c2; border-radius: 7px; color: transparent; background: #fff; font-size: 11px; font-weight: 900; }
.selection-mode .selection-check, .selected .selection-check { display: grid; }
.selected .selection-check { color: #fff; border-color: var(--primary); background: var(--primary); }
[data-bulk-controller] { position: relative; transition: padding .16s ease, background .16s ease, box-shadow .16s ease, transform .12s ease, filter .12s ease; }
[data-bulk-controller].selection-mode { padding-left: 48px; cursor: pointer; }
[data-bulk-controller] > .selection-check { position: absolute; z-index: 2; top: 13px; left: 14px; }
[data-bulk-controller].selected { background: #eff9f6; box-shadow: inset 0 0 0 1px #bfe2d9; }
.tag { display: inline-flex; padding: 3px 7px; border: 1px solid #dce1e7; border-radius: 999px; color: #586577; background: #f5f7f8; font-size: 9px; font-weight: 750; white-space: nowrap; }
#chat-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; margin: 0; padding: 0; overflow: hidden; }
#chat-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; padding: 14px 16px 12px 22px; border-bottom: 1px solid var(--border); color: #253141; font-size: 14px; font-weight: 750; }
#chat-contact-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-register-customer { margin-left: auto; white-space: nowrap; }
.chat-header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
.chat-header-actions select { width: auto; max-width: 180px; height: 34px; margin: 0; padding-block: 4px; font-size: 10px; }
.chat-internal-notes { padding: 12px 16px; border-bottom: 1px solid #eedba8; background: #fffaf0; }
.chat-notes-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.chat-notes-head b, .chat-notes-head small { display: block; }
.chat-notes-head small { margin-top: 2px; color: var(--muted); font-size: 9px; font-weight: 500; }
#chat-note-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; margin-top: 10px; }
#chat-note-form textarea { min-height: 54px; margin: 0; resize: vertical; }
#chat-note-list { display: grid; gap: 6px; max-height: 190px; margin-top: 9px; overflow-y: auto; }
.internal-note { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 8px 10px; border: 1px solid #f0dfb6; border-radius: 9px; background: #fff; font-size: 11px; }
.internal-note p { margin: 3px 0 0; white-space: pre-wrap; }
.internal-note small { color: var(--muted); font-size: 8px; }
.internal-note button { align-self: start; padding: 3px 6px; }
#chat-messages { flex: 1; min-height: 0; padding: 20px 14px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; background: #f5f3ee; }
.msg { max-width: min(72%, 620px); margin: 5px 8px; padding: 9px 12px; border: 1px solid rgba(16,24,40,.06); border-radius: 13px; box-shadow: none; font-size: 13px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg.in { margin-right: auto; border-bottom-left-radius: 4px; background: #fff; }
.msg.out { margin-left: auto; border-bottom-right-radius: 4px; background: #dff7ef; }
.msg.system-event { max-width: min(88%, 720px); margin: 12px auto; border: 1px solid #cddbd7; border-radius: 999px; color: #45615a; background: rgba(255,255,255,.84); font-size: 11px; text-align: center; }
.msg-author { display: block; margin: 0 6px 2px; color: #0b6958; font-size: 11px; font-weight: 800; }
.msg:has(.msg-media), .msg:has(.msg-document), .msg:has(.msg-audio) { padding: 6px; }
.msg-text { padding: 4px 6px 2px; }
.msg-media { display: block; width: auto; max-width: min(100%, 430px); max-height: 390px; border-radius: 10px; object-fit: contain; background: rgba(15,23,42,.06); }
.msg-media.sticker { width: min(190px, 100%); max-height: 190px; background: transparent; }
.msg-visual-link { display: block; color: inherit; text-decoration: none; }
.msg-audio { display: flex; align-items: center; gap: 8px; min-width: min(340px, 60vw); padding: 5px 6px; }
.msg-audio > span { display: grid; place-items: center; width: 33px; height: 33px; flex: 0 0 33px; border-radius: 50%; background: rgba(8,122,101,.1); }
.msg-audio audio { width: 100%; min-width: 0; height: 36px; }
.msg-document { display: grid; grid-template-columns: 38px minmax(0, 1fr) 20px; align-items: center; gap: 9px; min-width: min(330px, 60vw); padding: 9px; border-radius: 10px; color: #263241; background: rgba(255,255,255,.62); text-decoration: none; }
.msg.in .msg-document { background: #f3f5f7; }
.msg-document-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; background: rgba(8,122,101,.1); font-size: 19px; }
.msg-document b, .msg-document small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-document b { font-size: 11px; }
.msg-document small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.msg .meta { display: block; margin-top: 4px; color: #788697; font-size: 9px; text-align: right; }
#chat-send-form { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: #fff; }
#chat-send-form button { flex: 0 0 auto; }
.chat-composer { position: relative; display: flex; align-items: center; gap: 7px; min-width: 0; }
.chat-composer #chat-input { flex: 1; min-width: 80px; margin: 0; }
.composer-icon { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: 11px; font-size: 17px; }
.composer-icon.recording { width: auto; min-width: 76px; padding: 0 11px; color: #fff; border-color: #d14343; background: #d14343; animation: recording-pulse 1.2s ease-in-out infinite; }
.chat-upload-status { padding: 7px 16px; border-top: 1px solid #d6eee7; color: var(--primary-dark); background: #f0faf7; font-size: 10px; }
.chat-upload-status.error { color: var(--danger); background: #fff4f4; }
.emoji-picker { position: absolute; z-index: 20; bottom: calc(100% + 12px); left: 40px; display: grid; grid-template-columns: repeat(8, 34px); gap: 3px; width: 310px; max-height: 250px; padding: 8px; overflow-y: auto; border: 1px solid var(--border); border-radius: 15px; background: #fff; box-shadow: 0 16px 38px rgba(16,24,40,.18); }
.emoji-picker button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px; background: transparent; font-size: 19px; }
.emoji-picker button:hover { background: var(--primary-soft); box-shadow: none; transform: none; }
@keyframes recording-pulse { 50% { box-shadow: 0 0 0 5px rgba(209,67,67,.13); } }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; min-height: 240px; color: #7b8798; text-align: center; }
.empty-state > span { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 12px; border-radius: 16px; color: var(--primary); background: var(--primary-soft); font-size: 27px; }
.empty-state > span .ui-icon { width: 23px; height: 23px; }
.empty-state b { color: #445065; font-size: 13px; }
.empty-state small { margin-top: 5px; font-size: 11px; }

@media (min-width: 781px) {
  body:has(#tab-chats.active), body:has(#tab-internal.active) { overflow: hidden; }
  body:has(#tab-chats.active) main, body:has(#tab-internal.active) main { height: calc(100dvh - 72px); padding-bottom: 24px; overflow: hidden; }
  #tab-chats.active, #tab-internal.active { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; min-height: 0; }
  #tab-chats .chat-layout, #tab-internal .chat-layout { height: 100%; min-height: 0; overflow: hidden; }
  #tab-chats .contacts-panel, #tab-chats #chat-panel, #tab-internal .contacts-panel, #internal-chat-panel { height: 100%; min-height: 0; max-height: none; }
}

.manual-history-import { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.manual-history-import summary { color: var(--primary-dark); font-size: 11px; font-weight: 750; cursor: pointer; }
.manual-history-import p { font-size: 9px; line-height: 1.5; }
.manual-history-import label { margin-top: 7px; font-size: 9px; }
.manual-history-import input, .manual-history-import select { height: 36px; margin-top: 3px; font-size: 10px; }
.manual-history-import button { width: 100%; margin-top: 8px; }
#history-import-result { display: block; margin-top: 7px; }

#internal-contact-list { flex: 1; min-height: 0; overflow-y: auto; }
#internal-chat-panel { display: flex; flex-direction: column; min-width: 0; overflow: hidden; padding: 0; }
.internal-chat-header { min-height: 60px; padding: 19px 22px; border-bottom: 1px solid var(--border); font-size: 14px; font-weight: 750; }
#internal-messages { flex: 1; min-height: 0; padding: 20px 14px; overflow-y: auto; background: #f3f6f8; }
#internal-send-form { position: relative; display: flex; align-items: center; gap: 7px; padding: 12px; border-top: 1px solid var(--border); background: #fff; }
#internal-send-form input { min-width: 90px; flex: 1; margin: 0; }
#internal-send-form .emoji-picker { left: 120px; }
.team-role { margin-top: 3px; color: var(--muted); font-size: 9px; text-transform: capitalize; }

/* customer database */
.customers-heading { align-items: center; }
.customers-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(310px, .7fr); gap: 16px; align-items: start; }
.customers-main { min-height: 430px; }
.customers-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.customers-toolbar .search-box { flex: 1; margin: 0; }
.customer-form-card { position: sticky; top: 94px; }
.customer-form-card h3 { margin-top: 0; }
.customer-fields-help { margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--border); }
.optional { margin-left: 4px; color: #98a2b3; font-size: 9px; font-weight: 500; }
.customer-row { display: grid; grid-template-columns: 20px 42px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--border); transition: background .15s, transform .12s, filter .12s; }
.customer-row:last-child { border-bottom: 0; }
.customer-row > .selection-check { display: grid; visibility: hidden; }
.customer-row.selection-mode > .selection-check, .customer-row.selected > .selection-check { visibility: visible; }
.customer-row.selected { border-radius: 12px; background: #eff9f6; box-shadow: inset 0 0 0 1px #bfe2d9; }
.customer-avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; color: var(--primary); background: var(--primary-soft); font-size: 15px; font-weight: 800; }
.customer-summary { min-width: 0; }
.customer-summary > strong { display: block; overflow: hidden; color: var(--text); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.customer-summary > span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.customer-extras { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 7px; color: var(--muted); font-size: 10px; }
.customer-extras b { color: #596579; }
.customer-row .actions { display: flex; gap: 5px; }
.customer-empty { min-height: 330px; }

/* intelligent calendar */
.calendar-toolbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.calendar-toolbar h3 { margin: 0; text-align: center; text-transform: capitalize; }
.calendar-navigation { display: flex; gap: 6px; }
.calendar-legend { justify-self: end; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot.ai { background: var(--purple); }
.dot.manual { background: var(--primary); }
.calendar-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(310px, .8fr); gap: 16px; }
.calendar-main { overflow: hidden; }
.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-weekdays span { padding: 8px 4px 13px; color: #7d8999; font-size: 10px; font-weight: 800; text-align: center; text-transform: uppercase; }
.calendar-grid { border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.calendar-day { min-height: 96px; padding: 7px; overflow: hidden; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: #fff; cursor: pointer; transition: background .13s, box-shadow .13s; }
.calendar-day:hover { background: #f5fbf9; }
.calendar-day.other { color: #abb3bf; background: #fafbfc; }
.calendar-day.selected { outline: 2px solid var(--primary); outline-offset: -2px; background: #f0fbf8; }
.calendar-day.drag-over { position: relative; z-index: 1; outline: 2px dashed var(--primary); outline-offset: -4px; background: #e6f8f3; box-shadow: none; }
.calendar-day.today .day-number { color: #fff; background: var(--primary); }
.day-number { display: inline-flex; align-items: center; justify-content: center; width: 25px; height: 25px; border-radius: 50%; font-size: 11px; font-weight: 800; }
.day-status { display: inline-block; width: 7px; height: 7px; margin-left: 4px; border-radius: 50%; vertical-align: middle; }
.day-status.open { background: #c98a25; box-shadow: none; }
.day-status.closed { background: #d14343; box-shadow: none; }
.day-event { margin-top: 4px; padding: 3px 5px; overflow: hidden; border-radius: 5px; color: #fff; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; cursor: grab; touch-action: none; user-select: none; transition: opacity .13s, transform .13s, box-shadow .13s; }
.day-event:hover { box-shadow: none; transform: translateY(-1px); }
.day-event:focus-visible { outline: 2px solid #14263d; outline-offset: 2px; }
.day-event.dragging { opacity: .35; cursor: grabbing; transform: scale(.96); }
.day-event.ai { background: var(--purple); }
.day-event.manual { background: var(--primary); }
.day-event.cancelled { background: #8a94a0; text-decoration: line-through; }
.calendar-side h3, .calendar-side h4 { margin-top: 0; }
.calendar-tip { margin: -4px 0 12px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.availability-summary { margin-bottom: 12px; padding: 11px; border: 1px solid #cde8df; border-radius: 10px; color: var(--primary); background: #eff9f6; font-size: 11px; }
.availability-summary.closed { color: #a32d2d; background: #fff2f2; border-color: #f2cccc; }
.appointment-card { margin: 7px 0; padding: 10px; border-left: 3px solid var(--primary); border-radius: 8px; background: #f8faf9; font-size: 12px; cursor: grab; touch-action: none; user-select: none; transition: background .13s, box-shadow .13s, opacity .13s, transform .13s; }
.appointment-card:hover { background: #f1f8f6; box-shadow: none; }
.appointment-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.appointment-card.dragging { opacity: .38; cursor: grabbing; transform: scale(.98); }
.appointment-card.ai { border-left-color: var(--purple); }
.appointment-card.cancelled { opacity: .55; border-left-color: #8a94a0; }
.appointment-card .time { color: var(--primary); font-weight: 800; }
.appointment-card .actions { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }
.slots { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.slot { min-height: 27px; padding: 3px 7px; border: 1px solid #b9d8d1; border-radius: 6px; color: var(--primary); background: #fff; box-shadow: none; font-size: 10px; font-weight: 750; cursor: pointer; }
.slot:hover, .slot.selected { border-color: var(--primary); color: #fff; background: var(--primary); box-shadow: none; transform: none; }
.slot.drop-target { border: 2px dashed var(--primary); color: var(--primary); background: #d9f5ed; box-shadow: none; transform: scale(1.05); }
.calendar-is-dragging .calendar-day { cursor: copy; }
.calendar-is-dragging .slot { border-style: dashed; }
.calendar-settings { margin-top: 16px; }
.calendar-settings summary { padding: 3px; cursor: pointer; }
.weekly-row { display: grid; grid-template-columns: 110px 90px 1fr 1fr 110px auto; gap: 8px; align-items: end; padding: 9px 0; border-bottom: 1px solid #edf0f2; }
.weekly-row label { margin: 0; font-size: 11px; }
.exception-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 7px; padding: 9px 11px; border-radius: 9px; background: #f6f7f8; font-size: 12px; }

/* smart notes and lists */
.notes-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.notes-toolbar h3 { margin: 0 0 5px; }
.notes-toolbar p { margin: 0; }
.notes-toolbar label { min-width: 160px; margin: 0; }
.item { margin-bottom: 10px; padding: 16px 18px; }
.item .item-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.item .item-title { font-size: 13px; font-weight: 750; }
.item .item-body { margin: 8px 0; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.item.disabled { opacity: .55; }
.knowledge-sync-note { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; padding: 15px 17px; border: 1px solid #bfe5da; border-radius: 14px; color: #0d705e; background: linear-gradient(135deg, #edf9f5, #f8fcfb); }
.knowledge-sync-note > .ui-icon { width: 19px; height: 19px; flex: 0 0 19px; margin-top: 1px; }
.knowledge-sync-note div { display: flex; flex-direction: column; gap: 3px; }
.knowledge-sync-note b { font-size: 12px; }
.knowledge-sync-note span { color: #507269; font-size: 10px; line-height: 1.5; }
.smart-note { border-left: 4px solid #edae49; }
.smart-note.urgent { border-left-color: var(--danger); box-shadow: none; }
.smart-note.done { opacity: .7; border-left-color: #8a94a0; }
.note-category { display: inline-block; margin-bottom: 5px; color: #8a5d17; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.note-person { font-size: 16px; font-weight: 750; }
.note-phone { display: inline-block; margin-top: 3px; color: var(--primary); font-size: 12px; text-decoration: none; }
.note-phone:hover { text-decoration: underline; }
.note-content { padding: 11px 13px; border-radius: 10px; background: #fff9ec; }
.note-urgent-banner { margin: 11px 0 8px; padding: 9px 11px; border-radius: 9px; color: #9b3131; background: #fff0f0; font-size: 11px; font-weight: 750; }
.smart-note.urgent .note-content { background: #fff6f6; }
.smart-note.done .note-content { background: #f4f5f6; }

/* API usage and cost report */
.usage-report-brand { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.usage-report-brand img { width: 150px; height: auto; padding: 9px 12px; border-radius: 10px; background: var(--sidebar); }
.usage-report-brand > div { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; color: var(--muted); font-size: 11px; }
.usage-report-brand b { color: var(--text); font-size: 13px; }
.usage-heading { align-items: center; }
.report-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.usage-controls { display: grid; grid-template-columns: minmax(150px, 220px) minmax(150px, 220px) auto auto; align-items: end; gap: 12px; }
.usage-controls label { margin: 0; }
.usage-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.usage-kpi { position: relative; overflow: hidden; min-height: 134px; margin: 0; }
.usage-kpi::after { content: none; }
.usage-kpi > span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.usage-kpi strong { position: relative; z-index: 1; display: block; margin: 13px 0 7px; color: #17202e; font-size: clamp(22px, 2.1vw, 30px); line-height: 1; letter-spacing: -.04em; }
.usage-kpi small { position: relative; z-index: 1; color: #8591a2; font-size: 10px; }
.usage-kpi.accent { color: #fff; background: var(--primary); border-color: var(--primary); }
.usage-kpi.accent > span, .usage-kpi.accent strong, .usage-kpi.accent small { color: #fff; }
.usage-kpi.accent small { opacity: .72; }
.usage-kpi.accent::after { content: none; }
.budget-card { margin-top: 14px; }
.budget-summary { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.budget-summary h3 { margin: 5px 0 4px; font-size: 17px; }
.budget-summary p { margin: 0; }
#usage-budget-percent { color: var(--primary); font-size: 25px; letter-spacing: -.04em; }
.budget-track { height: 10px; margin: 16px 0 13px; overflow: hidden; border-radius: 999px; background: #edf1f4; }
.budget-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--primary); transition: width .35s ease; }
.budget-track span.warn { background: var(--warning); }
.budget-track span.danger { background: var(--danger); }
.budget-settings { margin-top: 4px; }
.budget-settings summary { display: inline-block; color: var(--primary); cursor: pointer; font-size: 11px; font-weight: 700; }
.budget-form { max-width: 780px; margin-top: 15px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.usage-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .75fr); gap: 14px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.section-title h3 { margin: 0 0 4px; font-size: 15px; }
.section-title p { margin: 0; color: var(--muted); font-size: 10px; }
.usage-chart { display: flex; align-items: flex-end; gap: 9px; min-height: 195px; padding: 18px 4px 0; overflow-x: auto; border-bottom: 1px solid var(--border); }
.chart-column { display: flex; flex: 1 0 42px; flex-direction: column; align-items: center; justify-content: flex-end; height: 175px; }
.chart-value { margin-bottom: 5px; color: #718095; font-size: 8px; white-space: nowrap; }
.chart-bar { width: min(28px, 70%); min-height: 3px; border-radius: 7px 7px 2px 2px; background: var(--primary); }
.chart-label { margin-top: 7px; color: #7d8999; font-size: 8px; white-space: nowrap; }
.purpose-list { display: flex; flex-direction: column; gap: 12px; }
.purpose-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; align-items: center; padding-bottom: 10px; border-bottom: 1px solid #eef1f4; }
.purpose-row:last-child { border: 0; }
.purpose-row b { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.purpose-row strong { color: var(--primary); font-size: 11px; }
.purpose-row small { grid-column: 1 / -1; color: var(--muted); font-size: 9px; }
.usage-table-card { overflow: hidden; }
.table-scroll { width: 100%; overflow-x: auto; }
.usage-table-card table { width: 100%; border-collapse: collapse; font-size: 11px; }
.usage-table-card th { padding: 9px 10px; border-bottom: 1px solid var(--border); color: #7b8798; background: #f8fafb; font-size: 9px; letter-spacing: .04em; text-align: right; text-transform: uppercase; white-space: nowrap; }
.usage-table-card td { padding: 10px; border-bottom: 1px solid #edf0f2; color: #475467; text-align: right; white-space: nowrap; }
.usage-table-card th:first-child, .usage-table-card td:first-child { text-align: left; }
.usage-table-card tbody tr:last-child td { border-bottom: 0; }
.usage-table-card tbody tr:hover td { background: #fbfcfd; }
.usage-report-footer { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 3px 4px 18px; color: var(--muted); font-size: 9px; line-height: 1.5; }
.usage-report-footer span:last-child { max-width: 600px; text-align: right; }

/* authentication */
#login-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 22px; overflow-y: auto; background: var(--sidebar); }
#login-overlay::before { content: none; }
#login-overlay .card { position: relative; width: min(430px, 100%); margin: 0; padding: 36px; border: 1px solid #263247; box-shadow: none; text-align: left; }
.auth-logo { display: block; width: 190px; max-width: 64%; height: auto; margin: 0 auto 28px; }
#login-overlay h2 { margin: 0 0 8px; color: #14202f; font-size: 23px; letter-spacing: -.025em; text-align: center; }
#login-overlay p { color: var(--muted); font-size: 13px; line-height: 1.5; text-align: center; }
#login-overlay input { margin: 0 0 11px; }
#login-overlay button[type=submit] { width: 100%; margin-top: 3px; }

/* toasts */
.toast-region { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 40px)); pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: 9px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; color: #2e3b4d; background: rgba(255,255,255,.97); box-shadow: var(--shadow); font-size: 12px; line-height: 1.45; animation: toast-in .22s ease both; }
.toast .ui-icon { width: 16px; height: 16px; flex: 0 0 16px; margin-top: 1px; }
.toast.error { border-color: #f2c2c2; color: #9f3030; }
.toast.success { border-color: #bfe7d8; color: #087454; }
.tenant-switcher { display: flex; align-items: center; gap: 7px; color: #c9d6e5; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.tenant-switcher select { min-width: 170px; padding: 8px 30px 8px 10px; border-color: rgba(255,255,255,.2); color: #fff; background-color: rgba(255,255,255,.1); font-size: 12px; text-transform: none; letter-spacing: 0; }
.tenant-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 18px; }
.tenant-card { margin: 0; }
.tenant-card.disabled { opacity: .7; }
.tenant-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 18px 0; }
.tenant-metrics span { padding: 10px; border-radius: 10px; color: var(--muted); background: var(--surface-soft); font-size: 11px; }
.tenant-metrics b { display: block; margin-bottom: 2px; color: var(--text); font-size: 15px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

@media (max-width: 1020px) {
  body { display: block; padding-top: 72px; }
  .app-header { position: fixed; height: 72px; inset: 0 0 auto; }
  nav#tabs { position: sticky; top: 0; z-index: 30; flex-direction: row; width: 100%; height: auto; padding: 9px 14px; overflow-x: auto; overflow-y: hidden; background: #fff; border-bottom: 1px solid var(--border); scrollbar-width: none; }
  nav#tabs::-webkit-scrollbar { display: none; }
  .nav-section { display: none; }
  nav#tabs button { width: auto; min-width: max-content; min-height: 38px; padding: 8px 11px; color: #637083; }
  nav#tabs button:hover { color: var(--primary); background: var(--primary-soft); transform: none; }
  nav#tabs button.active { color: var(--primary); background: var(--primary-soft); box-shadow: none; }
  nav#tabs button.active::after { content: ""; position: absolute; right: 12px; bottom: -9px; left: 12px; height: 2px; border-radius: 2px; background: var(--primary); }
  .nav-icon { color: inherit; }
  main { padding-top: 24px; }
  .chat-layout { min-height: 0; }
  #chat-panel { max-height: none; }
}

@media (min-width: 781px) and (max-width: 1020px) {
  body:has(#tab-chats.active) main, body:has(#tab-internal.active) main { height: calc(100dvh - 128px); }
}

@media (max-width: 780px) {
  main { padding: 22px 16px 60px; }
  .page-heading { margin-bottom: 17px; }
  .page-heading h2 { font-size: 25px; }
  .chat-layout, .calendar-layout, .customers-layout, .connection-layout { grid-template-columns: 1fr; }
  .chat-layout { height: auto; min-height: auto; overflow: visible; }
  .contacts-panel { max-height: 280px; }
  #contact-list { min-height: 110px; }
  #chat-panel { min-height: 540px; max-height: 70vh; }
  #internal-chat-panel { min-height: 500px; max-height: 70vh; }
  #chat-header { align-items: flex-start; flex-direction: column; }
  .chat-header-actions { width: 100%; flex-wrap: wrap; justify-content: flex-start; }
  .chat-header-actions select { flex: 1; max-width: none; }
  .calendar-toolbar { grid-template-columns: 1fr; }
  .calendar-toolbar h3 { order: -1; }
  .calendar-legend { justify-self: start; }
  .calendar-day { min-height: 74px; padding: 4px; }
  .customer-form-card { position: static; }
  .day-event { padding: 2px 3px; font-size: 8px; }
  .weekly-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-form { grid-template-columns: 1fr; }
  .notes-toolbar { align-items: stretch; flex-direction: column; }
  .usage-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .usage-grid { grid-template-columns: 1fr; }
  .usage-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .budget-form { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  body { padding-top: 64px; }
  .app-header { height: 64px; padding: 0 12px; }
  .brand-logo { width: 105px; }
  .brand-divider, .brand p, .current-user, .tenant-switcher { display: none; }
  .badge { padding: 6px 8px; font-size: 9px; }
  .header-actions { gap: 6px; }
  nav#tabs { padding: 8px 10px; }
  nav#tabs button { padding: 7px 9px; font-size: 11px; }
  .nav-icon { width: 16px; height: 16px; flex-basis: 16px; }
  .card { padding: 16px; border-radius: 14px; }
  .connection-hero { min-height: 330px; }
  .calendar-main { padding: 11px; }
  .calendar-day { min-height: 60px; }
  .calendar-day .day-event:nth-of-type(n+3) { display: none; }
  .day-number { width: 21px; height: 21px; }
  #chat-send-form { grid-template-columns: 1fr; }
  #chat-send-form > #btn-toggle-pause { width: 100%; }
  .chat-composer { flex-wrap: wrap; }
  .chat-composer #chat-input { order: -1; flex-basis: 100%; }
  .chat-composer .composer-icon { flex: 0 0 40px; }
  .chat-composer .chat-send-button { flex: 1; }
  .emoji-picker { left: 0; grid-template-columns: repeat(8, minmax(30px, 1fr)); width: 100%; }
  .msg { max-width: 86%; }
  .msg-audio, .msg-document { min-width: min(270px, 72vw); }
  .customers-heading { align-items: stretch; flex-direction: column; }
  .customers-heading button { width: 100%; }
  .customers-toolbar { align-items: stretch; flex-direction: column; }
  .customer-row { grid-template-columns: 20px 38px minmax(0, 1fr); }
  .customer-row .actions { grid-column: 1 / -1; }
  .context-menu { right: 12px !important; bottom: 14px; left: 12px !important; top: auto !important; width: auto; transform-origin: bottom center; }
  .selection-toolbar { align-items: stretch; flex-direction: column; }
  .selection-toolbar > div { justify-content: stretch; }
  .selection-toolbar button { flex: 1; }
  .secret-input { align-items: stretch; flex-direction: column; }
  .secret-input button { margin-top: 0; }
  #login-overlay .card { padding: 27px 22px; }
  .usage-report-brand { align-items: flex-start; flex-direction: column; }
  .usage-report-brand > div { align-items: flex-start; }
  .usage-heading { align-items: stretch; flex-direction: column; }
  .report-actions { justify-content: stretch; }
  .report-actions button { flex: 1; }
  .usage-controls, .usage-kpis { grid-template-columns: 1fr; }
  .budget-summary { align-items: flex-start; }
  .usage-report-footer { flex-direction: column; }
  .usage-report-footer span:last-child { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { display: block; padding: 0; color: #17202e; background: #fff; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .app-header, nav#tabs, .no-print, .toast-region { display: none !important; }
  main { display: block; max-width: none; margin: 0; padding: 0; }
  .tab { display: none !important; }
  #tab-usage { display: block !important; }
  .usage-report-brand { margin-bottom: 14px; }
  .page-heading { margin-bottom: 14px; }
  .page-heading h2 { font-size: 24px; }
  .card, .item { break-inside: avoid; box-shadow: none; }
  .usage-kpis { grid-template-columns: repeat(4, 1fr); }
  .usage-grid { grid-template-columns: 1.55fr .75fr; }
  .usage-table-card table { font-size: 9px; }
  .usage-table-card th, .usage-table-card td { padding: 6px; }
  .usage-report-footer { break-inside: avoid; }
}
