:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-muted: #eef2f4;
  --line: #d8dee4;
  --line-strong: #b8c2cc;
  --text: #17212b;
  --muted: #657282;
  --accent: #176b87;
  --accent-strong: #0f5067;
  --success: #1d7f4f;
  --danger: #b42318;
  --warning: #996500;
  --shadow: 0 1px 2px rgba(23, 33, 43, 0.08);
  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-width: 320px;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button,
.secondary-button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 600;
}

button:disabled,
textarea:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.secondary-button {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

.danger-button {
  border-color: var(--danger);
  background: #ffffff;
  color: var(--danger);
}

.chat-page,
.admin-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 248px minmax(0, 1fr);
}

.chat-sidebar,
.admin-sidebar {
  border-right: 1px solid var(--line);
  background: #111820;
  color: #ffffff;
  padding: 20px 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: #1f6f8b;
  color: #ffffff;
  font-weight: 800;
}

.login-panel .brand-mark {
  border-color: var(--line);
}

.brand-name {
  font-weight: 700;
}

.brand-subtitle {
  color: #b6c2cd;
  font-size: 13px;
}

.side-nav {
  display: grid;
  gap: 6px;
  margin-top: 28px;
}

.nav-link {
  border-radius: 6px;
  color: #d7e0e7;
  padding: 10px 12px;
}

.nav-link.active,
.nav-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 28px;
  color: #c7d3dc;
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--warning);
}

.status-dot.ready {
  background: var(--success);
}

.chat-main,
.admin-main {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
}

.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.workspace-header h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
}

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

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

.chat-thread {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.chat-thread.compact {
  min-height: 360px;
  box-shadow: none;
}

.message {
  max-width: 760px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.message.assistant {
  background: #f8fafb;
}

.message.user {
  align-self: flex-end;
  background: #eef7f4;
}

.message-author {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.message p {
  margin: 0;
  line-height: 1.55;
}

.composer {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  box-shadow: var(--shadow);
}

.composer.static {
  box-shadow: none;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.composer-actions select {
  max-width: 220px;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-panel .brand-block {
  margin-bottom: 20px;
}

.login-panel .brand-subtitle {
  color: var(--muted);
}

.stack-form,
.inline-form {
  display: grid;
  gap: 12px;
}

.stack-form label,
.inline-form label {
  display: grid;
  gap: 6px;
}

.stack-form span,
.inline-form span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.inline-form {
  grid-template-columns: repeat(3, minmax(140px, 1fr)) auto auto auto;
  align-items: end;
}

.check-field {
  display: flex !important;
  min-height: 36px;
  align-items: center;
  gap: 8px !important;
}

.check-field input,
.table-form input {
  width: auto;
}

.form-error {
  border: 1px solid #f3b7af;
  border-radius: 6px;
  background: #fff4f2;
  color: var(--danger);
  padding: 10px 12px;
}

.text-link {
  display: inline-flex;
  margin-top: 16px;
  color: var(--accent-strong);
  font-weight: 600;
}

.muted-text {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.metric-panel,
.content-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric-panel {
  display: grid;
  gap: 8px;
}

.metric-panel span {
  color: var(--muted);
  font-size: 13px;
}

.metric-panel strong {
  font-size: 22px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.menu-list {
  display: grid;
  gap: 8px;
}

.menu-list a {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

.menu-list a:hover {
  border-color: var(--accent);
}

.menu-list span {
  color: var(--muted);
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

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

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.table-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-form label {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.split-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 16px;
}

.empty-panel p {
  margin: 0 0 12px;
  color: var(--muted);
}

.toolbar {
  display: flex;
  gap: 8px;
}

.agent-list {
  display: grid;
}

.agent-row {
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

.agent-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.agent-row:last-child {
  padding-bottom: 0;
}

.agent-row-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.agent-row-header h2 {
  margin: 0;
  font-size: 18px;
}

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

.agent-row-header code {
  color: var(--accent-strong);
  font-weight: 700;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
}

.field-grid label {
  display: grid;
  gap: 6px;
}

.field-grid span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.wide-field,
.full-field {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.status-list {
  display: grid;
}

.status-list div {
  display: grid;
  gap: 4px;
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.status-list div:first-child {
  border-top: 0;
  padding-top: 0;
}

.status-list div:last-child {
  padding-bottom: 0;
}

.status-list span {
  color: var(--muted);
}

@media (max-width: 920px) {
  .chat-page,
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .chat-sidebar,
  .admin-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-nav {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

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

  .inline-form {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .chat-main,
  .admin-main {
    padding: 16px;
  }

  .workspace-header,
  .composer-actions,
  .agent-row-header,
  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .composer-actions select {
    max-width: none;
  }
}
