/* zai-dashboard — dark, quiet, dense. */
:root {
  --bg: #0d0f14;
  --panel: #14171f;
  --panel-2: #191d27;
  --line: #262b38;
  --text: #dfe3ec;
  --muted: #8b93a7;
  --accent: #7c5cff;
  --accent-2: #9d85ff;
  --danger: #ff5470;
  --ok: #3fd68f;
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.55 -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.error { color: var(--danger); }
a { color: var(--accent-2); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 14px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* login */
.login-wrap { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 36px; width: 340px; display: flex; flex-direction: column; gap: 12px;
}
.login-logo { font-size: 34px; font-weight: 700; color: var(--accent-2); font-family: var(--mono); text-align: center; }
.login-sub { text-align: center; color: var(--muted); margin: 0 0 8px; }
.login-error { color: var(--danger); min-height: 1em; margin: 0; font-size: 13px; }

/* layout */
.app { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 2px;
}
.brand { font-family: var(--mono); font-weight: 700; font-size: 20px; color: var(--accent-2); padding: 0 10px 14px; }
.sidebar a { color: var(--muted); padding: 8px 10px; border-radius: 8px; }
.sidebar a:hover { color: var(--text); background: var(--panel-2); }
.sidebar a.active { color: var(--text); background: var(--panel-2); border-left: 2px solid var(--accent); }
.spacer { flex: 1; }
.main { padding: 24px 28px 80px; max-width: 1100px; }

/* cards + rows */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 16px;
}
.list { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 12px; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 8px; color: var(--text);
}
.row:hover { background: var(--panel-2); }
.row.clickable { cursor: pointer; }
.row strong { flex-shrink: 0; }
.row span:not(.chip):not(.mono) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 10px; align-items: center; margin: 10px 0; }

/* chips + buttons */
.chip {
  display: inline-block; font-family: var(--mono); font-size: 11px;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 2px 8px; border-radius: 999px; color: var(--muted); margin: 2px 2px 2px 0;
}
.chips-select { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.chip-toggle {
  font-family: var(--mono); font-size: 12px; display: inline-flex; gap: 6px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; cursor: pointer;
}
.chip-toggle:has(input:checked) { border-color: var(--accent); color: var(--accent-2); }
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

/* forms */
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; color: var(--muted); font-size: 12.5px; margin: 10px 0 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
textarea { resize: vertical; }

/* chat */
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.topbar h1 { margin: 0; flex: 1; }
.topbar select { width: 240px; }
.chatlog {
  display: flex; flex-direction: column; gap: 10px; min-height: 200px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; margin-bottom: 12px; max-height: 62vh; overflow-y: auto;
}
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 12px; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.user .bubble-who { display: none; }
.bubble.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.assistant .bubble-who { display: none; }
.bubble-who { font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .05em; }
.chatbar { display: flex; gap: 10px; align-items: flex-end; }
.chatbar textarea { flex: 1; }
.typing { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* code + markdown */
.code {
  background: #0a0c10; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px;
  margin: 8px 0; white-space: pre;
}
code.inline { background: var(--panel-2); border-radius: 4px; padding: 1px 5px; font-family: var(--mono); font-size: 12.5px; }
.md { white-space: pre-wrap; overflow-wrap: anywhere; }
.md + .md { margin-top: 8px; }
.file-view { max-height: 70vh; overflow: auto; }
.readme { overflow-wrap: anywhere; }

/* agent run events */
.event {
  align-self: flex-start; max-width: 95%; font-size: 12.5px;
  border-left: 2px solid var(--line); padding: 4px 10px; margin-left: 8px;
}
.event.tool { border-left-color: var(--accent); display: flex; gap: 8px; align-items: center; }
.event.tool-result { border-left-color: var(--ok); white-space: pre-wrap; overflow-wrap: anywhere; }
.event.error { border-left-color: var(--danger); color: var(--danger); }
.loading { color: var(--muted); }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); }
  .main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
