/* Dev OS – panel sterowania maszyną.
   Metafora: pulpit maszyny, nie dashboard SaaS.
   Kolor niesie znaczenie: turkus = włączone/żywe, bursztyn = czeka na ciebie,
   czerwień = zepsute. Stan zdrowy jest celowo bezbarwny, żeby to, co wymaga
   decyzji, było widoczne kątem oka. */

:root {
  color-scheme: light dark;

  --bg: #d6dde3;
  --panel: #f3f7f9;
  --panel-2: #ffffff;
  --line: #bfccd5;
  --line-soft: #d8e1e7;
  --ink: #101a21;
  --dim: #556773;

  --teal: #006e68;
  --teal-soft: #cfe8e5;
  --amber: #8a5000;
  --amber-soft: #f6e3c4;
  --alarm: #a8301a;
  --alarm-soft: #f7ddd7;

  --scrim: rgba(16, 26, 33, .38);

  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont,
    system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --r: 14px;
  --r-sm: 10px;
  --tap: 44px;
  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1219;
    --panel: #151e27;
    --panel-2: #1c2833;
    --line: #293947;
    --line-soft: #1f2c37;
    --ink: #e6eef5;
    --dim: #8fa2b2;

    --teal: #4adad0;
    --teal-soft: #0e332f;
    --amber: #f2ac45;
    --amber-soft: #33260f;
    --alarm: #ff7a66;
    --alarm-soft: #3a1a15;

    --scrim: rgba(0, 0, 0, .58);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--teal); }

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- szkielet ---------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-t) + 8px) 10px 8px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
}

.topbar .mark {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.015em;
  margin: 0;
}

.topbar .sub {
  font-size: 13px;
  color: var(--dim);
  margin-left: 2px;
}

.topbar .grow { flex: 1; }

.iconbtn {
  width: var(--tap);
  height: var(--tap);
  min-width: var(--tap);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
}
.iconbtn:active { background: var(--line-soft); }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn.is-busy svg { animation: spin 900ms linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.view {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 14px var(--pad) 28px;
  scroll-behavior: auto;
}

.ptr {
  height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--dim);
  font-size: 13px;
  transition: height 180ms ease;
}
.ptr.is-armed { color: var(--teal); }

/* ---------- pasek kart ---------- */

.tabbar {
  display: flex;
  border-top: 1px solid var(--line-soft);
  background: var(--bg);
  padding-bottom: var(--safe-b);
}

.tabbar button {
  flex: 1;
  min-height: 56px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--dim);
  padding: 6px 2px 8px;
  position: relative;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button span { font-size: 11.5px; letter-spacing: -.005em; }
.tabbar button[aria-current="page"] { color: var(--ink); }
.tabbar button[aria-current="page"] svg { color: var(--teal); }
.tabbar button[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  width: 26px;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--teal);
}
.tabbar button .badge {
  position: absolute;
  top: 6px;
  right: 50%;
  margin-right: -20px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--amber);
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

/* ---------- hero: puls maszyny ---------- */

.hero {
  border-radius: var(--r);
  background: var(--panel);
  padding: 16px 16px 0;
  overflow: hidden;
  border: 1px solid var(--line-soft);
}
.hero.t-alarm { background: var(--alarm-soft); border-color: transparent; }
.hero.t-live { background: var(--teal-soft); border-color: transparent; }

.hero h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -.02em;
  text-wrap: balance;
}
.hero.t-alarm h1 { color: var(--alarm); }
.hero p {
  margin: 6px 0 0;
  font-size: 15px;
  color: var(--dim);
}
.hero.t-alarm p { color: var(--alarm); opacity: .85; }

.trace { display: block; width: 100%; height: 34px; margin-top: 8px; }
.trace path { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.trace .base { stroke: var(--dim); opacity: .55; }
.trace .live { stroke: var(--teal); opacity: 0; }
.trace.is-running .live {
  opacity: 1;
  stroke-dasharray: 46 660;
  animation: sweep 2.6s linear infinite;
}
.trace.is-off .base { stroke-dasharray: 3 6; }
.trace.is-dead .base { stroke: var(--alarm); opacity: .7; }

@keyframes sweep { from { stroke-dashoffset: 706; } to { stroke-dashoffset: 0; } }

/* ---------- liczniki „czeka na ciebie" ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 12px;
  border-radius: var(--r);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line-soft);
}
.stats button {
  border: 0;
  background: transparent;
  padding: 12px 4px 11px;
  display: grid;
  gap: 1px;
  justify-items: center;
  min-height: 68px;
  border-left: 1px solid var(--line-soft);
}
.stats button:first-child { border-left: 0; }
.stats button:active { background: var(--line-soft); }
.stats b {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stats span { font-size: 11.5px; color: var(--dim); text-align: center; }
.stats .is-zero b { color: var(--dim); opacity: .4; font-weight: 500; }
.stats .t-amber b { color: var(--amber); }
.stats .t-alarm b { color: var(--alarm); }

/* ---------- panele i wiersze ---------- */

.sec { margin-top: 22px; }
.sec > h2 {
  margin: 0 0 8px 2px;
  font-size: 15px;
  font-weight: 620;
  color: var(--dim);
  letter-spacing: -.005em;
}

.panel {
  border-radius: var(--r);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  overflow: hidden;
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 11px 14px 11px 17px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  color: inherit;
}
.row + .row { border-top: 1px solid var(--line-soft); }
button.row:active, .row.is-tappable:active { background: var(--line-soft); }

.row::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--spine, transparent);
}
.row.s-on { --spine: var(--teal); }
.row.s-off { --spine: var(--line); }
.row.s-wait { --spine: var(--amber); }
.row.s-bad { --spine: var(--alarm); }
.row.s-run { --spine: var(--teal); }
.row.s-run::before { animation: breathe 1.8s ease-in-out infinite; }

