/*
 * boxdb shell styles. Tokens from docs/requirements/ui-style-guide.md are
 * defined once here and mapped onto Bootstrap's variables; nothing else
 * hard-codes a colour.
 */

:root {
  --color-primary: #003e6e;
  --color-primary-hover: #002a4b;
  --color-accent: #00ace5;
  --color-text: #4b4b4c;
  --color-text-strong: #333333;
  --color-text-muted: #676c7c;
  --color-surface: #ffffff;
  --color-surface-alt: #f2f2f4;
  --color-border: #d1d1d2;
  --color-border-light: #e5e5e5;
  --color-danger: #da3a00;
  --color-success: #1e7b3a;
  --color-warning: #b25e00;
  --space: 15px;
  --radius: 4px;
  --sidebar-width: 220px;
  --sidebar-width-narrow: 56px;
  --topbar-height: 56px;

  /* Bootstrap mapping */
  --bs-primary: var(--color-primary);
  --bs-primary-rgb: 0, 62, 110;
  --bs-danger: var(--color-danger);
  --bs-danger-rgb: 218, 58, 0;
  --bs-success: var(--color-success);
  --bs-success-rgb: 30, 123, 58;
  --bs-warning: var(--color-warning);
  --bs-warning-rgb: 178, 94, 0;
  --bs-body-color: var(--color-text);
  --bs-body-bg: var(--color-surface);
  --bs-secondary-color: var(--color-text-muted);
  --bs-tertiary-bg: var(--color-surface-alt);
  --bs-border-color: var(--color-border);
  --bs-border-radius: var(--radius);
  --bs-link-color: var(--color-primary);
  --bs-link-color-rgb: 0, 62, 110;
  --bs-link-hover-color: var(--color-primary-hover);
  --bs-link-hover-color-rgb: 0, 42, 75;
  --bs-heading-color: var(--color-primary);
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  --bs-body-font-size: 1rem;
  --bs-body-line-height: 1.5;
  --bs-focus-ring-color: rgba(0, 172, 229, 0.4);
}

/* Typography */
h1, .h1 { font-size: 24px; }
h2, .h2 { font-size: 20px; }
h3, .h3 { font-size: 16px; }
h1, h2, h3, .h1, .h2, .h3 {
  font-weight: 600;
  line-height: 1.25;
  color: var(--color-primary);
}
label, th { color: var(--color-text-strong); }
.text-muted, .form-text { color: var(--color-text-muted) !important; }

/* Bootstrap component overrides */
.btn-primary {
  --bs-btn-bg: var(--color-primary);
  --bs-btn-border-color: var(--color-primary);
  --bs-btn-hover-bg: var(--color-primary-hover);
  --bs-btn-hover-border-color: var(--color-primary-hover);
  --bs-btn-active-bg: var(--color-primary-hover);
  --bs-btn-active-border-color: var(--color-primary-hover);
  --bs-btn-disabled-bg: var(--color-primary);
  --bs-btn-disabled-border-color: var(--color-primary);
}
.btn-outline-primary {
  --bs-btn-color: var(--color-primary);
  --bs-btn-border-color: var(--color-primary);
  --bs-btn-hover-bg: var(--color-primary);
  --bs-btn-hover-border-color: var(--color-primary);
  --bs-btn-active-bg: var(--color-primary-hover);
  --bs-btn-active-border-color: var(--color-primary-hover);
}
.btn-danger {
  --bs-btn-bg: var(--color-danger);
  --bs-btn-border-color: var(--color-danger);
  --bs-btn-hover-bg: #b83100;
  --bs-btn-hover-border-color: #b83100;
  --bs-btn-active-bg: #b83100;
  --bs-btn-active-border-color: #b83100;
}
.form-control, .form-select { border-color: var(--color-border-light); }
.form-control:focus, .form-select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 0.25rem var(--bs-focus-ring-color);
}
.table {
  --bs-table-striped-bg: var(--color-surface-alt);
  --bs-table-hover-bg: var(--color-surface-alt);
  --bs-table-border-color: var(--color-border);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.card { border-color: var(--color-border); }

/* Shell layout: the body fills the viewport and never scrolls; the main
   column scrolls instead, so the sidebar and the top bar stay in place on
   long pages (finding of 2026-09-04). */
html, body { height: 100%; }
body {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.icon {
  width: 1.25em;
  height: 1.25em;
  flex: 0 0 auto;
  vertical-align: -0.25em;
}

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.sidebar .brand {
  display: block;
  padding: 0 var(--space);
  height: var(--topbar-height);
  line-height: var(--topbar-height);
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.sidebar nav ul {
  list-style: none;
  margin: 0;
  padding: var(--space) 0;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--space);
  color: #fff;
  text-decoration: none;
  border-left: 3px solid transparent;
  white-space: nowrap;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.08); }
.sidebar nav a[aria-current="page"] {
  border-left-color: var(--color-accent);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.06);
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space);
  height: var(--topbar-height);
  padding: 0 var(--space);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
}
.topbar-search { flex: 1 1 auto; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space);
  margin-left: auto;
  white-space: nowrap;
}
.lang-switch {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-text-muted);
}
.lang-switch button {
  background: none;
  border: 0;
  padding: 2px 4px;
  color: var(--color-primary);
  font-weight: 600;
  border-radius: var(--radius);
}
.lang-switch button:hover { background: var(--color-surface-alt); }
.lang-switch button[aria-current="true"] {
  text-decoration: underline;
  text-decoration-color: var(--color-accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text-strong);
}
.user-menu .btn-link {
  padding: 0;
  color: var(--color-primary);
  text-decoration: none;
}
.user-menu .btn-link:hover { text-decoration: underline; }

