:root {
  color-scheme: dark;
  --bg: #08101c;
  --panel: #0d1726;
  --panel-2: #111e30;
  --panel-3: #16243a;
  --line: #23334a;
  --line-soft: #1a2a40;
  --text: #edf4ff;
  --muted: #8fa1b8;
  --muted-2: #6f829c;
  --accent: #37c6f4;
  --accent-strong: #0ea5d9;
  --accent-soft: rgba(55, 198, 244, 0.12);
  --success: #55d69e;
  --warning: #f5c45a;
  --danger: #ff707b;
  --note: #bda4ff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.3);
  --radius: 14px;
  --radius-sm: 9px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100vh; overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(circle at 18% 20%, rgba(55, 198, 244, 0.14), transparent 28%),
    radial-gradient(circle at 80% 70%, rgba(80, 110, 255, 0.10), transparent 28%),
    linear-gradient(145deg, #07101b, #0a1422 55%, #07101b);
}

.login-card {
  width: min(470px, 100%);
  border: 1px solid var(--line);
  background: rgba(13, 23, 38, 0.94);
  border-radius: 22px;
  padding: 34px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand-lockup { display: flex; align-items: center; gap: 11px; min-width: 190px; }
.brand-lockup--login { margin-bottom: 42px; }
.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 22px;
  color: #06111b;
  background: linear-gradient(145deg, #8be4ff, #34bfe9);
  box-shadow: 0 8px 25px rgba(55, 198, 244, 0.22);
}
.brand-mark--small { width: 36px; height: 36px; border-radius: 10px; font-size: 17px; }
.brand-name { font-weight: 720; letter-spacing: -0.02em; font-size: 19px; }
.brand-name--small { font-size: 16px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 10px; font-weight: 750; color: var(--muted); }

.login-copy h1 { font-size: 34px; line-height: 1.08; letter-spacing: -0.04em; margin: 18px 0 12px; }
.login-copy p { color: var(--muted); line-height: 1.55; margin: 0 0 28px; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 7px; color: #c9d5e5; font-size: 13px; font-weight: 650; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  color: var(--text);
  background: #091423;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}
input { height: 44px; padding: 0 13px; }
textarea { resize: none; padding: 12px 13px; line-height: 1.45; }
select { height: 38px; padding: 0 32px 0 10px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: #60738d; }
.form-error { color: #ff9aa2; font-size: 13px; margin: 0; }
.login-footnote { text-align: center; color: var(--muted-2); font-size: 11px; margin: 25px 0 0; }

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  min-height: 38px;
  padding: 0 13px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  background: var(--panel-3);
  transition: transform 120ms ease, filter 120ms ease, background 120ms ease, border-color 120ms ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: 0.42; }
.btn--primary { background: linear-gradient(135deg, var(--accent-strong), #2dc7ef); color: #06131c; }
.btn--secondary { border-color: var(--line); background: #122036; }
.btn--ghost { background: transparent; border-color: var(--line-soft); color: var(--muted); }
.btn--danger-ghost { background: rgba(255, 112, 123, 0.06); border-color: rgba(255, 112, 123, 0.25); color: #ff9ca4; }
.btn--wide { width: 100%; height: 46px; margin-top: 3px; }
.btn--compact { min-height: 33px; padding: 0 10px; }
.btn--send { align-self: stretch; min-width: 92px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #14233a;
  color: #aebed1;
  border: 1px solid var(--line);
  font-size: 10px;
  font-weight: 700;
}
.pill--live { color: #b9f3d8; border-color: rgba(85, 214, 158, 0.22); background: rgba(85, 214, 158, 0.08); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgba(85, 214, 158, 0.08); }

.app-shell { height: 100vh; display: grid; grid-template-rows: 60px 1fr; }
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-width: 0;
  padding: 0 18px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(8, 16, 28, 0.95);
}
.topbar-center { justify-self: center; }
.connection-state { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.connection-state.is-offline .live-dot { background: var(--danger); box-shadow: none; }
.operator-menu { justify-self: end; display: flex; align-items: center; gap: 9px; }
.operator-avatar, .contact-avatar {
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: #172945;
  color: #9adff5;
  border: 1px solid #25415d;
}
.operator-avatar { width: 34px; height: 34px; font-size: 10px; }
.operator-copy { display: grid; line-height: 1.2; min-width: 110px; }
.operator-copy strong { font-size: 12px; }
.operator-copy span { color: var(--muted); font-size: 10px; text-transform: capitalize; }

.workspace { min-height: 0; display: grid; grid-template-columns: 220px 350px minmax(0, 1fr); }
.team-sidebar, .queue-pane, .conversation-pane { min-height: 0; background: var(--panel); }
.team-sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--line-soft); padding: 16px 12px; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; padding: 2px 7px 12px; text-transform: uppercase; letter-spacing: 0.08em; font-size: 10px; font-weight: 750; color: var(--muted); }
.count-badge { min-width: 24px; height: 22px; padding: 0 6px; border-radius: 8px; display: inline-grid; place-items: center; background: #17253b; border: 1px solid var(--line); color: #bdd0e6; font-size: 10px; font-weight: 800; }
.count-badge--large { min-width: 31px; height: 28px; border-radius: 9px; font-size: 11px; }
.team-list { display: grid; gap: 4px; }
.team-item {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: 27px 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #b8c7da;
  padding: 0 8px;
  text-align: left;
}
.team-item:hover { background: rgba(255,255,255,0.025); }
.team-item.is-active { color: var(--text); background: var(--accent-soft); border-color: rgba(55,198,244,0.16); }
.team-icon { width: 25px; height: 25px; border-radius: 8px; display: grid; place-items: center; background: #142238; color: #88a5c3; font-size: 10px; font-weight: 800; }
.team-item.is-active .team-icon { background: rgba(55,198,244,0.16); color: #80ddf9; }
.team-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 630; }
.team-count { color: var(--muted); font-size: 10px; }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--line-soft); padding: 14px 7px 3px; display: grid; gap: 9px; }
.sidebar-stat { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.sidebar-stat strong { color: #c9d8e8; }

.queue-pane { border-right: 1px solid var(--line-soft); display: grid; grid-template-rows: auto auto auto 1fr; }
.queue-toolbar { display: flex; justify-content: space-between; align-items: end; gap: 10px; padding: 18px 16px 12px; }
.queue-toolbar h2 { font-size: 17px; margin: 3px 0 0; letter-spacing: -0.02em; }
.search-wrap { position: relative; margin: 0 14px 11px; }
.search-wrap input { height: 37px; padding-left: 34px; background: #0a1524; font-size: 11px; }
.search-icon { position: absolute; left: 11px; top: 7px; color: var(--muted-2); font-size: 17px; z-index: 1; }
.status-tabs { display: flex; gap: 4px; padding: 0 14px 10px; border-bottom: 1px solid var(--line-soft); }
.status-tab, .composer-tab { border: 0; background: transparent; color: var(--muted); font-weight: 700; font-size: 10px; border-radius: 7px; }
.status-tab { min-height: 29px; padding: 0 10px; }
.status-tab:hover, .status-tab.is-active { color: var(--text); background: #16243a; }
.conversation-list { min-height: 0; overflow-y: auto; }
.conversation-item {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: inherit;
  padding: 13px 14px;
  text-align: left;
  display: grid;
  gap: 7px;
}
.conversation-item:hover { background: rgba(255,255,255,0.02); }
.conversation-item.is-active { background: linear-gradient(90deg, rgba(55,198,244,0.11), rgba(55,198,244,0.035)); box-shadow: inset 2px 0 0 var(--accent); }
.item-top, .item-bottom { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.item-contact { font-size: 12px; font-weight: 750; color: #dce8f6; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.item-time { font-size: 9px; color: var(--muted-2); white-space: nowrap; }
.item-preview { font-size: 11px; color: var(--muted); line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-team { font-size: 9px; color: #7f94ae; }
.item-status { font-size: 9px; font-weight: 750; color: #9bb2c9; }
.list-empty { padding: 42px 22px; text-align: center; color: var(--muted); font-size: 11px; line-height: 1.55; }

.conversation-pane { background: #091321; position: relative; min-width: 0; }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; padding: 30px; }
.empty-icon { width: 54px; height: 54px; border-radius: 17px; display: grid; place-items: center; background: #112037; border: 1px solid var(--line); color: var(--accent); font-size: 23px; }
.empty-state h2 { font-size: 17px; margin: 16px 0 7px; }
.empty-state p { color: var(--muted); max-width: 330px; margin: 0; line-height: 1.55; font-size: 11px; }
.conversation-content { height: 100%; display: grid; grid-template-rows: auto auto 1fr auto; min-width: 0; }
.conversation-header { min-height: 72px; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 18px; border-bottom: 1px solid var(--line-soft); background: #0c1726; }
.contact-identity { display: flex; align-items: center; gap: 11px; min-width: 0; }
.contact-avatar { width: 39px; height: 39px; font-size: 10px; flex: 0 0 auto; }
.contact-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.contact-line h2 { margin: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-id { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.conversation-meta { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: end; }
.status-chip, .owner-chip { display: inline-flex; align-items: center; min-height: 25px; border-radius: 8px; padding: 0 8px; font-size: 9px; font-weight: 750; border: 1px solid var(--line); color: #b7c7d9; background: #132239; }
.status-chip[data-status="assigned"] { color: #9fe5fa; border-color: rgba(55,198,244,0.25); }
.status-chip[data-status="waiting_customer"] { color: #ffe09a; border-color: rgba(245,196,90,0.25); }
.status-chip[data-status="closed"] { color: #9aa9ba; background: #101b2a; }

.action-strip { min-height: 50px; display: flex; align-items: center; gap: 8px; padding: 7px 18px; border-bottom: 1px solid var(--line-soft); background: #0a1524; }
.transfer-control { display: flex; gap: 6px; align-items: center; }
.transfer-control select { width: 145px; }
.action-strip #close-button, .action-strip #reopen-button { margin-left: auto; }

.message-timeline { min-height: 0; overflow-y: auto; padding: 22px max(18px, 4vw); display: flex; flex-direction: column; gap: 10px; }
.message-row { display: flex; flex-direction: column; max-width: min(72%, 680px); }
.message-row--inbound { align-self: flex-start; align-items: flex-start; }
.message-row--outbound { align-self: flex-end; align-items: flex-end; }
.message-row--internal { align-self: center; width: min(82%, 760px); max-width: 760px; align-items: stretch; }
.message-bubble { border-radius: 13px; padding: 10px 12px; font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid var(--line-soft); box-shadow: 0 5px 18px rgba(0,0,0,0.08); }
.message-row--inbound .message-bubble { background: #122036; border-top-left-radius: 5px; }
.message-row--outbound .message-bubble { background: #0d4c63; border-color: #14677f; border-top-right-radius: 5px; color: #e8fbff; }
.message-row--internal .message-bubble { background: rgba(189,164,255,0.08); border-color: rgba(189,164,255,0.2); color: #d8cbff; border-radius: 9px; }
.message-meta { margin-top: 4px; color: var(--muted-2); font-size: 8px; }
.timeline-day { align-self: center; color: var(--muted-2); font-size: 9px; background: #0f1a2a; border: 1px solid var(--line-soft); border-radius: 999px; padding: 4px 8px; margin: 5px 0; }

.composer { border-top: 1px solid var(--line-soft); background: #0c1726; padding: 10px 16px 11px; }
.composer-tabs { display: flex; align-items: center; gap: 5px; margin-bottom: 7px; }
.composer-tab { min-height: 27px; padding: 0 9px; }
.composer-tab.is-active { color: var(--text); background: #192940; }
#note-mode.is-active { color: #d7c9ff; background: rgba(189,164,255,0.11); }
.composer-context { margin-left: auto; font-size: 9px; color: var(--muted); }
.composer-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }
.composer-row textarea { min-height: 58px; max-height: 140px; }
.composer.is-note textarea { border-color: rgba(189,164,255,0.28); background: rgba(189,164,255,0.05); }
.composer-footer { display: flex; justify-content: space-between; gap: 10px; color: var(--muted-2); font-size: 8px; padding-top: 6px; }
kbd { background: #16243a; border: 1px solid var(--line); border-radius: 4px; padding: 1px 3px; font: inherit; }

.toast-container { position: fixed; z-index: 100; right: 18px; bottom: 18px; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 250px; max-width: 390px; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--line); background: #142238; box-shadow: var(--shadow); font-size: 11px; color: #dbe8f7; animation: toast-in 180ms ease; }
.toast--error { border-color: rgba(255,112,123,0.3); color: #ffb4ba; }
.toast--success { border-color: rgba(85,214,158,0.3); color: #b9f3d8; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #243750; border-radius: 10px; }

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { min-height: 100vh; height: auto; }
  .workspace { grid-template-columns: 180px 310px minmax(430px, 1fr); min-height: calc(100vh - 60px); overflow-x: auto; }
  .operator-copy { display: none; }
}

@media (max-width: 680px) {
  .topbar { grid-template-columns: 1fr auto; }
  .topbar-center { display: none; }
  .workspace { display: block; overflow: visible; }
  .team-sidebar { display: none; }
  .queue-pane { height: calc(45vh - 30px); border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .conversation-pane { min-height: 55vh; }
  .conversation-content { min-height: 55vh; }
  .conversation-header { align-items: flex-start; flex-direction: column; }
  .conversation-meta { justify-content: flex-start; }
  .action-strip { flex-wrap: wrap; padding-block: 9px; }
  .action-strip #close-button, .action-strip #reopen-button { margin-left: 0; }
  .message-row { max-width: 88%; }
  .composer-footer { display: none; }
}
