@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap");

:root {
  color-scheme: dark;
  --bg: #06080c;
  --surface: #0c0f15;
  --surface-2: #10141c;
  --surface-3: #161b26;
  --panel: rgba(10, 13, 20, 0.92);
  --panel-strong: #0e1219;
  --text: #cdd6e0;
  --text-strong: #f0f4f8;
  --muted: #6b7a8d;
  --line: rgba(212, 175, 55, 0.12);
  --line-strong: rgba(212, 175, 55, 0.22);
  --gold: #d4af37;
  --gold-light: #f5d76e;
  --gold-dim: #a68a2a;
  --gold-glow: rgba(212, 175, 55, 0.35);
  --emerald: #00c9a7;
  --emerald-dim: rgba(0, 201, 167, 0.15);
  --red: #e74c5e;
  --red-dim: rgba(231, 76, 94, 0.14);
  --amber: #f0a840;
  --amber-dim: rgba(240, 168, 64, 0.14);
  --blue: #4ea8de;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  --shadow-gold: 0 0 40px rgba(212, 175, 55, 0.08);
  --radius: 10px;
  --radius-sm: 7px;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(212, 175, 55, 0.06), transparent 50%),
    radial-gradient(ellipse at 80% 0%, rgba(78, 168, 222, 0.04), transparent 45%),
    radial-gradient(ellipse at 50% 100%, rgba(212, 175, 55, 0.03), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(180deg, rgba(212, 175, 55, 0.04) 0%, transparent 18%),
    linear-gradient(rgba(212, 175, 55, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(212, 175, 55, 0.014) 1px, transparent 1px);
  background-size: auto, 60px 60px, 60px 60px;
  opacity: 0.7;
}

::selection {
  background: rgba(212, 175, 55, 0.25);
  color: var(--text-strong);
}

.shell {
  width: min(1340px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 24px 0 52px;
}

/* ───── LOGIN ───── */

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  display: grid;
  width: min(440px, 100%);
  gap: 20px;
  border: 1px solid rgba(212, 175, 55, 0.18);
  border-radius: 14px;
  padding: 36px 32px;
  background:
    linear-gradient(180deg, rgba(212, 175, 55, 0.03), transparent 40%),
    rgba(8, 10, 16, 0.96);
  box-shadow: var(--shadow), var(--shadow-gold);
}

.login-panel::before {
  display: block;
  content: "";
  height: 2px;
  margin: -36px -32px 0;
  border-radius: 14px 14px 0 0;
  background: linear-gradient(90deg, transparent, var(--gold) 30%, var(--gold-light) 50%, var(--gold) 70%, transparent);
  opacity: 0.7;
}

.login-panel h1 {
  font-size: 32px;
  letter-spacing: -0.5px;
}

.login-panel p {
  margin-top: 4px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 2.5px;
  text-transform: uppercase;
}

/* ───── TOPBAR ───── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(200px, 0.7fr) minmax(440px, 1.4fr) minmax(200px, 0.64fr);
  gap: 18px;
  align-items: end;
  margin-bottom: 22px;
  padding: 16px 20px;
  border: 1px solid rgba(212, 175, 55, 0.14);
  border-radius: 12px;
  background: rgba(8, 10, 16, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(1.3);
}

.topbar::before {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, var(--gold) 20%, var(--gold-light) 50%, var(--gold) 80%, transparent);
  opacity: 0.5;
  border-radius: 12px 12px 0 0;
}

h1, h2, p { margin: 0; }

h1 {
  color: var(--text-strong);
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.3px;
}

h2 {
  color: var(--text-strong);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.1px;
}

.topbar p {
  margin-top: 4px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.panel-title span,
.empty,
.meta,
.hint {
  color: var(--muted);
  font-size: 13px;
}

.hint {
  min-height: 20px;
  margin: 2px 0 12px;
  color: var(--gold-light);
  font-size: 13px;
}

/* ───── TABS ───── */

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(212, 175, 55, 0.12);
  border-radius: var(--radius);
  background: rgba(12, 15, 21, 0.9);
}

