/* =============================================================================
   components.css — Reusable UI components
   -----------------------------------------------------------------------------
   Cards, buttons, forms, badges, lists, empty states, the loading overlay and
   spinners, quick actions, helpers, responsive detail tables and a few
   SweetAlert2 overrides.

   Accessibility: every interactive control (buttons, icon buttons, inputs,
   selects) enforces min-height/min-width of var(--tap-min) so tap targets are
   >= 44x44px at all widths.

   Uses ONLY tokens from tokens.css. Loaded last.
   ============================================================================= */

/* =============================================================================
   Cards
   ============================================================================= */
.card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.card-title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* =============================================================================
   Buttons
   ============================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: var(--font-weight-semibold);
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--transition-fast),
    border-color var(--transition-fast), color var(--transition-fast),
    box-shadow var(--transition-fast), transform var(--transition-fast);
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled,
.btn.is-disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Primary — solid blue */
.btn-primary {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-contrast);
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: var(--color-primary-contrast);
}

.btn-primary:active {
  background-color: var(--color-primary-hover);
}

/* Secondary — outline */
.btn-secondary {
  background-color: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

.btn-secondary:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background-color: var(--color-primary-soft);
}

/* Danger — destructive solid */
.btn-danger {
  background-color: var(--color-danger);
  border-color: var(--color-danger);
  color: var(--color-primary-contrast);
}

.btn-danger:hover {
  background-color: var(--color-danger-hover);
  border-color: var(--color-danger-hover);
  color: var(--color-primary-contrast);
}

/* Success — confirm solid (e.g. accept selected cookies) */
.btn-success {
  background-color: var(--color-success);
  border-color: var(--color-success);
  color: var(--color-primary-contrast);
}

.btn-success:hover {
  filter: brightness(0.94);
  color: var(--color-primary-contrast);
}

/* Ghost — minimal, transparent */
.btn-ghost {
  background-color: transparent;
  border-color: transparent;
  color: var(--color-text-muted);
}

.btn-ghost:hover {
  background-color: var(--color-muted-soft);
  color: var(--color-text);
}

/* Full-width block button */
.btn-block {
  width: 100%;
}

/* Small button — still respects min tap target height */
.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
}

/* Icon-only button — square, still >= 44x44 */
.btn-icon {
  padding: var(--space-2);
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: var(--radius-md);
  font-size: var(--text-lg);
  line-height: 1;
}

/* =============================================================================
   Forms
   ============================================================================= */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.form-group label,
.form-label {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
}

.form-control {
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-3);
  background-color: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  line-height: var(--line-height-base);
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.form-control::placeholder {
  color: var(--color-text-muted);
  opacity: .8;
}

.form-control:hover {
  border-color: var(--color-text-muted);
}

.form-control:focus,
.form-control:focus-visible {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}

.form-control:disabled {
  background-color: var(--color-muted-soft);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

/* Textarea sizing */
textarea.form-control {
  min-height: calc(var(--tap-min) * 2);
}

/* Native select arrow affordance */
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235b6675' d='M1.41 0 6 4.58 10.59 0 12 1.42l-6 6-6-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-6);
}

/* Error state */
.form-control.is-invalid {
  border-color: var(--color-danger);
}

.form-control.is-invalid:focus {
  box-shadow: 0 0 0 var(--focus-ring-width) var(--color-danger-soft);
}

/* Field-level error helper text */
.field-error {
  font-size: var(--text-sm);
  color: var(--color-danger);
  min-height: 1em;
}

/* Form hint / helper text */
.form-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Side-by-side fields on desktop; stacked on mobile */
.form-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Form action footer */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* =============================================================================
   Badges — generic + service-entry type variants
   ============================================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  line-height: 1.4;
  white-space: nowrap;
  background-color: var(--color-muted-soft);
  color: var(--color-text-muted);
}

/* Generic muted badge */
.badge-muted {
  background-color: var(--color-muted-soft);
  color: var(--color-text-muted);
}

/* Service-entry type variants — distinct, subtle tinted backgrounds.
   Class names mirror the ServiceEntryType enum (lower-cased). */
.badge-technical_inspection {
  background-color: var(--color-primary-soft);
  color: var(--color-primary-hover);
}

.badge-oil_change {
  background-color: var(--color-warning-soft);
  color: var(--color-warning);
}

.badge-parts_replacement {
  background-color: var(--color-success-soft);
  color: var(--color-success);
}

