/* ============================================
   Components

   Buttons, inputs, address autocomplete,
   loading spinners, intent cards, incident rows,
   error states, dividers, dev panel syntax.
   ============================================ */

/* ============================================
   Secondary Step CTAs
   For small button CTAs under step inputs that aren't primary actions 
   (e.g. "I'm done adding drivers", "I don't have
   any accidents", etc.)
   ============================================ */

.secondary-step-cta-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  width: 100%;
  margin-top: clamp(var(--spacing-md), 3dvh, var(--spacing-lg));
  cursor: pointer;
  border-radius: var(--radius-md);
  border: 0;
  padding: clamp(var(--spacing-sm), 3dvh, var(--spacing-md));
  background-color: transparent;
  transition: background-color var(--transition-base);
}

.secondary-step-cta-btn.condensed {
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

@media (hover: hover) and (pointer: fine) {
  .secondary-step-cta-btn:hover {
    background-color: var(--theme-primary-focus, rgba(87, 71, 248, 0.06));
    border-style: solid;
  }
}

.secondary-step-cta-btn * {
  color: var(--color-primary-text);
  text-transform: uppercase;
  font-family: var(--theme-font-ui, var(--font-family));
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition:
    color var(--transition-base),
    transform var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
  .secondary-step-cta-btn:hover * {
    color: var(--color-primary-hover);
  }
}

.secondary-step-cta-btn:active * {
  transform: scale(0.98);
}

/* ============================================
   Incident Grouping cards (accidents, violations)
   ============================================ */
.incident-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
  padding-top: 36px;
  /* clears the remove button (8px offset + 24px button + 4px gap) */
  background-color: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  width: 100%;
}

.incident-card .input-field {
  max-width: none;
}

/* Ghost icon button — sits at the top-right corner of the card */
.incident-card .incident-remove-btn {
  position: absolute;
  top: var(--spacing-sm);
  right: var(--spacing-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: var(--spacing-xs);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  line-height: 0;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
  .incident-card .incident-remove-btn:hover:not(:disabled) {
    color: var(--color-danger);
    background-color: var(--color-danger-bg);
  }
}

.incident-card .incident-remove-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ============================================
   Gradient Border — Selected State
   Apply to any element that needs a gradient
   border when selected. Requires the element
   to have position: relative and overflow: visible.
   Uses a ::before pseudo-element to draw a
   gradient border that respects border-radius.
   ============================================ */
.selected-option-border {
  position: relative;
  border-color: transparent;
}

.selected-option-border::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  padding: 2px;
  background: linear-gradient(91deg, var(--color-gradient-start), var(--color-gradient-end));
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask-composite: exclude;
  pointer-events: none;
}

/* ============================================
   Secondary button (ghost style)
   ============================================ */
.btn-secondary {
  padding: 12px 24px;
  background-color: transparent;
  color: var(--color-primary-text);
  border: 1px solid var(--color-primary-text);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  font-family: var(--font-family);
  cursor: pointer;
  transition: background-color var(--transition-base), transform var(--transition-base);
  width: 100%;
  max-width: 400px;
  align-self: center;
}

@media (hover: hover) and (pointer: fine) {
  .btn-secondary:hover {
    background-color: var(--theme-primary-focus, rgba(87, 71, 248, 0.08));
    transform: scale(1.02);
  }
}

.btn-secondary:active {
  transform: scale(0.98);
}

/* focus-visible is in animations.css */

/* ============================================
   Text inputs
   ============================================ */
.input-field {
  padding: 14px 18px;
  width: 100%;
  max-width: 400px;
  border: 1.5px solid var(--theme-input-border, var(--color-border));
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-family: var(--theme-font-display, var(--font-family));
  background-color: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
  .input-field:hover:not(:focus-visible) {
    border-color: var(--theme-input-border-hover, var(--color-border));
  }
}

.input-field:focus-visible {
  outline: none;
  border-color: var(--color-primary);
  background-color: var(--color-surface-hover);
  box-shadow: 0 0 0 4px var(--color-focus);
}

.input-field::placeholder {
  color: var(--color-text-placeholder);
  font-family: var(--theme-font-display, var(--font-family));
}

/* ============================================
   Select Dropdowns
   Custom styling with chevron icon and loading state
   ============================================ */
select.input-field {
  /* Remove default browser appearance */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  /* Add right padding for custom arrow */
  padding-right: 42px;

  /* Custom chevron down arrow */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6L8 10L12 6' stroke='%231A202C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
  font-family: var(--theme-font-display, var(--font-family));
}

