:root {
  --app-primary: #7a2e5a;
  --app-primary-dark: #5e2245;
  --app-bg: #f6f2f4;
  --bs-primary: var(--app-primary);
  --bs-primary-rgb: 122, 46, 90;
  --bs-link-color: var(--app-primary);
  --bs-link-hover-color: var(--app-primary-dark);
}

html, body {
  min-height: 100%;
  background: var(--app-bg);
  /* Native-app feel: no tap flash, no rubber-band text selection on UI */
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.btn-primary {
  --bs-btn-bg: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary-dark);
  --bs-btn-hover-border-color: var(--app-primary-dark);
  --bs-btn-active-bg: var(--app-primary-dark);
  --bs-btn-active-border-color: var(--app-primary-dark);
}

/* ---------- Login ---------- */
.login-page {
  background: linear-gradient(160deg, var(--app-primary) 0%, var(--app-primary-dark) 100%);
}

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

.login-card {
  width: 100%;
  max-width: 400px;
  border-radius: 1.25rem;
}

.captcha-img {
  height: 48px;
  width: auto;
  user-select: none;
}

.captcha-input {
  min-width: 0;
}

/* ---------- Backoffice layout ---------- */
.app-navbar {
  background: var(--app-primary);
  padding-top: env(safe-area-inset-top);
}

.app-main {
  padding-top: calc(56px + env(safe-area-inset-top) + 1rem);
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.dropdown-menu {
  --bs-dropdown-link-active-bg: var(--app-primary);
}

/* Anchored rows (#r12) must not end up under the fixed menu */
.range-row {
  scroll-margin-top: calc(56px + env(safe-area-inset-top) + 1rem);
}

.range-main {
  flex: 1 1 12rem;
  min-width: 0;
}

.prio-input {
  width: 4.5rem;
}

/* A linked add-on (Tilläggsbehandling) under its treatment */
.range-addon {
  padding-left: 1.75rem;
  background: var(--app-bg);
  border-left: 3px solid var(--app-primary);
}

.range-addon-arrow {
  color: var(--app-primary);
  font-size: 1.1rem;
  margin-left: -0.9rem;
}

.range-addon-label {
  color: var(--app-primary);
  font-weight: 600;
}

.btn-outline-primary {
  --bs-btn-color: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary);
  --bs-btn-hover-border-color: var(--app-primary);
  --bs-btn-active-bg: var(--app-primary-dark);
  --bs-btn-active-border-color: var(--app-primary-dark);
}

/* ---------- Start ---------- */
.stat-tile {
  border: 1px solid var(--bs-border-color-translucent);
  border-radius: 0.5rem;
  padding: 0.6rem 0.25rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* ---------- Bokningar: the top (toolbar, search, klotterplank) ---------- */
/* Small screens: the view buttons (and the folded klotterplank) first, then the toolbar. */
.cal-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 0.5rem 1.5rem;
  margin-bottom: 1.25rem;  /* space down to the calendar */
}

.cal-top-side {
  order: -1;  /* small screens: the buttons above the heading */
}

/* Wider: toolbar and search on the left, buttons and klotterplank on the right */
@media (min-width: 768px) {
  .cal-top {
    grid-template-columns: minmax(0, 1fr) 17rem;
  }
  .cal-top-main {
    grid-column: 1;
    grid-row: 1;
  }
  .cal-top-side {
    grid-column: 2;
    grid-row: 1;
    order: 0;
  }
}

@media (min-width: 1200px) {
  .cal-top {
    grid-template-columns: minmax(0, 1fr) 20rem;
  }
}

.cal-search {
  max-width: 44rem;
}

/* ---------- Bokningar: klotterplank ---------- */
.notice-board {
  background: #fff8d6;
  border: 1px solid #f0e2a0;
  border-radius: 0.5rem;
  padding: 0.35rem 0.5rem 0.5rem;
}

.notice-board-title {
  font-size: 0.8rem;
  font-weight: 600;
}

.notice-board-save {
  font-size: 0.8rem;
}

