:root {
  --bg: #0B1220;
  --panel: #101C2B;
  --panel-2: #14263A;
  --accent: #2DD4BF;
  --accent-soft: #99F6E4;
  --warm: #F4B860;
  --soft: #ECFDF5;
  --text: #FFFFFF;
  --muted: #B8C7D9;
  --ink: #07131F;
  --line: rgba(255, 255, 255, 0.14);
  --danger: #ff7a7a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
  white-space: nowrap;
}
.material-symbols-rounded {
  font-size: 20px;
  line-height: 1;
  flex: 0 0 auto;
}
.secondary-btn {
  border: 1px solid rgba(37,214,155,0.32);
  background: rgba(37,214,155,0.12);
  color: var(--soft);
}
.danger-btn {
  border: 1px solid rgba(255,122,122,0.34);
  background: rgba(255,122,122,0.12);
  color: #ffd4d4;
}
.icon-btn {
  width: 42px;
  min-width: 42px;
  padding: 0;
}
.small-btn {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}
input, select, textarea {
  width: 100%;
  min-height: 42px;
  margin-top: 7px;
  padding: 10px 12px;
  border: 1px solid rgba(6, 33, 24, 0.14);
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
}
textarea { resize: vertical; }
label { color: var(--muted); font-size: 13px; font-weight: 900; }
.check-row { display: flex; align-items: center; gap: 10px; }
.check-row input { width: auto; min-height: auto; margin: 0; }
h1, h2, p { margin-top: 0; }
h2 { font-size: 20px; }
.hidden { display: none !important; }
.muted { color: var(--muted); line-height: 1.55; }
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--bg), #111827);
}
.login-card, .panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.035)), var(--panel);
  box-shadow: 0 24px 70px rgba(0,0,0,0.28);
}
.login-card { width: min(460px, 100%); padding: 32px; }
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 48px; height: 48px; }
.brand-word { font-size: 24px; font-weight: 900; }
.brand-word span { color: var(--accent); font-style: italic; }
.stack { display: grid; gap: 14px; }
.compact-form {
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 264px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #080F1A;
}
nav { display: grid; gap: 8px; }
.nav-btn, .ghost-btn {
  width: 100%;
  justify-content: flex-start;
  padding: 0 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
}
.nav-btn { min-height: 46px; }
.nav-btn.active, .nav-btn:hover {
  border-color: rgba(37,214,155,0.24);
  background: rgba(37,214,155,0.12);
  color: var(--text);
}
.nav-btn.active .material-symbols-rounded { color: var(--accent-soft); }
.ghost-btn { margin-top: auto; border-color: var(--line); }
.content {
  min-width: 0;
  max-width: 1680px;
  width: 100%;
  padding: 28px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 22px;
}
.topbar h1 { margin-bottom: 6px; font-size: 38px; line-height: 1.08; letter-spacing: 0; }
.topbar p { color: var(--muted); margin-bottom: 0; }
.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.scope-control {
  width: min(280px, 100%);
  text-align: left;
}
.scope-control select { margin-top: 0; }
.user-pill, .status-badge {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 900;
  text-transform: capitalize;
}
.status-badge.active, .status-badge.online, .status-badge.open { color: var(--accent-soft); border-color: rgba(45,212,191,0.35); }
.status-badge.pending, .status-badge.snoozed { color: var(--warm); border-color: rgba(244,184,96,0.45); }
.status-badge.disabled, .status-badge.blocked, .status-badge.resolved { color: var(--muted); }
.notice {
  padding: 12px 14px;
  border: 1px solid rgba(37,214,155,0.25);
  border-radius: 8px;
  background: rgba(37,214,155,0.1);
  color: var(--soft);
  margin-bottom: 16px;
}
.notice.error { border-color: rgba(255,122,122,0.4); background: rgba(255,122,122,0.1); color: var(--danger); }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat, .panel { padding: 18px; }
.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}
.stat span { color: var(--muted); font-weight: 900; }
.stat strong { display: block; margin-top: 8px; font-size: 34px; }
.analytics-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.analytics-filter-panel { margin-bottom: 16px; }
.analytics-filters { margin-bottom: 0; }
.two-col { display: grid; grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.conversation-workspace {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 16px;
  min-height: calc(100vh - 142px);
}
.conversation-sidebar-panel,
.conversation-thread-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.conversation-sidebar-panel { padding-bottom: 10px; }
.panel-head,
.thread-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2,
.thread-head h2 { margin: 0; }
.counter-pill,
.last-message-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid rgba(45,212,191,0.28);
  border-radius: 8px;
  color: var(--accent-soft);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.last-message-pill {
  color: var(--warm);
  border-color: rgba(244,184,96,0.38);
}
.thread-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}
.start-thread-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.start-thread-form button { grid-column: 1 / -1; }
.thread-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 0.55fr);
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.thread-controls .inline-form { margin-bottom: 0; }
.agent-layout {
  display: grid;
  grid-template-columns: minmax(420px, 0.85fr) minmax(520px, 1.65fr);
  gap: 20px;
  align-items: start;
  margin-bottom: 20px;
}
.narrow { max-width: 680px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--accent-soft); font-size: 12px; text-transform: uppercase; }
td { color: var(--soft); }
.cell-actions, .inline-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.inline-actions { justify-content: flex-start; }
.list, .conversation-list, .messages { display: grid; gap: 10px; }
.conversation-list {
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}
.list-item, .conversation-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  cursor: pointer;
}
.action-needed-item {
  border-color: rgba(244,184,96,0.28);
}
.action-needed-item:hover {
  border-color: rgba(244,184,96,0.62);
  background: rgba(244,184,96,0.09);
}
.list-item strong, .conversation-item strong { display: block; margin-bottom: 4px; }
.conversation-item {
  display: grid;
  gap: 7px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.conversation-item:hover { border-color: rgba(45,212,191,0.42); }
.conversation-item.active {
  border-color: var(--accent);
  background: rgba(45,212,191,0.12);
}
.conversation-top, .conversation-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.conversation-meta {
  justify-content: flex-start;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}
.conversation-preview {
  color: var(--soft);
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.list-pagination,
.thread-history-actions {
  display: flex;
  justify-content: center;
  padding: 6px 0;
}
.list-pagination button,
.thread-history-actions button {
  width: 100%;
  border-color: rgba(153,246,228,0.28);
}
.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--warm);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}
.messages {
  align-content: start;
  flex: 1;
  min-height: 260px;
  max-height: none;
  overflow-y: auto;
  padding: 18px 4px 18px 0;
}
.empty-thread {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed rgba(255,255,255,0.18);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}
.message {
  width: fit-content;
  max-width: min(680px, 78%);
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  background: rgba(236,253,245,0.95);
  color: var(--ink);
  line-height: 1.4;
}
.message.outgoing {
  justify-self: end;
  margin-left: auto;
  background: var(--accent);
}
.message small { display: block; margin-top: 6px; opacity: 0.7; }
.delivery-mark {
  display: inline-block;
  min-width: 22px;
  margin-left: 6px;
  color: var(--ink);
  font-weight: 900;
}
.readonly-grid {
  display: grid;
  gap: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.035);
}
.readonly-grid span { color: var(--muted); }
.readonly-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.75fr) minmax(0, 1.25fr);
  gap: 16px;
  align-items: start;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.readonly-row:first-child { padding-top: 0; }
.readonly-row:last-child { padding-bottom: 0; border-bottom: 0; }
.readonly-row strong {
  color: var(--soft);
  overflow-wrap: anywhere;
  line-height: 1.3;
}
.token-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}
.token-box input {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0;
}
.inline-form {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}
.filters-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.wide-field { grid-column: 1 / -1; }
.reply-composer {
  display: grid;
  gap: 12px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.reply-template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(3, 7, 18, 0.74);
}
.modal-card {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0,0,0,0.42);
  padding: 18px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.modal-head h2 { margin: 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
@media (max-width: 920px) {
  .app-shell, .two-col, .conversation-workspace, .agent-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .stats-grid, .analytics-stats { grid-template-columns: 1fr 1fr; }
  .topbar { flex-direction: column; }
  .topbar h1 { font-size: 32px; }
  .inline-form, .filters-grid, .token-box, .readonly-row, .reply-template-row, .start-thread-form, .thread-controls { grid-template-columns: 1fr; }
  .modal-actions { flex-direction: column-reverse; }
  .message { max-width: 92%; }
}