.badge-repair {
  background-color: var(--color-danger-soft);
  color: var(--color-danger-hover);
}

.badge-other {
  background-color: var(--color-muted-soft);
  color: var(--color-text-muted);
}

/* =============================================================================
   Lists — cars / entries / reminders
   ============================================================================= */
.list {
  display: flex;
  flex-direction: column;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--color-border);
  transition: background-color var(--transition-fast);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item:hover {
  background-color: var(--color-muted-soft);
}

/* Primary / secondary text inside a list row */
.list-item__main {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.list-item__title {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-item__meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Trailing actions / value cluster */
.list-item__aside {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* A list-item rendered as a link/card (e.g., a car row that navigates) */
.list-item--link {
  cursor: pointer;
  border-radius: var(--radius-md);
}

.list-item--link:hover {
  background-color: var(--color-primary-soft);
}

/* =============================================================================
   Empty state — reused across cars / entries / search / reminders
   ============================================================================= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  color: var(--color-text-muted);
}

.empty-state__icon {
  font-size: var(--text-2xl);
  line-height: 1;
  margin-bottom: var(--space-1);
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.empty-state__message {
  font-size: var(--text-sm);
  max-width: 42ch;
}

/* =============================================================================
   Loading overlay + spinners
   - Pairs with the JS loading indicator (#loading-overlay).
   ============================================================================= */
.loading-overlay,
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-overlay);
  backdrop-filter: blur(1px);
}

/* Hidden state — JS toggles this attribute/class */
.loading-overlay[hidden],
#loading-overlay[hidden],
.loading-overlay.is-hidden,
#loading-overlay.is-hidden {
  display: none;
}

/* Full-size spinner used in the overlay */
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-pill);
  animation: spinner-rotate 700ms linear infinite;
}

/* Small inline spinner (e.g., inside a button or beside text) */
.spinner-inline {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: var(--radius-pill);
  animation: spinner-rotate 700ms linear infinite;
}

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

/* =============================================================================
   Quick actions — dashboard row of action buttons / cards
   ============================================================================= */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: var(--space-1);
  flex: 1 1 160px;
  min-height: var(--tap-min);
  padding: var(--space-4);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast), transform var(--transition-fast);
}

.quick-action:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  text-decoration: none;
  color: var(--color-text);
}

.quick-action__icon {
  font-size: var(--text-lg);
  color: var(--color-primary);
}

.quick-action__label {
  font-weight: var(--font-weight-semibold);
}

.quick-action__desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* =============================================================================
   Text helpers & utilities
   ============================================================================= */
.section-title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.muted {
  color: var(--color-text-muted);
}

.text-sm {
  font-size: var(--text-sm);
}

.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.text-primary { color: var(--color-primary); }

.text-center { text-align: center; }

/* Vertical stack utility */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.stack-sm { gap: var(--space-2); }
.stack-lg { gap: var(--space-5); }

/* Horizontal row utility — wraps */
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.row-between {
  justify-content: space-between;
}

.row-end {
  justify-content: flex-end;
}

/* =============================================================================
   Definition list / details table — car technical details
   - Stacks label over value on mobile.
   - Two-column label : value layout on desktop.
   ============================================================================= */
.detail-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

.detail-item:last-child {
  border-bottom: none;
}

.detail-item__label {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
}

.detail-item__value {
  color: var(--color-text);
  word-break: break-word;
}

/* Responsive data table (service entries) — scrolls horizontally if needed */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.data-table th {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background-color: var(--color-muted-soft);
}

/* =============================================================================
   SweetAlert2 overrides — keep dialogs visually consistent with the app.
   Light-touch: align radii, shadows and the confirm/cancel button colors with
   our tokens without breaking SweetAlert2's own layout.
   ============================================================================= */
.swal2-popup {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-sans);
}

.swal2-title {
  color: var(--color-text);
  font-weight: var(--font-weight-semibold);
}

.swal2-html-container {
  color: var(--color-text-muted);
}

/* Confirm button uses primary; styled via SweetAlert2's button classes */
.swal2-styled.swal2-confirm {
  background-color: var(--color-primary) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: none !important;
}

.swal2-styled.swal2-confirm:hover {
  background-color: var(--color-primary-hover) !important;
}

/* A destructive confirm — opt in by passing this as the confirmButton class */
.swal2-styled.swal2-confirm.swal2-confirm--danger {
  background-color: var(--color-danger) !important;
}

