/* sow-v1.1 console — dense dark ops UI. Information first: this is a tool for watching
   long GPU runs, so tables stay tight and status colour carries meaning. */

:root {
  --bg:        #0d1117;
  --bg-2:      #131920;
  --bg-3:      #182029;
  --line:      #232c37;
  --line-2:    #2f3a47;
  --fg:        #d7dee7;
  --fg-dim:    #8896a5;
  --fg-faint:  #5d6b7a;
  --accent:    #4da3ff;
  --accent-dk: #1c5ea8;
  --ok:        #46c07a;
  --warn:      #e0a33a;
  --err:       #ef6a6a;
  --run:       #4da3ff;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --r: 7px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted  { color: var(--fg-dim); }
.mono   { font-family: var(--mono); }
.small  { font-size: 12px; }
.grow   { flex: 1; min-width: 0; }
.err    { color: var(--err); font-size: 13px; min-height: 0; }
.err:empty { display: none; }
.msg    { font-size: 13px; color: var(--fg-dim); min-height: 18px; }
.hint   { color: var(--fg-faint); font-weight: 400; font-size: 11px; }

/* ── login ──────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, #16324e33, transparent 70%), var(--bg);
}
.login-card {
  width: 100%; max-width: 360px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 28px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 18px 50px #0008;
}
.login-sub { margin: -4px 0 6px; color: var(--fg-dim); font-size: 13px; }

.brand { font-weight: 650; letter-spacing: -0.2px; font-size: 17px; display: flex;
         align-items: center; gap: 8px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
              box-shadow: 0 0 10px var(--accent); }

/* ── shell ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 18px; height: 52px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.tabs { display: flex; gap: 2px; }
.tab {
  background: none; border: 0; color: var(--fg-dim); font: inherit;
  padding: 8px 13px; border-radius: var(--r); cursor: pointer;
}
.tab:hover { color: var(--fg); background: var(--bg-3); }
.tab.active { color: var(--fg); background: var(--bg-3); box-shadow: inset 0 -2px 0 var(--accent); }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.tabpane { display: none; }
.tabpane.active { display: block; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin: 22px 0 12px; flex-wrap: wrap;
}
.section-head:first-child { margin-top: 0; }
.section-head h2 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: .2px; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.row   { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ── controls ───────────────────────────────────────────────────────────── */
button {
  font: inherit; cursor: pointer; border-radius: var(--r); padding: 7px 13px;
  border: 1px solid var(--line-2); background: var(--bg-3); color: var(--fg);
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: #202b36; border-color: #3d4a59; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent-dk); border-color: #2a72c4; color: #eaf3ff; }
button.primary:hover:not(:disabled) { background: #2470c2; }
button.ghost   { background: transparent; }
button.danger  { border-color: #6b2b2b; color: #f0a0a0; background: transparent; }
button.danger:hover:not(:disabled) { background: #3a1c1c; }
button.block { width: 100%; padding: 9px; }
button.tiny  { padding: 3px 8px; font-size: 12px; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 12px;
        color: var(--fg-dim); font-weight: 500; }
label.narrow { max-width: 130px; }
label.check { flex-direction: row; align-items: center; gap: 6px; }
input, select, textarea {
  font: inherit; background: var(--bg); color: var(--fg);
  border: 1px solid var(--line-2); border-radius: var(--r); padding: 7px 9px;
  width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px #4da3ff22;
}
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }

.card {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px;
}
.card-title { font-size: 12px; color: var(--fg-dim); text-transform: uppercase;
              letter-spacing: .6px; margin-bottom: 8px; }
.inline-form { display: flex; flex-direction: column; gap: 11px; margin-bottom: 14px; }
.checks { display: flex; flex-direction: column; gap: 5px; max-height: 190px;
          overflow: auto; border: 1px solid var(--line); border-radius: var(--r); padding: 8px; }
.checks label { flex-direction: row; align-items: center; gap: 7px; color: var(--fg);
                font-size: 13px; font-weight: 400; }

/* ── pills / status ─────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line-2); color: var(--fg-dim); white-space: nowrap;
  font-family: var(--mono);
}
.pill.ok    { color: var(--ok);   border-color: #2b5c40; background: #46c07a14; }
.pill.run   { color: var(--run);  border-color: #26547f; background: #4da3ff14; }
.pill.warn  { color: var(--warn); border-color: #6b5324; background: #e0a33a14; }
.pill.err   { color: var(--err);  border-color: #6b2b2b; background: #ef6a6a14; }
.pill.off   { color: var(--fg-faint); }
.pill .dot  { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.run .dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

/* ── account card ───────────────────────────────────────────────────────── */
.acct { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; }
.acct-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px;
             flex-wrap: wrap; }
.acct-name { font-weight: 600; }
.acct-head .spacer { flex: 1; }
.quota { min-width: 210px; }
.quota-bar { height: 6px; border-radius: 3px; background: var(--bg-3);
             overflow: hidden; margin-top: 4px; border: 1px solid var(--line); }
.quota-fill { height: 100%; background: linear-gradient(90deg, var(--ok), var(--warn)); }
.quota-fill.low { background: linear-gradient(90deg, var(--warn), var(--err)); }
.acct-body { border-top: 1px solid var(--line); padding: 12px 14px; }
.subtabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.subtab { font-size: 12px; padding: 4px 10px; }
.subtab.active { background: var(--accent-dk); border-color: #2a72c4; color: #eaf3ff; }

/* ── tables ─────────────────────────────────────────────────────────────── */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line);
         white-space: nowrap; }
th { color: var(--fg-dim); font-weight: 500; font-size: 11px; text-transform: uppercase;
     letter-spacing: .5px; background: var(--bg-3); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #ffffff06; }
td.wrap { white-space: normal; max-width: 340px; }
td.num { text-align: right; font-family: var(--mono); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.empty { padding: 22px; text-align: center; color: var(--fg-faint); font-size: 13px; }

/* ── editor ─────────────────────────────────────────────────────────────── */
.editor-wrap { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
#script-editor {
  width: 100%; height: 62vh; min-height: 380px; border: 0; border-radius: 0;
  background: #0a0e14; font-size: 12.5px; line-height: 1.55; padding: 12px;
  white-space: pre; tab-size: 4;
}
#script-editor:focus { box-shadow: none; }

/* ── job card ───────────────────────────────────────────────────────────── */
.job { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; }
.job-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; flex-wrap: wrap; }
.job-name { font-weight: 600; }
.job-body { border-top: 1px solid var(--line); padding: 12px 14px;
            display: flex; flex-direction: column; gap: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px;
      font-size: 12.5px; }
.kv dt { color: var(--fg-dim); }
.kv dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }

.log { background: #0a0e14; border: 1px solid var(--line); border-radius: var(--r);
       max-height: 260px; overflow: auto; font-family: var(--mono); font-size: 12px; }
.log div { padding: 2px 10px; border-bottom: 1px solid #ffffff08; display: flex; gap: 10px; }
.log div:last-child { border-bottom: 0; }
.log time { color: var(--fg-faint); flex: none; }
.log .lvl-warn  { color: var(--warn); }
.log .lvl-error { color: var(--err); }

/* ── inference ──────────────────────────────────────────────────────────── */
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
        padding: 10px 12px; }
.stat .v { font-family: var(--mono); font-size: 19px; font-weight: 600; letter-spacing: -.5px; }
.stat .v.hi { color: var(--accent); }
.stat .k { font-size: 10.5px; color: var(--fg-dim); text-transform: uppercase;
           letter-spacing: .6px; margin-top: 2px; }
.out {
  margin: 0; padding: 12px; background: #0a0e14; border-radius: var(--r);
  border: 1px solid var(--line); font-family: var(--mono); font-size: 12.5px;
  white-space: pre-wrap; overflow-wrap: anywhere; min-height: 150px;
  max-height: 60vh; overflow: auto;
}

/* ── modal & toasts ─────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center;
         padding: 24px; z-index: 60; }
.modal-card { background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 10px;
              width: min(1000px, 100%); max-height: 86vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between;
              padding: 11px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal-card .out { border: 0; border-radius: 0; max-height: none; overflow: auto;
                   white-space: pre; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex;
          flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--bg-3); border: 1px solid var(--line-2); border-left: 3px solid var(--accent);
         border-radius: var(--r); padding: 9px 14px; font-size: 13px; max-width: 420px;
         box-shadow: 0 8px 24px #0009; animation: slide .18s ease; }
.toast.err { border-left-color: var(--err); }
.toast.ok  { border-left-color: var(--ok); }
@keyframes slide { from { opacity: 0; transform: translateY(8px) } }

.spin { display: inline-block; width: 11px; height: 11px; border: 2px solid var(--line-2);
        border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }
