/* Consolidated main stylesheet extracted from inline styles */
:root {
  --row-height: 64px;
  --cell-width: 120px;
}
body {
  font-family: Arial;
  margin: 0;
  padding: 0;
  background: #fff;
}
.page {
  display: none;
  padding: 12px;
  padding-bottom: 80px; /* spazio per bottom-nav o pulsanti fissi */
}
.page.active {
  display: block;
}
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 56px;
  background: #fff;
  border-top: 1px solid #ddd;
  display: flex;
}
.nav-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #777;
  padding: 6px 0;
}
.nav-item .nav-icon {
  font-size: 18px;
  margin-bottom: 2px;
}
:root {
  --header-height: 56px;
}
.nav-item .nav-label {
  font-size: 12px;
}
.nav-item.active {
  background: #f0f0f0;
  color: #222;
}
.nav-item.center {
  position: relative;
}
.nav-item.center::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: #ddd;
}
.nav-item.center::after {
  content: "";
  position: absolute;
  right: 0;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: #ddd;
}
/* disabled nav item (when not logged in) */
.nav-item.disabled {
  opacity: 0.45;
  pointer-events: none;
}
/* page-level buttons styled like bottom nav (compact) */
.page-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: #fff;
  color: #333;
  font-size: 13px;
}
.page-btn .icon {
  font-size: 16px;
}
.page-btn.primary {
  background: #f0f0f0;
  border-color: #e0e0e0;
}
.grid {
  overflow: auto;
  white-space: nowrap;
}
.row {
  display: flex;
  align-items: center;
}
.cell {
  width: var(--cell-width);
  min-width: var(--cell-width);
  max-width: var(--cell-width);
  height: var(--row-height);
  min-height: var(--row-height);
  max-height: var(--row-height);
  border: 1px solid #ddd;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
  box-sizing: border-box;
  overflow: hidden;
}
.cell .booking-client {
  margin-bottom: 4px;
}
.cell.today {
  background: #e6e6e6;
}
.cell .day-week {
  font-size: 11px;
  font-weight: 700;
  text-transform: lowercase;
  color: #333;
}
.cell .day-date {
  font-size: 12px;
  color: #333;
}
/* legend uses up to 15% of viewport width (responsive), with sensible min/max */
.car-name {
  width: 15vw;
  max-width: 220px;
  min-width: 80px;
  padding-right: 6px;
  flex: 0 0 15vw;
}
.car-name .car-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  font-size: 13px;
}
.car-name .color-swatch {
  width: calc(15vw * 0.18);
  height: calc(15vw * 0.18);
  max-width: 40px;
  max-height: 40px;
  border-radius: 6px;
  flex: 0 0 auto;
  position: relative;
}
.car-name .color-swatch::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  right: 50%;
  bottom: 0;
  background: rgba(255, 255, 255, 0.45);
}
.card {
  border: 1px solid #ddd;
  padding: 8px;
  margin-bottom: 8px;
  border-radius: 6px;
}
/* compact card: sizes reduced by ~20% */
.car-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  border: 1px solid #ddd;
  margin-bottom: 8px;
}
/* scale main card swatch relative to viewport but clamp size */
/* reduce swatch to ~50% of previous size while keeping min/max limits */
.car-card .color-swatch {
  width: calc(9vw * 0.5);
  height: calc(9vw * 0.5);
  max-width: 45px;
  max-height: 45px;
  min-width: 10px;
  min-height: 16px;
  border-radius: 6px;
  flex: 0 0 auto;
  position: relative;
}
header {
  padding: 0;
  margin: 0;
}
.modal {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
}