.swal2-styled.swal2-confirm.swal2-confirm--danger:hover {
  background-color: var(--color-danger-hover) !important;
}

.swal2-styled.swal2-cancel {
  background-color: var(--color-surface) !important;
  border: 1px solid var(--color-border) !important;
  color: var(--color-text) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: none !important;
}

.swal2-styled.swal2-cancel:hover {
  background-color: var(--color-muted-soft) !important;
}

.swal2-styled:focus-visible {
  box-shadow: var(--focus-ring) !important;
}

/* =============================================================================
   Desktop refinements — single breakpoint per design (>=601px)
   ============================================================================= */
@media (min-width: 601px) {
  .card {
    padding: var(--space-5);
  }

  /* Side-by-side form fields on desktop */
  .form-row {
    flex-direction: row;
  }

  .form-row > * {
    flex: 1 1 0;
    min-width: 0;
  }

  /* Two-column label/value technical details on desktop */
  .detail-list {
    grid-template-columns: repeat(2, 1fr);
    column-gap: var(--space-5);
  }

  .detail-item {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
  }

  .detail-item__label {
    flex: 0 0 45%;
  }

  .detail-item__value {
    flex: 1 1 auto;
    text-align: right;
  }
}

/* =============================================================================
   RECONCILIATION LAYER
   -----------------------------------------------------------------------------
   Additional component styles to match the exact class names used by the
   Thymeleaf templates and JavaScript modules (modals, alerts, BEM-style
   card/list/page-header element classes, filter form, search result groups,
   accessibility helpers). Token-only values.
   ============================================================================= */

/* --- Card element (BEM __) aliases used in templates ----------------------- */
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.card__title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

/* --- Page header element classes ------------------------------------------ */
.page-header__title {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
}

.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* --- Navbar search cluster + screen-reader-only label --------------------- */
.app-nav__search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.app-nav__search .form-control {
  min-width: 160px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- List item element extensions ----------------------------------------- */
.list-item__sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

.list-item__note {
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  color: var(--color-text);
  word-break: break-word;
}

.list-item__badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background-color: var(--color-muted-soft);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.list-item__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* A list-item rendered as an anchor should not look like a link. */
a.list-item,
a.list-item:hover {
  color: inherit;
  text-decoration: none;
}

/* --- Empty-state hint (used by JS alongside __title) ---------------------- */
.empty-state__hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 42ch;
}

/* --- Search result group headings ----------------------------------------- */
.result-group__title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: var(--space-4) 0 var(--space-2);
}

.result-group__title:first-child {
  margin-top: 0;
}

/* --- Per-car filter form --------------------------------------------------- */
.filter-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.filter-form .form-group {
  margin-bottom: 0;
}

.filter-form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: end;
}

.section-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-3);
}

/* --- Alerts (login error / logout notice) --------------------------------- */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.alert-danger {
  background-color: var(--color-danger-soft);
  border-color: var(--color-danger);
  color: var(--color-danger-hover);
}

.alert-success {
  background-color: var(--color-success-soft);
  border-color: var(--color-success);
  color: var(--color-success);
}

/* =============================================================================
   Modal (inline modal containers toggled by JS via the [hidden] attribute)
   -----------------------------------------------------------------------------
   Templates use: <div class="modal-backdrop" hidden> > <div class="modal"> with
   .modal__header / .modal__title / .modal__body / .modal__footer.
   ============================================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-4);
  overflow-y: auto;
  background-color: var(--color-overlay);
}

/* The hidden attribute fully removes the modal from view. */
.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 560px;
  margin-block: var(--space-6);
  background-color: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal__header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.modal__body {
  padding: var(--space-5);
  max-height: 70vh;
  overflow-y: auto;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  background-color: var(--color-bg);
}

/* The modal footer inside the scrolling form stays visible at the bottom. */
.modal__body .modal__footer {
  margin: var(--space-4) calc(-1 * var(--space-5)) calc(-1 * var(--space-5));
}

/* =============================================================================
   Desktop refinements for the reconciliation layer
   ============================================================================= */
@media (min-width: 601px) {
  /* Filter form lays out as a responsive row on desktop. */
  .filter-form {
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    align-items: end;
  }

  /* Two-column car form fields inside the modal on desktop. */
  .modal__body #car-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2) var(--space-4);
  }

  .modal__body #car-form .form-group:first-child,
  .modal__body #car-form .modal__footer {
    grid-column: 1 / -1;
  }
}