.notice-board-text {
  background: transparent;
  border-color: #eadb93;
  font-size: 0.8rem;
  line-height: 1.3;
  white-space: pre-wrap;
  resize: vertical;
  min-height: 3.5rem;
  max-height: 12rem;
}

.notice-board-text:focus {
  background: #fffdf0;
}

/* ---------- Bokningar: calendar ---------- */
.cal-grid {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
}

.cal-grid th,
.cal-grid td {
  border-bottom: 1px solid #eee;
  border-left: 1px solid #eee;
  padding: 0;
}

.cal-grid thead th {
  position: sticky;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 2;
  background: #fff;
  border-bottom: 2px solid #ddd;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.15;
  padding: 0.3rem 0.1rem;
  overflow-wrap: anywhere;
}

.cal-grid thead th small {
  display: block;
  font-weight: normal;
  color: inherit;
  opacity: 0.75;
}

/* Sundays and public holidays */
.cal-grid thead th.red {
  background: #f8d7da;
  color: #842029;
}

.cal-grid thead th.today {
  box-shadow: inset 0 -3px 0 var(--app-primary);
}

/* The user is a room */
.cal-grid thead th.room {
  box-shadow: inset 0 3px 0 #00897b;
  color: #00695c;
}

.cal-grid thead th.room.red {
  color: #842029;
}

.cal-room-badge {
  background: #00897b;
}

.cal-grid .cal-time {
  width: 3rem;
  border-left: 0;
  font-size: 0.7rem;
  font-weight: normal;
  color: var(--bs-secondary-color);
  text-align: right;
  padding-right: 0.3rem;
  vertical-align: top;
}

.cal-grid tr.hour > * {
  border-top: 1px solid #c8c8c8;
}

.cal-grid tr.hour .cal-time {
  font-weight: 600;
  color: var(--bs-body-color);
}