@media (hover: hover) and (pointer: fine) {
  select.input-field:hover:not(:disabled) {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6L8 10L12 6' stroke='%233a6ef5' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

select.input-field:focus-visible {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6L8 10L12 6' stroke='%233a6ef5' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

select.input-field:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  background-color: var(--color-background);
  color: var(--color-text-muted);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6L8 10L12 6' stroke='%23A0AEC0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Option placeholder styling */
select.input-field option[disabled] {
  color: var(--color-text-placeholder);
}

select.input-field option:not([disabled]) {
  color: var(--color-text);
}

/* ============================================
   Select Loading State
   Wrapper pattern for showing spinner while options load
   Usage: 
   <div class="select-loading-wrapper">
     <select class="input-field loading" disabled>...</select>
     <div class="select-loading-spinner"></div>
   </div>
   ============================================ */
.select-loading-wrapper {
  position: relative;
  width: 100%;
  max-width: 400px;
  display: inline-block;
}

select.input-field.loading {
  background-image: none;
  /* Hide chevron when loading */
  cursor: wait;
  padding-right: 42px;
  /* Keep space for spinner */
}

.select-loading-spinner-wrapper {
  position: absolute;
  right: 14px;
  bottom: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.select-loading-spinner {
  height: 30px;
  width: 30px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  pointer-events: none;
}

/* ============================================
   Primary action button
   Rounded rectangle, gradient, uppercase tracked labels
   ============================================ */
.btn-primary {
  padding: 18px 36px;
  background: var(--theme-gradient, linear-gradient(91deg, var(--color-gradient-start), var(--color-gradient-end)));
  color: var(--color-text-inverse);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-xs);
  font-weight: 600;
  font-family: var(--theme-font-ui, var(--font-family));
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform var(--transition-base), box-shadow var(--transition-base);
  margin-top: var(--spacing-sm);
  box-shadow: var(--shadow-button);
  width: 100%;
  max-width: 400px;
  align-self: center;
}

/* Next button inside step-page: centered, fill to max-width */
.step-page>.btn-primary {
  align-self: center;
  width: 100%;
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled) {
    transform: scale(1.02);
    box-shadow: var(--shadow-button-hover);
  }
}

.btn-primary:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-sm);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  background: transparent;
  color: var(--theme-disabled-text, var(--color-text-muted));
  border: 1px solid var(--theme-disabled-border, var(--color-disabled));
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ============================================
   Address Autocomplete Dropdown
   ============================================ */
.address-autocomplete-container {
  position: relative;
  width: 100%;
}

.address-autocomplete-container .input-field {
  max-width: none;
}

.address-suggestions-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: var(--spacing-xs);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 300px;
  overflow-y: auto;
  z-index: 1000;
}

.address-suggestion-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background-color: var(--color-surface);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  border-bottom: 1px solid var(--color-border-light);
  font-family: var(--font-family);
}

.address-suggestion-item:last-child {
  border-bottom: none;
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

.address-suggestion-item:first-child {
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
}

@media (hover: hover) and (pointer: fine) {
  .address-suggestion-item:hover {
    background-color: var(--theme-primary-focus);
  }
}

.address-suggestion-item:active {
  background-color: var(--color-focus);
}

.address-suggestion-street {
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: var(--spacing-xs);
  font-size: var(--font-size-base);
  font-family: var(--theme-font-ui, var(--font-family));
}

.address-suggestion-locale {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  font-family: var(--theme-font-ui, var(--font-family));
}

/* ============================================
   Loading Spinner
   ============================================ */
.step-page:has(.step-content > .loading-spinner:first-child) {
  justify-content: center;
  padding: 0;
}

.loading-spinner {
  width: var(--spacing-2xl);
  height: var(--spacing-2xl);
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  align-self: center;
  margin: auto;
}

.loading-spinner.small {
  width: var(--spacing-lg);
  height: var(--spacing-lg);
}

.loading-spinner.large {
  width: var(--spacing-4xl);
  height: var(--spacing-4xl);
}

/* DevPanel JSON syntax is in DevPanel.razor.css (scoped) */

/* ============================================
   Form field error states
   ============================================ */
.input-field-error {
  border: 1px solid var(--color-danger-border);
  background-color: var(--color-danger-bg);
}

.input-error-message {
  color: var(--color-danger);
  font-size: var(--font-size-xs);
  margin-top: 2px;
}

/* ============================================
   Dividers
   ============================================ */
.divider {
  width: 100%;
  background-color: var(--color-border-light);
  height: 3px;
  margin: var(--spacing-md) 0;
}

/* ============================================
   Button grid layout — mobile-first
   See ButtonGridBehavior.md for the full spec.

   Count-range classes (count-2, count-3, count-4, count-5-6,
   count-7-8, count-many) are set server-side because
   Blazor CSS isolation breaks :has() selectors.
   ============================================ */

/* --- Base: 1 column, short buttons (covers count-many and long-option-text) --- */
.input-button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 1fr;
  gap: var(--spacing-sm);
  width: 100%;
  align-self: center;
  overflow-y: auto;
  padding: var(--spacing-xs);
  scroll-padding: 8px;
  -webkit-overflow-scrolling: touch;
}