.user-switcher {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.user-switcher strong {
  display: block;
  margin-top: 4px;
  color: var(--text-strong);
  font-size: 14px;
  overflow-wrap: anywhere;
}

/* ───── BUTTONS ───── */

button {
  min-height: 38px;
  border: 1px solid rgba(212, 175, 55, 0.18);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  background: rgba(16, 20, 28, 0.95);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0;
  transition: all 180ms ease;
}

button:hover {
  border-color: var(--gold);
  background: rgba(212, 175, 55, 0.08);
  color: var(--gold-light);
  box-shadow: 0 0 20px rgba(212, 175, 55, 0.06);
}

button:active {
  transform: translateY(1px);
}

button.danger {
  border-color: rgba(231, 76, 94, 0.35);
  color: #f5a0aa;
}

button.danger:hover {
  border-color: var(--red);
  background: var(--red-dim);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

a.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid rgba(212, 175, 55, 0.5);
  border-radius: var(--radius-sm);
  padding: 0 16px;
  color: #0a0c10;
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 12px rgba(212, 175, 55, 0.2);
  transition: all 180ms ease;
}

a.download-button:hover {
  background: linear-gradient(180deg, #ffe08a, var(--gold-light));
  box-shadow: 0 4px 20px rgba(212, 175, 55, 0.35);
}

.tab {
  min-height: 36px;
  padding: 0 10px;
  color: var(--muted);
  font-weight: 600;
  border-color: transparent;
  background: transparent;
}

.tab.active,
.primary {
  border-color: rgba(212, 175, 55, 0.6);
  background: linear-gradient(180deg, var(--gold), var(--gold-dim));
  color: #0a0c10;
  font-weight: 800;
  box-shadow: 0 0 0 1px rgba(245, 215, 110, 0.1), 0 0 24px rgba(212, 175, 55, 0.15);
}

.primary:hover {
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  box-shadow: 0 0 32px rgba(212, 175, 55, 0.25);
}

/* ───── VIEWS / LAYOUT ───── */

.view { display: none; }

.view.active {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(340px, 0.82fr);
  gap: 20px;
}

#system.view.active { display: block; }

#history.view.active,
#reports.view.active {
  display: grid;
  grid-template-columns: minmax(300px, 0.86fr) minmax(0, 1.14fr);
  gap: 20px;
}

#admin-users.view.active {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.admin-user-list-panel { grid-column: 1 / -1; }

/* ───── PANELS ───── */

.panel {
  position: relative;
  overflow: hidden;
  min-width: 0;
  border: 1px solid rgba(212, 175, 55, 0.1);
  border-radius: 12px;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(212, 175, 55, 0.015), transparent 30%),
    var(--panel);
  box-shadow: var(--shadow);
}

.panel::before {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(212, 175, 55, 0.4), rgba(245, 215, 110, 0.25), transparent);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-title h2 {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-title h2::before {
  display: inline-block;
  width: 3px;
  height: 18px;
  border-radius: 2px;
  content: "";
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.4);
}

/* ───── FORMS ───── */

.grid {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: #9aa8b8;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(212, 175, 55, 0.1);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: rgba(6, 8, 12, 0.8);
  color: var(--text-strong);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(212, 175, 55, 0.4);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.08), 0 0 16px rgba(212, 175, 55, 0.05);
}

input::placeholder,
textarea::placeholder {
  color: #4a5568;
}

textarea { resize: vertical; }

fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  border: 1px solid rgba(212, 175, 55, 0.08);
  border-radius: var(--radius);
  margin: 0 0 14px;
  padding: 14px;
  background: rgba(6, 8, 12, 0.4);
}

legend {
  padding: 0 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

fieldset label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  text-transform: none;
  font-size: 13px;
}

fieldset input {
  width: auto;
  min-height: auto;
  accent-color: var(--gold);
}

/* ───── ADVANCED SETTINGS ───── */

.advanced-settings {
  overflow: hidden;
  border: 1px solid rgba(212, 175, 55, 0.08);
  border-radius: var(--radius);
  margin: 0 0 14px;
  background: rgba(6, 8, 12, 0.4);
}

