:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #dfe3e8;
  --text: #1d232b;
  --muted: #667085;
  --accent: #176b87;
  --accent-2: #d85242;
  --ok: #18794e;
  --warn: #a15c07;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--bg);
  color: var(--text);
}

body.is-login {
  display: block;
}

body.is-login .sidebar,
body.is-login .main {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #17202a;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  background: white;
  border-radius: 8px;
  padding: 28px;
  display: grid;
  gap: 16px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
}

.login-brand {
  color: var(--text);
  padding: 0;
}

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

.login-card label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 600;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
}

button.secondary {
  background: white;
  color: var(--accent);
}

button.danger {
  border-color: var(--accent-2);
  background: var(--accent-2);
}

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

textarea {
  min-height: 86px;
  resize: vertical;
}

.sidebar {
  background: #17202a;
  color: white;
  min-height: 100vh;
  padding: 24px 16px;
}

.brand {
  display: grid;
  gap: 6px;
  padding: 0 8px 20px;
}

.brand strong {
  font-size: 20px;
}

.brand span {
  color: #bac6d3;
  font-size: 13px;
}

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

.nav button {
  width: 100%;
  text-align: left;
  background: transparent;
  border-color: transparent;
  color: #d8e1ea;
}

.nav button.active {
  background: #243447;
  color: white;
}

.main {
  padding: 24px;
  min-width: 0;
}

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

.topbar h1,
.panel h2 {
  margin: 0;
}

.topbar p,
.panel span {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.admin-user {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.summary {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

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

.metric b {
  display: block;
  font-size: 24px;
}

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

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.ops-card,
.detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
}

.ops-card h2,
.detail-card h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.ops-card p,
.detail-card p,
.detail-card small {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.warnings-card ul {
  margin: 0;
  padding-left: 18px;
  color: #344054;
  line-height: 1.7;
}

.kv {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #edf0f3;
}

.kv:last-child {
  border-bottom: 0;
}

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

.kv b {
  color: var(--text);
  font-size: 13px;
  text-align: right;
  overflow-wrap: anywhere;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 16px;
}

.workspace[hidden],
.summary[hidden],
.api-check-panel[hidden] {
  display: none;
}

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

.api-check-panel {
  margin-top: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 8px;
  margin-bottom: 12px;
}

.list {
  display: grid;
  gap: 8px;
  max-height: 62vh;
  overflow: auto;
}

.row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  background: #fff;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
}

.row.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(23, 107, 135, 0.12);
}

.row strong {
  display: block;
  margin-bottom: 5px;
}

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

.row-main {
  min-width: 0;
}

.avatar-thumb {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #edf2f7;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  background: #edf2f7;
  color: #364152;
  font-size: 12px;
}

.badge.ok {
  background: #e8f5ef;
  color: var(--ok);
}

.badge.warn {
  background: #fff3df;
  color: var(--warn);
}

.editor {
  display: grid;
  gap: 12px;
}

.detail-card {
  display: grid;
  gap: 12px;
  background: #fbfcfd;
}

.persona-card {
  grid-template-columns: auto 1fr;
  align-items: start;
}

.persona-card img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
}

.detail-card h3 span {
  margin-left: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

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

.token-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 8px;
  margin-top: 12px;
}

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

.field label {
  color: #344054;
  font-size: 13px;
  font-weight: 600;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.editor-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

.api-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.api-status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.api-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.api-table th,
.api-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

.api-table th {
  color: #344054;
  background: #f8fafc;
}

.api-table code {
  display: inline-block;
  max-width: 280px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.strategy-table th:nth-child(1) {
  width: 24%;
}

.strategy-table th:nth-child(2) {
  width: 96px;
}

.strategy-table th:nth-child(3),
.strategy-table th:nth-child(4),
.strategy-table th:nth-child(5) {
  width: 24%;
}

.api-table button {
  padding: 5px 8px;
}

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

@media (max-width: 1100px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .nav,
  .metrics-grid,
  .ops-grid,
  .workspace {
    grid-template-columns: 1fr;
  }

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