:root {
  --bg: #0e1116;
  --panel: #151a22;
  --panel-2: #1b222c;
  --border: #263041;
  --text: #e6edf6;
  --muted: #8a97ab;
  --accent: #5b8cff;
  --accent-soft: #1e2b4d;
  --green: #3fbf7f;
  --amber: #e0a83c;
  --red: #e5644f;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* --- login --- */
.login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 36px 32px; width: 320px; text-align: center;
}
.login-card .logo { font-size: 40px; }
.login-card h1 { margin: 6px 0 2px; font-size: 24px; letter-spacing: -0.02em; }
.login-card p { margin: 0 0 20px; font-size: 13px; }
.login-card input, .login-card button { width: 100%; }
.error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* --- shell --- */
.app { display: grid; grid-template-columns: 210px 1fr; height: 100vh; }

.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { font-size: 17px; font-weight: 650; margin: 4px 8px 20px; letter-spacing: -0.01em; }
.brand .logo { margin-right: 6px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-btn {
  background: none; border: none; color: var(--muted); text-align: left;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.nav-btn:hover { background: var(--panel-2); color: var(--text); }
.nav-btn.active { background: var(--accent-soft); color: #cddcff; font-weight: 550; }

.stats { margin-top: auto; padding: 12px 10px; font-size: 12px; color: var(--muted); line-height: 1.9; }
.stats b { color: var(--text); font-weight: 600; }
.logout { background: none; border: 1px solid var(--border); color: var(--muted); padding: 7px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.logout:hover { color: var(--text); }

.main { overflow: hidden; display: flex; flex-direction: column; }
.view { display: none; flex-direction: column; height: 100vh; overflow: hidden; }
.view.active { display: flex; }

.view-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.view-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.head-actions { display: flex; gap: 8px; align-items: center; }

/* --- controls --- */
input, textarea, select, button, a.ghost {
  font-family: inherit; font-size: 14px;
}
input, textarea, select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 8px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; width: 100%; }
button, a.ghost {
  cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); text-decoration: none; display: inline-block;
}
button:hover, a.ghost:hover { border-color: var(--accent); }
button.primary, .login-card button { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550; }
button.primary:hover { filter: brightness(1.1); }
button.ghost, a.ghost { background: none; color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.danger { color: var(--red); border-color: transparent; background: none; padding: 4px 8px; }

/* --- chat --- */
.chat-wrap { display: grid; grid-template-columns: 220px 1fr; flex: 1; overflow: hidden; }
.conversations { border-right: 1px solid var(--border); overflow-y: auto; padding: 10px; }
.conv-item {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover { background: var(--panel-2); color: var(--text); }
.conv-item.active { background: var(--accent-soft); color: #cddcff; }

.chat-main { display: flex; flex-direction: column; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 24px 28px; }

.empty-state { max-width: 620px; margin: 12vh auto; text-align: center; }
.empty-state h3 { font-weight: 600; font-size: 20px; margin-bottom: 20px; }
.suggestions { display: flex; flex-direction: column; gap: 8px; }
.chip {
  text-align: left; font-size: 13px; color: var(--muted); background: var(--panel);
  padding: 11px 14px; line-height: 1.45;
}
.chip:hover { color: var(--text); }

.msg { max-width: 780px; margin: 0 auto 20px; }
.msg .who { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 5px; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.msg.user .body {
  background: var(--accent-soft); border: 1px solid #2b3f6d;
  padding: 11px 14px; border-radius: var(--radius);
}
.msg.assistant .body { padding: 2px 0; }

.tool-log { max-width: 780px; margin: 0 auto 8px; font-size: 12.5px; }
.tool-line {
  color: var(--muted); padding: 6px 10px; border-left: 2px solid var(--border);
  background: rgba(255,255,255,.015); margin-bottom: 3px;
}
.tool-line b { color: #9fb4d8; font-weight: 600; }
.tool-line .result { display: block; color: #6f7d92; margin-top: 3px; white-space: pre-wrap; max-height: 90px; overflow: hidden; }

.thinking { max-width: 780px; margin: 0 auto 16px; color: var(--muted); font-size: 13px; }
.thinking::after { content: '▍'; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.meta-line { max-width: 780px; margin: -12px auto 20px; font-size: 11.5px; color: #5d6a7e; }

.composer {
  display: flex; gap: 10px; padding: 14px 28px 20px; border-top: 1px solid var(--border);
  align-items: flex-end;
}
.composer textarea { max-height: 200px; }
.composer button { height: 38px; }

/* --- tables and lists --- */
.table-wrap { overflow: auto; padding: 0 24px 24px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; color: var(--muted); font-weight: 550; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .05em; padding: 12px 10px;
  position: sticky; top: 0; background: var(--bg); border-bottom: 1px solid var(--border);
}
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:hover td { background: var(--panel); }
td a { color: var(--accent); }

.fit { font-weight: 600; }
.fit.high { color: var(--green); }
.fit.mid { color: var(--amber); }
.fit.low { color: var(--muted); }

.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { color: var(--green); border-color: #235c42; }
.badge.error { color: var(--red); border-color: #6b3129; }
.badge.running { color: var(--amber); border-color: #6b5423; }

.list { overflow-y: auto; padding: 18px 24px; display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin: 18px 24px 0;
}
.list .card { margin: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-title { font-weight: 600; }
.card-body { color: var(--muted); font-size: 13.5px; margin-top: 8px; white-space: pre-wrap; }
.card-actions { display: flex; gap: 6px; align-items: center; }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.card label input, .card label select, .card label textarea { width: 100%; margin-top: 5px; color: var(--text); font-size: 14px; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }

/* --- modal --- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: min(820px, 92vw); max-height: 82vh; overflow-y: auto; padding: 28px; position: relative;
}
.modal-close { position: absolute; top: 12px; right: 12px; border: none; background: none; color: var(--muted); }
.modal-card pre { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .chat-wrap { grid-template-columns: 1fr; }
  .conversations { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
