:root {
  --bg: #0b1020;
  --bg-soft: #101827;
  --surface: #151e2f;
  --surface-2: #1b2638;
  --surface-3: #223047;
  --line: #2a3850;
  --line-strong: #3b4d6b;
  --text: #edf3ff;
  --muted: #9ba8bd;
  --muted-2: #c4ccda;
  --primary: #5b5cf6;
  --primary-2: #7c7bff;
  --success: #11b981;
  --success-2: #34d399;
  --danger: #ef4444;
  --danger-2: #fb7185;
  --warn: #f59e0b;
  --ok: #22c55e;
  --focus: rgba(124, 123, 255, 0.38);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% -10%, rgba(91, 92, 246, 0.22), transparent 34rem),
    linear-gradient(180deg, #0b1020 0%, #101827 56%, #0b1020 100%);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus,
input:focus,
textarea:focus,
select:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  filter: saturate(0.7);
}

.btn,
button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 14px;
  font-weight: 700;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.btn:hover,
button:hover {
  transform: translateY(-1px);
  border-color: var(--primary-2);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
}

.btn.primary {
  border-color: rgba(124, 123, 255, 0.9);
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
}

.btn.success {
  border-color: rgba(17, 185, 129, 0.82);
  background: linear-gradient(135deg, #059669, var(--success-2));
  color: #06130f;
}

.btn.secondary {
  background: #202b41;
  color: var(--muted-2);
}

.btn.ghost {
  background: rgba(91, 92, 246, 0.1);
  border-color: rgba(124, 123, 255, 0.46);
  color: #dce2ff;
}

.btn.danger,
button.danger {
  border-color: rgba(239, 68, 68, 0.85);
  background: linear-gradient(135deg, #991b1b, var(--danger));
  color: #fff;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1726;
  color: var(--text);
  padding: 9px 11px;
}

select {
  min-height: 38px;
}

input::placeholder,
textarea::placeholder {
  color: #68758c;
}

textarea {
  min-height: 260px;
  resize: vertical;
  line-height: 1.58;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 86px;
  padding: 18px 28px;
  background: rgba(13, 20, 33, 0.92);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  box-shadow: 0 10px 26px rgba(91, 92, 246, 0.38);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
}

.topbar h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.auth {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 14px 28px 0;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 38, 0.88);
}

.tab {
  min-height: 42px;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.tab:hover {
  background: rgba(91, 92, 246, 0.12);
  box-shadow: none;
}

.tab.active {
  background: var(--surface);
  color: #fff;
  border-color: var(--line);
  border-bottom-color: var(--surface);
}

main {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 20px 28px 34px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--surface), #121b2b);
  padding: 15px 16px;
  box-shadow: var(--shadow);
}

.kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--primary-2), var(--success));
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi strong {
  display: block;
  margin-top: 7px;
  font-size: 25px;
  letter-spacing: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.split {
  display: grid;
  grid-template-columns: minmax(460px, 0.9fr) minmax(560px, 1.1fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 30, 47, 0.98);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 70px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(34, 48, 71, 0.58), rgba(21, 30, 47, 0));
}

.panel h2 {
  margin: 0;
  font-size: 18px;
}

.panel-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  max-height: 68vh;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #111a2a;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

td {
  color: var(--muted-2);
}

tr.selectable {
  cursor: pointer;
}

tr.selectable:hover {
  background: rgba(91, 92, 246, 0.1);
}

.confidence-low {
  color: var(--danger-2);
  font-weight: 800;
}

.confidence-mid {
  color: var(--warn);
  font-weight: 800;
}

.confidence-high {
  color: var(--ok);
  font-weight: 800;
}

.detail {
  min-height: 68vh;
}

.muted {
  color: var(--muted);
}

.thread-meta,
.message-list,
.draft-box,
.queue-list,
.kb-form {
  padding: 14px;
}

.thread-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.meta-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101827;
}

.meta-item span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  background: #0f1726;
}

.message-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #172235;
  border-bottom: 1px solid var(--line);
}

.message-body {
  white-space: pre-wrap;
  padding: 12px;
  max-height: 240px;
  overflow: auto;
  color: var(--muted-2);
}

.draft-box {
  border-top: 1px solid var(--line);
}

.draft-box label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 800;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.result {
  min-height: 20px;
  color: var(--success-2);
  font-weight: 700;
}

.queue-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101827;
  padding: 14px;
  margin-bottom: 12px;
}

.queue-item h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.queue-item p {
  margin: 7px 0;
  color: var(--muted-2);
  white-space: pre-wrap;
}

.kb-upload-panel {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 38, 0.52);
}

.kb-upload-panel h3 {
  margin: 0;
  font-size: 17px;
}

.kb-upload-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.file-type-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.file-type-list span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid rgba(124, 123, 255, 0.34);
  border-radius: 999px;
  padding: 4px 10px;
  background: rgba(91, 92, 246, 0.12);
  color: #dce2ff;
  font-size: 12px;
  font-weight: 800;
}

.dropzone {
  display: grid;
  min-height: 150px;
  place-items: center;
  gap: 6px;
  border: 1px dashed rgba(124, 123, 255, 0.68);
  border-radius: 8px;
  background: rgba(91, 92, 246, 0.08);
  color: var(--muted-2);
  padding: 20px;
  text-align: center;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.dropzone strong {
  color: var(--text);
  font-size: 16px;
}

.dropzone small {
  color: var(--muted);
}

.dropzone.dragover {
  border-color: var(--success-2);
  background: rgba(17, 185, 129, 0.14);
  transform: translateY(-1px);
}

.inline-tools {
  display: grid;
  grid-template-columns: minmax(180px, 280px) auto;
  gap: 10px;
}

.kb-form {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(260px, 1.2fr) auto;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.kb-form textarea {
  min-height: 78px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  padding: 14px;
}

.status-card {
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101827;
  padding: 14px;
}

.status-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-card strong {
  display: block;
  color: var(--text);
  font-size: 18px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.status-card small {
  display: block;
  margin-top: 12px;
  color: var(--muted-2);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  font-size: 12px;
  font-weight: 800;
}

.status-pill.ok {
  color: #064e3b;
  background: #a7f3d0;
}

.status-pill.warn {
  color: #78350f;
  background: #fde68a;
}

.status-pill.bad {
  color: #7f1d1d;
  background: #fecaca;
}

@media (max-width: 1180px) {
  .kpi-row {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

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

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .auth {
    justify-content: flex-start;
  }

  .kb-form,
  .kb-upload-panel,
  .inline-tools {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar,
  main {
    padding-left: 16px;
    padding-right: 16px;
  }

  .tabs {
    overflow-x: auto;
    padding-left: 16px;
    padding-right: 16px;
  }

  .kpi-row,
  .thread-meta {
    grid-template-columns: 1fr;
  }
}