/* Short-button sizing for 7-8 and >8 at all viewports */
.input-button-grid.count-7-8>.option-button,
.input-button-grid.count-many>.option-button {
  min-height: 44px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
}

/* --- Mobile: 2 items — tall, one row (2 cols) --- */
.input-button-grid.count-2 {
  grid-template-columns: repeat(2, 1fr);
}

.input-button-grid.count-2>.option-button {
  min-height: 90px;
  padding: var(--spacing-xl);

  border-radius: var(--radius-lg);
}

/* --- Mobile: 3-4 items — tall, two rows (2 cols) --- */
.input-button-grid.count-3,
.input-button-grid.count-4 {
  grid-template-columns: repeat(2, 1fr);
}

.input-button-grid.count-3>.option-button,
.input-button-grid.count-4>.option-button {
  min-height: 90px;
  padding: var(--spacing-xl);

  border-radius: var(--radius-lg);
}

/* --- Mobile: 5-6 items — tall, two columns --- */
.input-button-grid.count-5-6 {
  grid-template-columns: repeat(2, 1fr);
}

.input-button-grid.count-5-6>.option-button {
  min-height: 90px;
  padding: var(--spacing-xl);

  border-radius: var(--radius-lg);
}

/* --- Odd-button centering for 2-column grids (mobile) ---
   Span full width then pin to exact column width so orphan matches others. */
.input-button-grid.count-3>.option-button:last-child:nth-child(odd),
.input-button-grid.count-5-6>.option-button:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  justify-self: center;
  width: calc(50% - var(--spacing-sm) / 2);
}

/* ============================================
   Desktop (768px+)
   ============================================ */
@media (min-width: 768px) {
  .input-button-grid {
    gap: var(--spacing-md);
  }

  /* 3 items: tall, single row (3 cols) — no orphan on desktop */
  .input-button-grid.count-3 {
    grid-template-columns: repeat(3, 1fr);
  }

  .input-button-grid.count-3>.option-button:last-child:nth-child(odd) {
    grid-column: auto;
    justify-self: auto;
    width: auto;
  }

  /* 4 items: tall, single row (4 cols) */
  .input-button-grid.count-4 {
    grid-template-columns: repeat(4, 1fr);
  }

  /* 5-6 items: SHORT buttons, two columns */
  .input-button-grid.count-5-6>.option-button {
    min-height: 44px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
  }

  /* 7-8 items: short buttons, two columns */
  .input-button-grid.count-7-8 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Desktop odd-button centering (5-6 and 7-8 in 2 cols) */
  .input-button-grid.count-5-6>.option-button:last-child:nth-child(odd),
  .input-button-grid.count-7-8>.option-button:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    justify-self: center;
    width: calc(50% - var(--spacing-md) / 2);
  }
}

/* ============================================
   Long-text override — forces 1-col short at all sizes.
   ============================================ */
.input-button-grid.long-option-text {
  grid-template-columns: 1fr 1fr;
}

.input-button-grid.long-option-text>.option-button {
  min-height: 44px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
}

/* Reset orphan-centering that would otherwise bleed through at (0,5,0).
   Match that specificity so source order wins. */
.input-button-grid.long-option-text>.option-button:last-child:nth-child(odd) {
  grid-column: auto;
  justify-self: auto;
  width: auto;
}


/* ============================================
   Option buttons — Card style
   Hover: light blue tint + accent border
   Selected: deeper blue tint + primary border
   ============================================ */
.option-button {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px 20px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  transition:
    transform var(--transition-base),
    background-color var(--transition-base),
    border-color var(--transition-base),
    box-shadow var(--transition-base),
    color var(--transition-base);
  min-width: 0;
  min-height: 44px;
  box-shadow: var(--shadow-card);
  text-align: center;
}

@media (hover: hover) and (pointer: fine) {
  .option-button:hover {
    background-color: var(--color-hover-tint);
    border-color: var(--color-accent);
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
  }

  .option-button.selected:hover {
    background-color: var(--color-selected-hover-tint);
  }
}

.option-button:active {
  transform: translateY(0) scale(0.98);
  box-shadow: var(--shadow-card);
}

.option-button.selected {
  background-color: var(--color-selected-tint);
  color: var(--color-accent);
  box-shadow: var(--shadow-card-selected);
}

/* ============================================
   Custom scrollbar — webkit (Chrome, Safari, Edge)
   ============================================ */
.input-button-grid::-webkit-scrollbar {
  width: 8px;
}

.input-button-grid::-webkit-scrollbar-track {
  background: var(--color-background);
  border-radius: var(--radius-sm);
}

.input-button-grid::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.input-button-grid::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* ============================================
   Accessibility: Focus visible + keyboard navigation
   ============================================ */
.input-button-grid .option-button:focus-visible {
  z-index: 1;
}

.option-button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}