/* ==========================================================================
   WP Task Dashboard — dark operations console
   ========================================================================== */

:root {
  --bg:            #0d1117;
  --bg-raised:     #151b23;
  --bg-inset:      #0a0e14;
  --border:        #232b36;
  --border-strong: #303a48;

  --text:          #e4e8ef;
  --text-dim:      #9aa5b4;
  --text-faint:    #6b7684;

  --accent:        #4a9eff;
  --accent-dim:    #1f3a5f;
  --green:         #3fb950;
  --amber:         #d29922;
  --red:           #f85149;
  --purple:        #a371f7;
  --cyan:          #39c5cf;

  --radius:   8px;
  --radius-sm: 5px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted  { color: var(--text-dim); }

/* ── Buttons ──────────────────────────────────────────────────────────── */

.btn {
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #1d242e; border-color: #3d4959; }
.btn:disabled { opacity: .38; cursor: not-allowed; }

.btn-primary { background: #1f6feb; border-color: #2b7cf3; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2b7cf3; }

.btn-danger { background: #8b2c26; border-color: #a33730; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a33730; }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-raised); color: var(--text); }

.btn-danger-text { color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 9px; }

/* ── Form fields ──────────────────────────────────────────────────────── */

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 5px;
  letter-spacing: .02em;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, .13);
}
.field .help { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.checkbox-inline input { accent-color: var(--accent); }

.switch-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.switch-row:first-child { border-top: none; }
.switch-row .label { font-size: 13px; font-weight: 500; }
.switch-row .help { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

.switch { position: relative; width: 38px; height: 21px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: #303a48; border-radius: 999px;
  cursor: pointer; transition: background .15s;
}
.switch .track::before {
  content: ''; position: absolute;
  width: 15px; height: 15px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%;
  transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(17px); }

/* ── Login ────────────────────────────────────────────────────────────── */

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 70% 50% at 50% -10%, rgba(74,158,255,.10), transparent),
    var(--bg);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; }
.login-mark { font-size: 26px; color: var(--accent); line-height: 1; }
.login-brand h1 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.login-brand p { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }

.login-error {
  background: rgba(248, 81, 73, .10);
  border: 1px solid rgba(248, 81, 73, .35);
  color: #ff9d97;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* ── Layout ───────────────────────────────────────────────────────────── */

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  flex-shrink: 0;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-brand h1 { font-size: 14.5px; font-weight: 650; letter-spacing: -.01em; }
.topbar-brand .login-mark { font-size: 19px; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 12.5px; }

.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-dim); }
.conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.conn-open i   { background: var(--green); box-shadow: 0 0 7px rgba(63,185,80,.65); }
.conn-closed i { background: var(--red); }

.layout { display: flex; flex: 1; min-height: 0; }

/* ── Sidebar ──────────────────────────────────────────────────────────── */

.sidebar {
  width: 330px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #0b0f15;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-head h2 { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); }

.filters { display: flex; gap: 7px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.filters input, .filters select {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12px;
  min-width: 0;
}
.filters input { flex: 1; }
.filters select { width: 108px; }
.filters input:focus, .filters select:focus { outline: none; border-color: var(--accent); }

.task-list { overflow-y: auto; flex: 1; padding: 7px; }

.task-card {
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  margin-bottom: 7px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.task-card:hover { border-color: var(--border-strong); background: #1a212a; }
.task-card.active { border-color: var(--accent); background: #131c28; }
.task-card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.task-card-name {
  font-weight: 550; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.task-card-meta {
  font-size: 11px; color: var(--text-faint);
  display: flex; gap: 9px; font-family: var(--mono);
}
.task-card-meta .ins { color: var(--green); }

.pill {
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid;
  flex-shrink: 0;
}
.pill-idle      { color: var(--text-dim);  border-color: var(--border-strong); background: rgba(154,165,180,.08); }
.pill-running   { color: var(--green);     border-color: rgba(63,185,80,.4);  background: rgba(63,185,80,.10); }
.pill-paused    { color: var(--amber);     border-color: rgba(210,153,34,.4); background: rgba(210,153,34,.10); }
.pill-stopped   { color: var(--text-faint);border-color: var(--border-strong); background: rgba(107,118,132,.10); }
.pill-completed { color: var(--accent);    border-color: rgba(74,158,255,.4); background: rgba(74,158,255,.10); }
.pill-error     { color: var(--red);       border-color: rgba(248,81,73,.4);  background: rgba(248,81,73,.10); }

.pill-running::before {
  content: ''; display: inline-block;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--green); margin-right: 4px;
  vertical-align: middle;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* ── Detail ───────────────────────────────────────────────────────────── */

.detail { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.detail-body-holder { display: contents; }

#detail-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.detail-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.detail-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.detail-title h2 { font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-title .muted { font-size: 12px; font-family: var(--mono); }
.detail-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.detail-actions .sep { width: 1px; height: 18px; background: var(--border-strong); margin: 0 3px; }

.error-banner {
  background: rgba(248,81,73,.09);
  border-bottom: 1px solid rgba(248,81,73,.3);
  color: #ff9d97;
  padding: 9px 18px;
  font-size: 12.5px;
  font-family: var(--mono);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}
.stat { background: var(--bg); padding: 11px 14px; }
.stat .k {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); margin-bottom: 3px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.stat .v { font-size: 18px; font-weight: 600; font-family: var(--mono); letter-spacing: -.02em; }
.stat.hl .v { color: var(--green); }

.config-summary {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
}
.chip {
  font-size: 11px; font-family: var(--mono);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 3px 8px; border-radius: 999px;
}
.chip b { color: var(--text); font-weight: 550; }

/* ── Console ──────────────────────────────────────────────────────────── */

.console-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; gap: 14px; flex-wrap: wrap;
}
.console-head h3 { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); }
.console-tools { display: flex; align-items: center; gap: 10px; }
.console-tools input[type="search"] {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 5px 9px; font-family: var(--mono); font-size: 12px; width: 190px;
}
.console-tools input:focus { outline: none; border-color: var(--accent); }

.console {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg-inset);
  border-top: 1px solid var(--border);
  padding: 10px 0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
}
.log-line { display: flex; gap: 11px; padding: 1px 18px; white-space: pre-wrap; word-break: break-word; }
.log-line:hover { background: rgba(255,255,255,.025); }
.log-time { color: #4c5765; flex-shrink: 0; }
.log-msg  { flex: 1; }
.log-line.warn  .log-msg { color: var(--amber); }
.log-line.error .log-msg { color: #ff9d97; }
.log-line.debug .log-msg { color: var(--text-faint); }
.console-empty { color: var(--text-faint); padding: 18px; font-style: italic; }

/* ── Modal ────────────────────────────────────────────────────────────── */

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.66); backdrop-filter: blur(2px); }
.modal-card {
  position: relative;
  width: 100%; max-width: 560px; max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.modal-card-sm { max-width: 400px; }
/* When the body + footer are wrapped in a <form>, the form has to carry the
   column layout itself or the footer stops sitting at the bottom edge. */
.modal-card form { display: flex; flex-direction: column; min-height: 0; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 15px; font-weight: 650; }
.modal-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-desc { font-size: 12.5px; margin-bottom: 16px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 13px 18px; border-top: 1px solid var(--border);
}
.config-form { margin-top: 6px; }

.script-picker { display: grid; gap: 7px; margin-bottom: 16px; }
.script-option {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; cursor: pointer; background: var(--bg-inset);
  transition: border-color .12s, background .12s;
}
.script-option:hover { border-color: var(--border-strong); }
.script-option.selected { border-color: var(--accent); background: #131c28; }
.script-option .n { font-weight: 600; font-size: 13px; }
.script-option .d { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

/* ── Toast & empty ────────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-size: 13px; z-index: 80;
  box-shadow: 0 8px 26px rgba(0,0,0,.5);
  max-width: 90vw;
}
.toast.err { border-left-color: var(--red); }

.empty { padding: 44px 20px; text-align: center; color: var(--text-dim); }
/* Centred placeholder only while no task is selected; otherwise the detail
   body must stretch so the log console fills the remaining height. */
.detail.empty-detail { display: grid; place-items: center; }
.detail.has-task { display: flex; }

/* ── Scrollbars ───────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2b3440; border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #3a4553; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .detail-actions { width: 100%; }
}