@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.row .body { flex: 1; min-width: 0; }
.row .title {
  font-size: 16.5px;
  font-weight: 600;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
}
.row .meta {
  font-size: 13.5px;
  color: var(--dim);
  margin-top: 2px;
  overflow-wrap: anywhere;
}
.row .meta.t-bad { color: var(--alarm); }
.row .meta.t-wait { color: var(--amber); }
.row .id {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: -.01em;
}
.row .chev { color: var(--dim); flex: none; }
.row .chev svg { width: 20px; height: 20px; display: block; }

.dim { color: var(--dim); }
/* „meta” poza wierszem (np. linia „Review zaktualizowane…”) ma ten sam ciężar. */
.meta { font-size: 13.5px; color: var(--dim); }
.mono { font-family: var(--mono); font-size: 13.5px; }

/* ---------- przełącznik ---------- */

.switch {
  flex: none;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  position: relative;
  padding: 0;
  transition: background 160ms ease, border-color 160ms ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 26px; height: 26px;
  border-radius: 999px;
  background: var(--dim);
  transition: transform 160ms ease, background 160ms ease;
}
.switch[aria-checked="true"] { background: var(--teal); border-color: var(--teal); }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: var(--panel-2); }
.switch[disabled] { opacity: .5; }

.check {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  align-self: flex-start;
  margin: -4px 0 0 -8px;
  border: 0;
  background: transparent;
  padding: 0;
  display: grid;
  place-items: center;
}
.check i {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  display: grid;
  place-items: center;
  color: transparent;
  transition: background 140ms ease, border-color 140ms ease;
}
.check i svg { width: 18px; height: 18px; }
.check[aria-checked="true"] i {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--panel-2);
}

/* Wyłączony job ma się cofać, a nie krzyczeć na równi z włączonym. */
.row.is-off .title { color: var(--dim); }

.meta + .meta { margin-top: 1px; }

/* ---------- przyciski ---------- */

.btn {
  min-height: 50px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 16.5px;
  font-weight: 600;
  padding: 12px 18px;
  width: 100%;
}
.btn:active { background: var(--line-soft); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: var(--panel-2); }
.btn.warn { background: var(--amber); border-color: var(--amber); color: var(--panel-2); }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: .45; }

@media (prefers-color-scheme: dark) {
  .btn.primary, .btn.warn { color: #0d1219; }
}

.btn-run {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  display: grid;
  place-items: center;
  padding: 0;
}
.btn-run svg { width: 18px; height: 18px; color: var(--teal); }
.btn-run:active { background: var(--teal-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 10px; }
.chip {
  flex: none;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 14.5px;
  font-weight: 550;
  color: var(--dim);
  white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.seg {
  display: flex;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  padding: 3px;
  margin-bottom: 12px;
}
.seg button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--dim);
  font-size: 14.5px;
  font-weight: 570;
}
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--ink); }

/* ---------- węzły (§13) ---------- */

/* Plakietka węzła: identyfikator maszynowy, więc monospace i cicho.
   Kropki stanu tu nie ma – projekt widoczny na liście zawsze siedzi na
   węźle, który odpowiada. Stan węzłów mówi osobny wiersz na „Dziś”. */
.node {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: -.01em;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: 8px;
  vertical-align: 2px;
  white-space: nowrap;
}

/* Linia „na czym patrzysz” nad ekranami projektowymi. */
.scope {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0;
  margin: 0 2px 10px;
  font-size: 15px;
  font-weight: 620;
  letter-spacing: -.005em;
}
.scope .node { font-weight: 400; }

/* ---------- stany ---------- */

.note {
  border-radius: var(--r);
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  color: var(--dim);
  font-size: 15px;
}
.note.t-bad { background: var(--alarm-soft); border-color: transparent; color: var(--alarm); }
.note strong { color: var(--ink); font-weight: 600; }
.note.t-bad strong { color: var(--alarm); }
.note .btn { margin-top: 12px; }

