:root {
  --bg: #0b1020;
  --panel: #121a2f;
  --panel2: #18233f;
  --text: #e6e9ef;
  --muted: #9aa4b2;
  --accent: #45b6ff;
  --border: #26304d;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
.sidebar {
  border-right: 1px solid var(--border);
  padding: 18px;
  background: #0f172b;
}
.sidebar h1 { font-size: 20px; margin: 0 0 18px; }
.tab-btn, .sync-btn {
  width: 100%;
  margin: 6px 0;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.tab-btn.active { border-color: var(--accent); color: var(--accent); }
.sync-btn { margin-top: 20px; text-align: center; }

.content { padding: 20px; }
.tab { display: none; }
.tab.active { display: block; }
.muted { color: var(--muted); }

.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.agent-card, .skill-card, .usage-card, .task-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.task-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.task-create-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 12px;
  align-content: start;
}
.task-create-form .field {
  display: grid;
  gap: 6px;
  align-content: start;
}
.task-create-form .field.full {
  grid-column: 1 / -1;
}
.task-create-form label {
  font-size: 13px;
  color: #d7def0;
  font-weight: 600;
}
.field-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.task-create-form input,
.task-create-form select,
.task-create-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 10px;
}
.task-create-form textarea {
  min-height: 110px;
}
.task-create-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}
.task-create-actions .sync-btn {
  width: auto;
  min-width: 180px;
}

.board {
  display: grid;
  grid-template-columns: repeat(7, minmax(180px, 1fr));
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 10px;
}
.column {
  background: #10192f;
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 360px;
  padding: 8px;
}
.column h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
}
.tasks {
  min-height: 300px;
  display: grid;
  gap: 8px;
}
.task-card {
  cursor: grab;
}
.task-card .title { font-weight: 600; margin-bottom: 4px; }
.task-card .meta { color: var(--muted); font-size: 12px; }
.task-card .task-actions {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}
.task-link {
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--accent);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  text-decoration: none;
  display: inline-block;
}
.task-link:hover { border-color: var(--accent); }
.task-card.dragging,
.task-card.sortable-chosen {
  opacity: 0.65;
}

.skills-list, .usage-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.usage-cards { margin-bottom: 12px; }

.usage-split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, 0.72);
  display: grid;
  place-items: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-panel {
  width: min(1000px, 95vw);
  height: min(85vh, 900px);
  background: #0f172b;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 8px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.modal-header .tab-btn {
  width: auto;
  margin: 0;
  text-align: center;
  padding: 8px 12px;
}
.story-editor {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0b1020;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 10px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 100;
}
.login-overlay.hidden { display: none; }
.login-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 320px;
}
.login-panel h2 { margin: 0; font-size: 26px; }
.login-panel .sync-btn { margin-top: 8px; }
.login-error { font-size: 13px; }

/* Story cost */
.story-cost-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.story-cost {
  font-size: 12px;
  font-weight: 700;
  color: #7be495;
  background: #0a1a0a;
  border: 1px solid #1e3a1e;
  border-radius: 4px;
  padding: 1px 7px;
  font-family: monospace;
}

/* Audit tab */
.audit-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.audit-toolbar select {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
.audit-sessions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.audit-session-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.audit-session-card:hover { border-color: var(--accent); }
.audit-session-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.audit-agent {
  font-weight: 600;
  color: var(--accent);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.audit-preview {
  font-size: 14px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.audit-meta { font-size: 12px; }
/* Audit thread modal */
.modal-panel--wide { max-width: 820px; width: 95vw; }
.audit-thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 62vh;
  overflow-y: auto;
  padding: 4px 2px;
}
.audit-message {
  border-radius: 10px;
  padding: 12px 16px;
  max-width: 90%;
}
.audit-message--user {
  background: var(--panel2);
  border: 1px solid var(--border);
  align-self: flex-start;
}
.audit-message--assistant {
  background: #0f2040;
  border: 1px solid #1e3a60;
  align-self: flex-end;
}
.audit-message-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
}
.audit-role { font-weight: 600; }
.audit-model {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--muted);
}
.audit-message-text {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.audit-tools { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.audit-tool-call {
  background: #0a1a0a;
  border: 1px solid #1e3a1e;
  border-radius: 6px;
  padding: 8px 10px;
}
.audit-tool-name {
  font-size: 11px;
  font-weight: 700;
  color: #7be495;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.audit-tokens {
  font-size: 11px;
  color: #7be495;
  background: #0a1a0a;
  border: 1px solid #1e3a1e;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: monospace;
}
.audit-tool-input {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
  overflow: hidden;
  max-height: 120px;
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .task-create-form { grid-template-columns: 1fr; }
}
