:root {
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-border: #d1d5db;
  --color-border-light: #e5e7eb;
  --color-bg: #ffffff;
  --color-bg-page: #f9fafb;
  --color-bg-card: #ffffff;
  --color-bg-subtle: #f3f4f6;
  --color-error: #b00020;
  --color-success: #15803d;
  --radius: 8px;
  --radius-sm: 4px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg-page);
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  line-height: 1.5;
  overflow-x: hidden; /* safety net for the full-bleed .env-banner below */
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 0.75rem; }

/* Environment banner — shown at the very top of every page (nav.ejs)
   when running on Dev/Sandbox or QA, so the environment is obvious even
   though Render doesn't allow changing a service's .onrender.com
   subdomain after creation (Dev/Sandbox's URL doesn't say "dev"
   anywhere). Full-bleed across the actual browser viewport, not just
   body's own centered 1000px column — the standard "100vw + negative
   margin" technique for breaking a child out of a max-width container. */
.env-banner {
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  margin-bottom: 1rem;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.5rem;
  font-size: 0.85rem;
  color: #ffffff;
}
.env-banner-dev { background: #d97706; }
.env-banner-qa { background: #7c3aed; }

/* Nav */
nav {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}
nav a { margin-right: 1rem; text-decoration: none; color: var(--color-text-muted); font-size: 0.9rem; }
nav a:hover { color: var(--color-text); }
nav a.active { color: var(--color-accent); font-weight: 600; }
.nav-row { margin-bottom: 0.4rem; }
.nav-row:last-child { margin-bottom: 0; }
.nav-row-admin {
  font-size: 0.85rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border-light);
  display: flex;
  flex-wrap: wrap;
  row-gap: 0.4rem;
}
/* A subtle divider between admin nav items, applied as a border rather
   than a text character (e.g. "|") so it never wraps as part of a
   multi-word label and doesn't need per-label styling. Trails each item
   (border-right) rather than leading it (border-left): on a row that
   wraps, a trailing divider just extends into the empty space at the
   end of a line, while a leading one would float before the first item
   of the next line with nothing to its left — reads as a rendering
   glitch rather than a subtle divider. */
.nav-row-admin a { color: var(--color-text-muted); margin-right: 0; padding: 0 0.75rem; }
.nav-row-admin a:first-child { padding-left: 0; }
.nav-row-admin a:last-child { padding-right: 0; }
.nav-row-admin a:not(:last-child) { border-right: 1px solid var(--color-border-light); }
.nav-row-admin a.active { color: var(--color-accent); }
.brand { font-size: 1rem; font-weight: 600; color: var(--color-text); }
.brand.active { color: var(--color-accent); }

/* Card — the main "Minimal SaaS" building block: white panel, soft border,
   rounded corners, wraps forms and picker/filter bars. */
.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem 1.5rem;
  margin-bottom: 1.5rem;
}
.card h2 { margin-top: 0; }

/* Tables — kept as real tables (not restructured into card-lists) and
   wrapped in a horizontally-scrolling container so wide grids/lists don't
   break the layout on narrow screens. */
.table-wrap {
  overflow-x: auto;
  margin-bottom: 1.5rem;
  -webkit-overflow-scrolling: touch;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
}
table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid var(--color-border-light); padding: 0.6rem 0.75rem; text-align: left; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
thead th {
  background: var(--color-bg-subtle);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  font-weight: 600;
}
th a { color: inherit; text-decoration: none; }
th a:hover { text-decoration: underline; }
th a .sort-indicator { opacity: 0.4; }
th a.active .sort-indicator { opacity: 1; }

/* Forms */
form label {
  display: block;
  margin-top: 0.9rem;
  margin-bottom: 0.3rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.field-hint {
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}
input, select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
  max-width: 320px;
}
input:focus, select:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  border-color: var(--color-accent);
}
input:disabled { background: var(--color-bg-subtle); color: var(--color-text-muted); }
.error { color: var(--color-error); margin-bottom: 1rem; }
.saved-message { color: var(--color-success); margin-bottom: 1rem; }

/* Buttons */
.btn, form button[type="submit"] {
  display: inline-block;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.6rem 1.25rem;
  background: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  margin-top: 1.25rem;
}
.btn:hover, form button[type="submit"]:hover { background: var(--color-accent-hover); }

/* A plain <a> link styled to look like a <button>, for page-to-page
   navigation (not form submission) that should still look clickable. */
.button-link {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.9rem;
}
.button-link:hover { background: var(--color-border-light); }

.filter-bar, .picker-bar {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}
.filter-bar label, .picker-bar label { margin-top: 0; }
.filter-bar input, .filter-bar select,
.picker-bar input, .picker-bar select { max-width: 200px; }
.filter-bar button, .picker-bar button { margin-top: 0; }

/* Tablet: tighten spacing, let bars wrap more readily */
@media (max-width: 900px) {
  body { padding: 1.25rem 1rem 2.5rem; }
  .card { padding: 1rem 1.25rem 1.25rem; }
}

/* Phone: full-width inputs, tighter padding, stacked bars */
@media (max-width: 600px) {
  body { padding: 1rem 0.75rem 2rem; }
  h1 { font-size: 1.3rem; }
  .card { padding: 0.9rem 1rem 1.1rem; }
  input, select { max-width: 100%; }
  .filter-bar, .picker-bar { padding: 0.9rem 1rem; }
  .filter-bar input, .filter-bar select,
  .picker-bar input, .picker-bar select { max-width: 100%; }
  .btn, form button[type="submit"] { width: 100%; }
}
