:root {
  --bg: #0b0d10;
  --panel: #12151a;
  --panel-2: #171b21;
  --line: #222831;
  --line-2: #2c333d;
  --text: #e7eaef;
  --muted: #8b94a3;
  --dim: #78818f;
  --accent: #ff7a3d;
  --accent-soft: rgba(255, 122, 61, .14);
  --up: #3ecf8e;
  --down: #f2555a;
  --warn: #f5b544;
  --info: #5aa9ff;
  --radius: 12px;
  --nav-w: 216px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--down); margin: 0; }
.num { font-variant-numeric: tabular-nums; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: .04em; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: conic-gradient(from 200deg, var(--accent), #ffb36b, var(--accent)); box-shadow: 0 0 18px rgba(255,122,61,.35); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 9px; padding: 8px 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #3a434f; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0d05; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--down); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(800px 400px at 50% -10%, rgba(255,122,61,.12), transparent); }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.login-card p { margin: 0; }
label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
input, select, textarea { background: var(--bg); border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px; width: 100%; font-size: 14px; }
textarea { resize: vertical; min-height: 64px; }

/* shell */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100%; }
.nav { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; padding: 20px 12px; border-right: 1px solid var(--line); background: #0d1014; }
.nav .brand { padding: 0 10px 18px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; text-decoration: none; color: var(--muted); position: relative; }
.nav a:hover { color: var(--text); background: var(--panel); }
.nav a.active { color: var(--text); background: var(--panel-2); }
.nav a.active .ico { background: var(--accent); }
.nav-foot { margin-top: auto; display: grid; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.nav-foot #me { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #1a0d05; font-size: 11px; display: inline-grid; place-items: center; font-weight: 700; }

.ico { width: 18px; height: 18px; flex: none; background: currentColor; -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; }
.ico-overview { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='3' width='7' height='9' rx='1.5'/%3E%3Crect x='14' y='3' width='7' height='5' rx='1.5'/%3E%3Crect x='14' y='12' width='7' height='9' rx='1.5'/%3E%3Crect x='3' y='16' width='7' height='5' rx='1.5'/%3E%3C/svg%3E"); }
.ico-projects { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='4' width='5' height='16' rx='1.5'/%3E%3Crect x='10' y='4' width='5' height='11' rx='1.5'/%3E%3Crect x='17' y='4' width='4' height='7' rx='1.5'/%3E%3C/svg%3E"); }
.ico-agents { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='4' y='7' width='16' height='12' rx='3'/%3E%3Cpath d='M12 3v4M9 12h.01M15 12h.01M9 16h6'/%3E%3C/svg%3E"); }
.ico-systems { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='4' width='18' height='7' rx='2'/%3E%3Crect x='3' y='13' width='18' height='7' rx='2'/%3E%3Cpath d='M7 7.5h.01M7 16.5h.01'/%3E%3C/svg%3E"); }
.ico-approvals { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M8 12.5l2.5 2.5L16 9.5'/%3E%3C/svg%3E"); }

.view { padding: 28px 32px 48px; min-width: 0; outline: none; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.head .sub { width: 100%; margin: -4px 0 0; color: var(--muted); }
.head .spacer { flex: 1; }
.section { margin-top: 28px; }
.section > h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.section > h2 .count { color: var(--dim); }

/* KPI row */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; display: grid; gap: 2px; }
.kpi:hover { border-color: var(--line-2); }
.kpi .v { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi.warn .v { color: var(--warn); }
.kpi.bad .v { color: var(--down); }
.kpi.good .v { color: var(--up); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.list { list-style: none; margin: 0; padding: 4px 0; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 550; }
.list .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.list button.linkish { all: unset; cursor: pointer; display: block; width: 100%; }
.list button.linkish:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.empty { padding: 22px 16px; color: var(--muted); text-align: center; }

/* tags & dots */
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.tag.b-carbon { color: #ff9b6a; border-color: rgba(255,122,61,.35); }
.tag.b-balena { color: #8fd3ff; border-color: rgba(90,169,255,.35); }
.tag.b-hwayang { color: #e9c46a; border-color: rgba(233,196,106,.35); }
.tag.b-12mansion { color: #d6a4ff; border-color: rgba(190,130,255,.35); }
.tag.b-nestlink { color: #7be0c3; border-color: rgba(62,207,142,.35); }
.tag.b-flavourlab { color: #ff8fb1; border-color: rgba(255,120,160,.35); }
.tag.b-platform { color: #9fb4ff; border-color: rgba(130,150,255,.35); }
.tag.b-hq { color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--dim); margin-top: 5px; }
.dot.up, .dot.working, .dot.live { background: var(--up); box-shadow: 0 0 8px rgba(62,207,142,.6); }
.dot.down, .dot.error { background: var(--down); box-shadow: 0 0 8px rgba(242,85,90,.6); }
.dot.offline, .dot.waiting { background: var(--warn); }
.dot.idle { background: var(--info); }
.dot.off { background: var(--dim); }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.working, .pill.up { color: var(--up); background: rgba(62,207,142,.1); }
.pill.down, .pill.error { color: var(--down); background: rgba(242,85,90,.1); }
.pill.offline { color: var(--warn); background: rgba(245,181,68,.1); }
.pill.idle { color: var(--info); background: rgba(90,169,255,.1); }
.prio { font-size: 10px; font-weight: 700; letter-spacing: .04em; color: var(--dim); }
.prio.p1 { color: var(--accent); }

/* filter chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-2); background: transparent; border-radius: 999px; padding: 5px 12px; cursor: pointer; color: var(--muted); font-size: 12px; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: rgba(255,122,61,.5); color: var(--text); }
.search { max-width: 220px; padding: 6px 10px; font-size: 13px; }

/* board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: #0e1115; border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 190px); min-height: 120px; }
.col.drop { border-color: var(--accent); background: rgba(255,122,61,.05); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px; font-weight: 600; font-size: 13px; }
.col-head .count { color: var(--dim); font-weight: 500; }
.col-head .bar { width: 4px; height: 14px; border-radius: 2px; background: var(--dim); }
.col-head.s-in_progress .bar { background: var(--info); }
.col-head.s-waiting_on_you .bar { background: var(--warn); }
.col-head.s-built_not_live .bar { background: #b48cff; }
.col-head.s-live .bar { background: var(--up); }
.col-body { display: grid; gap: 8px; padding: 4px 8px 10px; overflow-y: auto; align-content: start; flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; display: grid; gap: 6px; text-align: left; width: 100%; }
.card:hover { border-color: var(--line-2); background: var(--panel-2); }
.card.dragging { opacity: .4; }
.card .top { display: flex; align-items: center; gap: 6px; }
.card .top .spacer { flex: 1; }
.card .name { font-weight: 560; }
.card .next { color: var(--muted); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .blocker { color: var(--warn); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.col-empty { color: var(--dim); font-size: 12px; text-align: center; padding: 14px 0; }

/* systems */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.sys, .agent { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.sys.is-down { border-color: rgba(242,85,90,.55); }
.sys-top, .agent-top { display: flex; align-items: flex-start; gap: 10px; }
.sys-top .grow, .agent-top .grow { flex: 1; min-width: 0; }
.sys-top .name, .agent-top .name { font-weight: 600; }
.sys-top a.url { color: var(--muted); font-size: 12px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.sys-top a.url:hover { color: var(--text); text-decoration: underline; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat { display: grid; }
.stat b { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 13px; }
.stat span { color: var(--dim); font-size: 11px; }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--down); }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 26px; }
.spark i { flex: 1; min-width: 2px; border-radius: 1px; background: rgba(62,207,142,.55); }
.spark i.fail { background: var(--down); }
.spark i.none { background: var(--line); }
.sys-foot, .agent-foot { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.sys-foot .spacer, .agent-foot .spacer { flex: 1; }
.err-line { color: var(--down); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.agent .desc { color: var(--muted); font-size: 13px; }
.agent .job { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.agent .job b { font-weight: 550; }

/* approvals */
.appr { display: flex; gap: 14px; align-items: flex-start; padding: 14px; border-top: 1px solid var(--line); }
.appr:first-child { border-top: 0; }
.appr .grow { flex: 1; min-width: 0; }
.appr .detail { color: var(--muted); font-size: 13px; white-space: pre-wrap; margin-top: 4px; }
.appr .acts { display: flex; gap: 8px; }

/* activity */
.feed li { font-size: 13px; }
.feed .when { color: var(--dim); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* dialog */
.dialog { border: 1px solid var(--line-2); border-radius: 16px; background: var(--panel); color: var(--text); padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
.dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(2px); }
.dialog form { display: grid; gap: 14px; padding: 22px; }
.dialog .dhead { display: flex; align-items: center; gap: 10px; }
.dialog .dhead h2 { flex: 1; font-size: 17px; }
.dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.dialog .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-top: 4px; }
.dialog .actions .spacer { flex: 1; }
.links-edit { display: grid; gap: 6px; }
.link-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: 6px; }
.history { max-height: 180px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; }
.history .list li { padding: 7px 10px; font-size: 12px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.5); z-index: 50; }
.toast.bad { border-color: rgba(242,85,90,.6); }

.updated { color: var(--dim); font-size: 12px; }

.mobile-only-logout { display: none !important; }

/* tablet */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
}

/* phone */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; z-index: 20; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); background: rgba(13,16,20,.96); backdrop-filter: blur(8px); gap: 0; }
  .nav .brand, .nav-foot { display: none; }
  .nav a { flex: 1; flex-direction: column; gap: 3px; font-size: 10.5px; padding: 6px 2px; justify-content: center; }
  .nav a.active { background: transparent; color: var(--accent); }
  .badge { position: absolute; top: 2px; left: calc(50% + 6px); margin: 0; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }
  .view { padding: 18px 14px calc(90px + env(safe-area-inset-bottom)); }
  h1 { font-size: 20px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpis .kpi:first-child { grid-column: span 2; }
  .kpi .v { font-size: 24px; }
  .board { grid-auto-columns: 84%; scroll-snap-type: x mandatory; margin: 0 -14px; padding: 0 14px 12px; scroll-padding: 0 14px; }
  .col { scroll-snap-align: start; max-height: none; }
  .cards { grid-template-columns: 1fr; }
  .search { max-width: none; flex: 1; }
  .dialog .row, .dialog .row3 { grid-template-columns: 1fr; }
  .mobile-only-logout { display: inline-flex !important; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: no-preference) {
  .card, .kpi, .btn, .chip { transition: border-color .15s, background-color .15s; }
}