/* banner shown when a user's booking was deleted */
.deletion-banner {
  position: relative;
  display: flex;
  gap: 8px;
  align-items: center;
  background: #fff3cd;
  border: 1px solid #ffeeba;
  padding: 8px 12px;
  margin: 8px 12px;
  border-radius: 6px;
  z-index: 9999;
}
.modal-content {
  background: #fff;
  padding: 12px;
  border-radius: 8px;
  min-width: 280px;
  position: relative;
}
.modal-close {
  position: absolute;
  right: 8px;
  left: auto;
  top: 8px;
  background: transparent;
  border: none;
  font-size: 16px;
  cursor: pointer;
}
/* override older duplicate rule: keep compact layout */
.car-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  border: 1px solid #ddd;
  margin-bottom: 8px;
}
.car-card .color-swatch {
  width: 12px;
  height: 12px;
  border-radius: 6px;
  flex: 0 0 12px;
  position: relative;
}
.car-card .color-swatch::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  right: 50%;
  bottom: 0;
  background: rgba(255, 255, 255, 0.6);
}
.car-info {
  flex: 1;
  padding-left: 8px;
  min-width: 0;
  white-space: nowrap;
  overflow: visible;
}
.car-actions {
  display: flex;
  gap: 8px;
}
.booking-client {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.1;
}
.booking-creator {
  font-size: 11px;
  color: #333;
  margin-top: 2px;
}
/* Global modal & input styles (shared) */
.modal .modal-content {
  background: #fff;
  padding: 14px;
  border-radius: 10px;
  max-width: 520px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}
.modal .modal-content h4 {
  margin: 0 0 8px 0;
}
.modal .modal-content form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal .modal-content .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
/* Ensure .field.hidden inside modals is truly hidden (higher specificity) */
.modal .modal-content .field.hidden {
  display: none;
}
.modal .modal-content label {
  font-size: 13px;
  color: #333;
}
.modal .modal-content input[type="text"],
.modal .modal-content input[type="date"],
.modal .modal-content input[type="number"],
.modal .modal-content select,
.modal .modal-content textarea {
  padding: 10px 12px;
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  box-shadow: none;
  transition:
    box-shadow 0.15s,
    border-color 0.15s;
}
.modal .modal-content input:focus,
.modal .modal-content select:focus,
.modal .modal-content textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.08);
}
.modal .modal-content .actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.modal .modal-content .actions .spacer {
  flex: 1;
}
/* make page buttons consistent */
.page-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #ddd;
  background: #fff;
  color: #333;
}
.page-btn.primary {
  background: #f0f6ff;
  border-color: #d6e4ff;
}

.bookings-body {
  display: flex;
  gap: 12px;
}
.sidebar {
  width: 20vw;
  min-width: 140px;
  flex: 0 0 20vw;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding-right: 8px;
  box-sizing: border-box;
}
.cars-col {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
}
.calendar-wrapper {
  overflow: auto;
  flex: 1;
  margin-left: 0;
}
.month-wrap {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 18px;
}
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, var(--cell-width));
  gap: 6px;
}
.month-grid .day-cell {
  width: var(--cell-width);
  min-width: var(--cell-width);
  max-width: var(--cell-width);
  box-sizing: border-box;
  border: 1px solid #ddd;
  padding: 4px;
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 1/2;
}
.month-grid .day-cell.today {
  background: #e6e6e6;
}
.month-grid .day-cell .day-label {
  position: absolute;
  left: 6px;
  top: 4px;
  font-size: 12px;
  color: #333;
}
.month-grid .day-cell .more-indicator {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: #999;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.month-grid .day-cell .dots {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: flex;
  gap: 4px;
}
.month-grid .day-cell .dots span {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.month-title {
  font-weight: 600;
  margin-bottom: 6px;
}
@media (max-width: 800px) {
  .sidebar {
    position: static;
    transform: none;
    left: auto;
    top: auto;
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    padding-bottom: 8px;
  }
  .calendar-wrapper {
    margin-left: 0;
  }
}

/* Mobile adjustments: allow calendar to shrink below previous min-widths */
@media (max-width: 800px) {
  :root {
    --cell-width: 72px;
  }
  .calendar-col {
    min-width: 0;
    min-width: auto;
  }
  .cars-col {
    width: 28vw;
    min-width: 80px;
  }
}

/* Bookings page: media overrides removed to reset layout for bookings column; keep general rules in place */
@media (max-width: 600px) {
  /* No bookings-specific overrides here; layout will follow base and home rules */
}

/* helper classes for header and month view */
.bookings-body {
  display: flex;
  gap: 12px;
}

.bookings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
#monthView {
  width: 100%;
}

