/* ── Reset / base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --border:    #334155;
  --text:      #f1f5f9;
  --muted:     #94a3b8;
  --accent:    #3b82f6;
  --success:   #10b981;
  --danger:    #ef4444;
  --warn:      #f59e0b;
  --log-bg:    #020617;
  --font: system-ui, -apple-system, sans-serif;
  --mono: 'Menlo', 'Consolas', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-title {
  font-size: 20px;
  font-weight: 600;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.login-error {
  background: rgba(239,68,68,.15);
  border: 1px solid var(--danger);
  border-radius: 6px;
  color: var(--danger);
  padding: 10px 14px;
  font-size: 13px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-left, .header-right { flex: 1; }
.header-right { justify-content: flex-end; }

.btn-start-main, .btn-stop-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 22px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .15s, box-shadow .15s;
  letter-spacing: .01em;
}
.btn-start-main:hover:not(:disabled), .btn-stop-main:hover:not(:disabled) { opacity: .88; }
.btn-start-main:disabled, .btn-stop-main:disabled { opacity: .35; cursor: not-allowed; }

.btn-start-main {
  background: var(--success);
  color: #fff;
  box-shadow: 0 0 0 0 rgba(16,185,129,0);
}
.btn-start-main:not(:disabled) {
  box-shadow: 0 2px 10px rgba(16,185,129,.35);
}
.btn-stop-main {
  background: rgba(239,68,68,.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,.3);
}
.btn-stop-main:not(:disabled) {
  box-shadow: 0 2px 10px rgba(239,68,68,.15);
}

.header-title { font-size: 16px; font-weight: 600; }
.header-meta  { color: var(--muted); font-size: 13px; }

/* ── Status dot ───────────────────────────────────────────────────────────── */
.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
  flex-shrink: 0;
}
.logo-dot.running  { background: var(--success); box-shadow: 0 0 6px var(--success); }
.logo-dot.starting { background: var(--warn); box-shadow: 0 0 6px var(--warn); animation: pulse 1s ease-in-out infinite; }
.logo-dot.stopped  { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

/* ── Status badge ─────────────────────────────────────────────────────────── */
.status-badge {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
}
.status-badge.running  { background: rgba(16,185,129,.15); color: var(--success); }
.status-badge.starting { background: rgba(245,158,11,.15); color: var(--warn); }
.status-badge.stopped  { background: rgba(239,68,68,.15);  color: var(--danger); }

/* ── Main layout ──────────────────────────────────────────────────────────── */
.main { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* ── Card header stat ─────────────────────────────────────────────────────── */
.card-header-stat {
  font-size: 12px;
  font-weight: 500;
  color: var(--success);
  text-transform: none;
  letter-spacing: 0;
  margin-left: auto;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: opacity .15s;
}
.btn:hover    { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary  { background: var(--accent);   color: #fff; }
.btn-success  { background: var(--success);  color: #fff; }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-ghost    { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-full     { width: 100%; }
.btn-icon     { padding: 6px 8px; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 380px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--border); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-desc { font-size: 13px; color: var(--muted); line-height: 1.5; }
.modal-field { display: flex; flex-direction: column; gap: 6px; }
.modal-field label { font-size: 13px; color: var(--muted); }
.modal-field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
}
.modal-field input:focus { border-color: var(--accent); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ── Fields ───────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); }
.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); }

/* ── Content grid ─────────────────────────────────────────────────────────── */
.content-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  align-items: stretch;
}

.content-grid > .card {
  display: flex;
  flex-direction: column;
  max-height: 700px;
}

.content-grid > .card .jobs-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Jobs table ───────────────────────────────────────────────────────────── */
.jobs-scroll {
  overflow-y: auto;
}

.jobs-table { width: 100%; border-collapse: collapse; }
.jobs-table thead { position: sticky; top: 0; z-index: 1; }
.jobs-table th {
  text-align: left;
  padding: 10px 18px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.jobs-table td {
  padding: 10px 18px;
  border-bottom: 1px solid rgba(51,65,85,.5);
  font-size: 13px;
}
.jobs-table tr:last-child td { border-bottom: none; }
.jobs-table td.empty { color: var(--muted); text-align: center; padding: 24px; }

/* ── Log viewer ───────────────────────────────────────────────────────────── */
.log-viewer {
  background: var(--log-bg);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  flex: 1;
  min-height: 520px;
  overflow-y: auto;
  padding: 12px 16px;
}

.log-line        { color: #94a3b8; white-space: pre-wrap; word-break: break-all; }
.log-line.warn   { color: var(--warn); }
.log-line.error  { color: var(--danger); }

/* ── Scroll toggle ────────────────────────────────────────────────────────── */
.scroll-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}

/* ── Settings card ────────────────────────────────────────────────────────── */
.settings-card { margin-bottom: 20px; }

.settings-body { padding: 0 18px 18px; }

.settings-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; }

