/* AI Workers control center - dark, compact, no framework. */
:root {
  --bg: #0d1117;
  --bg-soft: #131a24;
  --panel: #161d29;
  --panel-2: #1c2533;
  --line: #253044;
  --text: #dce3ee;
  --muted: #8b98ad;
  --accent: #4f9cf9;
  --accent-dim: #2b4d78;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --run: #58a6ff;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #17233a 0%, var(--bg) 55%);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; letter-spacing: .01em; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); font-weight: 400; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; }
.login-card {
  width: min(340px, 90vw);
  margin-top: 18vh;
  padding: 32px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
  text-align: center;
}
.login-mark { font-size: 30px; color: var(--accent); }
.login-card h1 { font-size: 20px; margin-top: 6px; }
.login-card p { margin: 2px 0 20px; }
.login-card input, .login-card button { width: 100%; }
.alert {
  background: rgba(248,81,73,.12);
  border: 1px solid rgba(248,81,73,.4);
  color: #ffb4ae;
  border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; font-size: 13px;
}

/* ---------- controls ---------- */
input, select, textarea, button {
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }
button {
  background: var(--accent); border-color: transparent; color: #06131f;
  font-weight: 600; cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.ghost, a.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  font-weight: 500; padding: 6px 10px; border-radius: 8px; cursor: pointer;
  display: inline-block; font-size: 13px;
}
button.ghost:hover, a.ghost:hover { color: var(--text); border-color: var(--accent-dim); }
button.danger { background: transparent; border: 1px solid rgba(248,81,73,.5); color: #ff9b95; font-weight: 500; }
button.danger:hover { background: rgba(248,81,73,.12); }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.check { color: var(--muted); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px;
  background: rgba(13,17,23,.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.brand .mark { color: var(--accent); }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 6px 14px; border-radius: 999px; font-weight: 500;
}
.tab.active { background: var(--panel-2); color: var(--text); }
.topright { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.topright form { margin: 0; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

main { padding: 22px 24px 60px; max-width: 1400px; margin: 0 auto; }
.view { display: grid; gap: 18px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--panel-2), var(--panel));
}
.panel-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.form-row { display: flex; gap: 10px; padding: 16px; flex-wrap: wrap; }
.form-row input { flex: 1 1 200px; }

/* ---------- worker cards ---------- */
.worker-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.worker {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px 14px;
  display: grid; gap: 12px;
  position: relative; overflow: hidden;
}
.worker::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--line);
}
.worker.is-running::before { background: var(--run); }
.worker.is-paused::before { background: var(--warn); }
.worker-head { display: flex; align-items: flex-start; gap: 10px; }
.worker-head h2 { font-size: 16px; }
.worker-id { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }

.badge {
  margin-left: auto; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge.running { color: var(--run); border-color: rgba(88,166,255,.45); background: rgba(88,166,255,.1); }
.badge.paused  { color: var(--warn); border-color: rgba(210,153,34,.45); background: rgba(210,153,34,.1); }
.badge.idle    { color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 6px; background: currentColor; }
.badge.running .dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

.kv { display: grid; grid-template-columns: 92px 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-family: ui-monospace, monospace; font-size: 12.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: ui-monospace, monospace; font-size: 12px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 8px; color: var(--muted);
}
.chip.next { color: var(--accent); border-color: var(--accent-dim); }
.worker-actions { display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; }
.status-line { font-size: 13px; color: var(--muted); }
.status-line b { color: var(--text); font-weight: 600; }
.outcome { font-weight: 600; }
.outcome.finished { color: var(--ok); }
.outcome.limit { color: var(--warn); }
.outcome.failed, .outcome.interrupted { color: var(--bad); }
.outcome.stopped { color: var(--muted); }
.outcome.running { color: var(--run); }
.warnline { color: var(--bad); font-size: 12.5px; }

/* ---------- log ---------- */
.log {
  margin: 0; padding: 14px 16px;
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-word;
  color: #c7d3e3; background: #0b0f16;
  max-height: 60vh; overflow-y: auto;
}
.log.small { max-height: 300px; font-size: 12px; }
.log-panel .panel-head h2 { display: flex; gap: 8px; align-items: baseline; }

/* ---------- runs table ---------- */
table.runs { width: 100%; border-collapse: collapse; font-size: 13px; }
table.runs th {
  text-align: left; font-weight: 500; color: var(--muted);
  padding: 9px 16px; border-bottom: 1px solid var(--line); font-size: 12px;
}
table.runs td { padding: 9px 16px; border-bottom: 1px solid rgba(37,48,68,.5); }
table.runs tr:hover td { background: rgba(88,166,255,.05); }
table.runs td:first-child { font-family: ui-monospace, monospace; }
table.runs td.actions { text-align: right; white-space: nowrap; }
table.runs td.actions button, table.runs td.actions a { margin-left: 6px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 45%), 1fr)); gap: 1px; background: var(--line); }
.stat { background: var(--panel); padding: 16px; }
.stat .n { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat.wide { grid-column: 1 / -1; }
.stat.wide .n { font-size: 15px; font-weight: 600; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(4,7,12,.7); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal-card {
  width: min(760px, 100%); max-height: 88vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; }
.modal-head .ghost { margin-left: auto; }
.modal-body { padding: 18px; display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field textarea { width: 100%; }
.field textarea { min-height: 320px; font: 12.5px/1.6 ui-monospace, monospace; resize: vertical; }
.hint { font-size: 12px; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 999px; z-index: 60;
  box-shadow: 0 12px 30px rgba(0,0,0,.5); font-size: 13px;
}
.toast.bad { border-color: rgba(248,81,73,.5); color: #ffb4ae; }


/* ---------- rate limits ---------- */
.usage {
  display: grid; gap: 7px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
.usage.is-blocked { border-color: rgba(248,81,73,.45); }
.usage-row { display: grid; grid-template-columns: 62px 1fr 42px auto; align-items: center; gap: 10px; font-size: 12px; }
.usage-label { color: var(--muted); }
.usage-track { height: 6px; border-radius: 999px; background: #202a3a; overflow: hidden; }
.usage-fill { display: block; height: 100%; border-radius: 999px; background: var(--ok); transition: width .4s ease; }
.usage-fill.high { background: var(--warn); }
.usage-fill.full { background: var(--bad); }
.usage-pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.usage-pct.high { color: var(--warn); }
.usage-pct.full { color: var(--bad); }
.usage-reset { color: var(--muted); white-space: nowrap; }
.usage-foot { color: var(--muted); font-size: 11.5px; }
.usage-foot.stale { color: var(--warn); }
.usage-none { color: var(--muted); font-size: 12px; }
.outcome.skipped { color: var(--muted); }
td .reason { font-size: 12px; }

/* ---------- switch row ---------- */
.switch-row {
  display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px;
}
.switch-row input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.switch-row span { display: grid; gap: 2px; }
.switch-row .hint { font-size: 12px; }

.time-chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 34px; align-items: center; }
.time-chip {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 6px 10px; cursor: pointer;
  background: var(--bg-soft); color: var(--text); border: 1px solid var(--line);
}
.time-chip span { color: var(--muted); font-size: 15px; line-height: 1; }
.time-chip:hover { border-color: rgba(248,81,73,.5); }
.time-chip:hover span { color: var(--bad); }
/* .field input is 100% wide, which would squeeze the button out of the row. */
.time-add { display: flex; gap: 8px; align-items: center; }
.time-add input { flex: 1 1 auto; width: auto; min-width: 0; }
.time-add button { flex: 0 0 auto; }

.table-wrap { overflow-x: auto; }
.only-narrow { display: none; }

/* ---------- narrow screens ---------- */
@media (max-width: 760px) {
  main { padding: 14px 12px 48px; }
  .topbar { flex-wrap: wrap; gap: 10px 14px; padding: 10px 12px; }
  .brand { order: 1; }
  .topright { order: 2; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; text-align: center; padding: 8px 6px; }
  .clock { font-size: 12px; }

  .worker-grid { gap: 12px; }
  .worker { padding: 14px; }
  .worker-head { flex-wrap: wrap; }
  .badge { margin-left: 0; }
  .kv { grid-template-columns: 1fr; gap: 0 0; }
  .kv dt { margin-top: 6px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
  .usage-row { grid-template-columns: 54px 1fr 40px; row-gap: 2px; }
  .usage-reset { grid-column: 2 / -1; font-size: 11px; }

  /* Full-width buttons in two columns instead of a ragged wrap. */
  .worker-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .worker-actions button, .worker-actions a { width: 100%; text-align: center; padding: 9px 6px; }

  .panel-head { flex-wrap: wrap; }
  .panel-actions { margin-left: 0; width: 100%; justify-content: space-between; }
  .log { max-height: 52vh; font-size: 12px; padding: 12px; }
  /* A seven-column table cannot work on a phone: show each run as a card. */
  table.runs thead { display: none; }
  table.runs, table.runs tbody, table.runs tr, table.runs td { display: block; width: 100%; }
  table.runs tr {
    border: 1px solid var(--line); border-radius: 10px;
    margin: 10px 12px; padding: 8px 4px; background: var(--bg-soft);
  }
  table.runs tr:hover td { background: transparent; }
  table.runs td { border: none; padding: 3px 12px; white-space: normal; }
  table.runs td::before {
    content: attr(data-label); color: var(--muted); font-size: 11.5px;
    display: inline-block; min-width: 74px;
  }
  table.runs td:first-child { font-size: 14px; }
  table.runs td.actions { display: flex; gap: 8px; padding: 10px 12px 4px; }
  table.runs td.actions button, table.runs td.actions a { flex: 1; margin: 0; text-align: center; }
  .only-narrow { display: inline; }

  /* In a column flex container flex-basis sizes the height, so reset it. */
  .form-row { flex-direction: column; }
  .form-row input, .form-row button { width: 100%; flex: none; }
  .modal { padding: 0; align-items: end; }
  .modal-card { width: 100%; max-height: 92vh; border-radius: 14px 14px 0 0; }
  .modal-body { padding: 14px; }
  .field textarea { min-height: 45vh; }
  .modal-actions { position: sticky; bottom: 0; background: var(--panel); padding-top: 10px; }
  .modal-actions button { flex: 1; }
  .toast { left: 12px; right: 12px; transform: none; text-align: center; }
}