/* The schema colour as a stripe on the left 10% of the slot; the rest is white */
.cal-slot {
  height: 1.5rem;
  background: linear-gradient(to right, var(--scheme-color, transparent) 10%, #fff 10%);
}

.cal-slot a {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 1.5rem;
}

@media (hover: hover) {
  .cal-slot:hover {
    box-shadow: inset 0 0 0 2px var(--app-primary);
  }
}

/* "Ej bokningsbar" and "Lunch" can't be clicked */
.cal-slot.blocked {
  cursor: not-allowed;
}

@media (hover: hover) {
  .cal-slot.blocked:hover {
    box-shadow: none;
  }
}

/* Each booking is a framed box, 1px inside its cells, so adjacent bookings stay apart */
.cal-booking {
  position: relative;
  vertical-align: top;
}

.cal-booking-box {
  position: absolute;
  inset: 1px;
  overflow: hidden;
  background: var(--booking-color, #f3d9e7);
  color: var(--booking-text, #000);
  border: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 4px;
}

.jump-menu {
  max-height: 20rem;
  overflow-y: auto;
}

/* A column from the top: browsers centre a button's content vertically otherwise */
.cal-booking-btn {
  all: unset;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  text-align: left;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 0.15rem 0.3rem;
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1.2;
}

.cal-booking-btn:focus-visible {
  outline: 2px solid var(--app-primary);
  outline-offset: -2px;
}

.cal-booking-name,
.cal-booking-info {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-booking-name {
  font-weight: 600;
}

/* Number of bookings for the customer and the web icon, above the name */
.cal-booking-meta {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.68rem;
  line-height: 1.1;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
}

.web-icon,
.message-icon {
  vertical-align: -0.1em;
}

/* Booking window */
.booking-modal-time {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.booking-modal-web {
  color: var(--app-primary);
}

.booking-modal-details dt {
  font-weight: normal;
  color: var(--bs-secondary-color);
}

.cal-booking-info {
  opacity: 0.85;
}

/* Day view: one column per user, scrolls sideways on small screens */
.cal-scroll {
  overflow-x: auto;
}

.cal-day thead th {
  position: static;
}

.cal-day thead th a {
  color: inherit;
}

/* ---------- Bokningar: form and print ---------- */
.booking-summary dt {
  font-weight: normal;
  color: var(--bs-secondary-color);
}

.booking-summary dd {
  font-weight: 600;
}

.booking-swatch {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border-radius: 0.2em;
  border: 1px solid rgba(0, 0, 0, 0.15);
  vertical-align: -0.05em;
}

#customer-matches {
  max-height: 16rem;
  overflow-y: auto;
}

.print-page {
  background: #fff;
}

/* ---------- Kundregister ---------- */
.letter-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.letter-filter .btn {
  min-width: 2.1rem;
}

.history-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- Schema grid ---------- */
.scheme [data-type="1"] { --scheme-color: #8fd19e; } /* Bokningsbar */
.scheme [data-type="2"] { --scheme-color: #ffe08a; } /* Ej bokningsbar från hemsidan */
.scheme [data-type="3"] { --scheme-color: #c4c4c4; } /* Ej bokningsbar */
.scheme [data-type="4"] { --scheme-color: #9ec5fe; } /* Lunch */
.scheme [data-type="5"] { --scheme-color: #7fd6c2; } /* Angiven bokningsbar */
.scheme [data-type="6"] { --scheme-color: #d3aef5; } /* Drop-In */
.scheme-discount [data-type="1"] { --scheme-color: #ffb877; } /* Rabatterad tid */

.scheme-swatch {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  border-radius: 0.2em;
  vertical-align: -0.05em;
  background: var(--scheme-color);
}

.scheme-grid {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
  user-select: none;
  -webkit-user-select: none;
}

.scheme-grid th,
.scheme-grid td {
  border-bottom: 1px solid #eee;
  border-left: 1px solid #eee;
}

.scheme-grid thead th {
  position: sticky;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 1;
  background: #fff;
  border-bottom: 2px solid #ddd;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.15;
  padding: 0.3rem 0;
}

.scheme-grid thead th small {
  display: block;
  font-weight: normal;
  color: var(--bs-secondary-color);
}

.scheme-grid thead th.today {
  color: var(--app-primary);
}

.scheme-grid .scheme-time {
  width: 3rem;
  border-left: 0;
  font-size: 0.7rem;
  font-weight: normal;
  color: var(--bs-secondary-color);
  text-align: right;
  padding-right: 0.3rem;
  vertical-align: top;
}

.scheme-grid tr.hour > * {
  border-top: 1px solid #c8c8c8;
}

.scheme-grid tr.hour .scheme-time {
  font-weight: 600;
  color: var(--bs-body-color);
}

.scheme-grid td {
  height: 1.5rem;
  cursor: pointer;
  background: var(--scheme-color, transparent);
}

.scheme-grid td[data-booked] {
  cursor: not-allowed;
  background-image: repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.28) 0 3px, transparent 3px 7px);
}

@media (hover: hover) {
  .scheme-grid td:not([data-booked]):hover {
    box-shadow: inset 0 0 0 2px var(--app-primary);
  }
}

.logout-form .nav-link {
  background: none;
  border: 0;
  width: 100%;
  text-align: start;
}

/* Mobile: full-height slide-in menu with large touch targets */
@media (max-width: 991.98px) {
  .app-navbar .offcanvas {
    padding-top: env(safe-area-inset-top);
  }
  .app-navbar .offcanvas .nav-link {
    color: var(--bs-body-color);
    padding: 0.85rem 0.5rem;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--bs-border-color-translucent);
  }
  .app-navbar .offcanvas .nav-link.active {
    color: var(--app-primary);
    font-weight: 600;
  }
  .app-navbar .offcanvas .dropdown-menu {
    border: 0;
    padding: 0;
  }
  .app-navbar .offcanvas .dropdown-item {
    padding: 0.75rem 1.25rem;
    font-size: 1.05rem;
    border-bottom: 1px solid var(--bs-border-color-translucent);
  }
  .logout-form {
    margin-top: 1rem;
  }
  .logout-form .nav-link {
    color: var(--bs-danger) !important;
  }
}

/* Desktop: inline menu */
@media (min-width: 992px) {
  .logout-form .nav-link {
    color: rgba(255, 255, 255, 0.75);
  }
  .logout-form .nav-link:hover {
    color: #fff;
  }
}