.skel {
  height: 62px;
  border-radius: var(--r);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  margin-bottom: 8px;
  animation: fade 1.4s ease-in-out infinite;
}
@keyframes fade { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

/* ---------- pasek akcji ---------- */

.actionbar {
  position: sticky;
  bottom: 0;
  margin: 16px -16px -28px;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: var(--bg);
  border-top: 1px solid var(--line-soft);
}

/* ---------- arkusz ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  transition: opacity 200ms ease;
  z-index: 40;
}
.scrim.is-open { opacity: 1; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 41;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--line);
  padding: 8px var(--pad) calc(var(--pad) + var(--safe-b));
  max-height: 88dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 240ms cubic-bezier(.2, .8, .2, 1);
}
.sheet.is-open { transform: translateY(0); }
.sheet .grip {
  width: 38px; height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 4px auto 12px;
}
.sheet h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -.015em;
}
.sheet .lead { margin: 0 0 14px; font-size: 15.5px; color: var(--dim); }
.sheet .readback {
  background: var(--panel-2);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  font-size: 15.5px;
  margin-bottom: 14px;
}
.sheet .acts { display: grid; gap: 8px; margin-top: 4px; }
.sheet label { display: block; font-size: 14px; color: var(--dim); margin-bottom: 6px; }

input[type="text"], input[type="password"], textarea {
  width: 100%;
  min-height: 50px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 12px 14px;
  font-size: 16px;
}
input[type="password"].pin {
  font-family: var(--mono);
  letter-spacing: .35em;
  font-size: 20px;
  text-align: center;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.4; }

/* ---------- toast ---------- */

#toasts {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(72px + var(--safe-b));
  z-index: 60;
  display: grid;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  animation: rise 200ms ease;
}
.toast.t-bad { background: var(--alarm); color: #fff; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }

/* ---------- ekran tokenu ---------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px var(--pad) calc(24px + var(--safe-b));
  overflow-y: auto;
}
.gate .trace { height: 46px; margin-bottom: 18px; }
.gate h1 { margin: 0 0 6px; font-size: 27px; font-weight: 650; letter-spacing: -.02em; }
.gate p { margin: 0 0 18px; color: var(--dim); font-size: 15.5px; max-width: 34em; }
.gate form { display: grid; gap: 10px; }
.gate input { font-family: var(--mono); font-size: 15px; }
.gate .err { color: var(--alarm); font-size: 14.5px; min-height: 20px; }

/* ---------- markdown ---------- */

.md { font-size: 16px; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 18px 0 6px;
  line-height: 1.25;
  letter-spacing: -.015em;
  font-weight: 640;
}
.md h1 { font-size: 21px; }
.md h2 { font-size: 18.5px; }
.md h3 { font-size: 17px; }
.md h4 { font-size: 16px; color: var(--dim); }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 4px 0; }
.md ul.tasks { list-style: none; padding-left: 2px; }
.md ul.tasks li { display: flex; gap: 9px; align-items: flex-start; }
.md .box {
  flex: none;
  width: 20px; height: 20px;
  margin-top: 1px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 13px;
  color: var(--teal);
}
.md .box.on { border-color: var(--teal); }
.md code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--panel-2);
  border-radius: 5px;
  padding: 1px 5px;
}
.md pre {
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}
.md pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.md blockquote {
  margin: 10px 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--line);
  color: var(--dim);
}
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md .tablewrap { overflow-x: auto; margin: 10px 0; }
.md table { border-collapse: collapse; font-size: 14.5px; min-width: 100%; }
.md th, .md td {
  border: 1px solid var(--line-soft);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
.md th { background: var(--panel-2); font-weight: 620; }

/* ---------- log / wynik komendy ---------- */

.out {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  padding: 12px;
  margin: 0;
}
.out.wrap { white-space: pre-wrap; }

/* ---------- głos ---------- */

.voice-wrap {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 14px;
  min-height: calc(100dvh - 190px);
}
.mic {
  width: 148px; height: 148px;
  border-radius: 999px;
  border: 2px solid var(--teal);
  background: var(--panel-2);
  display: grid;
  place-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 620;
  padding: 0;
}
.mic svg { width: 34px; height: 34px; color: var(--teal); }
.mic.is-live { background: var(--teal); border-color: var(--teal); color: var(--panel-2); }
.mic.is-live svg { color: var(--panel-2); }
.mic.is-live { animation: mic 2s ease-in-out infinite; }
@keyframes mic { 0%, 100% { box-shadow: 0 0 0 0 var(--teal-soft); } 50% { box-shadow: 0 0 0 14px transparent; } }
.voice-state { font-size: 15px; color: var(--dim); text-align: center; }
.bubble {
  border-radius: var(--r);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  padding: 12px 14px;
  font-size: 15.5px;
  width: 100%;
}
.bubble.you { background: var(--teal-soft); border-color: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