/* =============================================================================
   ADMIN PANEL
   -----------------------------------------------------------------------------
   User table action clusters, status pill grouping, the email-template editor
   layout and the sandboxed live-preview iframe. Token-only values.
   ============================================================================= */

/* Per-row action buttons in the users table — wrap and keep spacing. */
.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Grouped status badges (Active/Blocked + Verified/Unverified). */
.admin-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Monospace body editor for HTML email templates. */
.admin-code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  font-size: var(--text-sm);
  line-height: var(--line-height-base);
}

/* Email-template editor: form + live preview, stacked on mobile. */
.admin-template-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
}

.admin-preview {
  min-width: 0;
}

/* Sandboxed preview frame for rendered email body HTML. */
.admin-preview-frame {
  width: 100%;
  min-height: 320px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
}

@media (min-width: 601px) {
  /* Side-by-side editor and preview on desktop. */
  .admin-template-grid {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* =============================================================================
   Brand / auth logo marks + auth helper links
   -----------------------------------------------------------------------------
   SVG brand mark in the navbar lockup and the larger logo in auth-card headers.
   Token-only sizing; images sit inline with their adjacent text.
   ============================================================================= */
.app-brand__logo {
  display: inline-block;
  width: 28px;
  height: 28px;
  vertical-align: middle;
}

.auth-card__logo {
  display: block;
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-2);
}

/* Row of secondary auth links (e.g., forgot password / verify email on login) */
.auth-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

/* =============================================================================
   PREFERENCES: theme toggle + language switch
   ============================================================================= */
.prefs-toggles {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.theme-toggle__icon {
  font-size: 1.1rem;
  line-height: 1;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  background-color: var(--color-surface);
}

.lang-switch__btn {
  min-width: 40px;
  min-height: var(--tap-min);
  padding: 0 var(--space-3);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.lang-switch__btn:hover {
  color: var(--color-text);
  background-color: var(--color-muted-soft);
}

.lang-switch__btn.is-active {
  background-color: var(--color-primary);
  color: var(--color-primary-contrast);
}

/* On the auth pages, float the toggles to the top-right of the viewport. */
.auth-prefs {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 50;
}

/* =============================================================================
   CUSTOM MODAL + DIALOG (replaces SweetAlert2) — .ccl-* namespace
   ============================================================================= */
.ccl-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background-color: var(--color-overlay);
  animation: ccl-fade-in 140ms ease;
}

.ccl-modal {
  width: 100%;
  max-width: 420px;
  background-color: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-5);
  text-align: center;
  animation: ccl-pop-in 160ms ease;
}

.ccl-modal__icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-3);
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-primary-contrast);
  background-color: var(--color-primary);
}

.ccl-modal__icon--success { background-color: var(--color-success); }
.ccl-modal__icon--error { background-color: var(--color-danger); }
.ccl-modal__icon--warning { background-color: var(--color-warning); }
.ccl-modal__icon--question { background-color: var(--color-primary); }
.ccl-modal__icon--info { background-color: var(--color-primary); }

.ccl-modal__title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-2);
  color: var(--color-text);
}

.ccl-modal__text {
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
  line-height: var(--line-height-base);
}

.ccl-modal__actions {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

@keyframes ccl-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ccl-pop-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* =============================================================================
   TOASTS
   ============================================================================= */
.ccl-toast-container {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: max-content;
  max-width: calc(100vw - 2 * var(--space-4));
  pointer-events: none;
}

.ccl-toast {
  pointer-events: auto;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  background-color: var(--color-text);
  color: var(--color-bg);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--transition-base), transform var(--transition-base);
  cursor: pointer;
}

.ccl-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.ccl-toast--success { background-color: var(--color-success); color: #fff; }
.ccl-toast--error { background-color: var(--color-danger); color: #fff; }
.ccl-toast--info { background-color: var(--color-primary); color: var(--color-primary-contrast); }

/* =============================================================================
   Bottom spacing below tile/card grids so the last row never sticks to the
   viewport edge on mobile.
   ============================================================================= */
.page {
  padding-bottom: var(--space-8);
}

.grid,
.grid-2,
.grid-3,
.grid-auto,
.dashboard-grid,
.quick-actions {
  margin-bottom: var(--space-5);
}

.card {
  margin-bottom: var(--space-4);
}

.card:last-child {
  margin-bottom: 0;
}

/* =============================================================================
   Password field — show/hide toggle (auth forms)
   -----------------------------------------------------------------------------
   The input is wrapped in .password-field (position: relative) and gets right
   padding so its text never sits under the toggle button. .password-toggle is
   an absolutely positioned, transparent icon button that keeps a min tap
   target. Pairs with /js/password-toggle.js.
   ============================================================================= */
.password-field {
  position: relative;
}

.password-field .form-control {
  padding-right: var(--space-8);
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: var(--space-2);
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-lg);
  line-height: 1;
  cursor: pointer;
}

.password-toggle:focus-visible {
  outline: none;
  border-radius: var(--radius-md);
  box-shadow: var(--focus-ring);
}

/* =============================================================================
   Form check — checkbox + label row (e.g., "Remember me" on login)
   ============================================================================= */
.form-check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  cursor: pointer;
}

