/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

:root {
  --table-font-size: 0.8rem;
}

/* Bulma declares `display` on classes such as .help, and any author rule beats
   the browser's own [hidden] { display: none }: without this, elements toggled
   through the hidden attribute stay on screen. */
[hidden] {
  display: none !important;
}

/* Shrink table text on mobile to fit more columns without horizontal scroll.
   Controlled by the global --table-font-size variable. */
@media screen and (max-width: 768px) {
  .table {
    font-size: var(--table-font-size);
  }
}

.event-image {
  display: block;
  width: 100%;
  max-height: 22rem;
  object-fit: cover;
  border-radius: 6px;
}

.event-image-thumb {
  display: block;
  max-width: 200px;
  height: auto;
  border-radius: 6px;
}

.event-card {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s ease;

  &:hover {
    box-shadow: 0 8px 16px rgba(10, 10, 10, 0.15);
  }

  .card-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
  }

  /* The whole card is clickable: the title link stretches over the card. */
  .event-card-link {
    color: inherit;

    &::after {
      content: "";
      position: absolute;
      inset: 0;
    }
  }

  /* Actions sit above the stretched link so they stay clickable. */
  .event-card-actions {
    position: relative;
    z-index: 1;
    margin-top: auto;
    padding-top: 1rem;
  }
}

