:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --line: #d9e2ec;
  --text: #172033;
  --muted: #667085;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --teal: #0f766e;
  --danger: #d92d20;
  --code-bg: #111827;
  --shadow: 0 12px 30px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef6ff 0%, #f8fafc 48%, #edf7f5 100%);
}

.login-card {
  width: min(420px, 100%);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.login-card h1 {
  margin: 0;
  font-size: 26px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.login-card label {
  display: grid;
  gap: 7px;
  font-weight: 650;
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--teal));
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
}

.user-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.user-panel strong {
  display: block;
}

.user-panel span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.brand-subtitle,
.topbar p,
.section-title {
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item,
.primary-action,
.ghost-button,
.send-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 8px 12px;
  background: transparent;
  color: var(--text);
}

.nav-item {
  text-align: left;
  white-space: nowrap;
}

.nav-item.active {
  color: var(--primary);
  background: #eff6ff;
  border-color: #bfdbfe;
  font-weight: 650;
}

.primary-action,
.send-button {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.primary-action:hover,
.send-button:hover {
  background: var(--primary-dark);
}

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

.ghost-button:disabled,
.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.sidebar-section {
  display: grid;
  gap: 12px;
  min-height: 0;
}

.conversation-list {
  display: grid;
  gap: 6px;
  overflow: auto;
  max-height: calc(100vh - 260px);
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px;
}

.conversation-item.active {
  border-color: #93c5fd;
  background: #f8fbff;
}

.conversation-title {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  min-width: 0;
}

.conversation-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-title span {
  color: var(--muted);
  font-size: 12px;
}

.delete-button {
  border: 0;
  background: transparent;
  color: var(--danger);
  width: 28px;
  height: 28px;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  height: 100vh;
  overflow: hidden;
}

.view.active {
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 78px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.topbar p {
  margin: 0;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.select,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.message-list {
  flex: 1;
  overflow: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-state {
  max-width: 760px;
  margin: auto;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--text);
  margin: 12px 0 8px;
  font-size: 28px;
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 22px;
}

.agent-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
  text-align: left;
}

.message {
  display: grid;
  grid-template-columns: 40px minmax(0, 760px);
  gap: 12px;
  align-items: start;
}

.message.user {
  justify-content: end;
  grid-template-columns: minmax(0, 760px) 40px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  font-size: 13px;
  font-weight: 700;
  background: var(--teal);
}

.message.user .avatar {
  grid-column: 2;
  background: var(--primary);
}

.bubble {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.04);
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  grid-column: 1;
  grid-row: 1;
  background: #eff6ff;
  border-color: #bfdbfe;
}

.bubble pre {
  background: var(--code-bg);
  color: #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
}

.bubble code {
  font-family: "SFMono-Regular", Consolas, monospace;
}

.bubble :not(pre) > code {
  background: #eef2f7;
  color: #344054;
  border-radius: 5px;
  padding: 2px 5px;
}

.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
}

.bubble th,
.bubble td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}

.composer {
  border-top: 1px solid var(--line);
  background: white;
  padding: 14px 24px;
  display: grid;
  gap: 10px;
}

.composer textarea {
  width: 100%;
  min-height: 82px;
  resize: vertical;
}

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

.table-wrap {
  margin: 24px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  box-shadow: var(--shadow);
}

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

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: #f8fafc;
  color: #475467;
  font-weight: 650;
}

tr.clickable:hover {
  background: #f8fbff;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
}

.status.success,
.status.enabled {
  color: #027a48;
  background: #ecfdf3;
}

.status.failed,
.status.disabled {
  color: #b42318;
  background: #fef3f2;
}

.detail-panel {
  margin: 0 24px 24px;
  padding: 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: 38vh;
}

.detail-panel.empty {
  color: var(--muted);
}

.metric-grid {
  margin: 24px 24px 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.05);
}

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

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.detail-block {
  margin: 0 0 14px;
}

.detail-block h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.detail-block pre {
  margin: 0;
  white-space: pre-wrap;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.settings-grid {
  width: min(860px, calc(100% - 48px));
  margin: 24px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.settings-grid label,
.dialog label {
  display: grid;
  gap: 7px;
  font-weight: 650;
  color: #344054;
}

.settings-grid label span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  font-weight: 400;
}

.switch-line {
  display: flex !important;
  align-items: center;
  gap: 8px !important;
  flex-wrap: wrap;
}

.switch-line input {
  min-height: auto;
  width: 16px;
  height: 16px;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog form {
  padding: 22px;
  display: grid;
  gap: 14px;
}

.dialog h2 {
  margin: 0;
  font-size: 20px;
}

.dialog textarea {
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #101828;
  color: white;
  border-radius: 8px;
  padding: 10px 12px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
    padding: 8px 6px;
  }

  .conversation-list {
    max-height: 160px;
  }

  .view {
    height: auto;
    min-height: calc(100vh - 300px);
  }

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

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions select,
  .topbar-actions button {
    flex: 1;
  }

  .message,
  .message.user {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .message.user .avatar {
    grid-column: 1;
  }

  .message.user .bubble {
    grid-column: 2;
  }

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

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .metric-grid {
    grid-template-columns: 1fr;
  }
}