.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--color-primary);
}
/* =============================================================================
   Account page styles
   ============================================================================= */

.account-avatar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-4) 0;
}

@media (min-width: 601px) {
  .account-avatar {
    flex-direction: row;
    align-items: flex-start;
  }
}

.account-avatar__preview {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  overflow: hidden;
  background-color: var(--color-muted-soft);
  border: 2px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.account-avatar__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
  padding: var(--space-2);
}

.account-avatar__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.account-avatar__form {
  flex: 1;
  min-width: 0;
}

.account-avatar__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  align-items: flex-start;
}

.account-avatar__actions .form-group {
  margin-bottom: 0;
}

.account-avatar__actions .form-actions {
  display: flex;
  gap: var(--space-2);
}

/* Account forms */
.account-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.account-info {
  background-color: var(--color-muted-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
}

.account-info__item {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
}

.account-info__label {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  font-size: var(--text-sm);
}

.account-info__value {
  color: var(--color-text);
  word-break: break-all;
}

/* Danger card styling */
.card-danger {
  border-color: var(--color-danger-soft);
  background-color: var(--color-danger-soft);
}

.account-danger {
  color: var(--color-danger-hover);
}

.account-danger .muted {
  color: var(--color-danger);
  opacity: 0.8;
}

/* CSRF token handling for multipart forms */
.multipart-form {
  position: relative;
}

.multipart-form input[name="_csrf"] {
  position: absolute;
  top: 0;
  right: 0;
  opacity: 0;
  pointer-events: none;
}
/* =============================================================================
   ATTACHMENTS
   ============================================================================= */

.attachment-upload {
  margin-bottom: var(--space-5);
}

.attachment-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.attachments-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  transition: background-color var(--transition-fast);
}

.attachment-item:hover {
  background-color: var(--color-muted-soft);
}

.attachment-item__main {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}

.attachment-item__icon {
  font-size: 1.2rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.attachment-item__info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.attachment-item__name {
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-item__meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  display: flex;
  gap: var(--space-2);
}

.attachment-item__actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Export section */
.export-section {
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.export-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

/* Desktop refinements */
@media (min-width: 601px) {
  .attachment-form {
    flex-direction: row;
    align-items: flex-end;
  }
  
  .attachment-form .form-group {
    flex: 1;
    margin-bottom: 0;
  }
  
  .attachment-form .form-actions {
    margin-top: 0;
  }
}


/* =============================================================================
   STATISTICS TILES & CHARTS
   ============================================================================= */

/* Statistics tiles */
.stats-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

@media (min-width: 601px) {
  .stats-tiles {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-tile {
  background-color: var(--color-muted-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

.stat-tile__value {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-primary);
  line-height: 1.2;
  margin-bottom: var(--space-1);
}

.stat-tile__label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.4;
}

/* Charts grid */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
}

@media (min-width: 601px) {
  .charts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .charts-grid .chart-container:first-child {
    grid-column: 1 / -1;
  }
}

.chart-container {
  position: relative;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  min-height: 300px;
  display: flex;
  flex-direction: column;
}

.chart-title {
  font-size: var(--text-base);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--space-3);
  text-align: center;
}

.chart-container canvas {
  flex: 1;
  min-height: 200px;
  width: 100% !important;
  height: auto !important;
}

.chart-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-surface);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  padding: var(--space-4);
  text-align: center;
}

/* Dashboard grid adjustments for charts */
.dashboard-grid__col--main {
  order: 2;
}

#charts-section {
  order: 1;
  margin-bottom: var(--space-5);
}

#cost-stats-section {
  order: 1;
  margin-bottom: var(--space-5);
}

