
:root {
  --bg: #111;
  --panel: #1d1f21;
  --panel2: #151719;
  --header: #151515;
  --text: #eee;
  --muted: #aaa;
  --border: #333;
  --table-head: #2b3138;
  --row-even: #2b3442;
  --row-hover: #354052;
  --input-bg: #111;
  --link: #58a6ff;
}

body.light {
  --bg: #f4f6f8;
  --panel: #f8fafc;
  --panel2: #f1f5f9;
  --header: #ffffff;
  --text: #111827;
  --muted: #334155;
  --border: #94a3b8;
  --table-head: #dbeafe;
  --row-even: #e6edf7;
  --row-hover: #dbeafe;
  --input-bg: #ffffff;
  --link: #0b63ce;
}

body { margin: 0; background: var(--bg); color: var(--text); font-family: Arial, sans-serif; }
header { padding: 18px 24px; border-bottom: 1px solid var(--border); background: var(--header); }
h1 { margin: 0; font-size: 28px; }
.header-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.theme-toggle { white-space: nowrap; }
.sub { color: var(--muted); margin-top: 6px; }
main { padding: 20px 24px; display: grid; gap: 18px; }
section { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
h2 { margin: 0 0 12px; font-size: 20px; }
.table-wrap { max-height: none; overflow: visible; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: var(--table-head); }
.sticky-table thead th { position: sticky; top: 0; z-index: 4; background: var(--table-head); }
tbody tr:nth-child(even):not(.backup-detail-row) td { background: var(--row-even); }
tr:hover td { background: var(--row-hover); }
a { color: var(--link); text-decoration: none; }
button { background: #2563eb; color: white; border: none; padding: 7px 11px; border-radius: 5px; cursor: pointer; }
button:hover { filter: brightness(1.1); }
button.danger { background: #b91c1c; }
button.secondary { background: #444; }
button.disabled, button:disabled { background: #4b5563; color: #aaa; cursor: not-allowed; filter: none; }
input, select { background: var(--input-bg); color: var(--text); border: 1px solid #555; padding: 8px; border-radius: 5px; }
input.search { min-width: 280px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.controls { gap: 8px; }
.status-running, .fresh, .job-completed, .remote-ok { color: #22c55e; font-weight: bold; }
.status-stopped, .old, .job-failed, .remote-bad { color: #ef4444; font-weight: bold; }
.aging, .job-running { color: #facc15; font-weight: bold; }
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid transparent;
}
.status-pill.running {
  background: #0f3b22;
  color: #6ee7a8;
  border-color: #198754;
}
.status-pill.stopped {
  background: #4c1111;
  color: #fca5a5;
  border-color: #dc2626;
}
.status-pill.busy {
  background: #4a3b00;
  color: #fde68a;
  border-color: #ca8a04;
}
.status-pill.unknown {
  background: #374151;
  color: #d1d5db;
  border-color: #6b7280;
}
body.light .status-pill.running {
  background: #dcfce7;
  color: #166534;
  border-color: #22c55e;
}
body.light .status-pill.stopped {
  background: #fee2e2;
  color: #991b1b;
  border-color: #ef4444;
}
body.light .status-pill.busy {
  background: #fef3c7;
  color: #92400e;
  border-color: #f59e0b;
}
body.light .status-pill.unknown {
  background: #e5e7eb;
  color: #374151;
  border-color: #9ca3af;
}
.message { white-space: pre-wrap; color: #facc15; }
.muted { color: var(--muted); }
.small { font-size: 12px; color: #bbb; }
.kind-icon { opacity: 0.9; margin-right: 6px; }
.protection-pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 9px; font-weight: 800; font-size: 12px; }
.protection-today { background: #0f3b22; color: #6ee7a8; border: 1px solid #198754; }
.protection-recent { background: #5f4700; color: #ffd84d; border: 1px solid #c89600; }
.protection-stale { background: #5c2e00; color: #fdba74; border: 1px solid #f97316; }
.protection-none { background: #4c1111; color: #fca5a5; border: 1px solid #dc2626; }
.protection-failed { background: #4c1111; color: #fca5a5; border: 1px solid #dc2626; }
.job-chip { display: inline-block; border-radius: 999px; padding: 3px 8px; background: #3a2f00; color: #facc15; font-weight: 800; }
.job-chip.running { animation: pulse 1.4s infinite; }
.job-chip.completed { background: #0f3b22; color: #6ee7a8; }
.job-chip.failed { background: #4c1111; color: #fca5a5; }
@keyframes pulse { 0% { opacity: 0.55; } 50% { opacity: 1; } 100% { opacity: 0.55; } }
.backup-detail-row td { padding: 0 !important; background: #11161d !important; border-top: none; }
.backup-detail-wrap { padding: 12px 18px; border-left: 3px solid #2d74ff; background: #11161d; }
.backup-detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; flex-wrap: wrap; gap: 10px; }
.backup-detail-title { font-weight: 700; color: #d7e3ff; }
.backup-detail-meta { color: #8fa7c7; font-size: 12px; }
.backup-detail-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.backup-detail-controls input, .backup-detail-controls select { min-width: 180px; }
.backup-detail-controls button { white-space: nowrap; }
.collapse-button { background: #374151; padding: 3px 8px; margin-right: 8px; }
.badge { display: inline-block; background: #374151; color: #ddd; border-radius: 999px; padding: 2px 8px; font-size: 12px; margin-left: 8px; }
.inline-action { margin-left: 8px; }
.icon-button-group { display: flex; gap: 6px; flex-wrap: wrap; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-top: 12px; }
.stat-card { background: var(--panel2); border: 1px solid var(--border); border-radius: 6px; padding: 10px; }
.stat-label { font-size: 13px; margin-bottom: 4px; font-weight: 800; }
.stat-value {
  font-size: 17px;
  font-weight: 900;
  line-height: 1.2;
}
.remote-details { margin-top: 10px; }
.remote-details summary { cursor: pointer; color: #ddd; font-weight: bold; }
.remote-health-grid { margin-top: 10px; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.remote-card { background: #151719; border: 1px solid #333; border-radius: 8px; padding: 10px; }
.remote-card.offline { border-color: #7f1d1d; }
.remote-summary { display: flex; flex-direction: column; gap: 4px; }
.remote-summary-main { font-size: 14px; font-weight: 700; }
.remote-summary-sub { font-size: 12px; color: #bbb; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable::after { content: ' ↕'; color: #8fa7c7; font-size: 11px; opacity: 0.75; }
th.sortable.sort-asc,
th.sortable.sort-desc {
  color: #58a6ff;
}
th.sortable.sort-asc::after { content: ' ▲'; color: #58a6ff; opacity: 1; font-weight: 900; }
th.sortable.sort-desc::after { content: ' ▼'; color: #58a6ff; opacity: 1; font-weight: 900; }
th.sortable:hover { background: #30363d; color: #ffffff; }
body.light th.sortable.sort-asc,
body.light th.sortable.sort-desc {
  color: #0b63ce;
}
.sticky-table thead th {
  border-top: 1px solid #3b4652;
  border-bottom: 2px solid #58a6ff;
  box-shadow: 0 3px 12px rgba(0,0,0,0.45);
}
.sticky-table thead th {
  border-bottom-width: 3px;
}

body.light .sticky-table thead th {
  background: #cfe3ff;
  border-top: 1px solid #8bbcff;
  border-bottom: 4px solid #0b63ce;
  color: #0f172a;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28);
}

body.light th.sortable::after {
  color: #2563eb;
  opacity: 0.95;
}

body.light th.sortable.sort-asc,
body.light th.sortable.sort-desc {
  color: #003f91;
  background: #bfdbfe;
}


body.light .small,
body.light .muted,
body.light .stat-card .small,
body.light summary,
body.light .sub {
  color: #334155 !important;
}

body.light .stat-card {
  background: #f8fafc;
  border-color: #94a3b8;
  color: #0f172a;
}

body.light .remote-card {
  background: #f8fafc;
  border: 1px solid #94a3b8;
  color: #0f172a;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.10);
}

body.light .remote-card .remote-ok,
body.light .remote-card .remote-bad {
  font-weight: 800;
}

body.light .remote-card .small,
body.light .remote-card .muted {
  color: #334155 !important;
}

body.light .remote-card strong,
body.light .remote-card b {
  color: #0f172a;
}

body.light #lastRefreshTime {
  color: #475569 !important;
}

body.light .backup-detail-row td {
  background: #f8fafc;
  color: #0f172a;
}

body.light .backup-detail-meta {
  color: #334155;
}

body.light .backup-detail-row td {
  background: #f8fafc !important;
  color: #0f172a !important;
}

body.light .backup-detail-wrap {
  background: #f8fafc !important;
  border-left: 3px solid #0b63ce !important;
}

body.light .backup-detail-title {
  color: #0f172a !important;
}

body.light .backup-detail-title a {
  color: #0b63ce !important;
}

body.light .backup-detail-meta {
  color: #475569 !important;
}

body.light .backup-detail-controls input,
body.light .backup-detail-controls select {
  background: #ffffff !important;
  color: #0f172a !important;
  border: 1px solid #94a3b8 !important;
}

body.light th.sortable.sort-asc::after,
body.light th.sortable.sort-desc::after {
  color: #003f91;
  opacity: 1;
}
.event-feed { margin-top: 8px; display: grid; gap: 4px; }
.event-item { font-size: 12px; color: #bbb; }
.event-item.success { color: #6ee7a8; }
.event-item.error { color: #fca5a5; }
.event-item.info { color: #bbb; }
.event-time { color: #777; margin-right: 8px; }
#toastBox { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 9999; }
.toast { background: #1f2937; border: 1px solid #4b5563; color: #fff; border-radius: 8px; padding: 10px 14px; box-shadow: 0 8px 30px rgba(0,0,0,0.35); min-width: 260px; }
.toast.good { border-color: #22c55e; }
.toast.bad { border-color: #ef4444; }
.toast.warn { border-color: #facc15; }
/* FINAL light-mode stat label override */
body.light .status-grid .stat-card .stat-label,
body.light .status-grid .stat-label,
body.light .stat-label {
  color: #1e293b !important;
  font-weight: 900 !important;
  opacity: 1 !important;
}

body.light .status-grid .stat-card .stat-value,
body.light .status-grid .stat-value,
body.light .stat-value {
  color: #020617 !important;
  font-weight: 900 !important;
}

/* Final themed status label/value weight */
body.light .status-grid .stat-label,
body.light .stat-card .stat-label,
body.light .stat-label {
  color: #334155 !important;
  font-weight: 800 !important;
  opacity: 1 !important;
}

body.light .status-grid .stat-value,
body.light .stat-card .stat-value,
body.light .stat-value {
  color: #0f172a !important;
  font-weight: 900 !important;
}

body:not(.light) .status-grid .stat-label,
body:not(.light) .stat-card .stat-label,
body:not(.light) .stat-label {
  color: #cbd5e1 !important;
  font-weight: 800 !important;
  opacity: 1 !important;
}

body:not(.light) .status-grid .stat-value,
body:not(.light) .stat-card .stat-value,
body:not(.light) .stat-value {
  color: #ffffff !important;
  font-weight: 900 !important;
}


.schedule-editor-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}
.schedule-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.schedule-field label {
  font-size: 12px;
  color: #9fb5d1;
  font-weight: 700;
}
.schedule-field input,
.schedule-field select {
  min-width: 150px;
}
.schedule-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}
.schedule-check input {
  min-width: auto;
}
.schedule-hidden {
  display: none !important;
}
body.light .schedule-field label {
  color: #334155;
}


.search-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.clear-search-button {
  background: #374151;
  color: #e5e7eb;
  border: 1px solid #4b5563;
  border-radius: 999px;
  width: 28px;
  height: 28px;
  padding: 0;
  font-weight: 900;
  line-height: 1;
}
.clear-search-button:hover {
  background: #4b5563;
}
.clear-search-button.hidden {
  display: none;
}
body.light .clear-search-button {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #94a3b8;
}
body.light .clear-search-button:hover {
  background: #cbd5e1;
}


/* Put search clear X inside the search field */
.search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.search-wrap input.search {
  padding-right: 34px;
}

.search-wrap .clear-search-button {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 900;
  line-height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  z-index: 2;
}

.search-wrap .clear-search-button:hover {
  background: #4b5563;
  color: #ffffff;
}

.search-wrap .clear-search-button.hidden {
  display: none;
}

body.light .search-wrap .clear-search-button {
  background: #e2e8f0;
  color: #334155;
  border-color: #94a3b8;
}

body.light .search-wrap .clear-search-button:hover {
  background: #cbd5e1;
  color: #0f172a;
}


.instance-details-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: stretch;
  margin-top: 4px;
}

.instance-detail-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(96, 165, 250, 0.28);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 20px;
  font-size: 15px;
  line-height: 1.35;
}

.instance-detail-label {
  font-weight: 800;
  color: #d7e3ff;
  white-space: nowrap;
}

.instance-detail-value {
  color: #f3f7ff;
  word-break: break-word;
}

body.light .instance-detail-chip {
  background: #eaf3ff;
  border-color: #bfd8ff;
}

body.light .instance-detail-label {
  color: #0f172a;
}

body.light .instance-detail-value {
  color: #1e293b;
}


/* Prevent the main instance table from crushing columns on narrower screens */
.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  max-width: 100%;
}

.table-wrap table {
  min-width: 1450px;
}

/* Keep operational columns readable */
.sticky-table th,
.sticky-table td {
  white-space: nowrap;
}

.sticky-table th:nth-child(2),
.sticky-table td:nth-child(2) {
  min-width: 210px;
}

.sticky-table th:nth-child(6),
.sticky-table td:nth-child(6) {
  min-width: 150px;
}

.sticky-table th:nth-child(7),
.sticky-table td:nth-child(7),
.sticky-table th:nth-child(8),
.sticky-table td:nth-child(8) {
  min-width: 160px;
}

/* Allow expanded detail rows to use full readable width */
.backup-detail-row td {
  white-space: normal !important;
}

.backup-detail-wrap {
  min-width: 1300px;
}

/* Make the top controls wrap more cleanly */
.controls {
  align-items: center;
}

.search-wrap input.search {
  min-width: 320px;
}


.bulk-schedule-card {
  width: min(760px, 92vw);
}

.bulk-schedule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.bulk-schedule-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.bulk-schedule-grid label span {
  font-size: 12px;
  font-weight: 800;
  color: #9fb5d1;
}

.bulk-schedule-grid input,
.bulk-schedule-grid select {
  width: 100%;
  min-width: 0;
}

.bulk-schedule-hidden {
  display: none !important;
}

.bulk-schedule-note {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(96, 165, 250, 0.25);
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.08);
  color: #c7d9f4;
  font-size: 13px;
}

body.light .bulk-schedule-grid label span {
  color: #334155;
}

body.light .bulk-schedule-note {
  background: #eaf3ff;
  border-color: #bfd8ff;
  color: #1e293b;
}


/* Forced inline bulk schedule panel */
.bulk-inline-panel {
  margin: 12px 0 14px;
  padding: 14px;
  border: 1px solid rgba(96, 165, 250, 0.35);
  border-left: 4px solid #58a6ff;
  border-radius: 8px;
  background: rgba(17, 22, 29, 0.92);
}

.bulk-inline-panel.hidden {
  display: none !important;
}

body.light .bulk-inline-panel {
  background: #f8fafc;
  border-color: #bfd8ff;
  border-left-color: #0b63ce;
}


/* Retire old broken bulk modal path */
#bulkScheduleModal {
  display: none !important;
}


.self-protected-mode {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 150px;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid #198754;
  background: #0f3b22;
  color: #6ee7a8;
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
}

body.light .self-protected-mode {
  background: #dcfce7;
  color: #166534;
  border-color: #22c55e;
}


/* Current selected instance row */
#instances tr.current-instance-row > td {
  background: rgba(37, 99, 235, 0.34) !important;
  box-shadow: inset 0 1px 0 rgba(88, 166, 255, 0.45), inset 0 -1px 0 rgba(88, 166, 255, 0.45);
}

#instances tr.current-instance-row > td:first-child {
  border-left: 5px solid #58a6ff;
}

#instances tr.current-instance-row:hover > td {
  background: rgba(37, 99, 235, 0.45) !important;
}

body.light #instances tr.current-instance-row > td {
  background: #bfdbfe !important;
  box-shadow: inset 0 1px 0 #60a5fa, inset 0 -1px 0 #60a5fa;
}

body.light #instances tr.current-instance-row > td:first-child {
  border-left-color: #0b63ce;
}


/* Floating header for the Containers table.
   This avoids fragile position: sticky / overflow interactions. */
#floatingInstancesHeader {
  position: fixed;
  top: 0;
  left: 0;
  display: none;
  z-index: 5000;
  overflow: hidden;
  pointer-events: auto;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
}

#floatingInstancesHeader table {
  border-collapse: collapse;
  margin: 0;
  table-layout: fixed;
}

#floatingInstancesHeader th {
  background: var(--table-head) !important;
  color: var(--text);
  border-top: 1px solid #3b4652;
  border-bottom: 3px solid #58a6ff;
  white-space: nowrap;
}

body.light #floatingInstancesHeader th {
  background: #cfe3ff !important;
  color: #0f172a;
  border-top: 1px solid #8bbcff;
  border-bottom: 4px solid #0b63ce;
}


/* Floating scroll-to-top button */
#scrollTopButton {
  position: fixed;
  right: 26px;
  bottom: 28px;
  z-index: 6000;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid #2dd4bf;
  background: linear-gradient(180deg, #14b8a6 0%, #0f766e 100%);
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

#scrollTopButton:hover {
  background: linear-gradient(180deg, #2dd4bf 0%, #0f766e 100%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.52);
  filter: none;
}

#scrollTopButton.visible {
  display: inline-flex;
}

body.light #scrollTopButton {
  background: linear-gradient(180deg, #14b8a6 0%, #0f766e 100%);
  color: #ffffff;
  border-color: #0f766e;
}

