/* ─── Dark dashboard theme ─────────────────────────────────────────────
   Palette validated for contrast against the app surfaces:
   text 15:1, secondary 8.7:1, muted 5.2:1, accent 9.6:1.
   Data marks use a single accent hue — the charts encode magnitude,
   not identity, so one hue is correct and no legend is needed.
   ──────────────────────────────────────────────────────────────────── */
:root {
  color-scheme: dark;

  --bg: #0b0f14;
  --surface: #141b24;
  --surface-2: #1b2531;
  --surface-hover: #1f2a37;
  --border: #26303d;
  --border-strong: #33404f;

  --text: #e9eff6;
  --text-2: #a9bacb;
  --muted: #7d8fa3;

  --accent: #22d3ee;
  --accent-ink: #04222a;
  --accent-soft: rgba(34, 211, 238, 0.12);
  --accent-glow: rgba(34, 211, 238, 0.25);

  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --success: #34d399;

  --radius: 12px;
  --radius-sm: 8px;

  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(34, 211, 238, 0.07), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

h1 {
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}

h2 {
  font-size: 0.8rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 36px 0 12px;
}

/* ─── Top navigation ─────────────────────────────────────────────── */
.topnav {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  height: 60px;
  background: rgba(20, 27, 36, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topnav-brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.topnav-brand .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

.topnav-links {
  display: flex;
  gap: 4px;
  flex: 1;
}

.topnav-links a {
  color: var(--text-2);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.topnav-links a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.topnav-links a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.topnav-user {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

/* ─── Buttons ────────────────────────────────────────────────────── */
.button,
button[type='submit']:not(.link-button),
.quick-ranges button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid transparent;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  transition: filter 0.15s, background 0.15s, border-color 0.15s;
}

.button:hover,
button[type='submit']:not(.link-button):hover {
  filter: brightness(1.12);
}

.button.secondary {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--border-strong);
  font-weight: 500;
}

.button.secondary:hover {
  background: var(--surface-hover);
  color: var(--text);
  filter: none;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: 0.85rem;
  font-family: inherit;
}

.link-button:hover {
  text-decoration: underline;
}

.link-button.danger {
  color: var(--danger);
}

.inline-form {
  display: inline;
}

/* ─── Page header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-header .subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

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

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover td {
  background: var(--surface-hover);
}

.data-table td.wrap {
  white-space: normal;
  min-width: 200px;
  color: var(--text-2);
}

.num {
  font-variant-numeric: tabular-nums;
}

.duration-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}

.blank {
  color: var(--muted);
  font-style: italic;
}

.row-actions {
  display: flex;
  gap: 14px;
  justify-content: flex-end;
}

.tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-size: 0.78rem;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.tag.ok {
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.1);
}

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

.tag.admin {
  color: var(--accent);
  border-color: rgba(34, 211, 238, 0.35);
  background: var(--accent-soft);
}

/* ─── Empty state ────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
}

.empty .mark {
  font-size: 2rem;
  opacity: 0.5;
  display: block;
  margin-bottom: 12px;
}

.empty p {
  margin: 0 0 18px;
}

/* ─── Forms ──────────────────────────────────────────────────────── */
.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
}

.stacked-form label,
.filter-form label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-2);
}

input[type='text'],
input[type='password'],
input[type='date'],
input[type='number'],
textarea,
select {
  font-size: 0.95rem;
  font-family: inherit;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
}

select {
  cursor: pointer;
}

.hint {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 10px !important;
  cursor: pointer;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Combo field — dropdown of saved values + inline "add new" text box */
.combo {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.combo select,
.combo input {
  width: 100%;
}

.combo input[hidden] {
  display: none;
}

.combo input:not([hidden]) {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Add-a-value row on the pick-lists page */
.add-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.add-row input {
  flex: 1;
  min-width: 140px;
}

.section-note {
  font-size: 0.82rem;
  color: var(--muted);
  margin: -6px 0 12px;
}

.bu-name {
  color: var(--muted);
  font-size: 0.82rem;
  margin-left: 6px;
}

.data-table td.bu-cell {
  white-space: normal;
}

/* The PIM list runs to a couple of hundred rows — keep the page scannable. */
.scroll-list {
  max-height: 460px;
  overflow: auto;
}

/* The machine list carries an extra column, so give it the wider half. */
.lists-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(340px, 1.5fr);
  gap: 18px;
  align-items: start;
}

@media (max-width: 800px) {
  .lists-grid {
    grid-template-columns: 1fr;
  }
}

.scroll-list thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Duration — required, visually emphasised, never blankable */
.duration-fieldset {
  border: 1px solid var(--accent-soft);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 14px 16px 16px;
  margin: 0;
  display: flex;
  gap: 10px;
}

.duration-fieldset legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  padding: 0 6px;
}

.duration-fieldset input {
  flex: 1;
  min-width: 0;
}

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* ─── Filter bar ─────────────────────────────────────────────────── */
.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 24px;
}

