:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #efece6;
  --ink: #1d1b18;
  --ink-2: #5f5a52;
  --ink-3: #8f897f;
  --line: #e2ddd4;
  --wait: #b45309;
  --wait-bg: #fdf3e4;
  --work: #15803d;
  --fail: #b91c1c;
  --fail-bg: #fdecec;
  --bar: #2f6f8f;
  --bar-bg: #e3e8ea;
  --tabbar: calc(58px + env(safe-area-inset-bottom));
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121110; --surface: #1c1a18; --surface-2: #262320; --ink: #ece8e1; --ink-2: #aaa398; --ink-3: #7a746b;
    --line: #2e2b27; --wait: #f0a54a; --wait-bg: #2a2014; --work: #5fbf7f; --fail: #f07a6e; --fail-bg: #2c1817;
    --bar: #6fb2d2; --bar-bg: #2a3033; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121110; --surface: #1c1a18; --surface-2: #262320; --ink: #ece8e1; --ink-2: #aaa398; --ink-3: #7a746b;
  --line: #2e2b27; --wait: #f0a54a; --wait-bg: #2a2014; --work: #5fbf7f; --fail: #f07a6e; --fail-bg: #2c1817;
  --bar: #6fb2d2; --bar-bg: #2a3033; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; min-height: 100%; }
body {
  margin: 0;
  /* iOS home-screen apps place the fixed tab bar a status bar's height too high while the page doesn't
     scroll (only on short tabs). app.js sets --fill to just over the full screen height in standalone mode,
     so every tab scrolls like a long one does. */
  min-height: var(--fill, 100dvh);
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(var(--tabbar) + 24px) max(16px, env(safe-area-inset-left));
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-size: 12px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 10px;
  margin: 0 calc(-1 * max(16px, env(safe-area-inset-left)));
  padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.015em; margin: 0; flex: 1; }