/* Bookings layout: ensure calendar fits the right column (remaining after 15% sidebar) */
#bookings .bookings-body {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
#bookings .bookings-body .sidebar {
  /* match the global sidebar size so cards have the same width as Home */
  flex: 0 0 20vw;
  max-width: 20vw;
  min-width: 120px;
  box-sizing: border-box;
}
#bookings .bookings-body .sidebar {
  /* ensure sidebar content does not overflow into the calendar */
  overflow-x: hidden;
}
#bookings .bookings-body .sidebar .cars-col {
  /* on the bookings page the machines column must fit the sidebar width */
  width: 100% !important;
  min-width: 0 !important;
  flex: 1 1 100% !important;
  box-sizing: border-box;
}

/* bookings page: use the same horizontal compact car-card as on Home */
#bookings .bookings-body .sidebar .cars-col .car-card {
  position: relative;
  background: #fff;
  box-sizing: border-box;
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid #ddd;
  margin-bottom: 0;
  width: 100%;
}

#bookings .bookings-body .sidebar .cars-col .car-card .color-swatch {
  width: 12px;
  height: 12px;
  border-radius: 6px;
  flex: 0 0 12px;
  position: relative;
  margin-right: 8px;
}

#bookings .bookings-body .sidebar .cars-col .car-card .car-info {
  flex: 1;
  padding-left: 0;
  min-width: 0;
}

#bookings .bookings-body .sidebar .cars-col .car-card .car-info strong {
  display: block;
  font-size: 13px;
}

#bookings .bookings-body .sidebar .cars-col .car-card .car-plate {
  font-size: 12px;
  color: #666;
  margin-top: 0;
}
#bookings .bookings-body .calendar-wrapper {
  flex: 1;
  margin-left: 0;
  overflow-x: hidden;
  overflow-y: auto;
}
#bookings .calendar-col {
  min-width: 0;
  width: 100%;
}
#bookings .month-grid {
  grid-template-columns: repeat(7, 1fr);
  width: 100%;
}
#bookings .month-grid .day-cell {
  width: auto;
  min-width: 0;
  max-width: none;
}

/* enforce fixed heights across calendar rows and machine cards */
.car-card {
  height: var(--row-height);
  box-sizing: border-box;
}
.car-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}

/* small utility */
.sr-only {
  position: absolute !important;
  left: -9999px !important;
}

/* Home partial styles */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.home-body {
  display: flex;
  gap: 0;
  align-items: flex-start;
}
.cars-col {
  /* size to content: don't stretch wider than necessary */
  width: max-content;
  min-width: 0;
  flex: 0 0 auto;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  align-items: stretch; /* ensure children stretch to the container width */
}
.calendar-wrapper {
  overflow-x: auto;
  flex: 1;
}
.calendar-col {
  min-width: 900px;
}
.cars-col .car-card {
  position: relative;
  background: #fff;
  box-sizing: border-box;
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid #ddd;
  margin-bottom: 0;
}

/* make each car-card fill the container width so all cards equal the widest */
.cars-col .car-card {
  width: 100%;
}

/* separator line between car entries without shifting layout */
.cars-col .car-card + .car-card {
  border-top: 1px solid #e8e8e8;
  padding-top: 6px;
}

/* ensure header row border is not heavier than column borders */
.row:first-child .cell {
  border-bottom: 1px solid #ddd;
}

/* stronger header/date-row separation */
.row:first-child .cell {
  border-bottom: 2px solid #ccc;
}

/* day booking card model small text */
.card-meta .car-model {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}
/* header-placeholder: keep a sticky placeholder at top of machines column */
.cars-col .header-placeholder {
  position: sticky;
  top: 0;
  background: transparent;
  border: 0;
  margin-bottom: 0;
  min-height: 0;
  height: var(--row-height);
  box-sizing: border-box;
}