.filter-form input,
.filter-form select {
  padding: 8px 10px;
  font-size: 0.875rem;
}

.quick-ranges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.quick-ranges button {
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 500;
}

.quick-ranges button:hover {
  background: var(--surface-hover);
  color: var(--text);
  filter: none;
}

.filter-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-left: auto;
}

/* Display toggles — pick which visuals appear */
.view-toggles {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.view-toggles .toggles-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.view-toggles label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
}

.view-toggles input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ─── Stat cards ─────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 8px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-card .stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.stat-card .stat-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.stat-card.primary {
  border-color: rgba(34, 211, 238, 0.3);
  background: linear-gradient(160deg, var(--accent-soft), var(--surface) 65%);
}

.stat-card.primary .stat-value {
  color: var(--accent);
}

/* ─── Bar chart ──────────────────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 14px;
}

.chart {
  position: relative;
  height: 200px;
  margin-left: 52px;
  border-bottom: 1px solid var(--border-strong);
}

.chart-gridline {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.chart-gridline span {
  position: absolute;
  right: calc(100% + 10px);
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transform: translateY(-50%);
  white-space: nowrap;
}

.chart-bars {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.chart-bar {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 100%;
  cursor: default;
}

.chart-bar .fill {
  position: relative;
  width: 100%;
  max-width: 46px;
  background: linear-gradient(180deg, var(--accent), rgba(34, 211, 238, 0.55));
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: filter 0.15s;
}

.chart-bar:hover .fill {
  filter: brightness(1.25);
}

.chart-bar .peak-label {
  position: absolute;
  bottom: calc(100% + 4px);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Anchored to the top of the bar itself, not the full-height column. */
.chart-bar .fill .tip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translate(-50%, -8px);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: 0.78rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  z-index: 5;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}

.chart-bar .fill .tip strong {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.chart-bar:hover .fill .tip {
  opacity: 1;
}

.chart-axis {
  display: flex;
  gap: 2px;
  margin-left: 52px;
  margin-top: 8px;
}

.chart-axis span {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Proportional bars inside breakdown tables ──────────────────── */
.bar-cell {
  width: 200px;
  min-width: 140px;
}

.meter {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.meter > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, rgba(34, 211, 238, 0.6), var(--accent));
  border-radius: 999px;
}

/* ─── Panels row (breakdowns side by side) ───────────────────────── */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
}

/* ─── Login ──────────────────────────────────────────────────────── */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}

.login-brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
}

.login-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0 0 24px;
}

.login-card .stacked-form {
  max-width: none;
}

.login-card button[type='submit'] {
  justify-content: center;
  width: 100%;
  padding: 11px;
}

/* ─── Backup & restore ───────────────────────────────────────────── */
.card.pad {
  padding: 20px;
}

.stacked-form.flush {
  background: none;
  border: none;
  padding: 0;
  max-width: none;
  gap: 16px;
}

.danger-note {
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.85rem;
  color: var(--text-2);
  margin: 0 0 18px;
}

.danger-note strong {
  color: var(--danger);
}

button.danger-button {
  background: var(--danger);
  color: #2a0606;
}

button.danger-button:disabled {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border-strong);
  cursor: not-allowed;
  filter: none;
}

.file-summary {
  font-size: 0.82rem;
  margin: 0;
  min-height: 1em;
}

.file-summary.good {
  color: var(--success);
}

.file-summary.bad {
  color: var(--danger);
}

input[type='file'] {
  font-size: 0.9rem;
  font-family: inherit;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
}

input[type='file']::file-selector-button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 12px;
  margin-right: 12px;
  cursor: pointer;
  font-family: inherit;
}

/* ─── Alerts ─────────────────────────────────────────────────────── */
.notice {
  color: var(--success);
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.35);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.875rem;
  margin: 0 0 18px;
}


.error {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.875rem;
  margin: 0 0 18px;
}

@media (max-width: 640px) {
  /* Too many bars to label each one at this width — show every third and
     let it spill into the blanked neighbours rather than truncating all. */
  .chart-axis span {
    overflow: visible;
  }
  .chart-axis span:not(:nth-child(3n + 1)) {
    visibility: hidden;
  }

  .container {
    padding: 24px 16px 60px;
  }
  .topnav {
    gap: 14px;
    padding: 0 16px;
  }
  .topnav-user span {
    display: none;
  }
  .filter-actions {
    margin-left: 0;
  }
}
