/* Supercraft Permit System -- brand colours for light and dark mode.
 *
 * Loaded after Bootstrap, which is 5.3 here and has native dark mode: setting
 * data-bs-theme="dark" on <html> re-themes every component on its own. This
 * file only does the two things Bootstrap can't know about:
 *
 *   1. the Supercraft blue, so the two sites look like one system, and
 *   2. a darker ground (#121212) than Bootstrap's default dark (#212529),
 *      to match playsupercraft.com exactly.
 *
 * The theme itself is rendered server-side from a cookie shared with
 * playsupercraft.com -- see app.js and views/partials/theme_head.ejs.
 */

:root {
  --sc-blue: #0d67b5;
  --sc-blue-hover: #0b5699;
  --sc-blue-active: #094a85;

  /* Bootstrap builds link colours from an RGB triplet, not a hex. */
  --bs-link-color-rgb: 11, 90, 160;         /* #0b5aa0 */
  --bs-link-hover-color-rgb: 8, 68, 119;    /* #084477 */
}

[data-bs-theme="dark"] {
  /* Match playsupercraft.com's ground rather than Bootstrap's lighter default. */
  --bs-body-bg: #121212;
  --bs-body-color: #e9ecef;
  --bs-emphasis-color: #ffffff;
  --bs-secondary-bg: #1e1e1e;
  --bs-tertiary-bg: #1a1a1a;
  --bs-border-color: #2c2c2c;

  --bs-link-color-rgb: 94, 176, 255;        /* #5eb0ff */
  --bs-link-hover-color-rgb: 156, 207, 255; /* #9ccfff */
}

/* Cards default to --bs-body-bg, which would make them vanish against the
   darker ground, so lift them one step. */
[data-bs-theme="dark"] .card {
  --bs-card-bg: var(--bs-secondary-bg);
  --bs-card-border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
  background-color: var(--bs-secondary-bg);
  border-color: #3a3a3a;
}

[data-bs-theme="dark"] .list-group {
  --bs-list-group-bg: var(--bs-secondary-bg);
  --bs-list-group-border-color: var(--bs-border-color);
}

/* ---- Navbar -------------------------------------------------------------
   Supercraft blue in both themes. data-bs-theme="dark" on the <nav> itself is
   how 5.3 asks for light-on-dark navbar text; the old .navbar-dark class is
   deprecated. */
.permits-navbar {
  background-color: var(--sc-blue);
  margin-bottom: 1.5rem;
}

.permits-navbar .navbar-brand,
.permits-navbar .nav-link,
.permits-navbar .btn-link {
  color: #ffffff;
}

.permits-navbar .nav-link:hover,
.permits-navbar .nav-link:focus,
.permits-navbar .btn-link:hover {
  color: rgba(255, 255, 255, 0.78);
}

/* The logout control is a real <button> in a form, so that logging out is a
   POST. Make it sit on the same line as the links without looking like one. */
.permits-navbar .btn-link {
  text-decoration: none;
  padding: 0.5rem;
  border: 0;
}

/* ---- Buttons and links --------------------------------------------------- */
.btn-primary {
  --bs-btn-bg: var(--sc-blue);
  --bs-btn-border-color: var(--sc-blue);
  --bs-btn-hover-bg: var(--sc-blue-hover);
  --bs-btn-hover-border-color: var(--sc-blue-hover);
  --bs-btn-active-bg: var(--sc-blue-active);
  --bs-btn-active-border-color: var(--sc-blue-active);
}

/* Outline buttons whose colour is a dark grey are close to invisible against
   the dark ground -- .btn-outline-dark on #121212 in particular. Bootstrap
   leaves these alone in dark mode, so lift them to something readable. */
[data-bs-theme="dark"] .btn-outline-dark {
  --bs-btn-color: #dee2e6;
  --bs-btn-border-color: #6c757d;
  --bs-btn-hover-bg: #dee2e6;
  --bs-btn-hover-color: #121212;
  --bs-btn-hover-border-color: #dee2e6;
}

[data-bs-theme="dark"] .btn-outline-secondary {
  --bs-btn-color: #ced4da;
  --bs-btn-border-color: #6c757d;
  --bs-btn-hover-bg: #ced4da;
  --bs-btn-hover-color: #121212;
  --bs-btn-hover-border-color: #ced4da;
}

/* The login page sits on --bs-tertiary-bg, which in dark mode is close enough
   to the card behind it that the card stops reading as a card. Lift it. */
[data-bs-theme="dark"] .login-card {
  --bs-card-bg: #262626;
}

/* ---- Tables -------------------------------------------------------------
   Replaces .table-light on <thead>, which stays light whatever the theme. */
.permits-thead {
  --bs-table-bg: #e6eef7;
  --bs-table-color: #17324d;
}

[data-bs-theme="dark"] .permits-thead {
  --bs-table-bg: #1c3550;
  --bs-table-color: #ffffff;
}

/* ---- Theme toggle -------------------------------------------------------
   Deliberately identical to #dark-mode-toggle on playsupercraft.com. */
#dark-mode-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: #333;
  color: #fff;
  border: none;
  padding: 10px 15px;
  border-radius: 50px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 1080;
  transition: background-color 0.3s ease-in-out;
}

#dark-mode-toggle:hover {
  background-color: #555;
}

#dark-mode-toggle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  #dark-mode-toggle { transition: none; }
}