.confirmation-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4.5rem;
  height: 4.5rem;
  margin-bottom: 1rem;
  border-radius: 50%;
  background-color: var(--bulma-success-light, #eafff3);
  color: var(--bulma-success, #48c78e);
}

.booking {
  max-width: 32rem;
  margin-inline: auto;
}

.booking-header {
  margin-bottom: 1.5rem;
  text-align: center;
}

.booking-message {
  text-align: center;
}

.booking-image {
  & img {
    width: 100%;
    max-height: 16rem;
    object-fit: cover;
    border-radius: var(--bulma-radius-large, 0.75rem);
  }
}

.booking-description {
  text-align: center;
}

.booking-contact {
  text-align: center;
}

/* Consent checkbox: enlarged and given a generous tap area for mobile use. */
.consent-field .checkbox {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--bulma-border, #dbdbdb);
  border-radius: var(--bulma-radius, 0.5rem);
  font-size: 1rem;
  line-height: 1.4;
}

.consent-field input[type="checkbox"] {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
  accent-color: var(--bulma-primary, #00d1b2);
}

/* The checkbox is already required (browser + server side): hide the lone
   "required" mark that would otherwise float between box and label. */
.consent-field .checkbox abbr {
  display: none;
}

/* Whole-row link: the first-cell link stretches over the entire row so a click
   anywhere on the row opens the group. */
.clickable-row {
  position: relative;
  cursor: pointer;

  .row-link {
    color: inherit;

    &::after {
      content: "";
      position: absolute;
      inset: 0;
    }
  }
}

/* Date + time cell: a monospace font keeps the day/date/time parts aligned in a
   column across every row while packing them into less horizontal space. */
.group-datetime {
  white-space: nowrap;
  font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;

  .group-datetime-day {
    color: var(--bulma-grey, #7a7a7a);
  }
}

/* Arrow in a column header showing which way the rows are currently sorted. */
.sort-indicator {
  color: var(--bulma-text-weak, #7a7a7a);
  margin-left: 0.2rem;

  /* Scale the icon down to the header text so the arrow sits on its baseline. */
  .icon {
    height: 1em;
    width: 1em;
    vertical-align: -0.1em;
  }

  svg {
    height: 1em;
    width: 1em;
  }
}

/* On mobile the event name is truncated to a single line to keep rows compact. */
@media screen and (max-width: 768px) {
  .group-event .row-link {
    display: inline-block;
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }
}

/* Keep row action buttons (edit link + delete form) inline within a table cell. */
td form.button_to {
  display: inline-block;
  margin-left: 0.25rem;
  vertical-align: top;
}

/* Keep the reservation row actions on a single line so the buttons never wrap
   and grow the row height (the table already scrolls horizontally on mobile). */
.reservation-actions {
  white-space: nowrap;
}

/* The name and phone always stay on a single line (the notes below the name
   are free to wrap). */
.reservation-name > a {
  white-space: nowrap;
}

.reservation-phone {
  white-space: nowrap;
}

/* Reservation notes shown under the name: the whole note is a single clickable
   link (icon + "Note:" + text) that opens the edit modal, kept on one compact
   block to save vertical space. */
.reservation-notes-edit {
  display: inline;
  color: var(--bulma-text-weak, #7a7a7a);
  text-decoration: none;

  &:hover .has-text-dark {
    text-decoration: underline;
  }

  & .icon {
    vertical-align: text-bottom;
    margin-right: 0.1rem;
  }
}

/* Confirmation modal (Turbo confirm override): compact card, headerless. */
.confirm-modal-card {
  max-width: 26rem;
  width: calc(100% - 2rem);

  & .modal-card-body {
    border-radius: var(--bulma-radius-large, 0.75rem) var(--bulma-radius-large, 0.75rem) 0 0;
  }
}

/* "Avvisato" checkbox column: keep the toggle centered and enlarge the hit
   area so it stays comfortable to tap on mobile. */
.reservation-notified {
  display: flex;
  justify-content: center;

  & input {
    width: 1.25rem;
    height: 1.25rem;
  }
}

/* Number inputs are edited by typing: the spinner arrows only add noise and
   make accidental scroll-wheel edits possible. */
input[type="number"] {
  appearance: textfield;

  &::-webkit-outer-spin-button,
  &::-webkit-inner-spin-button {
    appearance: none;
    -webkit-appearance: none;
    margin: 0;
  }
}

.table-input {
  width: 6rem;
}

.table-input-narrow {
  width: 4rem;
}

.navbar {
  position: relative;
}

@media screen and (min-width: 769px) {
  .search-container {
    min-width: 26rem;
  }
}

/* On mobile the results overlay spans the full navbar width (edge to edge). */
@media screen and (max-width: 768px) {
  .navbar .search-container {
    position: static;
  }

  .navbar .search-container .search-dropdown {
    margin-top: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
}

.search-container {
  position: relative;
  max-width: 34rem;

  .search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 30;
    margin-top: 0.25rem;
    background-color: var(--bulma-scheme-main, #fff);
    border: 1px solid var(--bulma-border, #dbdbdb);
    border-radius: 6px;
    box-shadow: 0 8px 16px rgba(10, 10, 10, 0.1);
    overflow: hidden;

    &.is-active {
      display: block;
    }
  }

  .search-option {
    display: block;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--bulma-border-weak, #ededed);
    color: var(--bulma-text, #363636);
    font-size: 0.85rem;
  }

  #search_results {
    display: block;
    max-height: 20rem;
    overflow-y: auto;
  }

  .search-result {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--bulma-text, #363636);

    &:hover {
      background-color: var(--bulma-scheme-main-bis, #f5f5f5);
    }

    &.is-highlighted {
      background-color: color-mix(in srgb, var(--bulma-primary, #7048e8) 15%, transparent);
    }

    & + .search-result {
      border-top: 1px solid var(--bulma-border-weak, #ededed);
    }
  }
}

.message-template-help {
  margin-top: 0.75rem;

  .message-variables {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.5rem;

    li {
      display: flex;
      flex-wrap: wrap;
      align-items: baseline;
      gap: 0.5rem;
    }

    code {
      flex-shrink: 0;
    }

    span {
      color: var(--bulma-text-weak, #6b6b6b);
      font-size: 0.85rem;
    }
  }
}

/* Live ERB highlighting: a highlighted <pre> sits behind a transparent textarea.
   Both layers must share identical box metrics so the text lines up exactly. */
.erb-editor {
  position: relative;
}

.erb-editor__input,
.erb-editor__highlight {
  margin: 0;
  padding: 0.625em 0.75em;
  border: 1px solid transparent;
  border-radius: 4px;
  font-family: var(--bulma-family-code, monospace);
  font-size: 0.85rem;
  line-height: 1.5;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.erb-editor__highlight {
  position: absolute;
  inset: 0;
  overflow: auto;
  pointer-events: none;
  background-color: var(--bulma-scheme-main, #fff);
  color: var(--bulma-text, #363636);
}

.erb-editor__input {
  position: relative;
  display: block;
  width: 100%;
  min-height: unset;
  border-color: var(--bulma-border, #dbdbdb);
  background-color: transparent;
  color: transparent;
  caret-color: var(--bulma-text, #363636);
  resize: vertical;

  &:focus {
    border-color: var(--bulma-link, #485fc7);
    box-shadow: 0 0 0 0.125em color-mix(in srgb, var(--bulma-link, #485fc7) 25%, transparent);
  }
}

.erb-output {
  color: var(--bulma-primary, #7048e8);
  font-weight: 600;
}

.erb-control {
  color: var(--bulma-info, #3082c5);
  font-weight: 600;
}

code.erb-output {
  background-color: color-mix(in srgb, var(--bulma-primary, #7048e8) 12%, transparent);
}

.reservation-event-card {
  transition: box-shadow 0.15s ease;

  &:hover {
    box-shadow: 0 8px 16px rgba(10, 10, 10, 0.15);
  }
}

.reservation-slots {
  margin-top: 1.25rem;
  border-top: 1px solid var(--bulma-border, #dbdbdb);
}

.reservation-slot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--bulma-border, #dbdbdb);

  &:last-child {
    border-bottom: 0;
  }

  .reservation-slot-info {
    min-width: 0;
  }

  @media (max-width: 480px) {
    .button {
      width: 100%;
    }
  }
}

.booking-slots {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.booking-slot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  /* Every date keeps the height of the tallest one (the one announcing its last
     seats), so the rows stay uniform and comfortable to tap. */
  min-height: 4.5rem;
  border: 1px solid var(--bulma-border, #dbdbdb);
  border-radius: var(--bulma-radius, 6px);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;

  &:has(input:checked) {
    border-color: var(--bulma-primary, #00d1b2);
    background-color: color-mix(in srgb, var(--bulma-primary, #00d1b2) 8%, transparent);
  }

  .booking-slot-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
  }

  .booking-slot-datetime {
    font-weight: 600;
  }

  /* The last-seats notice is a nudge: it has to stand out from the date. */
  .booking-slot-seats {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--bulma-warning-on-scheme, #946c00);
  }

  .booking-slot-full-tag {
    display: none;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--bulma-danger, #f14668);
  }

  &.is-full {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: color-mix(in srgb, var(--bulma-danger, #f14668) 6%, transparent);
    border-color: var(--bulma-border, #dbdbdb);

    .booking-slot-full-tag {
      display: inline;
    }
  }
}

.is-highlighted-row > td {
  animation: row-flash 2.5s ease-out;
}

@keyframes row-flash {
  0%, 25% {
    background-color: color-mix(in srgb, var(--bulma-primary, #00d1b2) 30%, transparent);
  }

  100% {
    background-color: transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .is-highlighted-row > td {
    animation: none;
  }
}

/* Smooth the shared event image morph between the reservation list and the
 * reservation form (see reservation_image_transition_name). */
::view-transition-group(*) {
  animation-duration: 0.35s;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none;
  }
}
