/* OpenWard custom styles — supplements Pico CSS classless */

/* === Print === */
@media print {
  nav, footer, .no-print, [hx-get], [hx-post], button:not(.print-visible) { display: none !important; }
  body { font-size: 10pt; }
  table { font-size: 9pt; }
  .page-break { page-break-before: always; }
  article { border: none; box-shadow: none; }
}

/* === Flag severity badges === */
.flag-critical {
  background: #dc3545;
  color: #fff;
  padding: 0.1em 0.4em;
  border-radius: 3px;
  font-size: 0.8em;
  font-weight: 600;
  white-space: nowrap;
}
.flag-warning {
  background: #ffc107;
  color: #000;
  padding: 0.1em 0.4em;
  border-radius: 3px;
  font-size: 0.8em;
  white-space: nowrap;
}
.flag-info {
  background: #0d6efd;
  color: #fff;
  padding: 0.1em 0.4em;
  border-radius: 3px;
  font-size: 0.8em;
  white-space: nowrap;
}

/* === Population gauge === */
.gauge {
  height: 1.5rem;
  background: var(--pico-secondary-background);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--pico-muted-border-color);
}
.gauge-fill {
  height: 100%;
  transition: width 0.3s;
}
.gauge-safe { background: #198754; }
.gauge-warning { background: #ffc107; }
.gauge-critical { background: #dc3545; }

/* === Basis breakdown bar === */
.basis-bar {
  display: flex;
  gap: 1px;
  height: 2rem;
  border-radius: 4px;
  overflow: hidden;
}
.basis-bar > div {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75em;
  color: #fff;
  min-width: 0;
}

/* === Stats grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}
.stat-card {
  text-align: center;
}
.stat-card .stat-value {
  font-size: 2em;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}
.stat-card .stat-label {
  font-size: 0.85em;
  color: var(--pico-muted-color);
}

/* === Alerts grid === */
.alerts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.5rem;
}
.alerts-grid > div {
  padding: 0.3rem 0;
}

/* === Action buttons row === */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}
.actions button,
.actions a[role="button"] {
  font-size: 0.85em;
  padding: 0.4em 0.8em;
}

/* === Inline HTMX form === */
.action-form {
  border: 1px solid var(--pico-muted-border-color);
  padding: 1rem;
  border-radius: 4px;
  margin-top: 0.5rem;
  background: var(--pico-card-background-color);
}

/* === HTMX indicators === */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-block; }

/* === Released banner === */
.released-banner {
  background: #198754;
  color: #fff;
  border: 2px solid #0f5132;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  border-radius: 4px;
}
.released-banner > header {
  background: transparent;
  color: #fff;
  font-size: 1.25em;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0;
  border: none;
  margin-bottom: 0.25rem;
}
.released-banner > p {
  margin: 0;
  color: #fff;
}
.status-released {
  color: #0f5132;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stale-basis {
  color: var(--pico-muted-color);
}

/* === Flash messages === */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}
.flash-success {
  background: #d1e7dd;
  border: 1px solid #198754;
  color: #0f5132;
}
.flash-error {
  background: #f8d7da;
  border: 1px solid #dc3545;
  color: #842029;
}

/* === Legend row === */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.8em;
  margin-top: 0.5rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.legend-swatch {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border-radius: 2px;
}

/* === Compact table for small screens === */
@media (max-width: 1024px) {
  table { font-size: 0.85em; }
  th, td { padding: 0.3rem 0.5rem; }
}

/* === Definition lists: bold terms === */
dl dt {
  font-weight: 700;
}

/* === Detail panels === */
.detail-section {
  margin-bottom: 1.5rem;
}
.detail-section h3 {
  border-bottom: 1px solid var(--pico-muted-border-color);
  padding-bottom: 0.3rem;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5rem 1.5rem;
}
.detail-grid dt {
  font-weight: 600;
  font-size: 0.85em;
  color: var(--pico-muted-color);
  margin: 0;
}
.detail-grid dd {
  margin: 0 0 0.5rem 0;
}

/* === Quick link buttons === */
.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

/* === Filter form inline === */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 1rem;
}
.filter-bar label {
  margin-bottom: 0;
}
.filter-bar select,
.filter-bar input {
  margin-bottom: 0;
}

/* === Advanced filters panel === */
.advanced-filters {
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}
.advanced-filters summary {
  cursor: pointer;
  font-size: 0.9em;
  color: var(--pico-primary);
}
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}
.filter-group label {
  font-size: 0.85em;
  margin-bottom: 0.25rem;
}
.filter-group select,
.filter-group input {
  margin-bottom: 0.5rem;
}

/* === Alert card links === */
.alert-card-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  transition: background-color 0.15s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.alert-card-link:hover {
  background-color: var(--pico-secondary-hover);
  text-decoration: none;
}

/* === Pagination === */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  font-size: 0.9em;
}
.pagination a {
  cursor: pointer;
}

/* ==========================================================================
   Mobile rework — phone-friendly nav, tables, filters, tap targets.
   Desktop layout (>= 768px) is unchanged from above.
   ========================================================================== */

/* Login page layout. */
.login-main {
  margin-top: 15vh;
}
.login-card {
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}
@media (max-width: 767px) {
  .login-main {
    margin-top: 4vh;
    padding: 0 0.75rem;
  }
  .login-card {
    max-width: 100%;
  }
}

