:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #dce2ea;
  --text: #18202f;
  --muted: #667085;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #b42318;
  --success: #067647;
  --warning: #b54708;
  --nav: #111827;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

.auth-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 12px 30px rgba(16, 24, 40, .08);
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: var(--nav);
  color: #fff;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-weight: 800;
  font-size: 18px;
  padding: 6px 10px 18px;
}

.org-name {
  color: #cbd5e1;
  font-size: 12px;
  padding: 0 10px 12px;
  line-height: 1.45;
}

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

.nav a {
  color: #d1d5db;
  display: block;
  padding: 9px 10px;
  border-radius: 6px;
}

.nav a:hover,
.nav a.active {
  background: #253044;
  color: #fff;
  text-decoration: none;
}

.nav-group {
  border-top: 1px solid rgba(255, 255, 255, .08);
  padding-top: 6px;
}

.nav-group summary {
  cursor: pointer;
  list-style: none;
  color: #9ca3af;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 10px 6px;
  border-radius: 6px;
}

.nav-group summary::-webkit-details-marker {
  display: none;
}

.nav-group summary::after {
  content: "＋";
  float: right;
  color: #6b7280;
}

.nav-group[open] summary::after {
  content: "−";
}

.nav-group summary:hover {
  background: rgba(255, 255, 255, .05);
  color: #e5e7eb;
}

.nav-group-items {
  display: grid;
  gap: 3px;
  padding-left: 8px;
}

.nav-group-items a {
  padding: 8px 10px;
  font-size: 13px;
}

.main {
  min-width: 0;
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.content {
  padding: 24px;
}

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

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

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

.search-panel {
  margin-bottom: 12px;
}

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

.metric strong {
  font-size: 28px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stats > div {
  display: grid;
  gap: 4px;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.stats strong {
  font-size: 18px;
}

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

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

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

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

th {
  font-size: 12px;
  color: var(--muted);
  background: #f8fafc;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  margin-bottom: 12px;
}

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

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

.code-textarea {
  min-height: 260px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 14px;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.tabs a {
  color: var(--muted);
  padding: 10px 12px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  font-weight: 700;
}

.tabs a:hover {
  text-decoration: none;
  background: #f8fafc;
}

.tabs a.active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
}

.code-block {
  background: #101828;
  color: #f8fafc;
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  line-height: 1.5;
}

.section-head,
.list-row,
.inline-form {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-head {
  margin-bottom: 12px;
}

.section-head h2 {
  margin-bottom: 0;
}

.list-row {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.list-row:first-of-type {
  border-top: 0;
}

.inline-form {
  margin-bottom: 10px;
}

.inline-form select {
  min-width: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  font-weight: 650;
  cursor: pointer;
}

.btn:hover {
  text-decoration: none;
  background: #f8fafc;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  font-weight: 700;
}

.badge.ok { background: #ecfdf3; color: var(--success); }
.badge.warn { background: #fff7ed; color: var(--warning); }
.badge.bad { background: #fef3f2; color: var(--danger); }

.notice,
.error {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.notice {
  background: #eff8ff;
  border: 1px solid #b2ddff;
  color: #175cd3;
}

.error {
  background: #fef3f2;
  border: 1px solid #fecdca;
  color: var(--danger);
}

.chat {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  min-height: calc(100vh - 130px);
}

.chat-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow: auto;
}

.chat-list a {
  display: block;
  padding: 10px;
  border-radius: 6px;
  color: var(--text);
}

.chat-list a.active,
.chat-list a:hover {
  background: #eef2ff;
  text-decoration: none;
}

.messages {
  display: grid;
  gap: 10px;
  max-height: 56vh;
  overflow: auto;
  padding-right: 4px;
}

.message-wrap {
  display: grid;
  gap: 6px;
}

.message-wrap.user {
  justify-items: end;
}

.message {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  white-space: pre-wrap;
}

.message.user {
  margin-left: auto;
  background: #eff6ff;
}

.message.assistant {
  background: #f8fafc;
}

.typing-message {
  color: var(--muted);
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

.typing-indicator span {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: #94a3b8;
  animation: typing-pulse 1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: .15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: .3s;
}

@keyframes typing-pulse {
  0%, 80%, 100% {
    opacity: .35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.message-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.message-actions .btn {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.kanban {
  display: grid;
  grid-template-columns: repeat(6, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.kanban-col {
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-height: 420px;
}

.kanban-col h2 {
  font-size: 14px;
}

.kanban-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
}

.pre {
  white-space: pre-wrap;
  word-break: break-word;
}

.runtime-detail {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.runtime-detail:first-of-type {
  border-top: 0;
}

.runtime-detail summary {
  cursor: pointer;
  font-weight: 700;
}

.runtime-detail h3 {
  margin-top: 12px;
  font-size: 14px;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
  }
  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .chat {
    grid-template-columns: 1fr;
  }
  .span-3,
  .span-4,
  .span-6,
  .span-8 {
    grid-column: span 12;
  }
  .stats {
    grid-template-columns: 1fr;
  }
}
