:root {
  color-scheme: light dark;
  /* Marine palette: deep navy as the primary accent, teal for "on"/positive
     state (paired with, not identical to, the accent so interactive vs.
     status color stay visually distinct), warm-neutral page background so
     white cards actually stand out instead of blending into the page. */
  --accent: #0e6ba8;
  --accent-dark: #0a4f7a;
  --accent-tint: #e5f1f8;
  --teal: #0d9488;
  --teal-tint: #d9f2ef;
  --border: #d7dee5;
  --muted: #64748b;
  --danger: #b91c1c;
  --text: #1e293b;
  --bg: #f4f7fa;
  --surface: #ffffff;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

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

h1, h2 { color: var(--accent-dark); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--accent-dark);
  color: #fff;
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: #fff;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.stack { display: flex; flex-direction: column; gap: 0.9rem; max-width: 360px; }
.stack label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; }
input { padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 1rem; }

button, .button {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95rem;
  width: fit-content;
}

.topnav { display: flex; align-items: center; gap: 1rem; }
.topnav a { color: rgba(255, 255, 255, 0.92); text-decoration: none; font-size: 0.9rem; }

.logout-form button {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}

.page-head { display: flex; align-items: center; justify-content: space-between; }
.button-row { display: flex; gap: 0.5rem; }
.button-secondary { background: transparent; color: var(--accent); }

.boat-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.boat-list li { display: flex; justify-content: space-between; border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 1rem; background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.boat-list a { text-decoration: none; font-weight: 600; color: var(--accent-dark); }

.muted { color: var(--muted); }
.error { color: var(--danger); }
.success { color: #166534; }
.warn { color: #92400e; background: #fef3c7; padding: 0.6rem 0.9rem; border-radius: 6px; }
.checkbox-row { flex-direction: row !important; align-items: center; gap: 0.5rem !important; }

.creds { border: 1px solid var(--border); border-radius: 8px; padding: 0.8rem 1rem; background: var(--surface); }
.creds dt { font-size: 0.8rem; color: var(--muted); margin-top: 0.5rem; }
.creds dd { margin: 0; font-size: 1.05rem; }

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  vertical-align: middle;
}
.badge-unknown { background: #e5e7eb; color: #374151; }
.badge-on { background: var(--teal-tint); color: var(--teal); }
.badge-off { background: #e5e7eb; color: #374151; }

/* Fixed 2 columns (not auto-fill) so the Status grid's row grouping is
   identical on a wide browser window and a narrow phone screen — an
   auto-fill grid packs more cards per row as width grows, which is exactly
   the "web looks different from the app" mismatch this avoids. */
.card-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin: 1rem 0; }
.card { border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.3rem; background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.card-wide { grid-column: span 2; }
.card-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; }
.card-value { font-size: 1.2rem; font-weight: 600; color: var(--accent-dark); }
.card-value.danger { color: var(--danger); }
.card.card-alert { background: #fee2e2; border-color: var(--danger); }
.card.card-alert .card-label, .card.card-alert .card-value { color: var(--danger); }

.channel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.6rem; margin: 0.75rem 0 1.5rem; }
.channel { border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.8rem; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.channel-label { font-size: 0.9rem; }
/* RF remote buttons sit below their label instead of beside it — a device
   can have several named buttons (Start/Shutdown/Up/Down), which doesn't
   fit next to the label the way a single relay toggle does. Both lines
   (label, button row) are centered within the box. */
.channel.channel-stacked { flex-direction: column; align-items: center; text-align: center; }

.toggle {
  border: 1px solid var(--border);
  background: #e5e7eb;
  color: #374151;
  min-width: 3rem;
  text-transform: uppercase;
  font-size: 0.75rem;
}
.toggle.toggle-on { background: var(--teal); border-color: var(--teal); color: #fff; }

.rf-buttons { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }
.rf-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: transform 0.08s ease, background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.rf-btn:hover { background: var(--accent-tint); }
/* Real press feedback, not just a static outline — :active covers mouse/
   most touch browsers on its own; the .pressed class (toggled in boat.js
   via pointer events) is the reliable fallback so a held-down finger always
   shows the state, even on the mobile browsers where bare :active is flaky. */
.rf-btn:active, .rf-btn.pressed {
  background: var(--accent);
  color: #fff;
  transform: scale(0.92);
  box-shadow: none;
}

/* Settings-page editable rows (instruments, channels, RF buttons): each is
   a bordered box with an Enabled/Remove header and a wrapping row of
   properly-captioned fields below, so a field with several inputs (source,
   slot, MAC, key...) stays readable instead of one giant unlabeled row. */
.settings-item { border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; margin-bottom: 0.75rem; background: var(--surface); }
.settings-item-header { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.6rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--border); }
.settings-fields { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.settings-fields + .settings-fields { margin-top: 0.6rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field-caption { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }
.field input, .field select { width: 100%; }
.field-sm { width: 5rem; }
.field-md { width: 9rem; }
.field-lg { width: 13rem; }
.settings-item .checkbox-row { font-size: 0.85rem; white-space: nowrap; }
.settings-fields.divider { padding-top: 0.6rem; border-top: 1px solid var(--border); }

.alert-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.alert-list li { border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.75rem; font-size: 0.9rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; background: var(--surface); }

/* Shown in place of the whole boat page when the boat has no active
   subscription (views/boat-inactive.ejs). */
.plan-card { border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; margin: 1rem 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.4rem; background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.plan-price { font-size: 1.6rem; font-weight: 600; color: var(--accent-dark); }
.plan-card p { margin: 0.3rem 0; max-width: 28rem; }
.plan-card form { margin-top: 0.5rem; }