.advanced-settings[open] {
  border-color: rgba(212, 175, 55, 0.2);
}

.advanced-settings summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.advanced-settings summary::-webkit-details-marker { display: none; }

.advanced-settings summary::after {
  content: "▾";
  display: inline-grid;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(212, 175, 55, 0.15);
  border-radius: 999px;
  color: var(--gold);
  font-size: 11px;
  transition: transform 0.2s ease;
}

.advanced-settings[open] summary::after {
  transform: rotate(180deg);
}

.advanced-settings-note {
  margin: 0;
  padding: 0 14px 10px;
  color: var(--muted);
  font-size: 13px;
}

.advanced-settings .grid { padding: 0 14px 14px; }

/* ───── LISTS ───── */

.list,
.settings {
  display: grid;
  gap: 10px;
}

.settings { align-content: start; }

/* ───── SETTINGS GROUPS ───── */

.settings-group {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(212, 175, 55, 0.1);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(212, 175, 55, 0.02), transparent 40%),
    rgba(10, 13, 20, 0.8);
}

.settings-group[open] { border-color: rgba(212, 175, 55, 0.22); }

.settings-group-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.settings-group-header::-webkit-details-marker { display: none; }

.settings-group-copy { display: grid; min-width: 0; gap: 4px; }

.settings-group-title {
  color: var(--text-strong);
  font-weight: 800;
}

.settings-group-description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.settings-group-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.settings-group-chevron {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(212, 175, 55, 0.15);
  border-radius: 999px;
  color: var(--gold);
  font-size: 11px;
  transition: transform 0.2s ease;
}

.settings-group[open] .settings-group-chevron { transform: rotate(180deg); }

.settings-group-body {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

/* ───── CARDS ───── */

.job,
.setting,
.event,
.report {
  min-width: 0;
  border: 1px solid rgba(212, 175, 55, 0.08);
  border-radius: var(--radius);
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent),
    rgba(10, 13, 20, 0.85);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.job {
  display: grid;
  gap: 8px;
  width: 100%;
  text-align: left;
}

.job:hover {
  border-color: rgba(212, 175, 55, 0.2);
  box-shadow: 0 0 20px rgba(212, 175, 55, 0.04);
}

.job.selected {
  border-color: var(--gold);
  box-shadow: inset 3px 0 0 var(--gold), 0 0 28px rgba(212, 175, 55, 0.08);
}

.job-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-strong);
  font-weight: 800;
}

.job-title > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.meta { overflow-wrap: anywhere; }

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.user-row-actions { display: flex; gap: 8px; }

.report-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

/* ───── DETAILS GRID ───── */

.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.details-grid > div {
  min-width: 0;
  border: 1px solid rgba(212, 175, 55, 0.06);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: rgba(6, 8, 12, 0.6);
}

.details-grid dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.details-grid dd {
  margin: 4px 0 0;
  color: var(--text-strong);
  font-weight: 700;
  font-size: 14px;
}

/* ───── BADGES ───── */

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid rgba(107, 122, 141, 0.2);
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(107, 122, 141, 0.08);
  color: #9aa8b8;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.3px;
}

.badge.completed {
  border-color: rgba(0, 201, 167, 0.3);
  background: var(--emerald-dim);
  color: #7aefdb;
}

.badge.failed {
  border-color: rgba(231, 76, 94, 0.3);
  background: var(--red-dim);
  color: #f5a0aa;
}

.badge.running,
.badge.queued {
  border-color: rgba(240, 168, 64, 0.3);
  background: var(--amber-dim);
  color: #ffd08a;
}

.badge.stale,
.runtime-warning {
  border-color: rgba(231, 76, 94, 0.3);
  background: var(--red-dim);
  color: #f5a0aa;
}

.runtime-warning {
  border: 1px solid rgba(231, 76, 94, 0.3);
  border-radius: var(--radius-sm);
  margin: 10px 0;
  padding: 10px 12px;
  font-weight: 700;
}

