:root {
  --bg: #0d1117;
  --bg-raised: #151b23;
  --bg-inset: #1c2431;
  --border: #2a3441;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --accent: #4f8cff;
  --accent-strong: #2f6fe0;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* The hidden attribute must always win. Class rules like .drawer/.modal set
   display:flex/grid, which would otherwise override the UA's display:none and
   leave invisible full-screen overlays trapping every click after sign-in. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0 0 .35rem; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 .75rem; }
.muted { color: var(--text-dim); }

/* ------------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--text);
  border-radius: var(--radius);
  padding: .55rem 1rem;
  font-size: .95rem;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border-color: var(--accent-strong);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .3rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }

.btn-yolo {
  background: linear-gradient(180deg, #ff6b4a, #e03e2f);
  border-color: #c2331f;
  color: #fff;
  font-weight: 800;
  letter-spacing: .04em;
  padding: .85rem 1.8rem;
  font-size: 1.05rem;
}
.btn-yolo:hover { filter: brightness(1.1); border-color: #c2331f; }

/* ---------------------------------------------------------------- auth */
.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(79, 140, 255, .14), transparent 60%),
    radial-gradient(700px 400px at 110% 110%, rgba(248, 81, 73, .07), transparent 60%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2rem;
}
.brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.4rem; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  font-weight: 750;
  font-size: 1.05rem;
  flex: none;
}
.brand h1 { font-size: 1.35rem; }
.brand-sub { color: var(--text-dim); font-size: .9rem; margin: 0; }
.brand--small { margin: 0; }
.brand--small strong { font-size: 1rem; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg-inset);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 1.25rem;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: .5rem;
  border-radius: 8px;
  font-weight: 550;
  cursor: pointer;
}
.tab.is-active { background: var(--bg-raised); color: var(--text); }

/* ---------------------------------------------------------------- forms */
label { display: block; margin-bottom: .8rem; }
label > span {
  display: block;
  font-size: .82rem;
  font-weight: 550;
  color: var(--text-dim);
  margin-bottom: .3rem;
}
input, textarea, select {
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: .55rem .7rem;
  font: inherit;
  font-size: .95rem;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, .18);
}
textarea { resize: vertical; }
.form-error { color: var(--red); font-size: .9rem; margin: .6rem 0 0; }
.form-success { color: var(--green); font-size: .9rem; margin: .6rem 0 0; }
.auth-foot { color: var(--text-dim); font-size: .85rem; margin: 1rem 0 0; }

