/* ============================================================
   Projects Hub — minimalist console
   Two themes via [data-theme]; one green accent; hairline rules.
   ============================================================ */

:root {
  --font-display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --maxw: 1120px;

  --kind-npm: #cb3837;
  --kind-node: #5fa04e;
  --kind-python: #3b82f6;
  --kind-shell: #a855f7;
  --kind-launchd: #f59e0b;

  --ease: cubic-bezier(.22, .61, .36, 1);
}

[data-theme="light"] {
  --bg: #f5f5f2;
  --bg-grad: radial-gradient(1200px 600px at 78% -10%, #eef0ec 0%, transparent 60%);
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --text: #17171a;
  --text-2: #51515a;
  --muted: #8b8b93;
  --border: #e7e7e2;
  --border-strong: #d8d8d2;
  --accent: #15803d;
  --accent-2: #16a34a;
  --accent-weak: rgba(21, 128, 61, .10);
  --accent-line: rgba(21, 128, 61, .28);
  --shadow: 0 1px 2px rgba(24, 24, 27, .04), 0 8px 24px -12px rgba(24, 24, 27, .12);
  --shadow-card: 0 1px 0 rgba(24, 24, 27, .03);
  --danger: #c2410c;
}

[data-theme="dark"] {
  --bg: #0b0b0c;
  --bg-grad: radial-gradient(1100px 560px at 80% -12%, #15171a 0%, transparent 62%);
  --surface: #141416;
  --surface-2: #1a1a1d;
  --text: #f3f3f2;
  --text-2: #b4b4bb;
  --muted: #76767f;
  --border: #242427;
  --border-strong: #323237;
  --accent: #4ade80;
  --accent-2: #34d399;
  --accent-weak: rgba(74, 222, 128, .12);
  --accent-line: rgba(74, 222, 128, .32);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 40px -20px rgba(0, 0, 0, .7);
  --shadow-card: 0 1px 0 rgba(0, 0, 0, .25);
  --danger: #fb923c;
}

* { box-sizing: border-box; }

/* Ensure the [hidden] attribute always wins over component display rules. */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .35s var(--ease), color .35s var(--ease);
}

body.locked { overflow: hidden; }

a { color: inherit; text-decoration: none; }

::selection { background: var(--accent-weak); }

/* ───────── Topbar ───────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(18px, 5vw, 44px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.brand-mark {
  align-self: center;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-weak);
}

.brand-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -.02em;
}
.brand-dot { color: var(--accent); }

.brand-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: .02em;
  color: var(--text-2);
  white-space: nowrap;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  transition: background .3s var(--ease), box-shadow .3s var(--ease);
}
.status.live .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
  animation: pulse 2.4s var(--ease) infinite;
}
.status.live { color: var(--text); border-color: var(--accent-line); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-weak); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: color .2s, border-color .2s, background .2s, transform .2s var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0); }

.theme-toggle .i-sun,
.theme-toggle .i-moon { display: none; }
[data-theme="light"] .theme-toggle .i-moon { display: block; }
[data-theme="dark"]  .theme-toggle .i-sun  { display: block; }

/* ───────── Layout ───────── */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(28px, 5vw, 56px) clamp(18px, 5vw, 44px) 80px;
}