.runtime-grid dd { font-size: 13px; }

/* ───── JOB DETAILS COLLAPSIBLE ───── */

.job-details {
  border: 1px solid rgba(212, 175, 55, 0.08);
  border-radius: var(--radius);
  margin: 12px 0 0;
  background: rgba(6, 8, 12, 0.4);
}

.job-details[open] { border-color: rgba(212, 175, 55, 0.2); }

.job-details-toggle {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.job-details-toggle::-webkit-details-marker { display: none; }

.job-details-toggle::after {
  content: "▾";
  display: inline-grid;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid rgba(212, 175, 55, 0.15);
  border-radius: 999px;
  color: var(--gold);
  font-size: 10px;
  transition: transform 0.2s ease;
}

.job-details[open] .job-details-toggle::after { transform: rotate(180deg); }

.job-details-body {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

.job-details-body .details-grid { margin: 0; }
.job-details-body .event:first-child { margin-top: 0; }

/* ───── MARKDOWN PREVIEW ───── */

.markdown-preview {
  margin-top: 14px;
  max-height: 620px;
  overflow: auto;
  border: 1px solid rgba(212, 175, 55, 0.08);
  border-radius: var(--radius);
  padding: 20px;
  background: rgba(6, 8, 12, 0.7);
}

body.report-preview-expanded { overflow: hidden; }

.report-preview-panel.expanded {
  position: fixed;
  inset: 16px;
  z-index: 50;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: auto;
  height: auto;
  padding: 20px;
  background: rgba(6, 8, 12, 0.98);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}

.report-preview-panel.expanded #report-detail { min-height: 0; overflow: hidden; }

.report-preview-panel.expanded .markdown-preview {
  max-height: calc(100vh - 190px);
  height: calc(100vh - 190px);
}

body.report-preview-expanded::after {
  position: fixed;
  inset: 0;
  z-index: 40;
  content: "";
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
}

.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5 {
  margin: 20px 0 8px;
  color: var(--text-strong);
  line-height: 1.3;
}

.markdown-preview h2:first-child,
.markdown-preview h3:first-child,
.markdown-preview h4:first-child,
.markdown-preview h5:first-child { margin-top: 0; }

.markdown-preview p,
.markdown-preview li {
  color: #b8c4d0;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.markdown-preview p { margin: 0 0 12px; }

.markdown-preview ul {
  margin: 0 0 12px 20px;
  padding: 0;
}

.markdown-preview strong {
  color: var(--gold-light);
}

pre {
  max-height: 360px;
  overflow: auto;
  border: 1px solid rgba(212, 175, 55, 0.06);
  border-radius: var(--radius);
  padding: 14px;
  background: #05070c;
  color: #c8d4e0;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
}

/* ───── MODAL ───── */

body.modal-open { overflow: hidden; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
}

.modal-overlay.hidden { display: none; }

.modal-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(880px, 100%);
  max-height: calc(100vh - 48px);
  border: 1px solid rgba(212, 175, 55, 0.18);
  border-radius: 14px;
  background: rgba(8, 10, 16, 0.97);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), var(--shadow-gold);
  overflow: hidden;
}

.modal-panel::before {
  display: block;
  content: "";
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold) 30%, var(--gold-light) 50%, var(--gold) 70%, transparent);
  opacity: 0.5;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid rgba(212, 175, 55, 0.1);
}

.modal-body {
  padding: 22px;
  overflow-y: auto;
}

.modal-body .markdown-preview {
  max-height: calc(100vh - 240px);
}

/* ───── RESPONSIVE ───── */

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .shell {
    width: min(100vw - 20px, 720px);
    padding-top: 10px;
  }

  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .view.active,
  #history.view.active,
  #reports.view.active,
  #admin-users.view.active,
  .grid.two,
  .details-grid,
  .settings-group-header,
  .user-row {
    grid-template-columns: 1fr;
  }

  .settings-group-info {
    justify-content: space-between;
    white-space: normal;
  }

  .admin-user-list-panel { grid-column: auto; }

  .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab { min-height: 40px; }
}
