:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-muted: #f3f5f9;
  --border: #d7dce5;
  --border-strong: #b7c0cf;
  --text: #172033;
  --muted: #647083;
  --accent: #0067c0;
  --accent-strong: #00549e;
  --accent-soft: #e9f3ff;
  --success: #16794c;
  --warning: #9a5b00;
  --danger: #b42318;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 1060px;
  background: var(--bg);
  color: var(--text);
}

.shell {
  height: 100vh;
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 12px;
}

.topbar, .source-tabs, .toolbar, .panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
}

.brand {
  display: grid;
  gap: 1px;
}
.eyebrow {
  color: var(--accent);
  font-size: 12px;
  line-height: 16px;
  font-weight: 700;
  text-transform: uppercase;
}

h1, h2, h3, h4, h5, h6, p { margin: 0; }
h1, h2, h3, h4, h5, h6 {
  color: var(--text);
  letter-spacing: 0;
}
h1 {
  font-size: 26px;
  line-height: 32px;
  font-weight: 700;
}
h2 {
  font-size: 17px;
  line-height: 22px;
  font-weight: 650;
}
h3 {
  font-size: 14px;
  line-height: 20px;
  font-weight: 650;
}
h4 {
  font-size: 13px;
  line-height: 18px;
  font-weight: 650;
}
h5, h6 {
  font-size: 12px;
  line-height: 16px;
  font-weight: 650;
}

.header-actions, .chat-actions, .modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

label { font-size: 12px; color: var(--muted); }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  font: inherit;
}
input { height: 34px; padding: 0 10px; }
select { height: 34px; padding: 0 10px; }
textarea { resize: vertical; padding: 9px 10px; min-height: 38px; }

button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled {
  background: #f7f8fb !important;
  border-color: var(--border) !important;
  color: #8b95a5 !important;
  opacity: 1;
  cursor: not-allowed;
}
button[type="submit"], #autoReply, #submitAddChat, #saveSourceSettings {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button[type="submit"]:hover:not(:disabled), #autoReply:hover:not(:disabled) {
  background: var(--accent-strong);
}
#toggleAutomation {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #7c2d12;
}
#toggleAutomation:hover:not(:disabled) { border-color: var(--warning); }

.source-tabs {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
}
.source-tab.active {
  background: var(--accent-soft);
  border-color: #9ac8f5;
  color: var(--accent-strong);
  font-weight: 650;
}

.toolbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px;
}
.search-input {
  width: 260px;
  height: 34px;
}

.status {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status.ok { color: var(--success); }
.status.warn { color: var(--warning); }
.status.error { color: var(--danger); }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(440px, 1fr) 360px;
  gap: 12px;
}
.workspace.tools-collapsed {
  grid-template-columns: 300px minmax(560px, 1fr) 72px;
}

.panel {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.panel-header {
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.timeline-header {
  align-items: flex-start;
}
.timeline-header p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.badge {
  min-width: 26px;
  height: 24px;
  border-radius: 999px;
  background: var(--panel-muted);
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  font-size: 12px;
}

.conversation-list, .timeline, .side-panel, .analysis-output, .context-output {
  min-height: 0;
  overflow: auto;
}
.conversation-list { padding: 8px; }
.conversation-item {
  width: 100%;
  min-height: 72px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  display: grid;
  gap: 4px;
  text-align: left;
}
.conversation-item.active {
  border-color: #9ac8f5;
  background: #eaf4ff;
}
.conversation-item strong {
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.conversation-item span { color: var(--muted); font-size: 12px; }
.unread-badge {
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff !important;
  display: inline-grid;
  place-items: center;
  font-size: 11px !important;
  font-weight: 700;
}
.channel-badge {
  min-width: 74px;
  height: 20px;
  padding: 0 7px;
  margin-right: 6px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 11px !important;
  font-weight: 700;
}
.channel-badge.whatsapp {
  background: #e8f5ee;
  color: #16794c !important;
}
.channel-badge.messenger {
  background: #eaf4ff;
  color: #00549e !important;
}
.channel-badge.instagram {
  background: #fff1f2;
  color: #be123c !important;
}
.conversation-item mark {
  width: fit-content;
  max-width: 100%;
  padding: 2px 5px;
  border-radius: 4px;
  background: #fff4ce;
  color: #5c3d00;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.timeline-panel { grid-template-rows: auto minmax(0, 1fr) auto; }
.timeline {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fbfcfe;
}
.message {
  max-width: 76%;
  padding: 10px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}
.message.outbound {
  align-self: flex-end;
  background: #e7f1ff;
  border-color: #bad8f8;
}
.message-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 5px;
}
.delivery-status {
  padding: 2px 6px;
  border-radius: 999px;
  background: #e8f5ee;
  color: var(--success);
  font-weight: 650;
}
.message-text { white-space: pre-wrap; font-size: 14px; line-height: 1.35; }
.composer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.side-panel {
  display: block;
  padding: 0;
}
.side-panel-header {
  min-height: 48px;
  padding: 10px 12px 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.side-panel-header button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}
.side-panel.collapsed {
  overflow: hidden;
}
.side-panel.collapsed .side-panel-header {
  height: 100%;
  min-height: 0;
  padding: 8px;
  border-bottom: 0;
  justify-content: center;
  align-items: flex-start;
}
.side-panel.collapsed .side-panel-header h2 {
  display: none;
}
.side-panel.collapsed .side-panel-header button {
  width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 18px;
}
.side-panel.collapsed .tool-section {
  display: none;
}
.tool-section {
  border-bottom: 1px solid var(--border);
}
.tool-section summary {
  min-height: 46px;
  padding: 13px 14px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 650;
}
.triage-form, .analysis-form, .assistant-form {
  padding: 0 14px 14px;
  display: grid;
  gap: 8px;
}
.triage-form button, .analysis-form button, .assistant-form button {
  width: fit-content;
}
.analysis-output {
  max-height: 260px;
  margin: 0 14px 14px;
  padding: 12px;
  border-radius: 7px;
  background: #101828;
  color: #e5e7eb;
  font: 12px/1.45 Consolas, "Cascadia Mono", monospace;
  white-space: pre-wrap;
}
.context-output {
  max-height: 280px;
  margin: 10px 14px 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fbfcfe;
  color: var(--text);
  font: 12px/1.45 Consolas, "Cascadia Mono", monospace;
  white-space: pre-wrap;
}
.file-meta, .form-note {
  color: var(--muted);
  font-size: 12px;
}

.modal {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.22);
}
.modal::backdrop {
  background: rgba(15, 23, 42, 0.28);
}
.modal-card {
  padding: 16px;
  display: grid;
  gap: 10px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.icon-button {
  width: 32px;
  min-height: 32px;
  padding: 0;
}
.dynamic-fields {
  display: grid;
  gap: 10px;
}
.modal-actions {
  justify-content: flex-end;
  padding-top: 4px;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
}
.checkbox-row input {
  width: 16px;
  height: 16px;
}

.empty {
  color: var(--muted);
  padding: 18px;
  font-size: 13px;
}