.updated { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.updated.off { color: var(--fail); }
.icon-btn { background: none; border: 0; padding: 8px; margin: -8px -8px -8px 0; color: var(--ink-2); border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:active { background: var(--surface-2); }
.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.tabs-inner { max-width: 680px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.tabs button {
  background: none; border: 0; padding: 8px 0 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 500; color: var(--ink-3); letter-spacing: .01em;
}
.tabs button[aria-current="page"] { color: var(--ink); }
.ticon { position: relative; width: 26px; height: 26px; display: grid; place-items: center; }
.ticon svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; fill: currentColor; }
.ticon svg path, .ticon svg rect { fill: none; }
.tabs button[aria-current="page"] .ticon svg { stroke-width: 2.1; }
.tbadge {
  position: absolute; top: -3px; left: 17px; min-width: 17px; height: 17px; padding: 0 5px;
  border-radius: 9px; background: var(--wait); color: var(--bg);
  font-size: 11px; font-weight: 700; line-height: 17px; text-align: center; font-variant-numeric: tabular-nums;
}
.tbadge.calm { background: var(--ink-2); }

main { max-width: 680px; margin: 0 auto; }
section { margin-top: 20px; }
h2 {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); margin: 0 0 8px 2px;
}
.empty { color: var(--ink-3); margin: 18px 2px; font-size: 14px; }

/* cards and lists */
.card {
  display: block; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 8px;
}
button.card { cursor: pointer; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.item {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 11px 14px; border-top: 1px solid var(--line); cursor: pointer;
}
div.item { cursor: default; }
.item:first-child { border-top: 0; }
button.item:active, button.card:active { background: var(--surface-2); }
.row { display: flex; align-items: center; gap: 9px; min-width: 0; }
.row .grow, .grow { flex: 1; min-width: 0; }
.name { font-weight: 600; overflow-wrap: anywhere; }
.sub { color: var(--ink-3); font-size: 13px; font-weight: 400; }
.meta { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num { font-weight: 650; font-variant-numeric: tabular-nums; }
.preview {
  color: var(--ink-2); font-size: 13.5px; margin: 3px 0 0 17px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.working { background: var(--work); box-shadow: 0 0 0 3px color-mix(in srgb, var(--work) 22%, transparent); }
.dot.waiting, .dot.permission { background: var(--wait); }
.dot.idle, .dot.shell { background: transparent; border: 1.5px solid var(--ink-3); }
.dot.ok { background: var(--work); }
.dot.fail { background: var(--fail); }
.state.working { color: var(--work); }
.state.waiting, .state.permission { color: var(--wait); }
.state.fail { color: var(--fail); }

/* Now */
.calm-state { display: flex; align-items: center; gap: 12px; padding: 18px 2px 4px; }
.calm-state p { margin: 0; font-size: 17px; }
.calm-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--work); box-shadow: 0 0 0 5px color-mix(in srgb, var(--work) 18%, transparent); }
.waiting h2 { color: var(--wait); }
.waitcard { border-color: color-mix(in srgb, var(--wait) 35%, var(--line)); background: var(--wait-bg); }
.flag { color: var(--wait); font-size: 13px; font-weight: 600; margin-top: 2px; }
.msg { margin-top: 6px; font-size: 14.5px; color: var(--ink); overflow-wrap: anywhere; }
.msg.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; color: var(--ink-2); }
.msg p { margin: 0 0 10px; }
.msg code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.msg pre { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; overflow-x: auto; margin: 4px 0 10px; }
.msg ul { margin: 0 0 10px; padding-left: 20px; }
.msg li { margin-bottom: 3px; }
.problem .name { font-weight: 500; }

/* jobs */
.job .pct { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.bar { height: 6px; background: var(--bar-bg); border-radius: 3px; margin: 8px 0 6px; overflow: hidden; }
.bar.thin { height: 4px; margin: 7px 0 1px; }
.bar > i { display: block; height: 100%; background: var(--bar); border-radius: 3px; transition: width .4s ease; }
.bar.indet > i { width: 30%; animation: indet 1.6s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.log {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.45; color: var(--ink-2);
  white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 6px;
  max-height: 4.4em; overflow: hidden;
}
.log.open { max-height: none; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }

/* machines */
.machine.bad { border-color: color-mix(in srgb, var(--fail) 40%, var(--line)); }
.machine .gauges { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 10px; align-items: center; margin-top: 10px; font-size: 13px; }
.machine .gauges .bar { margin: 0; height: 5px; }
.machine .gauges .lbl { color: var(--ink-2); font-family: var(--mono); font-size: 12px; }
.bar.hot > i { background: var(--fail); }
.bar.warm > i { background: var(--wait); }

/* messages */
.feeditem .row { align-items: flex-start; }
.feeditem .t { color: var(--ink-3); font-size: 12.5px; font-variant-numeric: tabular-nums; width: 42px; flex: none; padding-top: 1px; }
.feeditem .body { color: var(--ink-2); font-size: 13.5px; margin-top: 2px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.feeditem .body.full { display: block; white-space: pre-wrap; }
.kind-job_failed .name, .kind-warning .name { color: var(--fail); }
.kind-waiting .name, .kind-permission .name { color: var(--wait); }
.kind-info .name { font-weight: 500; }

/* banner, buttons */
.banner { display: flex; gap: 12px; align-items: center; background: var(--surface-2); border-radius: 14px; padding: 12px 14px; margin-top: 16px; font-size: 14px; }
.banner p { margin: 0; flex: 1; color: var(--ink-2); }
.btn {
  background: var(--ink); color: var(--bg); border: 0; border-radius: 10px; padding: 9px 14px;
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn.ghost { background: none; color: var(--ink-2); border: 1px solid var(--line); }
.btn.more { display: block; width: 100%; margin-top: 8px; padding: 11px; }
.foot { display: flex; gap: 8px; justify-content: center; margin-top: 28px; flex-wrap: wrap; }

/* sheet */
.sheet {
  position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / 0);
  display: flex; align-items: flex-end; justify-content: center;
  transition: background .2s ease;
}
.sheet[hidden] { display: none; }
.sheet.in { background: rgb(0 0 0 / .4); }
.sheet-panel {
  width: 100%; max-width: 680px; max-height: calc(100% - 44px - env(safe-area-inset-top));
  background: var(--bg); border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .24s cubic-bezier(.2, .8, .2, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.in .sheet-panel { transform: none; }
.sheet-head { display: flex; gap: 10px; align-items: flex-start; padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.sheet-title { font-size: 18px; }
.sheet-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; white-space: normal; flex-wrap: wrap; }
.sheet-body { overflow-y: auto; padding: 10px 16px 24px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet-body .msg { font-size: 15px; line-height: 1.5; }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding-bottom: 0; }
.login form { width: min(320px, 100%); display: flex; flex-direction: column; gap: 10px; text-align: center; }
.login img { margin: 0 auto; border-radius: 14px; }
.login h1 { margin: 4px 0 14px; font-size: 24px; }
.login label { text-align: left; font-size: 13px; color: var(--ink-2); }
.login input[type=password] {
  font: inherit; font-size: 17px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
}
.login input:focus { outline: 2px solid var(--bar); outline-offset: 1px; }
.login button { font-size: 16px; padding: 12px; border-radius: 10px; border: 0; background: var(--ink); color: var(--bg); font-weight: 600; margin-top: 6px; cursor: pointer; }
.login .err { color: var(--fail); margin: 0; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
