:root {
  --bg-1: #07111f;
  --bg-2: #11243d;
  --bg-3: #1f5d5b;
  --glow-1: rgba(20, 184, 166, 0.25);
  --glow-2: rgba(249, 115, 22, 0.2);
  --bg-dim: 0.45;
  /* Colour laid over a background image to darken it (dark themes) or lighten it (light themes). */
  --overlay-rgb: 3, 8, 15;
  /* Card surfaces. Light themes and card colour themes redefine these, so the card rules never use fixed colours. */
  --surface: color-mix(in srgb, var(--bg-1) 80%, transparent);
  --surface-border: rgba(148, 163, 184, 0.18);
  --surface-header: linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent);
  --surface-line: rgba(148, 163, 184, 0.12);
  --surface-track: rgba(255, 255, 255, 0.08);
  --tile-bg: rgba(255, 255, 255, 0.05);
  --tile-border: rgba(255, 255, 255, 0.08);
  --error-bg: rgba(239, 68, 68, 0.12);
  --error-border: rgba(239, 68, 68, 0.22);
  --error-text: #fecaca;
  --status-ok: #22c55e;
  --status-warning: #f59e0b;
  --status-alarm: #ef4444;
  /* Panels are tinted with the theme's darkest colour, so they match whichever theme the view uses. */
  --panel: color-mix(in srgb, var(--bg-1) 78%, transparent);
  --panel-strong: rgba(6, 13, 24, 0.9);
  --panel-border: rgba(148, 163, 184, 0.18);
  --text: #edf6ff;
  --muted: #9ab0c4;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.18);
  --accent-2: #14b8a6;
  --danger: #ef4444;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.32);
  --radius: 24px;
  --radius-small: 16px;
  --button-radius: 8px;
  --button-height: 45px;
}

/* Light view themes: dark text on light cards. The management UI keeps its dark look (see app.css). */
html[data-mode="light"] {
  --text: #0f172a;
  --muted: #52637a;
  --shadow: 0 18px 44px rgba(15, 23, 42, 0.12);
  --overlay-rgb: 255, 255, 255;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-border: rgba(15, 23, 42, 0.1);
  --surface-header: linear-gradient(180deg, rgba(15, 23, 42, 0.03), transparent);
  --surface-line: rgba(15, 23, 42, 0.08);
  --surface-track: rgba(15, 23, 42, 0.08);
  --tile-bg: rgba(15, 23, 42, 0.035);
  --tile-border: rgba(15, 23, 42, 0.08);
  --error-bg: rgba(220, 38, 38, 0.08);
  --error-border: rgba(220, 38, 38, 0.25);
  --error-text: #b91c1c;
  --status-ok: #16a34a;
  --status-warning: #b45309;
  --status-alarm: #dc2626;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

[hidden] {
  display: none !important;
}

body {
  overflow: hidden;
  font-family: Aptos, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, var(--glow-1), transparent 25%),
    radial-gradient(circle at 80% 20%, var(--glow-2), transparent 20%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2) 48%, var(--bg-3));
}

/* A view background image: darkened by --bg-dim so the cards stay readable; the theme colour shows while it loads. */
html.has-bg-image body {
  background:
    linear-gradient(rgba(var(--overlay-rgb), var(--bg-dim)), rgba(var(--overlay-rgb), var(--bg-dim))),
    var(--bg-image) var(--bg-position, center) / var(--bg-size, cover) var(--bg-repeat, no-repeat),
    var(--bg-1);
}

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

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

label,
input,
select,
textarea,
button {
  display: block;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 14px;
  padding: 11px 13px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: rgba(154, 176, 196, 0.72);
}

textarea {
  resize: vertical;
}

select option {
  color: #0f172a;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--button-radius);
  min-height: var(--button-height);
  padding: 0 18px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #fb923c);
  color: #fff7ed;
}

.btn-secondary {
  border-color: rgba(148, 163, 184, 0.18);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.26);
}

.btn-small {
  min-height: var(--button-height);
  padding: 0 14px;
}

.btn-add {
  width: var(--button-height);
  height: var(--button-height);
  padding: 0;
  border-radius: var(--button-radius);
  display: grid;
  place-items: center;
  background: rgba(20, 184, 166, 0.18);
  border-color: rgba(20, 184, 166, 0.28);
  color: #ccfbf1;
  font-size: 1.35rem;
  line-height: 1;
  font-weight: 700;
}

.btn-add:hover {
  background: rgba(20, 184, 166, 0.26);
  border-color: rgba(20, 184, 166, 0.38);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 0.84rem;
  color: var(--muted);
}

.form-grid {
  display: grid;
  gap: 14px;
}

.compact-field {
  min-width: 220px;
}

.eyebrow,
.section-kicker {
  font-size: 0.76rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.status-pill {
  align-self: start;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(20, 184, 166, 0.12);
  border: 1px solid rgba(20, 184, 166, 0.24);
  font-size: 0.82rem;
  color: #ccfbf1;
}

.status-pill.is-dirty {
  background: rgba(249, 115, 22, 0.18);
  border-color: rgba(249, 115, 22, 0.3);
  color: #ffedd5;
}

.checkbox-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.checkbox-field input {
  width: auto;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 320px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--panel-strong);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow);
  z-index: 50;
}

@media (max-width: 1080px) {
  .compact-field {
    min-width: 100%;
  }
}