@media (min-width: 601px) {
  .dashboard-grid__col--main {
    order: 1;
  }
  
  #charts-section {
    order: 2;
    margin-bottom: 0;
  }
  
  #cost-stats-section {
    order: 1;
    margin-bottom: var(--space-5);
  }
}

/* Print styles for charts */
@media print {
  .chart-container {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  
  .stat-tile {
    border: 1px solid #ddd;
  }
}

/* =============================================================================
   Ad slots (Google AdSense placements)
   -----------------------------------------------------------------------------
   Rendered by the "ad-slot" Thymeleaf fragment only when an admin has enabled
   ads. The placeholder variant keeps the reserved space discreet while no
   AdSense publisher id is configured yet.
   ============================================================================= */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 90px;
  margin: var(--space-4) 0;
  overflow: hidden;
}

.ad-slot .adsbygoogle {
  display: block;
  width: 100%;
}

.ad-slot--placeholder {
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  color: var(--color-text-muted);
}

.ad-slot--placeholder::before {
  content: "Reklama";
  font-size: var(--text-sm);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.55;
}

/* =============================================================================
   Legal pages (Regulamin / Polityka prywatności)
   ============================================================================= */
.legal-layout {
  max-width: 860px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-8);
}

.legal-card {
  padding: var(--space-6);
}

.legal-card__header {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.legal-card__title {
  margin: 0;
  font-size: var(--text-2xl);
  color: var(--color-text);
}

.legal-content {
  color: var(--color-text);
  line-height: 1.7;
}

.legal-content h2 {
  margin: var(--space-5) 0 var(--space-2);
  font-size: var(--text-lg);
  color: var(--color-text);
}

.legal-content p {
  margin: 0 0 var(--space-3);
  color: var(--color-text);
}

.legal-content ul {
  margin: 0 0 var(--space-3);
  padding-left: var(--space-5);
}

.legal-content li {
  margin-bottom: var(--space-2);
}

.legal-content a {
  color: var(--color-primary);
}

.legal-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.legal-disclaimer {
  margin-top: var(--space-5);
  padding: var(--space-3) var(--space-4);
  background: var(--color-muted-soft);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.legal-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding-top: var(--space-5);
  margin-top: var(--space-5);
  border-top: 1px solid var(--color-border);
}

.legal-links {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.legal-links a {
  color: var(--color-primary);
}

.legal-footer__copyright {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* =============================================================================
   Cookie consent banner (RODO/GDPR) — see cookie-consent.js
   ============================================================================= */
.cookie-consent {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -8px 24px rgba(16, 24, 40, .18);
  padding: var(--space-4);
}

.cookie-consent__inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.cookie-consent__title {
  margin: 0 0 var(--space-1);
  font-size: var(--text-lg);
  color: var(--color-text);
}

.cookie-consent__text {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.cookie-consent__links {
  margin: var(--space-2) 0 0;
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  font-size: var(--text-sm);
}

.cookie-consent__links a {
  color: var(--color-primary);
}

.cookie-consent__options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}

.cookie-consent__option {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  cursor: pointer;
}

.cookie-consent__option--locked {
  opacity: .8;
  cursor: default;
}

.cookie-consent__option input {
  margin-top: 3px;
}

.cookie-consent__option-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cookie-consent__option-title {
  font-weight: var(--font-weight-semibold, 600);
  color: var(--color-text);
  font-size: var(--text-sm);
}

.cookie-consent__option-desc {
  color: var(--color-text-muted);
  font-size: .8125rem;
  line-height: 1.5;
}

.cookie-consent__actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 640px) {
  .cookie-consent__actions {
    flex-direction: column;
  }
  .cookie-consent__actions .btn {
    width: 100%;
  }
}

/* =============================================================================
   App footer (authenticated pages) — legal links + copyright
   -----------------------------------------------------------------------------
   Rendered by the "footer" Thymeleaf fragment, placed as a block below the
   <main class="page"> content. Uses a top margin so it never overlaps the page
   content, and a hairline top border to separate it visually.
   ============================================================================= */
.app-footer {
  margin-top: var(--space-6);
  padding: var(--space-4) var(--space-5);
  background-color: var(--color-surface);
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
}

.app-footer__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
}

.app-footer__links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.app-footer__links a {
  color: var(--color-primary);
  text-decoration: none;
}

.app-footer__links a:hover {
  text-decoration: underline;
}

.app-footer__copyright {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* Stack and center on narrow screens. */
@media (max-width: 640px) {
  .app-footer__inner {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-2);
  }
}