.content {
  --content-padding-x: calc(var(--space) * 2);
  flex: 1 1 auto;
  padding: calc(var(--space) * 1.5) var(--content-padding-x);
}
/* Title and actions stay visible while a page scrolls; the negative margins
   let the header cover the content padding at its sides. */
.page-header {
  position: sticky;
  top: var(--topbar-height); /* the top bar is sticky at 0 and above it */
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  margin: 0 calc(var(--content-padding-x) * -1) var(--space);
  padding: 8px var(--content-padding-x);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
}
.page-header h1 { margin: 0; }

/* List pages fill the viewport: title, filter and actions keep their place,
   the table scrolls on its own with a sticky header row. */
.content-fill {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.content-fill .page-header, .content-fill .filter-bar, .content-fill > p { flex: 0 0 auto; }
.list-form {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  min-height: 0;
}
.table-scroll {
  flex: 0 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll .table { margin-bottom: 0; }
.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-surface);
  box-shadow: inset 0 -1px 0 var(--color-border);
}
.table-scroll-capped { max-height: 50vh; margin-bottom: var(--space); }
.list-actions { flex: 0 0 auto; padding-top: var(--space); }
.empty-state {
  padding: calc(var(--space) * 3) var(--space);
  text-align: center;
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}
.empty-state .btn { margin-top: var(--space); }

/* Breadcrumb path (style guide section 5) */
.breadcrumb-path {
  color: var(--color-text-muted);
  font-size: 14px;
  margin-bottom: 6px;
}
.breadcrumb-path a { color: var(--color-text-muted); text-decoration: none; }
.breadcrumb-path a:hover { color: var(--color-primary); text-decoration: underline; }
.breadcrumb-path .sep { margin: 0 6px; }
.breadcrumb-path .current { color: var(--color-text-strong); }

/* Status badges */
.badge {
  font-weight: 500;
  font-size: 12px;
  border: 1px solid transparent;
}
.badge.status-active { background: var(--color-surface-alt); color: var(--color-text); }
.badge.status-retired { background: transparent; color: var(--color-text-muted); border-color: var(--color-border); }
.badge.status-lost, .badge.status-consumed {
  background: transparent; color: var(--color-danger); border-color: var(--color-danger);
}
.badge.status-unverified {
  background: transparent; color: var(--color-warning); border-color: var(--color-warning);
}

/* Detail and edit pages: details (or the form) on the left, the picture
   card on the right. The frame keeps 3:4 (portrait, the phone camera's
   default) whatever the picture's proportions; the picture is cropped to
   fill it (object-fit: cover, centred), so a landscape photo shows its
   middle and cannot move the rest of the page; on a phone one column with
   the picture first, capped so the details stay in reach. */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 0 calc(var(--space) * 2);
  align-items: start;
}
.detail-grid > * { min-width: 0; }
.picture-card {
  margin-bottom: calc(var(--space) * 1.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.picture-frame {
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-alt);
}
.picture-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.picture-placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--color-text-muted);
}
.picture-placeholder .icon { width: 2em; height: 2em; }
@media (max-width: 767.98px) {
  .detail-grid { grid-template-columns: 1fr; }
  .picture-card { order: -1; }
  .picture-frame { max-height: 50vh; margin: 0 auto; }
}