/* ───────── Gate ───────── */
.gate {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
}
.gate-card {
  width: min(440px, 92vw);
  text-align: center;
  padding: 8px 4px;
  animation: rise .6s var(--ease) both;
}
.gate-kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--accent);
}
.gate-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(28px, 6vw, 40px);
  letter-spacing: -.03em;
  margin: 14px 0 10px;
}
.gate-note {
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.55;
  margin: 0 auto 26px;
  max-width: 360px;
}
#login-form { display: flex; flex-direction: column; gap: 8px; text-align: left; }
#login-form input {
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-weak); }
#lg-totp { letter-spacing: .35em; text-align: center; }
#login-form button {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 12px 20px;
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: filter .2s, transform .15s var(--ease);
}
[data-theme="dark"] #login-form button { color: #07210f; font-weight: 500; }
#login-form button:hover:not(:disabled) { filter: brightness(1.06); }
#login-form button:active:not(:disabled) { transform: scale(.98); }
#login-form button:disabled { opacity: .6; cursor: default; }
.gate-action {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 11px 18px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-sm);
  color: var(--accent);
  background: var(--accent-weak);
  transition: filter .2s;
}
.gate-action:hover { filter: brightness(1.05); }
.gate-textlink {
  display: inline-block;
  margin-top: 14px;
  background: none;
  border: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color .2s;
}
.gate-textlink:hover { color: var(--accent); }
.gate-textlink:disabled { color: var(--accent); cursor: default; text-decoration: none; }
.gate-error {
  margin-top: 14px;
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

/* ───────── Intro ───────── */
.intro { margin-bottom: 26px; animation: rise .5s var(--ease) both; }
.intro-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(32px, 7vw, 52px);
  letter-spacing: -.035em;
  margin: 0 0 8px;
  line-height: 1;
}
.intro-sub {
  color: var(--text-2);
  font-size: 15px;
  max-width: 560px;
  margin: 0;
  line-height: 1.55;
}

/* ───────── Toolbar ───────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  margin-bottom: 26px;
  border-bottom: 1px solid var(--border);
  animation: rise .5s .05s var(--ease) both;
}
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 200px;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--muted);
  transition: border-color .2s, box-shadow .2s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-weak); color: var(--text-2); }
.search input {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  width: 100%;
}
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: all .2s var(--ease);
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

/* ───────── Groups & cards ───────── */
.groups { display: flex; flex-direction: column; gap: 40px; }

.group-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}
.group-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .02em;
}
.group-rule { flex: 1; height: 1px; background: var(--border); }
.group-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  padding: 18px 18px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card);
  transition: border-color .25s var(--ease), transform .25s var(--ease), box-shadow .25s var(--ease);
  animation: rise .5s var(--ease) both;
}
.card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.card-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -.01em;
  margin: 0;
  line-height: 1.2;
}
.card-open {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: all .2s var(--ease);
}
.card-open:hover { color: var(--accent); border-color: var(--accent-line); }
.card-open svg { transition: transform .2s var(--ease); }
.card-open:hover svg { transform: translate(1px, -1px); }

.card-desc {
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0 0 14px;
  flex: 1;
}

/* actions */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-top: 13px;
  border-top: 1px dashed var(--border);
}
.actions-empty {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  padding-top: 13px;
  border-top: 1px dashed var(--border);
}

.act {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: all .18s var(--ease);
}
.act:hover:not(:disabled) {
  border-color: var(--accent-line);
  color: var(--accent);
  background: var(--accent-weak);
}
.act:active:not(:disabled) { transform: scale(.97); }
.act:disabled { opacity: .42; cursor: not-allowed; }

