:root {
  --bg: #0b0f14;
  --bg-elevated: #121821;
  --panel: #151c27;
  --card: #1a2330;
  --ink: #e8eef7;
  --muted: #8b98ab;
  --line: rgba(232, 238, 247, 0.1);
  --accent: #3dd6c6;
  --accent-ink: #041512;
  --accent-2: #7aa2ff;
  --ok: #3ecf8e;
  --bad: #ff6b6b;
  --warn: #f0b429;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 500px at 0% -10%, rgba(61, 214, 198, 0.12), transparent 55%),
    radial-gradient(700px 400px at 100% 0%, rgba(122, 162, 255, 0.1), transparent 50%),
    linear-gradient(180deg, #0e141c 0%, var(--bg) 45%, #0a0e13 100%);
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(232, 238, 247, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 238, 247, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5), transparent 80%);
}

.top {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1.5rem;
  padding: 2.25rem clamp(1.25rem, 4vw, 3rem) 1.25rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
  font-family: var(--mono);
}

.brand {
  margin: 0;
  font-size: clamp(2rem, 4.5vw, 2.85rem);
  line-height: 1;
  letter-spacing: -0.04em;
  font-weight: 650;
}

.tagline {
  margin: 0.6rem 0 0;
  max-width: 28rem;
  color: var(--muted);
  font-size: 0.98rem;
}

.top-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

main {
  position: relative;
  display: grid;
  gap: 1.1rem;
  padding: 0 clamp(1.25rem, 4vw, 3rem) 3rem;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem clamp(1rem, 2vw, 1.4rem) 1.35rem;
  overflow: hidden;
  animation: rise 0.45s ease both;
}

.panel:nth-child(2) { animation-delay: 0.05s; }
.panel:nth-child(3) { animation-delay: 0.1s; }
.panel:nth-child(4) { animation-delay: 0.15s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.panel-head h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.panel-head p {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.panel-head.row {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

.service-grid,
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
  align-items: stretch;
}

.service-card,
.config-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  background: var(--card);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.service-card.is-disabled,
.config-card.is-disabled {
  opacity: 0.42;
  pointer-events: none;
  user-select: none;
  filter: grayscale(0.35);
}

.disabled-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 600;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: rgba(232, 238, 247, 0.08);
  border: 1px solid var(--line);
  vertical-align: middle;
}

.service-card h3,
.config-card h3 {
  margin: 0;
  text-transform: capitalize;
  font-size: 1.05rem;
  font-weight: 650;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.55rem;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--mono);
  background: rgba(232, 238, 247, 0.06);
  width: fit-content;
}

.status-pill.running { color: var(--ok); background: rgba(62, 207, 142, 0.12); }
.status-pill.stopped { color: var(--bad); background: rgba(255, 107, 107, 0.12); }
.status-pill.other { color: var(--warn); background: rgba(240, 180, 41, 0.12); }

.dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.9rem;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn-danger {
  background: rgba(255, 107, 107, 0.12);
  color: var(--bad);
  border-color: rgba(255, 107, 107, 0.22);
}

.btn-run {
  background: rgba(122, 162, 255, 0.14);
  color: var(--accent-2);
  border-color: rgba(122, 162, 255, 0.28);
}

.config-card form {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.85rem;
  min-width: 0;
  width: 100%;
}

.field {
  display: grid;
  gap: 0.28rem;
  min-width: 0;
}

.field label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-family: var(--mono);
}

.field input,
.field select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-size: 0.92rem;
  background: var(--bg-elevated);
  color: var(--ink);
}

.field input:focus,
.field select:focus {
  outline: 2px solid rgba(61, 214, 198, 0.35);
  outline-offset: 1px;
  border-color: rgba(61, 214, 198, 0.5);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  min-width: 0;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: var(--ink);
}

.check input {
  accent-color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 1rem;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 560px;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  font-family: var(--mono);
}

td a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  word-break: break-word;
}

td a:hover { text-decoration: underline; }

.muted { color: var(--muted); }

.badge-new {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: rgba(61, 214, 198, 0.14);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--mono);
}

.results-table {
  min-width: 980px;
}

.thumb-cell {
  width: 64px;
}

.result-thumb {
  width: 56px;
  height: 42px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  background: #0d131b;
}

.result-thumb-empty {
  border: 1px solid var(--line);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.results-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.icon-btn {
  appearance: none;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 107, 107, 0.28);
  background: rgba(255, 107, 107, 0.1);
  color: var(--bad);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255, 107, 107, 0.18);
  border-color: rgba(255, 107, 107, 0.45);
}

.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  max-width: min(420px, calc(100vw - 2rem));
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: #1f2a38;
  border: 1px solid var(--line);
  color: var(--ink);
  box-shadow: var(--shadow);
  z-index: 20;
  animation: rise 0.25s ease both;
}

.toast.error {
  background: rgba(80, 24, 28, 0.95);
  border-color: rgba(255, 107, 107, 0.35);
  color: #ffd4d4;
}