/* Foldable sections (Contents, History): native <details>, open by
   default, the heading and its count stay readable when folded. */
.fold summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  margin-bottom: 10px;
}
.fold summary::-webkit-details-marker { display: none; }
.fold summary h2 { margin: 0; }
.fold summary .icon { color: var(--color-text-muted); transition: transform 0.15s; }
.fold[open] > summary .icon { transform: rotate(90deg); }

/* Forms and detail lists */
.form-narrow { max-width: 640px; }
.required { color: var(--color-danger); }
.detail-list dt { font-weight: 600; color: var(--color-text-strong); }
.detail-list dd { margin-bottom: 8px; }
section h2 { margin-bottom: 10px; }
section h3 { margin-top: 12px; margin-bottom: 6px; }
code { color: var(--color-text-strong); background: var(--color-surface-alt); padding: 1px 4px; border-radius: var(--radius); }
.identifier-rows td { vertical-align: top; }
.select-col { width: 2.5rem; }
.history td { font-size: 14px; }
.identifier-rows .form-control, .identifier-rows .form-select { font-size: 14px; }

/* Global search (P-40): top bar and, larger, on the home page */
.search-form { width: 100%; max-width: 560px; }
.search-input { position: relative; }
.search-input .icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}
.search-input .form-control { padding-left: 36px; }
.search-form-large { max-width: 720px; margin-bottom: calc(var(--space) * 2); }
.search-form-large .search-input .icon { width: 1.5em; height: 1.5em; left: 12px; }
.search-form-large .form-control-lg { padding-left: 44px; }
.search-results .breadcrumb-path { margin-bottom: 0; }
.count-tiles { display: flex; flex-wrap: wrap; gap: var(--space); }
.count-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 160px;
  padding: var(--space);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
}
.count-tile:hover { border-color: var(--color-primary); }
.count-tile .icon { width: 1.5em; height: 1.5em; color: var(--color-primary); }
.count-tile .count { font-size: 24px; font-weight: 600; color: var(--color-primary); }

/* List filter and sortable headers (P-42) */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: var(--space);
}
.filter-bar .form-control { max-width: 320px; }
.filter-bar .form-select { width: auto; }
th .sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
th .sort-link:hover { text-decoration: underline; }
th[aria-sort] .sort-link { color: var(--color-primary); }

/* Sidebar toggle: hidden checkbox, label in the top bar */
.nav-toggle-input { position: absolute; opacity: 0; pointer-events: none; }
.nav-toggle {
  display: none;
  margin: 0;
  padding: 6px;
  color: var(--color-primary);
  cursor: pointer;
}

/* Tablet (P-93): sidebar collapses to icons */
@media (max-width: 1023.98px) {
  .sidebar { flex-basis: var(--sidebar-width-narrow); width: var(--sidebar-width-narrow); }
  .sidebar .brand { padding: 0; text-align: center; font-size: 16px; }
  .sidebar .brand span { display: none; }
  .sidebar nav a span { display: none; }
  .sidebar nav a { justify-content: center; padding-left: 0; padding-right: 3px; }
  .sidebar nav a .icon { width: 1.5em; height: 1.5em; }
}

/* Small screens: sidebar hidden behind the toggle */
@media (max-width: 767.98px) {
  .sidebar { display: none; position: fixed; z-index: 10; left: 0; top: 0; height: 100vh; height: 100dvh; }
  .nav-toggle-input:checked ~ .sidebar { display: flex; }
  .nav-toggle { display: inline-flex; }
  .content { --content-padding-x: var(--space); padding: var(--space); }
  .page-header { flex-wrap: wrap; }
}

/* Login page */
.login-page {
  width: 100%;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space);
  background: var(--color-surface-alt);
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: calc(var(--space) * 2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.login-card .brand {
  font-size: 24px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space);
}