.act .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.act[data-kind="npm"] .dot { background: var(--kind-npm); }
.act[data-kind="node"] .dot { background: var(--kind-node); }
.act[data-kind="python"] .dot { background: var(--kind-python); }
.act[data-kind="shell"] .dot { background: var(--kind-shell); }
.act .spin { display: none; }
.act.running .dot { display: none; }
.act.running .spin {
  display: block;
  width: 11px; height: 11px;
  border: 1.6px solid var(--accent-weak);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.act.long::after { content: none; }
.act.sensitive .lock { color: var(--kind-launchd); font-weight: 700; }
.act.locked-action { opacity: .5; }
.act.locked-action .dot { background: var(--kind-launchd); }
.act.locked-action::after { content: "⤓ local"; font-size: 9px; color: var(--kind-launchd); letter-spacing: .04em; }
.job.sensitive .job-label .dot { background: var(--kind-launchd); box-shadow: 0 0 0 2px var(--accent-weak); }

/* primary "run the whole thing" button + collapsed steps */
.act-primary {
  width: 100%;
  justify-content: center;
  padding: 11px 14px;
  font-size: 13px;
  border-color: var(--accent-line);
  background: var(--accent-weak);
  color: var(--accent);
}
.act-primary .play { font-size: 8px; line-height: 1; }
.act-primary:hover:not(:disabled) { background: var(--accent); color: #fff; border-color: var(--accent); }
[data-theme="dark"] .act-primary:hover:not(:disabled) { color: #07210f; }
.act-primary.running .play { display: none; }
.more-toggle {
  align-self: flex-start;
  background: none;
  border: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  padding: 2px;
  transition: color .2s;
}
.more-toggle:hover { color: var(--text); }
.more-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  width: 100%;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.more-actions[hidden] { display: none; }

/* action + info-icon wrapper */
.act-wrap { display: inline-flex; align-items: center; gap: 6px; }
.act-wrap-primary { display: flex; width: 100%; }
.act-wrap-primary .act-primary { flex: 1; }

/* little (i) with hover/tap explanation */
.info {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  font-style: normal;
  line-height: 1;
  cursor: help;
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
}
.info:hover, .info:focus { color: var(--accent); border-color: var(--accent-line); outline: none; }
.tip {
  position: absolute;
  bottom: calc(100% + 9px);
  right: -6px;
  width: max-content;
  max-width: 250px;
  padding: 9px 11px;
  background: var(--text);
  color: var(--bg);
  border-radius: 9px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 400;
  font-style: normal;
  line-height: 1.45;
  letter-spacing: 0;
  text-align: left;
  white-space: normal;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(3px);
  transition: opacity .15s var(--ease), transform .15s var(--ease), visibility .15s;
  z-index: 70;
  pointer-events: none;
}
.tip::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 10px;
  border: 5px solid transparent;
  border-top-color: var(--text);
}
.info:hover .tip, .info:focus .tip, .info.show .tip { opacity: 1; visibility: visible; transform: translateY(0); }

/* launchd grouped control */
.job {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.job-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 10px;
  color: var(--text);
  border-right: 1px solid var(--border);
}
.job-label .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--kind-launchd); }
.job-op {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: all .18s var(--ease);
}
.job-op:last-child { border-right: 0; }
.job-op:hover:not(:disabled) { background: var(--accent-weak); color: var(--accent); }
.job-op:disabled { opacity: .42; cursor: not-allowed; }

/* ───────── Empty ───────── */
.empty {
  text-align: center;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 60px 0;
}

/* ───────── Footer ───────── */
.foot {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 22px clamp(18px, 5vw, 44px) 40px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

/* ───────── Output drawer ───────── */
.drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  max-width: var(--maxw);
  margin: 0 auto;
  height: min(42vh, 460px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom: 0;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow);
  transform: translateY(0);
  animation: drawerUp .32s var(--ease) both;
}
@keyframes drawerUp { from { transform: translateY(105%); } to { transform: translateY(0); } }
.drawer[hidden] { display: none; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.run-state {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.run-state.running { background: var(--accent); animation: pulse 1.6s var(--ease) infinite; }
.run-state.ok { background: var(--accent); }
.run-state.fail { background: var(--danger); }
.run-cmd {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-actions { display: flex; align-items: center; gap: 8px; }
.ghost-btn {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  transition: all .18s var(--ease);
}
.ghost-btn:hover { color: var(--text); border-color: var(--border-strong); }
#run-stop { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.run-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 6px 12px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-sm);
  color: var(--accent);
  background: var(--accent-weak);
}
.run-link[hidden] { display: none; }
.drawer-out {
  flex: 1;
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
}
.drawer-out .err { color: var(--danger); }
.drawer-out .meta { color: var(--muted); }
.drawer-out a { color: var(--accent); text-decoration: underline; }

/* ───────── Toast ───────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  padding: 11px 18px;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  animation: rise .25s var(--ease);
}
.toast[hidden] { display: none; }

/* ───────── Motion ───────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

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

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .count { text-align: right; }
  .drawer { height: 52vh; }
}
