:root {
  --bg: #f4f5fa;
  --panel: #ffffff;
  --border: #e4e6ef;
  --text: #16182b;
  --muted: #6b7086;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-soft: #eef0ff;
  --success: #16a34a;
  --success-soft: #e7f8ec;
  --warn: #d97706;
  --warn-soft: #fff4e0;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --info: #0284c7;
  --info-soft: #e5f4fd;
  --side-bg: #12142a;
  --side-text: #c4c7dc;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(20, 24, 60, 0.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.boot { padding: 40px; color: var(--muted); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; color: #fff; font-weight: 700; font-size: 17px; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #8b5cf6); display: grid; place-items: center; font-size: 15px; }
.nav-group { margin-top: 14px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d82a6; padding: 0 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--side-text);
  font-weight: 500; text-decoration: none; margin-bottom: 2px;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(99,102,241,.25); color: #fff; }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }
.sidebar .spacer { flex: 1; }
.userbox { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg,#22d3ee,#6366f1); display: grid; place-items: center; color: #fff; font-weight: 700; }
.userbox .name { color: #fff; font-weight: 600; font-size: 13.5px; }
.userbox .role { font-size: 11.5px; color: #8d92b5; }
.main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin: 2px 0 0; }

/* ---------- components ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
@media (max-width: 1100px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } .main { padding: 18px; } }

.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-weight: 550; font-size: 13.5px; cursor: pointer; line-height: 1.2; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f7f8fc; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--danger); border-color: #f3c3c3; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.lg { padding: 11px 18px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
input[type=text], input[type=password], input[type=date], input[type=number], textarea, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; font: inherit; background: #fff; color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(79,70,229,.25); border-color: var(--primary); }
textarea { min-height: 120px; resize: vertical; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.check input { width: 16px; height: 16px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f6; color: #444a6a; }
.chip.running, .chip.done { background: var(--success-soft); color: var(--success); }
.chip.building, .chip.queued { background: var(--warn-soft); color: var(--warn); }
.chip.error, .chip.failed, .chip.blocked { background: var(--danger-soft); color: var(--danger); }
.chip.stopped, .chip.draft, .chip.cancelled { background: #eef0f6; color: #5b6180; }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.building .dot { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: .3 } 50% { opacity: 1 } }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid #eef0f6; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- agent cards ---------- */
.agent-card { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.agent-card .thumb { height: 140px; background: linear-gradient(135deg, #c7d2fe, #e9d5ff); display: grid; place-items: center; font-size: 40px; font-weight: 800; color: rgba(79,70,229,.55); overflow: hidden; }
.agent-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.agent-card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.agent-card .title { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.agent-card .title h3 { margin: 0; font-size: 15.5px; }
.agent-card .desc { color: var(--muted); font-size: 13px; min-height: 18px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.agent-card .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.agent-card .actions { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- progress ---------- */
.progress-panel { border: 1px solid #dfe2f5; background: linear-gradient(180deg, #fbfbff, #f5f6ff); border-radius: var(--radius); padding: 16px 18px; }
.progress-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.progress-stage { font-weight: 650; font-size: 15px; display: flex; gap: 10px; align-items: center; }
.spinner { width: 16px; height: 16px; border: 2px solid #c7c9f5; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 10px; background: #e7e8f5; border-radius: 999px; overflow: hidden; margin: 12px 0 8px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); border-radius: 999px; transition: width .6s ease; }
.bar > i.failed { background: var(--danger); }
.bar > i.done { background: var(--success); }
.progress-nums { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.progress-msg { font-size: 13px; color: #3f4460; margin-top: 4px; }
.log { font-family: var(--mono); font-size: 12px; background: #0f1120; color: #d5d8ef; border-radius: 9px; padding: 12px 14px; max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin-top: 10px; }
.log.small { max-height: 220px; }
details.logbox summary { cursor: pointer; font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.preview-frame { width: 100%; height: 72vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.url-box { display: flex; align-items: center; gap: 8px; background: #f7f8fc; border: 1px solid var(--border); border-radius: 9px; padding: 8px 12px; font-family: var(--mono); font-size: 13px; overflow: hidden; }
.url-box span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.files-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; }
.file-list { border: 1px solid var(--border); border-radius: 9px; max-height: 60vh; overflow: auto; font-family: var(--mono); font-size: 12.5px; }
.file-list div { padding: 6px 10px; cursor: pointer; border-bottom: 1px solid #f0f1f7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-list div:hover, .file-list div.active { background: var(--primary-soft); color: var(--primary); }
.code { font-family: var(--mono); font-size: 12.5px; background: #0f1120; color: #e2e5f7; border-radius: 9px; padding: 14px; max-height: 60vh; overflow: auto; white-space: pre; margin: 0; }
.version { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid #eef0f6; }
.version:last-child { border-bottom: 0; }
.version .v { font-weight: 700; color: var(--primary); min-width: 44px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* ---------- metrics ---------- */
.stat { padding: 16px 18px; }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 28px; font-weight: 750; margin-top: 4px; letter-spacing: -0.02em; }
.stat .sub { font-size: 12.5px; color: var(--muted); }
.chart { width: 100%; height: 180px; display: block; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); display: inline-block; animation: pulse 1.4s infinite; margin-right: 6px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% -10%, #dfe1ff, transparent), radial-gradient(900px 500px at 100% 100%, #e6dbff, transparent), var(--bg); padding: 20px; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { color: var(--text); padding: 0 0 14px; }
.login-card .brand .logo { color: #fff; }

/* ---------- toasts / modal ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #16182b; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.2); font-size: 13.5px; max-width: 380px; animation: fadein .2s ease; }
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,17,32,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 480px; box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.modal h2 { margin-bottom: 12px; }
.modal .btn-row { justify-content: flex-end; margin-top: 16px; }
.alert { padding: 10px 14px; border-radius: 9px; font-size: 13.5px; margin-bottom: 14px; }
.alert.warn { background: var(--warn-soft); color: #92400e; }
.alert.error { background: var(--danger-soft); color: #991b1b; }
.alert.info { background: var(--info-soft); color: #075985; }
.notes { background: #f7f8fc; border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; white-space: pre-wrap; font-size: 13px; }
.prompt-box { min-height: 220px; font-size: 14.5px; line-height: 1.55; }
.examples { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.examples button { font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); background: #fff; cursor: pointer; color: #444a6a; }
.examples button:hover { border-color: var(--primary); color: var(--primary); }