/* utility hidden class used for modals */
.hidden {
  display: none;
}

/* small typography helpers */
.section-title {
  font-size: 14px;
}

.overlap-warning {
  color: #900;
  margin-top: 8px;
}
.passcodes-list {
  max-height: 300px;
  overflow: auto;
  margin-bottom: 8px;
}
.passcodes-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}

/* release info in passcodes modal */
.release-info {
  font-size: 13px;
  color: #666;
  margin-bottom: 8px;
}
.pass-input {
  flex: 1;
  padding: 6px;
}
.passcodes-row-bottom {
  margin-top: 12px;
}

.settings-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.dayBookings-list {
  max-height: 400px;
  overflow: auto;
  margin-top: 8px;
}

/* Login page styles */
body.login-page {
  font-family:
    system-ui,
    Segoe UI,
    Roboto,
    Arial;
  margin: 20px;
}
.login-card {
  max-width: 420px;
  margin: 40px auto;
  padding: 18px;
  border: 1px solid #ddd;
  border-radius: 8px;
}
.login-card input {
  width: 100%;
  padding: 8px;
  margin: 6px 0;
  border: 1px solid #ccc;
  border-radius: 6px;
}
.login-card .row {
  display: flex;
  gap: 8px;
}
.login-card button {
  padding: 8px 12px;
  border-radius: 6px;
  border: 0;
  background: #2b7;
  cursor: pointer;
}
.login-card button.secondary {
  background: #eee;
  color: #111;
}
.login-msg {
  margin-top: 10px;
  color: #b00;
}
.login-row {
  margin-top: 8px;
}

/* Additional helpers inserted by cleanup patch */
.days-wrap {
  display: inline-flex;
}
/* ensure calendar cells stay below modals */
.days-wrap .cell { z-index: 0; position: relative; }
.cell.booked {
  background: transparent; /* background controlled inline per-car */
}

/* create a pseudo element to extend booked background slightly and hide hairline gaps */
.days-wrap .cell.booked {
  position: relative;
}
.days-wrap .cell.booked::before{
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -1px; right: -1px; /* extend 1px to cover subpixel gaps */
  background: inherit; /* inherit the inline background color set on the cell */
  z-index: 0;
  border-radius: inherit;
}
.days-wrap .cell.booked > * { position: relative; z-index: 1; }

/* merge adjacent booked cells visually */
.cell.booked-single {
  border-radius: 8px;
}
.cell.booked-start {
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
  border-right: none;
}
.cell.booked-end {
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
  border-left: none;
}
.cell.booked-mid {
  border-left: none;
  border-right: none;
}

/* ensure no gap between cells so merged background looks continuous */
.days-wrap .cell { margin: 0; }
.car-plate {
  font-size: 12px;
  color: #666;
}

/* small toast used for inactivity reload and update notifications */
.toast {
  position: fixed;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 9999;
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
}
.toast .page-btn {
  margin-left: 10px;
}

/* month view helpers */
.weekday-header {
  text-align: center;
  font-size: 11px;
  color: #666;
}
.day-cell.clickable {
  cursor: pointer;
}
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-meta .title {
  font-weight: 600;
  font-size: 14px;
}
.card-meta .dates {
  font-size: 12px;
  color: #666;
}
.card-meta .creator {
  font-size: 11px;
  color: #333;
  margin-top: 4px;
}
.card-desc {
  margin-top: 6px;
}
.page-btn.danger {
  color: #900;
}

/* settings helpers */
.device-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}
.device-left {
  flex: 1;
}
.device-id {
  font-size: 12px;
  color: #333;
}
.device-name-input {
  width: 100%;
  margin-top: 6px;
  padding: 6px;
  border: 1px solid #e6e6e6;
  border-radius: 6px;
}
.device-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 12px;
}
.pass-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}
.pass-row .info {
  flex: 1;
}
.swatch-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #fff;
}
.swatch-btn.selected {
  outline: 3px solid #333;
}
