:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --line: #d8e0ea;
  --text: #171923;
  --muted: #667085;
  --accent: #475467;
  --accent-strong: #344054;
  --danger: #b42318;
  --warn-bg: #fff7ed;
  --ok-bg: #ecfdf5;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

button.secondary {
  background: #fff;
  color: var(--accent-strong);
}

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: #1f2937;
  color: #f2f4f7;
  padding: 20px 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark {
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  font-weight: 800;
}

.brand-mark img {
  display: block;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.brand strong,
.brand small {
  display: block;
}

.brand > span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.brand small {
  color: #d0d5dd;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: #e4e7ec;
  text-align: left;
  min-height: 36px;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-session {
  margin-top: auto;
  padding: 18px 10px 4px;
  display: grid;
  gap: 4px;
  color: #d0d5dd;
  font-size: 12px;
}

.sidebar-session strong {
  color: #fff;
  font-size: 14px;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar,
.action-band,
.panel,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  padding: 18px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 26px;
}

h2 {
  margin-bottom: 12px;
  font-size: 16px;
}

p,
label,
.status-line {
  color: var(--muted);
}

.connection,
.compact-form {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 4px;
  font-size: 12px;
}

input,
select,
textarea {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 86px;
  padding: 10px;
  resize: vertical;
}

.connection input {
  width: 260px;
}

.action-band {
  margin: 14px 0;
  padding: 12px;
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.status-line {
  margin-left: auto;
  align-self: center;
}

.status-line.error {
  color: var(--danger);
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric,
.panel {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.metric strong {
  overflow-wrap: anywhere;
}

.work-welcome {
  margin-bottom: 14px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.work-welcome h2 {
  margin: 0;
  font-size: 24px;
}

.session-facts {
  display: flex;
  gap: 24px;
}

.session-facts span,
.session-facts small,
.session-facts strong {
  display: block;
}

.session-facts span {
  min-width: 100px;
}

.session-facts small {
  margin-bottom: 4px;
  color: var(--muted);
  text-transform: uppercase;
}

.work-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.work-panel {
  min-height: 180px;
}

.work-panel table {
  min-width: 0;
}

.work-stat {
  min-height: 92px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.work-stat strong {
  font-size: 32px;
}

.work-stat span,
.work-error {
  color: var(--muted);
}

.work-error {
  padding: 18px 0;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 14px;
  align-items: start;
}

.split.below {
  margin-top: 14px;
}

.stack {
  display: grid;
  gap: 14px;
}

.panel {
  min-width: 0;
}

.panel-head,
.panel-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-subhead {
  margin-top: 18px;
}

.panel-head h2,
.panel-subhead h2 {
  margin-bottom: 0;
}

.form-panel {
  display: grid;
  gap: 10px;
}

.source-editor {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.source-editor .form-note,
.source-editor button { grid-column: 1 / -1; }

.source-editor .form-note { margin: 0; color: var(--muted); font-size: 13px; }

#sourcesTable td:last-child { display: flex; flex-wrap: wrap; gap: 6px; }

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #f8fafc;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
}

.output {
  min-height: 280px;
  overflow: auto;
  background: #101828;
  color: #e4e7ec;
  padding: 14px;
  border-radius: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 13px;
}

.badge.ok {
  background: var(--ok-bg);
  color: #067647;
}

.badge.warn {
  background: var(--warn-bg);
  color: #b54708;
}

@media (max-width: 980px) {
  .shell,
  .split {
    grid-template-columns: 1fr;
  }

  .source-editor { grid-template-columns: 1fr; }

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

  .sidebar {
    align-self: start;
    width: 100%;
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav-item {
    padding-inline: 10px;
  }

  .sidebar-session {
    margin-top: 10px;
    padding: 8px 10px 0;
    display: flex;
    justify-content: space-between;
  }

  .topbar {
    display: grid;
  }

  .connection input,
  .compact-form input {
    width: min(100%, 320px);
  }

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

  .work-welcome {
    align-items: start;
    flex-direction: column;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 14px;
  }

  .work-grid {
    grid-template-columns: 1fr;
  }

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

  .session-facts {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .session-facts span {
    min-width: 0;
  }
}

.paged-table { overflow: visible; }
.paged-data { overflow-x: auto; }
.pagination-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 0; }
.pagination-controls button { width: 36px; height: 36px; padding: 0; }
.pagination-controls select { width: 72px; margin-left: 4px; }
.pagination-controls label { display: flex; align-items: center; margin-left: auto; }
.paging-error { color: var(--danger); padding-bottom: 8px; }
button:disabled { opacity: 0.45; cursor: default; }

/* UX-055: dark palette for operators working at night / in dark rooms.
   The light palette above remains the default and is unchanged; this block
   only re-skins variables and light-only surfaces under prefers-color-scheme. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d1117;
    --panel: #161b22;
    --line: #30363d;
    --text: #e6edf3;
    --muted: #a8b3bf;
    --accent: #475467;
    --accent-strong: #e6edf3;
    --danger: #f85149;
    --warn-bg: #2d1f0f;
    --ok-bg: #10281c;
  }

  .sidebar {
    background: #1c2128;
    border-right: 1px solid var(--line);
  }

  button.secondary {
    background: var(--panel);
    color: var(--accent-strong);
    border-color: var(--line);
  }

  input,
  select,
  textarea {
    background: var(--bg);
    color: var(--text);
  }

  th {
    background: #1c2128;
  }

  .output {
    background: #0a0d12;
    border: 1px solid var(--line);
  }

  .badge.ok {
    color: #3fb950;
  }

  .badge.warn {
    color: #f0883e;
  }
}
