/* Base elements and reusable components. Depends on tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--color-canvas);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { margin: 0 0 0.5rem; font-weight: 650; line-height: 1.25; }
h1, .h1 { font-size: clamp(1.5rem, 4vw, 2rem); }
h2, .h2 { font-size: clamp(1.3rem, 3vw, 1.6rem); }
h3, .h3 { font-size: 1.3rem; }
h4, .h4 { font-size: 1.15rem; }
h5, .h5 { font-size: 1.02rem; }
h6, .h6 { font-size: 0.925rem; }
p { margin: 0 0 1rem; }
a { color: var(--color-primary); }
a:hover { color: var(--color-primary-strong); }
img, svg, video { max-width: 100%; vertical-align: middle; }
img { height: auto; }
small, .small { font-size: var(--text-sm); }
hr { border: 0; border-top: 1px solid var(--color-border); margin: 1rem 0; }
ul, ol { padding-left: 1.25rem; margin: 0 0 1rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
fieldset { border: 0; margin: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 2000; background: var(--color-surface); padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.skip-link:focus { top: 8px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: var(--touch); padding: 0.5rem 1.1rem;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--color-text);
  font-weight: 600; line-height: 1.3; text-decoration: none; text-align: center;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled, .btn.disabled { opacity: 0.55; pointer-events: none; }
.btn-sm { min-height: 36px; padding: 0.3rem 0.75rem; font-size: var(--text-sm); }
.btn-lg { min-height: 52px; padding: 0.75rem 1.5rem; font-size: var(--text-lg); }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-strong); border-color: var(--color-primary-strong); color: #fff; }
.btn-secondary { background: #55625c; border-color: #55625c; color: #fff; }
.btn-secondary:hover { background: #414b46; color: #fff; }
.btn-success { background: var(--color-success-text); border-color: var(--color-success-text); color: #fff; }
.btn-success:hover { color: #fff; filter: brightness(0.92); }
.btn-danger { background: var(--color-danger-text); border-color: var(--color-danger-text); color: #fff; }
.btn-danger:hover { color: #fff; filter: brightness(0.92); }
.btn-dark { background: var(--color-text); border-color: var(--color-text); color: #fff; }
.btn-dark:hover { background: #000; color: #fff; }
.btn-light { background: #eef2ef; border-color: var(--color-border); }
.btn-light:hover { background: #e2e9e4; color: var(--color-text); }
.btn-outline-primary { border-color: var(--color-primary); color: var(--color-primary); }
.btn-outline-primary:hover { background: var(--color-primary); color: #fff; }
.btn-outline-secondary, .btn-outline-dark { border-color: var(--color-border-strong); }
.btn-outline-secondary:hover, .btn-outline-dark:hover { background: var(--color-primary-soft); color: var(--color-primary-strong); }
.btn-outline-danger { border-color: var(--color-danger); color: var(--color-danger-text); }
.btn-outline-danger:hover { background: var(--color-danger-text); color: #fff; }
.btn-link { border: 0; color: var(--color-primary); text-decoration: underline; font-weight: 500; }
.btn-close { width: var(--touch); height: var(--touch); border: 0; background: transparent; border-radius: var(--radius-sm); position: relative; flex: none; }
.btn-close::before { content: "\00d7"; font-size: 1.6rem; line-height: 1; }
.btn-close-white { color: #fff; }
.btn-group { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.btn-group-sm > .btn { min-height: 36px; padding: 0.3rem 0.7rem; font-size: var(--text-sm); }
.btn-check { position: absolute; opacity: 0; pointer-events: none; }
.btn-check:checked + .btn { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-check:focus-visible + .btn { box-shadow: var(--focus-ring); }
.btn-check:disabled + .btn { opacity: 0.5; }

/* forms */
.form-label, label.form-label { display: inline-block; margin-bottom: 0.35rem; font-weight: 600; font-size: var(--text-sm); }
.form-control, .form-select, input[type="text"].ui, select.ui {
  display: block; width: 100%; min-height: var(--touch); padding: 0.5rem 0.8rem;
  background: var(--color-surface); border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
}
textarea.form-control { min-height: 96px; resize: vertical; }
.form-control:focus, .form-select:focus { outline: 0; border-color: var(--color-primary); box-shadow: var(--focus-ring); }
.form-control[readonly], .form-control:disabled, .form-select:disabled { background: #eef2ef; }
.form-control-sm, .form-select-sm { min-height: 36px; padding: 0.3rem 0.6rem; font-size: var(--text-sm); }
.form-control-lg, .form-select-lg { min-height: 52px; }
.form-text { margin-top: 0.3rem; font-size: var(--text-sm); color: var(--color-muted); }
.form-check { display: flex; align-items: flex-start; gap: 0.6rem; min-height: 28px; margin-bottom: 0.25rem; }
.form-check-input { width: 1.15rem; height: 1.15rem; margin: 0.2rem 0 0; accent-color: var(--color-primary); flex: none; }
.form-check-inline { display: inline-flex; margin-right: 1rem; }
.form-switch .form-check-input { width: 2.2rem; }
.input-group { display: flex; width: 100%; }
.input-group > .form-control, .input-group > .form-select { flex: 1 1 auto; min-width: 0; border-radius: 0; }
.input-group > :first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group > :last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-group-text { display: flex; align-items: center; padding: 0 0.8rem; background: #eef2ef; border: 1px solid var(--color-border-strong); }
.input-group-sm > .form-control { min-height: 36px; }
.is-invalid, .was-validated .form-control:invalid { border-color: var(--color-danger) !important; }
.invalid-feedback, .field-error { display: block; margin-top: 0.3rem; color: var(--color-danger-text); font-size: var(--text-sm); }
.is-invalid + .invalid-feedback { display: block; }

/* cards, lists, tables */
.card { display: flex; flex-direction: column; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); min-width: 0; }
.card-header { padding: 0.85rem 1.15rem; border-bottom: 1px solid var(--color-border); font-weight: 600; }
.card-body { flex: 1 1 auto; padding: 1.15rem; }
.card-footer { padding: 0.85rem 1.15rem; border-top: 1px solid var(--color-border); }
.card-title { margin-bottom: 0.5rem; }
.card-text:last-child { margin-bottom: 0; }
.list-group { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; }
.list-group-flush { border: 0; border-radius: 0; }
.list-group-item { display: block; padding: 0.75rem 1rem; background: var(--color-surface); border-bottom: 1px solid var(--color-border); }
.list-group-item:last-child { border-bottom: 0; }
.list-group-item-action { width: 100%; text-align: left; text-decoration: none; color: inherit; }
.list-group-item-action:hover { background: var(--color-primary-soft); }
.table { width: 100%; margin: 0; border-collapse: collapse; }
.table th, .table td { padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--color-border); text-align: left; vertical-align: top; }
.table th { font-size: var(--text-xs); letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-muted); }
.table-sm th, .table-sm td { padding: 0.4rem 0.6rem; }
.table-hover tbody tr:hover { background: #f1f5f2; }
.table-light { background: #f1f5f2; }
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.align-middle td, .align-middle th { vertical-align: middle; }

/* status */
.badge { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.22em 0.65em; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 650; line-height: 1.4; white-space: nowrap; }
.alert { position: relative; margin-bottom: 1rem; padding: 0.85rem 1rem; border: 1px solid transparent; border-radius: var(--radius); }
.alert-success { background: var(--color-success-soft); color: var(--color-success-text); }
.alert-warning { background: var(--color-warning-soft); color: var(--color-warning-text); }
.alert-danger, .alert-error { background: var(--color-danger-soft); color: var(--color-danger-text); }
.alert-info, .alert-secondary { background: var(--color-info-soft); color: #204e69; }
.alert-dismissible { padding-right: 3.5rem; }
.alert-dismissible > .btn-close { position: absolute; top: 4px; right: 4px; }
.spinner-border, .spinner-grow { display: inline-block; width: 1.5rem; height: 1.5rem; border-radius: 50%; animation: spin 0.75s linear infinite; }
.spinner-border { border: 0.18em solid currentColor; border-right-color: transparent; }
.spinner-border-sm, .spinner-grow-sm { width: 1rem; height: 1rem; border-width: 0.14em; }
.spinner-grow { background: currentColor; animation: pulse 0.9s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
.skeleton { display: block; min-height: 1rem; border-radius: var(--radius-sm); background: linear-gradient(90deg, #e8ede9 25%, #f3f6f4 50%, #e8ede9 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* navigation */
.nav { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.nav-link { display: inline-flex; align-items: center; min-height: var(--touch); padding: 0.4rem 0.9rem; border: 0; background: transparent; text-decoration: none; }
.nav-tabs { border-bottom: 1px solid var(--color-border); }
.nav-tabs .nav-link { border-bottom: 2px solid transparent; }
.nav-tabs .nav-link.active { border-color: var(--color-primary); font-weight: 650; }
.breadcrumb { display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0 0 0.75rem; padding: 0; list-style: none; font-size: var(--text-sm); }
.breadcrumb-item + .breadcrumb-item::before { content: "/"; padding-right: 0.35rem; color: var(--color-muted); }
.pagination { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.page-link { display: inline-flex; align-items: center; justify-content: center; min-width: var(--touch); min-height: var(--touch); padding: 0 0.7rem; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface); text-decoration: none; }
.page-item.active .page-link { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.page-item.disabled .page-link { opacity: 0.5; pointer-events: none; }

/* overlays */
.modal { position: fixed; inset: 0; z-index: 1055; display: none; overflow-y: auto; padding: 1rem; }
.modal.show { display: block; }
.modal-dialog { width: 100%; max-width: 500px; margin: 2rem auto; }
.modal-dialog-centered { display: flex; align-items: center; min-height: calc(100% - 4rem); }
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1100px; }
.modal-sm { max-width: 320px; }
.modal-fullscreen { max-width: none; margin: 0; min-height: 100%; }
.modal-dialog-scrollable .modal-body { max-height: 70vh; overflow-y: auto; }
.modal-content { display: flex; flex-direction: column; width: 100%; background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 1.15rem; border-bottom: 1px solid var(--color-border); }
.modal-title { margin: 0; }
.modal-body { padding: 1.15rem; }
.modal-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; padding: 0.75rem 1.15rem; border-top: 1px solid var(--color-border); }
.modal-backdrop, .offcanvas-backdrop { position: fixed; inset: 0; z-index: 1050; background: rgba(18, 28, 24, 0.5); }
.offcanvas-backdrop { z-index: 1040; }
body.modal-open { overflow: hidden; }
.offcanvas { position: fixed; top: 0; bottom: 0; z-index: 1045; display: flex; flex-direction: column; width: min(400px, 100%); background: var(--color-surface); visibility: hidden; transition: transform 0.25s ease, visibility 0.25s; }
.offcanvas.show { visibility: visible; transform: none !important; box-shadow: var(--shadow-lg); }
.offcanvas-start { left: 0; transform: translateX(-100%); }
.offcanvas-end { right: 0; transform: translateX(100%); }
.offcanvas-bottom { top: auto; left: 0; right: 0; width: 100%; max-height: 85vh; transform: translateY(100%); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.offcanvas-header { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1.15rem; border-bottom: 1px solid var(--color-border); }
.offcanvas-title { margin: 0; }
.offcanvas-body { flex: 1 1 auto; overflow-y: auto; padding: 1.15rem; }
.collapse:not(.show) { display: none; }
.dropdown { position: relative; }
.dropdown-toggle::after { content: ""; display: inline-block; margin-left: 0.35rem; border: 0.3em solid transparent; border-top-color: currentColor; border-bottom: 0; }
.dropdown-menu { position: absolute; top: 100%; left: 0; z-index: 1080; display: none; min-width: 12rem; margin: 4px 0 0; padding: 0.35rem; list-style: none; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.dropdown-menu.show { display: block; }
.dropdown-menu-end { left: auto; right: 0; }
.dropdown-item { display: flex; align-items: center; gap: 0.5rem; width: 100%; min-height: 40px; padding: 0.4rem 0.75rem; border: 0; border-radius: var(--radius-sm); background: transparent; text-align: left; text-decoration: none; color: inherit; }
.dropdown-item:hover { background: var(--color-primary-soft); }
.dropdown-header { padding: 0.4rem 0.75rem; font-size: var(--text-xs); color: var(--color-muted); }
.dropdown-divider { margin: 0.25rem 0; }
.accordion-item { border: 1px solid var(--color-border); background: var(--color-surface); }
.accordion-item + .accordion-item { border-top: 0; }
.accordion-header { margin: 0; }
.accordion-button { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 52px; padding: 0.75rem 1rem; border: 0; background: transparent; text-align: left; font-weight: 600; }
.accordion-button::after { content: "\2212"; font-size: 1.3rem; }
.accordion-button.collapsed::after { content: "+"; }
.accordion-body { padding: 0.25rem 1rem 1rem; }
.carousel { position: relative; }
.carousel-inner { position: relative; width: 100%; overflow: hidden; }
.carousel-item { display: none; width: 100%; }
.carousel-item.active { display: block; animation: fade-in 0.45s ease; }
@keyframes fade-in { from { opacity: 0.35; } to { opacity: 1; } }
.carousel-indicators { position: absolute; left: 0; right: 0; bottom: 8px; z-index: 2; display: flex; justify-content: center; gap: 6px; }
.carousel-indicators [data-bs-slide-to] { width: 24px; height: 6px; padding: 0; border: 0; border-radius: 3px; background: rgba(255, 255, 255, 0.55); }
.carousel-indicators .active { background: #fff; }
.carousel-control-prev, .carousel-control-next { position: absolute; top: 50%; z-index: 2; width: var(--touch); height: var(--touch); transform: translateY(-50%); display: flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: rgba(18, 28, 24, 0.45); color: #fff; }
.carousel-control-prev { left: 8px; }
.carousel-control-next { right: 8px; }
.carousel-control-prev-icon::before { content: "\2039"; font-size: 1.8rem; }
.carousel-control-next-icon::before { content: "\203a"; font-size: 1.8rem; }
.toast-container { position: fixed; right: 0; bottom: 0; z-index: 1090; display: flex; flex-direction: column; gap: 0.5rem; max-width: 100%; padding: 1rem; }
.toast { display: none; width: 340px; max-width: 100%; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.toast.show { display: block; }
.toast-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--color-border); }
.toast-body { padding: 0.75rem; }
.toast.bg-success .toast-body, .toast.bg-danger .toast-body { color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* application bar and avatars (admin portal) */
.navbar { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-height: 60px; }
.navbar ul { margin: 0; }
.btn-icon { width: var(--touch); height: var(--touch); min-height: var(--touch); padding: 0; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex: none; }
.avatar-md { width: 44px; height: 44px; }
.avatar-initials { display: inline-flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-weight: 700; }
.avatar-primary .avatar-initials { background: var(--color-primary); color: #fff; }
.dropdown-menu-md { min-width: min(320px, calc(100vw - 24px)); }

/* searchable selects: the wrapper inherits the form classes, only the inner control is drawn */
.ts-wrapper.form-select, .ts-wrapper.form-control { display: block; height: auto; min-height: 0; padding: 0; border: 0; background: none; box-shadow: none; }
.ts-wrapper .ts-control { display: flex; align-items: center; min-height: var(--touch); padding: 0.45rem 0.75rem; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface); box-shadow: none; }
.ts-wrapper.focus .ts-control { border-color: var(--color-primary); box-shadow: var(--focus-ring); }
.ts-wrapper.is-invalid .ts-control { border-color: var(--color-danger); }