/* Hide hamburger checkbox accessibly (still keyboard-focusable via label). */
.nav-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Hamburger button: hidden by default, shown on mobile. */
.nav-burger {
  display: none;
}

/* On desktop, the brand <ul> behaves like a normal Pico nav <ul>:
   the burger <li> is hidden, so it's just the "OpenWard" wordmark. */
.nav-brand .nav-burger {
  display: none;
}

.logout-form {
  display: inline;
  margin: 0;
}

/* Form button that should look like a plain nav link, not a Pico primary button. */
button.link-button {
  background: transparent;
  color: var(--pico-primary);
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  box-shadow: none;
}
button.link-button:hover,
button.link-button:focus {
  background: transparent;
  color: var(--pico-primary-hover);
  text-decoration: underline;
}

@media (max-width: 767px) {
  /* Sticky header keeps the nav reachable without a long scroll back to top. */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--pico-background-color);
    border-bottom: 1px solid var(--pico-muted-border-color);
    padding: 0.25rem 0.75rem;
    margin: 0;
  }

  .site-header nav {
    flex-wrap: wrap;
    gap: 0;
    padding: 0;
  }

  .site-header nav > ul {
    margin: 0;
    padding: 0;
  }

  /* Top row: brand + burger, always visible. */
  .nav-brand {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.25rem 0;
  }
  .nav-brand li {
    padding: 0;
  }

  .nav-brand .nav-burger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
    border-radius: 4px;
  }
  .nav-burger:hover {
    background: var(--pico-secondary-background);
  }
  .nav-burger span {
    display: block;
    width: 24px;
    height: 2px;
    background: currentColor;
    transition: transform 0.2s ease, opacity 0.15s ease;
  }

  /* Collapsed by default; expanded when checkbox is checked. */
  .nav-links,
  .nav-user {
    display: none !important;
    flex-direction: column !important;
    width: 100%;
    padding: 0.25rem 0 0.5rem;
    gap: 0;
    border-top: 1px solid var(--pico-muted-border-color);
    margin-top: 0.25rem;
  }
  .nav-toggle:checked ~ .nav-links,
  .nav-toggle:checked ~ .nav-user {
    display: flex !important;
  }

  .nav-links li,
  .nav-user li {
    width: 100%;
    padding: 0;
  }

  .nav-links a,
  .nav-user a,
  .nav-user button.link-button {
    display: block;
    width: 100%;
    padding: 0.75rem 0.5rem;
    min-height: 44px;
    text-align: left;
    border-radius: 4px;
    text-decoration: none;
    line-height: 1.4;
  }
  .nav-links a[aria-current="page"] {
    background: var(--pico-primary-background);
    color: var(--pico-primary-inverse);
    font-weight: 600;
  }
  .nav-links a:hover,
  .nav-user a:hover,
  .nav-user button.link-button:hover {
    background: var(--pico-muted-border-color);
    color: var(--pico-color);
  }

  /* Burger → X animation when nav open. */
  .nav-toggle:checked ~ .nav-brand .nav-burger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }
  .nav-toggle:checked ~ .nav-brand .nav-burger span:nth-child(2) {
    opacity: 0;
  }
  .nav-toggle:checked ~ .nav-brand .nav-burger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  /* Stack filter and action bars on phones. */
  .filter-bar,
  .filter-grid,
  .actions,
  .quick-links {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-bar select,
  .filter-bar input,
  .filter-grid select,
  .filter-grid input {
    width: 100%;
  }
  .actions button,
  .actions a[role="button"],
  .quick-links a[role="button"] {
    width: 100%;
    min-height: 44px;
    font-size: 1em;
  }

  /* Detail panels: single column on phones. */
  .detail-grid {
    grid-template-columns: 1fr;
    gap: 0.25rem 0;
  }
  .detail-grid dd {
    margin-bottom: 0.75rem;
  }

  /* Stat cards: 2-up on phones instead of one giant column. */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }
  .stat-card .stat-value {
    font-size: 1.6em;
  }

  /* Pagination: wrap nicely. */
  .pagination {
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
  }

  /* Non-opt-in tables get a horizontal-scroll fallback so they don't blow out
     the viewport. The .responsive-table override below uses card layout instead. */
  main table:not(.responsive-table) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* Responsive tables: each row becomes a card, each cell stacks with its label. */
  table.responsive-table,
  table.responsive-table thead,
  table.responsive-table tbody,
  table.responsive-table tr,
  table.responsive-table td {
    display: block;
    width: 100%;
  }
  table.responsive-table thead {
    /* Header row is redundant once labels are inline; hide it visually. */
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
  table.responsive-table tr {
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--pico-card-background-color);
  }
  table.responsive-table td {
    padding: 0.35rem 0;
    border: none;
    text-align: left;
    font-size: 0.95em;
  }
  table.responsive-table td[data-label]::before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: var(--pico-muted-color);
    font-size: 0.85em;
    display: inline-block;
    margin-right: 0.4em;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }
  /* Primary cell (usually the linked name) gets bigger treatment and no label. */
  table.responsive-table td.cell-primary {
    padding: 0 0 0.5rem 0;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
    font-size: 1.05em;
  }
  table.responsive-table td.cell-primary::before {
    content: none;
  }
  table.responsive-table td.cell-primary a {
    display: block;
    min-height: 32px;
  }
}