.toast.ok {
  background: rgba(18, 56, 42, 0.95);
  border-color: rgba(62, 207, 142, 0.35);
  color: #c9f5df;
}

.countdown {
  margin-top: 0.65rem;
  font-size: 0.82rem;
  font-family: var(--mono);
  color: var(--muted);
}

.countdown strong {
  color: var(--accent);
  font-weight: 600;
}

.label-row {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.check {
  flex-wrap: wrap;
}

.status-fieldset {
  margin: 0;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 0;
}

.status-fieldset legend {
  padding: 0 0.25rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-family: var(--mono);
}

.status-options {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.field-hint {
  margin: 0.45rem 0 0;
  font-size: 0.8rem;
}

.suggest-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.45rem;
}

.suggest-chip {
  border: 1px solid var(--line);
  background: rgba(232, 238, 247, 0.05);
  color: var(--text);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.78rem;
  font-family: var(--mono);
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.suggest-chip:hover {
  border-color: rgba(61, 214, 198, 0.45);
}

.suggest-chip.is-active {
  border-color: rgba(61, 214, 198, 0.65);
  background: rgba(61, 214, 198, 0.14);
  color: var(--accent, #3dd6c6);
}

.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.6rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 12, 18, 0.55);
  cursor: text;
}

.tag-input:focus-within {
  border-color: rgba(61, 214, 198, 0.55);
  box-shadow: 0 0 0 2px rgba(61, 214, 198, 0.12);
}

.tag-input.is-invalid {
  border-color: rgba(255, 107, 107, 0.45);
}

.tag-input.is-invalid:focus-within {
  border-color: rgba(255, 107, 107, 0.65);
  box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.12);
}

.tag-list {
  display: contents;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
  padding: 0.2rem 0.3rem 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(61, 214, 198, 0.12);
  border: 1px solid rgba(61, 214, 198, 0.28);
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1.2;
}

.tag-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-remove {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.tag-remove:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}

.tag-draft {
  flex: 1 1 8rem;
  min-width: 7rem;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 0.25rem 0.15rem !important;
  margin: 0;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.warn-hint {
  color: #f0c674;
}

.form-banner {
  margin: 0.15rem 0 0.35rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.4;
}

.warn-banner {
  color: #f0c674;
  background: rgba(240, 198, 116, 0.1);
  border: 1px solid rgba(240, 198, 116, 0.28);
}

.info-btn {
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(232, 238, 247, 0.06);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  flex: 0 0 auto;
}

.info-btn:hover {
  color: var(--accent);
  border-color: rgba(61, 214, 198, 0.45);
}

.field-tip {
  position: absolute;
  z-index: 40;
  max-width: min(340px, calc(100vw - 24px));
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  background: #1f2a38;
  border: 1px solid rgba(61, 214, 198, 0.28);
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.45;
  box-shadow: var(--shadow);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.form-actions .btn {
  width: 100%;
}

.preview-error { color: var(--bad); margin: 0; }

body.modal-open { overflow: hidden; }

.modal[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 12, 0.72);
  backdrop-filter: blur(6px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(1100px, calc(100vw - 2rem));
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  animation: rise 0.25s ease both;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.25rem;
  text-transform: capitalize;
}

.modal-head p {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
}

.modal-body {
  padding: 1.1rem 1.25rem 1.35rem;
  overflow: auto;
}

.preview-loading,
.preview-empty {
  padding: 2.5rem 1rem;
  text-align: center;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.9rem;
}

.preview-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--card);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.preview-card:hover {
  transform: translateY(-2px);
  border-color: rgba(61, 214, 198, 0.4);
}

.preview-thumb {
  aspect-ratio: 16 / 11;
  background: #0d131b;
  overflow: hidden;
}

.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-thumb-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-family: var(--mono);
}

.preview-card-body {
  padding: 0.75rem 0.8rem 0.9rem;
  display: grid;
  gap: 0.3rem;
}

.preview-card-body h4 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.25;
  word-break: break-word;
}

.preview-card-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.modal-dialog-sm {
  width: min(520px, calc(100vw - 2rem));
}

.wipe-modal-body {
  display: grid;
  gap: 0.75rem;
}

.wipe-modal-body p {
  margin: 0;
  line-height: 1.45;
}

.wipe-warn {
  color: #ffb4b4;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.28);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
}

.wipe-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 0.35rem;
  flex-wrap: wrap;
}

.preview-scope-actions {
  display: grid;
  gap: 0.55rem;
}

.preview-scope-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  text-align: left;
  width: 100%;
  padding: 0.75rem 0.9rem;
  white-space: normal;
  height: auto;
}

.preview-scope-btn strong {
  font-size: 0.95rem;
}

.preview-scope-btn .muted {
  font-size: 0.78rem;
  font-weight: 400;
}

@media (max-width: 900px) {
  .field-row {
    grid-template-columns: 1fr;
  }
  .form-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .top { flex-direction: column; align-items: start; }
  .panel-head.row { flex-direction: column; align-items: start; }
  .modal-dialog { max-height: 92vh; }
}
