:root {
  --bg: #050912;
  --panel: #0c1526;
  --panel-2: #101c33;
  --text: #dbe7ff;
  --muted: #7f93bf;
  --orange: #ff9f43;
  --peach: #ffc78a;
  --blue: #5ea8ff;
  --lilac: #b58cff;
  --green: #3ddc97;
  --red: #ff5d6c;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: Consolas, "Cascadia Mono", monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); display: flex; flex-direction: column; }

.bar { display: flex; align-items: center; gap: 16px; padding: 10px 18px; border-bottom: 4px solid var(--orange); }
.elbow { width: 60px; height: 28px; background: var(--orange); border-radius: 14px 0 0 14px; }
h1 { font-size: 18px; letter-spacing: 3px; margin: 0; color: var(--peach); }
h1 .sub { color: var(--muted); font-weight: 400; letter-spacing: 0; font-size: 12px; }
.status-lights { margin-left: auto; display: flex; gap: 8px; }
.light { font-size: 11px; letter-spacing: 2px; padding: 4px 10px; border-radius: 12px; background: #2a3550; color: #9fb0d8; }
.light.on { background: var(--green); color: #032; }
.light.warn { background: var(--orange); color: #320; }
.light.err { background: var(--red); color: #fff; }

main { flex: 1; display: grid; grid-template-columns: 260px 1fr 380px; gap: 10px; padding: 10px; min-height: 0; }
aside, .instances { background: var(--panel); border-radius: 10px; padding: 12px; overflow: auto; min-height: 0; }
h2 { font-size: 12px; letter-spacing: 3px; color: var(--blue); margin: 4px 0 10px; text-transform: uppercase; }
section + section { margin-top: 18px; }

.list { list-style: none; padding: 0; margin: 0 0 8px; }
.list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; border-radius: 6px; background: var(--panel-2); margin-bottom: 4px; font-size: 13px; }
.list li .path { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.list li.missing { opacity: 0.5; text-decoration: line-through; }
.list li .row-actions { display: flex; gap: 4px; flex-shrink: 0; }
.list li .row-actions button { padding: 2px 8px; }
.list li .row-actions button:last-child { background: #22304f; color: var(--text); }
.list li .count { display: inline-block; min-width: 18px; text-align: center; font-size: 10px; padding: 1px 5px; border-radius: 9px; background: var(--green); color: #032; margin-left: 4px; }
.list li .proj { min-width: 0; }
.list li .ci { display: flex; flex-wrap: wrap; gap: 3px 6px; margin-top: 4px; font-size: 10px; line-height: 1; }
.list li .ci:empty { display: none; }
.list li .ci .repo { color: var(--muted); text-decoration: none; font-size: 10px; }
.list li .ci .repo:hover { color: var(--blue); }
.list li .ci .run { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); text-decoration: none; white-space: nowrap; max-width: 100%; overflow: hidden; }
.list li .ci .run:hover { color: var(--text); }
.list li .ci .run i { width: 7px; height: 7px; border-radius: 50%; background: #3a4a70; flex-shrink: 0; }
.list li .ci .run.ok i { background: var(--green); }
.list li .ci .run.fail i { background: var(--red); box-shadow: 0 0 6px var(--red); }
.list li .ci .run.fail { color: var(--red); }
.list li .ci .run.busy i { background: var(--orange); animation: pulse 1s infinite; }
.list li .ci .run.err i { background: var(--red); }
.hint { font-size: 11px; color: var(--muted); margin: -4px 0 8px; }

.inline-form { display: flex; gap: 6px; }
.inline-form.stacked { flex-direction: column; }
input, select, button { font: inherit; font-size: 13px; }
input, select { flex: 1; background: #060b16; color: var(--text); border: 1px solid #22304f; border-radius: 6px; padding: 6px 8px; min-width: 0; }
button { background: var(--blue); color: #021; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer; font-weight: 600; }
button:hover { filter: brightness(1.1); }
button.danger { background: var(--red); color: #fff; }

.instances { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 10px; align-content: start; }
.card { background: var(--panel-2); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; min-height: 260px; max-height: 60vh; border-left: 6px solid var(--muted); }
.card[data-status="idle"] { border-left-color: var(--green); }
.card[data-status="working"] { border-left-color: var(--orange); }
.card[data-status="starting"] { border-left-color: var(--blue); }
.card[data-status="error"] { border-left-color: var(--red); }
.card header { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 6px; flex-wrap: wrap; }
.card .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.card[data-status="idle"] .dot { background: var(--green); }
.card[data-status="working"] .dot { background: var(--orange); animation: pulse 1s infinite; }
.card[data-status="error"] .dot { background: var(--red); }
.card .name { color: var(--peach); letter-spacing: 1px; }
.card .project { color: var(--muted); font-size: 12px; }
.card .activity { color: var(--orange); font-size: 12px; flex-basis: 100%; min-height: 14px; font-family: var(--mono); }
.card .elapsed { color: var(--muted); }
.card .actions { margin-left: auto; display: flex; gap: 4px; }
.card .actions button { padding: 2px 8px; background: #22304f; color: var(--text); }
.transcript { flex: 1; overflow: auto; font-size: 12px; font-family: var(--mono); background: #060b16; border-radius: 6px; padding: 8px; margin-bottom: 6px; white-space: pre-wrap; word-break: break-word; }
.transcript .line { margin-bottom: 6px; }
.transcript .user { color: var(--blue); }
.transcript .assistant { color: var(--text); }
.transcript .tool { color: var(--lilac); }
.transcript .result { color: var(--green); }
.transcript .stderr { color: var(--red); }
.transcript .attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.transcript .att { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--peach); text-decoration: none; background: #101c33; border: 1px solid #22304f; border-radius: 6px; padding: 2px 6px; max-width: 100%; }
.transcript .att.img { padding: 0; overflow: hidden; }
.transcript .att img { display: block; max-height: 90px; max-width: 160px; object-fit: cover; }
.transcript .att:hover { border-color: var(--blue); }

/* composer: pending attachments + drag & drop */
.card { position: relative; }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; background: #101c33; border: 1px solid #22304f; border-radius: 6px; padding: 2px 4px 2px 2px; max-width: 220px; }
.chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.chip .icon { width: 28px; text-align: center; }
.chip button { padding: 0 6px; background: transparent; color: var(--muted); font-size: 12px; }
.chip button:hover { color: var(--red); }
.card form.send .attach { background: #22304f; color: var(--text); padding: 6px 8px; }
.drop-hint { display: none; position: absolute; inset: 0; border: 2px dashed var(--blue); border-radius: 10px; background: rgba(94,168,255,0.12); color: var(--blue); font-size: 14px; letter-spacing: 2px; align-items: center; justify-content: center; pointer-events: none; }
.card.dragging .drop-hint { display: flex; }

.permission { background: #2a1a05; border: 1px solid var(--orange); border-radius: 8px; padding: 8px; margin-bottom: 6px; animation: pulse 1.6s infinite; }
.perm-title { font-size: 10px; letter-spacing: 3px; color: var(--orange); margin-bottom: 4px; }
.perm-summary { font-size: 13px; color: var(--peach); font-family: var(--mono); }
.perm-detail { font-size: 11px; color: var(--muted); max-height: 100px; overflow: auto; margin: 6px 0; white-space: pre-wrap; }
.perm-actions { display: flex; gap: 6px; }
.perm-actions button { flex: 1; }
.transcript .permission { animation: none; background: transparent; border: 0; padding: 0; margin: 0; color: var(--orange); }

.voice { display: flex; flex-direction: column; }
.controls { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 10px; }
.engage { width: 160px; height: 160px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffd2a0, var(--orange) 60%, #b35c00); color: #200; font-size: 18px; letter-spacing: 4px; box-shadow: 0 0 30px rgba(255,159,67,0.35); }
.engage.active { background: radial-gradient(circle at 35% 35%, #b6ffe0, var(--green) 60%, #0a7a4f); box-shadow: 0 0 40px rgba(61,220,151,0.5); }
.engage.listening { animation: glow 1.2s infinite alternate; }
.voice-state { font-size: 12px; letter-spacing: 3px; color: var(--muted); text-transform: uppercase; }
#meter { background: #060b16; border-radius: 4px; }
.conversation { flex: 1; overflow: auto; background: #060b16; border-radius: 6px; padding: 8px; font-size: 13px; margin-bottom: 6px; }
.conversation .msg { margin-bottom: 8px; line-height: 1.4; }
.conversation .msg.user { color: var(--blue); }
.conversation .msg.assistant { color: var(--peach); }
.conversation .msg.system { color: var(--lilac); font-size: 12px; }
.conversation .msg .who { font-size: 10px; letter-spacing: 2px; text-transform: uppercase; opacity: 0.7; display: block; }
.log { margin-top: 8px; max-height: 120px; overflow: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes glow { from { box-shadow: 0 0 20px rgba(61,220,151,0.4); } to { box-shadow: 0 0 60px rgba(61,220,151,0.9); } }

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; grid-auto-rows: auto; }
  .card { max-height: none; }
}

/* ---- login / pincode screen ---- */
.login[hidden] { display: none; }
.login { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.login-box { background: var(--panel); border-radius: 12px; border-top: 4px solid var(--orange); padding: 28px 32px; width: 320px; display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.login-box h1 { letter-spacing: 6px; }
.login-sub { color: var(--muted); font-size: 12px; margin: 0; }
.login-box input { width: 100%; text-align: center; font-size: 24px; letter-spacing: 10px; padding: 10px; }
.login-box button { width: 100%; padding: 10px; }
.login-error { min-height: 16px; font-size: 12px; color: var(--red); }
.login-box.shake { animation: shake 0.3s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