.settings-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.restart-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--warn);
  text-transform: none;
  letter-spacing: 0;
}

.experimental-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--warn);
  background: rgba(245,158,11,.12);
  border: 1px solid rgba(245,158,11,.3);
  border-radius: 4px;
  padding: 1px 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
  vertical-align: middle;
  margin-left: 6px;
}

.setting { margin-bottom: 18px; }
.setting:last-child { margin-bottom: 0; }

.setting-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-bottom: 4px;
}

.setting-label { font-size: 13px; font-weight: 500; }
.setting-desc  { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 0 0 0; }

/* ── Category grid ────────────────────────────────────────────────────────── */
.category-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.cat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s, border-color .15s;
}
.cat-btn::before {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
.cat-btn.active {
  background: rgba(59,130,246,.1);
  border-color: var(--accent);
  color: var(--text);
}
.cat-btn.active::before {
  background: var(--accent);
  border-color: var(--accent);
}

@media (max-width: 900px) {
  .category-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Toggle switch ────────────────────────────────────────────────────────── */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Schedule details (collapsible) ───────────────────────────────────────── */
.schedule-details {
  margin-top: 14px;
  padding: 16px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: none;
}
.schedule-details.visible { display: block; }

/* ── Time row ─────────────────────────────────────────────────────────────── */
.time-row {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  margin-bottom: 0;
}
.time-row .field { flex: 0 0 auto; }
.time-row input[type="time"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  padding: 7px 10px;
  outline: none;
  transition: border-color .15s;
  color-scheme: dark;
}
.time-row input[type="time"]:focus { border-color: var(--accent); }

/* ── Day picker ───────────────────────────────────────────────────────────── */
.day-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.day-btn {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  transition: background .15s, color .15s, border-color .15s;
}
.day-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Refresh delay input ──────────────────────────────────────────────────── */
.poll-input {
  width: 72px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  padding: 7px 10px;
  outline: none;
  text-align: center;
  flex-shrink: 0;
  transition: border-color .15s;
}
.poll-input:focus { border-color: var(--accent); }
.poll-presets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.poll-preset {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  transition: background .15s, color .15s, border-color .15s;
}
.poll-preset.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Toast notifications ──────────────────────────────────────────────────── */
.settings-toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 100;
}
.settings-toast.visible {
  opacity: 1;
  transform: translateY(0);
}
.settings-toast.success {
  background: #064e35;
  border: 1px solid var(--success);
  color: #6ee7b7;
}
.settings-toast.error {
  background: #4c1010;
  border: 1px solid var(--danger);
  color: #fca5a5;
}
.settings-toast.warn {
  background: #4a2d08;
  border: 1px solid var(--warn);
  color: #fcd34d;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .content-grid   { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  /* Header: status row on top, controls below */
  .header {
    height: auto;
    flex-wrap: wrap;
    padding: 10px 16px;
    gap: 8px;
  }
  .header-left  { flex: 1; min-width: 0; }
  .header-right { flex: 0; }
  .header-meta  { display: none; } /* uptime hidden — saves space */
  .header-center {
    order: 3;
    flex: 0 0 100%;
    gap: 8px;
  }
  .btn-start-main,
  .btn-stop-main,
  #btn-restart {
    flex: 1;
    justify-content: center;
    padding: 8px 10px;
    font-size: 13px;
  }

  /* Main layout */
  .main { padding: 12px; }

  /* Log viewer shorter on phones */
  .log-viewer { min-height: 260px; }

  /* Category grid single column on small phones */
  .category-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 400px) {
  .category-grid { grid-template-columns: 1fr; }
  .status-badge  { display: none; }
}

/* Login page on small screens */
@media (max-width: 480px) {
  .login-card { padding: 28px 20px; }
}

/* Toast on mobile */
@media (max-width: 600px) {
  .settings-toast {
    left: 12px;
    right: 12px;
    bottom: 16px;
    text-align: center;
  }
}