/* --------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1.25rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.balance {
  display: flex;
  align-items: baseline;
  gap: .35rem;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .25rem .8rem;
}
.balance-label { color: var(--text-dim); font-size: .78rem; }
.balance-value { font-weight: 700; font-size: 1rem; color: var(--accent); }

/* ----------------------------------------------------------- mode switch */
.mode-switch {
  display: flex;
  gap: 4px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.mode {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-weight: 700;
  font-size: .88rem;
  padding: .35rem 1.2rem;
  border-radius: 999px;
  cursor: pointer;
}
.mode.is-active { background: var(--accent); color: #fff; }
.mode--yolo.is-active { background: linear-gradient(180deg, #ff6b4a, #e03e2f); }

/* ------------------------------------------------------------ mode panels */
.mode-panel { max-width: 880px; margin: 1.5rem auto 0; padding: 0 1.25rem; }
.ask-card, .yolo-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow);
}
.ask-title { font-size: 1.25rem; margin-bottom: .8rem; }
#manual-input { font-size: 1.02rem; }
.ask-actions { display: flex; align-items: center; gap: 1rem; margin-top: .9rem; }
.ask-cost { color: var(--text-dim); font-size: .88rem; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .9rem; }
.chip {
  display: inline-block;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: .22rem .75rem;
  font-size: .8rem;
  font-weight: 550;
}
.chip.is-active { border-color: var(--accent); color: var(--text); background: rgba(79, 140, 255, .12); }
.chip-model { border-color: rgba(139, 92, 246, .5); color: #b8a5f5; }

/* ---------------------------------------------------------------- yolo */
.yolo-card { border-color: rgba(248, 81, 73, .35); }
.yolo-head { margin-bottom: 1rem; }
.yolo-title {
  font-size: 1.5rem;
  letter-spacing: .02em;
  background: linear-gradient(90deg, #ff6b4a, #e03e2f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-block;
}
.yolo-sub { color: var(--text-dim); max-width: 620px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 1rem; }
.yolo-row { display: flex; align-items: end; gap: 1.4rem; margin-top: .4rem; }
.yolo-count { flex: 1; margin: 0; }
.yolo-count input[type="range"] { accent-color: #ff6b4a; padding: 0; }
.yolo-cost { color: var(--text-dim); font-size: .88rem; margin-top: .9rem; }

/* ---------------------------------------------------------------- kanban */
.board-wrap { max-width: 1500px; margin: 1.5rem auto 3rem; padding: 0 1.25rem; }
.crumbs { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem; }
.crumb-link {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: .92rem;
}
.crumb-link:hover { text-decoration: underline; }
.crumb-sep { color: var(--text-dim); }

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(240px, 1fr);
  gap: .9rem;
  overflow-x: auto;
  padding-bottom: .8rem;
  align-items: start;
}

.dept-col {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-width: 0;
}
.dept-head {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: .9rem 1rem .6rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.dept-head:hover .dept-name { color: var(--accent); }
.dept-name { font-weight: 700; font-size: .98rem; margin: 0; }
.dept-tagline { color: var(--text-dim); font-size: .78rem; margin: .2rem 0 0; }
.dept-count {
  display: inline-block;
  margin-top: .45rem;
  font-size: .72rem;
  color: var(--accent);
  background: rgba(79, 140, 255, .1);
  border: 1px solid rgba(79, 140, 255, .3);
  border-radius: 999px;
  padding: .05rem .55rem;
  font-weight: 650;
}
.dept-body { padding: .7rem; display: grid; gap: .55rem; }

.worker-card {
  width: 100%;
  text-align: left;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .65rem .75rem;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.worker-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.worker-card-top { display: flex; align-items: center; gap: .5rem; }
.worker-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  background: var(--accent);
}
.worker-dot--internal { background: var(--amber); }
.worker-name { font-weight: 650; font-size: .9rem; }
.worker-line { color: var(--text-dim); font-size: .78rem; margin: .3rem 0 0; }

/* --------------------------------------------------------- drawers */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  justify-content: flex-end;
  z-index: 40;
}
.drawer-card {
  width: min(560px, 94vw);
  height: 100%;
  overflow: auto;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  padding: 1.4rem 1.5rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }
.panel-head h2 { margin: 0; }
.drawer-close { font-size: 1.4rem; line-height: 1; }

/* --------------------------------------------------------------- jobs */
.jobs-list { display: grid; gap: .7rem; }
.job-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .35rem .9rem;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  cursor: pointer;
  transition: border-color .15s;
}
.job-card:hover { border-color: var(--accent); }
.job-title { font-weight: 600; }
.job-meta { color: var(--text-dim); font-size: .85rem; grid-column: 1; }
.badge {
  justify-self: end;
  align-self: start;
  font-size: .75rem;
  font-weight: 650;
  padding: .15rem .6rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-queued { background: rgba(210, 153, 34, .16); color: var(--amber); }
.badge-running { background: rgba(79, 140, 255, .16); color: var(--accent); }
.badge-done { background: rgba(63, 185, 80, .16); color: var(--green); }
.badge-failed { background: rgba(248, 81, 73, .16); color: var(--red); }

/* --------------------------------------------------------------- modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 86vh;
  overflow: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.5rem;
}
.modal-close {
  position: absolute;
  top: .7rem;
  right: .9rem;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }

/* --------------------------------------------------------- worker modal */
.worker-modal-head { display: flex; align-items: center; gap: .9rem; margin-bottom: .9rem; }
.worker-avatar {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  font-weight: 800;
  font-size: 1.2rem;
  flex: none;
}
.worker-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.worker-detail { color: var(--text); font-size: .95rem; margin-bottom: 1.1rem; }
#worker-task-box label span { color: var(--text-dim); }
#worker-task-input { margin-bottom: .8rem; }
#worker-auto-note { font-size: .9rem; }

/* ---------------------------------------------------------- job modal */
.progress-track {
  height: 7px;
  border-radius: 999px;
  background: var(--bg-inset);
  overflow: hidden;
  margin: .9rem 0 .4rem;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  transition: width .5s ease;
}
.job-progress-text { color: var(--text-dim); font-size: .88rem; }
.job-log {
  background: #0a0e13;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
  color: #9fb0c0;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.job-downloads { display: flex; gap: .6rem; margin-top: 1rem; flex-wrap: wrap; align-items: center; }

/* -------------------------------------------------------------- redeem */
.redeem-form { display: flex; gap: .6rem; align-items: stretch; margin-top: .5rem; }
.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* ----------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .grid-3 { grid-template-columns: 1fr; }
  .yolo-row { flex-direction: column; align-items: stretch; }
  .user-email { display: none; }
  .topbar { flex-wrap: wrap; }
  .board { grid-auto-columns: minmax(230px, 78vw); }
  .mode-panel { padding: 0 .8rem; }
}
