:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #181b20;
  --panel-2: #20242b;
  --panel-3: #13161a;
  --text: #f1f3f5;
  --muted: #a9b0ba;
  --line: #303641;
  --green: #3ddc97;
  --red: #ff6b6b;
  --yellow: #ffd166;
  --blue: #7cc7ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 720;
}

h2 {
  font-size: 15px;
  font-weight: 680;
}

p {
  color: var(--muted);
  margin-top: 4px;
}

button,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

button {
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.primary {
  background: var(--blue);
  color: #071018;
  border-color: var(--blue);
  font-weight: 700;
}

.actions,
.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.login-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.login-form input {
  width: 128px;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  width: fit-content;
}

.tab {
  min-height: 34px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--line);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 480px);
  gap: 16px;
  align-items: start;
}

.utility-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.panel + .panel {
  margin-top: 16px;
}

.workspace .panel + .panel,
.utility-grid .panel + .panel {
  margin-top: 0;
}

.caption {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.search-panel {
  margin-bottom: 16px;
}

.search-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.2fr) 120px;
  gap: 12px;
  margin-top: 14px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.service {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.service strong {
  display: block;
  margin-bottom: 6px;
}

.service span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.ok {
  color: var(--green);
}

.bad {
  color: var(--red);
}

.warn {
  color: var(--yellow);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
}

select {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

textarea {
  width: 100%;
  min-height: 86px;
  padding: 10px;
  resize: vertical;
}

.lead-table {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  max-height: 620px;
  overflow: auto;
}

.crm-filters,
.crm-editor {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(90px, 0.8fr) minmax(88px, 0.6fr);
  gap: 8px;
  margin-top: 12px;
}

.crm-editor {
  grid-template-columns: minmax(120px, 1fr) 86px minmax(90px, 1fr) minmax(140px, 1.4fr) auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-3);
}

.lead-table.empty,
.lead-detail.empty {
  color: var(--muted);
}

.lead-row {
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(88px, 0.55fr) minmax(86px, 0.5fr) minmax(138px, 0.75fr);
  gap: 10px;
  align-items: center;
  text-align: left;
}

.lead-row.active {
  border-color: var(--blue);
}

.lead-row span {
  overflow-wrap: anywhere;
}

.lead-row small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.lead-head {
  min-height: 32px;
  color: var(--muted);
  font-size: 12px;
  background: transparent;
}

.lead-detail {
  margin-top: 12px;
  display: grid;
  gap: 12px;
}

.detail-panel {
  position: sticky;
  top: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.detail-grid div,
.brief {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.detail-grid .takeover-on {
  border-color: var(--red);
}

.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.detail-grid strong,
.brief strong,
.brief p,
.brief li {
  overflow-wrap: anywhere;
}

.brief h3 {
  margin: 0 0 8px;
  font-size: 13px;
}

.brief p {
  margin: 6px 0 0;
  color: #dbe4ee;
}

.brief ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.decision-row {
  margin-top: 4px;
  justify-content: flex-end;
}

.inbound-box {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-3);
}

.conversation-item {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-3);
}

.conversation-item + .conversation-item {
  margin-top: 8px;
}

.conversation-item.outbound {
  border-color: #42566a;
}

.conversation-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.message-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.tool-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.knowledge-panel {
  grid-column: 1 / -1;
}

.dropzone {
  margin-top: 12px;
  min-height: 94px;
  display: grid;
  place-items: center;
  border: 1px dashed #536170;
  border-radius: 8px;
  background: var(--panel-3);
  text-align: center;
  cursor: pointer;
}

.dropzone.dragging {
  border-color: var(--blue);
  background: #16212b;
}

.dropzone input {
  width: min(320px, 100%);
  min-height: auto;
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: transparent;
}

.document-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.document-list.empty {
  color: var(--muted);
}

.document-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.document-item span {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.job-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.job-list.empty {
  color: var(--muted);
}

.job-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  background: var(--panel-2);
}

.job-item.done {
  border-left-color: var(--green);
}

.job-item.failed {
  border-left-color: var(--red);
}

.job-item.running {
  border-left-color: var(--yellow);
}

.job-item span,
.job-item small {
  color: var(--muted);
  font-size: 13px;
}

.result {
  margin-top: 12px;
  min-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  color: #dbe4ee;
}

.result.empty {
  color: var(--muted);
  font-family: inherit;
}

.log-panel {
  margin-bottom: 16px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.log {
  margin-top: 12px;
  height: 320px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-entry {
  padding: 9px 10px;
  border-left: 3px solid var(--yellow);
  background: var(--panel-2);
  border-radius: 4px;
  font-size: 13px;
}

.log-entry .meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

@media (max-width: 980px) {
  .topbar,
  .workspace,
  .utility-grid,
  .search-grid {
    display: block;
  }

  .tabs,
  .actions,
  .panel {
    margin-top: 12px;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }

  .lead-row {
    grid-template-columns: 1fr;
  }

  .crm-filters,
  .crm-editor {
    grid-template-columns: 1fr;
  }
}
