:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: #e1e6ec;
  --text: #1b2430;
  --text-dim: #6b7685;
  --accent: #2f6feb;
  --accent-soft: #e8f0fe;
  --day-col: 44px;
  --sidebar-col: 270px;
  --row-h: 46px;
  --today: #ffe9b3;
  --weekend: #f0f2f6;
  --month-bg: #e5e8ed;
  --avail: #d3f3df;
  --avail-border: #34a853;
  --busy: #fbeae9;
  --busy-border: #e05c4d;

  /* Type scale — every font-size in this file should be one of these. */
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 20px;

  /* Spacing scale (4px base unit) — used for padding/gap/margin. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

.icon {
  width: 15px;
  height: 15px;
  flex: none;
  vertical-align: -3px;
  margin-right: 6px;
}
.icon-only { margin-right: 0; }
.icon-badge { width: 12px; height: 12px; margin-right: 4px; vertical-align: -2px; }

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

/* Only .timeline-scroll should ever scroll — if the page itself also scrolls,
   the sticky date header detaches and slides away with the rest of the content. */
body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar-left, .topbar-center, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}
.save-status.saving { color: var(--text-dim); }
.save-status.saving::before { content: "⏳ "; }
.save-status.saved { color: var(--avail-border); }
.save-status.saved::before { content: "✓ "; }
.save-status.error { color: var(--busy-border); }
.save-status.error::before { content: "⚠ "; }

.topbar h1 {
  font-size: 17px;
  margin: 0 14px 0 0;
  white-space: nowrap;
}

.brand-logo {
  height: 34px;
  width: auto;
  display: block;
  margin-right: 14px;
}

.select, .search, .btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
}

.btn {
  cursor: pointer;
  min-width: 34px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn .icon { margin-right: 6px; }
.btn .icon.icon-only { margin-right: 0; }
.btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn:disabled {
  cursor: not-allowed;
  opacity: .5;
  color: var(--text-dim);
  background: var(--panel);
  border-color: var(--border);
}
.btn:disabled:hover { background: var(--panel); border-color: var(--border); }

.range-label {
  color: var(--text-dim);
  min-width: 160px;
  text-align: center;
  font-weight: 600;
}

.tz-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
  cursor: default;
}

.search { width: 220px; }

.archived-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  cursor: pointer;
}
.archived-toggle input { cursor: pointer; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #2559c9; border-color: #2559c9; }

.avail-wrap { position: relative; }

.avail-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 20;
  width: 308px;
}
.avail-panel.hidden { display: none; }
.avail-panel-actions { display: flex; justify-content: flex-end; gap: 8px; }

.avail-cal { user-select: none; }
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cal-header .cal-month { font-size: 17px; font-weight: 700; color: var(--text); }
.cal-nav {
  border: none;
  background: none;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-nav:hover { background: var(--accent-soft); }

.cal-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}
.cal-dow span {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  padding: 4px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 38px;
}

.cal-day {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  box-sizing: border-box;
  border-top: 2px solid transparent;
  border-bottom: 2px solid transparent;
}
.cal-day span {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text);
}
.cal-day.outside span { color: #c7ccd4; }
.cal-day:hover:not(.outside) span { background: var(--weekend); }
.cal-day.today span { font-weight: 800; text-decoration: underline; }

.cal-day.in-range { background: var(--accent-soft); border-color: var(--accent); }
.cal-day.in-range.row-start { border-left: 2px solid var(--accent); }
.cal-day.in-range.row-end { border-right: 2px solid var(--accent); }
.cal-day.in-range.range-start { border-top-left-radius: 999px; border-bottom-left-radius: 999px; }
.cal-day.in-range.range-end { border-top-right-radius: 999px; border-bottom-right-radius: 999px; }
.cal-day.in-range span { font-weight: 700; color: #1c3f8f; }

.avail-summary {
  flex-shrink: 0;
  padding: 8px 18px;
  background: var(--avail);
  border-bottom: 1px solid var(--avail-border);
  font-size: 13px;
  font-weight: 600;
  color: #1b2430;
  display: flex;
  align-items: center;
  gap: 12px;
}
.avail-summary.hidden { display: none; }
.btn-sm { padding: 4px 10px; font-size: 12px; min-width: unset; }

/* Full-width backdrop for the "Camping Equipment" divider row — separate from the sticky
   label below since a position:sticky element spanning the full grid width (grid-column:
   1/-1) doesn't actually stick during horizontal scroll (see the comment at this row's call
   site in app.js). Just paints the background/border stripe across every column. */
.section-header-bg {
  background: var(--month-bg);
  border-bottom: 1px solid var(--border);
  border-top: 2px solid var(--border);
}

.section-header {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--month-bg);
  border-bottom: 1px solid var(--border);
  border-top: 2px solid var(--border);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  padding: 0 12px;
  white-space: nowrap;
}

.equip-cell { color: var(--text); }
.equip-qty { color: var(--text-dim); font-weight: 400; font-size: 12px; margin-left: 8px; }

.day-header.in-range { background: var(--avail); }
.day-col-bg.in-range { background: var(--avail); }

.car-cell.avail-free, .car-cell.avail-busy { padding-left: 10px; }
.car-cell .avail-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  flex: none;
}
.car-cell.avail-free .avail-dot { background: var(--avail-border); }
.car-cell.avail-busy .avail-dot { background: var(--busy-border); }
.car-cell.avail-busy { background: var(--busy); }

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  flex-shrink: 0;
  padding: 8px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.timeline-scroll {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--panel);
}

.timeline-grid {
  display: grid;
  grid-auto-rows: var(--row-h);
  width: max-content;
  min-width: 100%;
}

.cell {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 4;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.month-header.month-divider {
  border-left: 1px solid #94a3b8;
}

.month-header {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--month-bg);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.day-header {
  position: sticky;
  top: 26px;
  z-index: 3;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 2px 0;
}
.day-header.today { background: var(--today); color: #6b4a00; font-weight: 700; }
.day-header .dow { text-transform: uppercase; font-size: 9px; opacity: .8; }
.day-header .dnum { font-size: 13px; font-weight: 700; color: var(--text); }
.day-header.compact { padding: 0; }
.day-header.compact .dow {
  writing-mode: vertical-lr;
  font-size: 10px;
  font-weight: 700;
  opacity: 1;
  color: var(--accent);
}

.car-cell {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  border-right: 2px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.car-cell.dim { opacity: .35; }

/* Zebra striping for odd rows — :not() chains so it never overrides the more meaningful
   availability/overbooked colors regardless of stylesheet order. */
.car-cell.zebra-odd:not(.avail-busy):not(.avail-free):not(.overbooked) { background: #f3f4f6; }
/* No z-index here on purpose — it must stay in the default paint layer alongside
   .day-col-bg so their relative DOM order (row-bg first, day-col-bg second — see app.js)
   decides which wins per cell, instead of a stacking context swallowing it entirely. */
.row-bg { pointer-events: none; }
.row-bg.zebra-odd { background: #f3f4f6; }

.row-track {
  position: relative;
  border-bottom: 1px solid var(--border);
}

.day-col-bg {
  border-right: 1px solid var(--border);
  pointer-events: none;
  z-index: 0;
}
.day-col-bg.today { background: var(--today); }

.bar {
  position: absolute;
  border-radius: 6px;
  padding: 0 9px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  background: color-mix(in srgb, var(--bar-accent, var(--accent)) 15%, white);
  border-left: 3px solid var(--bar-accent, var(--accent));
  overflow: hidden;
  cursor: pointer;
  z-index: 2;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  transition: transform .08s ease, box-shadow .08s ease;
}
.bar-label, .bar-dates {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.bar-dates {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-dim);
  line-height: 1;
}
.bar:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,.16); z-index: 5; }

.bar-conflict {
  box-shadow: 0 0 0 2px var(--busy-border), 0 1px 2px rgba(0,0,0,.06);
}

.bar-invalid {
  background: repeating-linear-gradient(
    45deg, var(--busy-border), var(--busy-border) 6px, #7a1f14 6px, #7a1f14 12px
  ) !important;
  border: 1px solid #5c160e;
  color: #fff;
}
.bar-invalid .bar-dates { color: rgba(255,255,255,.85); }

.bar-needs-confirmation {
  box-shadow: 0 0 0 2px #f2b558, 0 1px 2px rgba(0,0,0,.06);
}

.car-cell.overbooked { background: var(--busy); }
.overbook-badge { margin-right: 6px; }

/* Calendar notes — freeform text pinned to a car/equipment row across a date range (delivery
   logistics, maintenance, etc). Sits below .bar in z-index (2) so a booking bar on the same
   day stays fully visible/clickable on top, while the note still catches clicks across the
   row's full height wherever no bar covers it. Color deliberately distinct from the 4 booking
   colors — keep in sync with NOTE_COLOR in app.js. */
.note-marker {
  position: absolute;
  top: 0;
  z-index: 1;
  background: color-mix(in srgb, #8e5cd9 16%, white);
  border-left: 3px solid #8e5cd9;
  border-radius: 4px;
  cursor: pointer;
  padding: 4px;
  box-sizing: border-box;
}
.note-marker .icon { margin: 0; color: #8e5cd9; }

.note-form { display: flex; flex-direction: column; gap: 12px; }
.note-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}
.note-form input, .note-form textarea {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  box-sizing: border-box;
}
.note-form textarea { resize: vertical; }
.note-form-actions { display: flex; gap: 8px; margin-top: 4px; }

.loading {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.1);
  display: none;
}
.loading.visible { display: block; }

.page-loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.page-loading.hidden { display: none; }
.page-loading-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 16px 24px;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20,25,35,.35);
  z-index: 10;
}
.panel-backdrop.hidden { display: none; }

/* A flex column so the action buttons (Save/Delete/Open in Bitrix/etc, in
   .deal-panel-footer) stay pinned to the bottom edge regardless of how tall
   .deal-panel-scroll's content grows once its async parts (the booking items list) finish
   loading — previously the whole panel scrolled as one block, so those buttons visibly
   jumped down mid-load and staff would click the wrong one or miss entirely. */
.deal-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(0,0,0,.15);
  z-index: 11;
  display: flex;
  flex-direction: column;
}
.deal-panel.hidden { display: none; }
.deal-panel-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  padding: 22px;
}
.deal-panel-footer {
  flex-shrink: 0;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
}
.deal-panel-footer:empty { display: none; }
.deal-panel-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-dim);
}
.deal-panel h2 { margin: 0 26px 4px 0; font-size: 18px; }
.deal-panel .stage-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 14px;
}
.invalid-date-warning {
  background: var(--busy);
  border: 1px solid var(--busy-border);
  color: #7a1f14;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  margin: 0 0 14px;
}
.deal-panel dl { margin: 0; }
.deal-panel dt { color: var(--text-dim); font-size: 11px; text-transform: uppercase; margin-top: 12px; }
.deal-panel dd { margin: 2px 0 0; font-size: 14px; font-weight: 600; }
.panel-items {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.panel-items h3 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 700;
}
.panel-items-list { display: flex; flex-direction: column; gap: 6px; }
.panel-item-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}
.panel-item-name { color: var(--text); }
.panel-item-total { color: var(--text-dim); font-weight: 600; white-space: nowrap; }
.panel-items-total {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
}
.panel-items-loading, .panel-items-empty {
  color: var(--text-dim);
  font-size: 13px;
}
.deal-panel a.open-in-bitrix {
  display: block;
  text-align: center;
  background: var(--accent);
  color: #fff;
  padding: 10px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 700;
}
.deal-panel a.open-booking-page {
  display: block;
  margin-top: 10px;
  text-align: center;
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 10px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 700;
}

/* --- Shared secondary-page layout (booking detail, equipment settings) --- */

.back-link {
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  margin-right: 14px;
}
.back-link:hover { color: var(--accent); }

.page-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  width: 100%;
  scrollbar-width: none;
}
.page-content::-webkit-scrollbar { display: none; }

.page-content-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 18px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.page-content-inner-wide {
  max-width: none;
  padding-left: 32px;
  padding-right: 32px;
}

#carsTable th:nth-child(1), #carsTable td:nth-child(1) { width: 22%; }
#carsTable th:nth-child(2), #carsTable td:nth-child(2) { width: 24%; }
#carsTable th:nth-child(3), #carsTable td:nth-child(3) { width: 12%; }
#carsTable th:nth-child(4), #carsTable td:nth-child(4) { width: 32%; }
#carsTable th:nth-child(5), #carsTable td:nth-child(5) { width: 10%; white-space: nowrap; }
#carsTable td { overflow: visible; }

.panel-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
}
.panel-card h2 {
  font-size: 15px;
  margin: 0 0 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.btn-danger { color: #c0362c; }
.btn-danger:hover { background: #fbeae9; border-color: #e05c4d; }

/* Equipment settings page */

.equip-form {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.equip-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}
.equip-form input, .equip-form select {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 180px;
}

.month-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 320px;
}
.month-check {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 400 !important;
  color: var(--text) !important;
  width: 60px;
}

.template-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 2px 9px;
  vertical-align: middle;
  margin-left: 8px;
}
.template-placeholders code {
  background: var(--panel-alt, var(--avail));
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}
.template-textarea {
  width: 100%;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--panel);
  resize: vertical;
  box-sizing: border-box;
}
.template-textarea-small { resize: none; }
.template-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.template-save-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.equip-table, .lineitems-table {
  width: 100%;
  border-collapse: collapse;
}
.equip-table th, .lineitems-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
}
.equip-table td, .lineitems-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.cell-input {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  width: 100%;
  box-sizing: border-box;
  background: transparent;
}
.cell-input:hover, .cell-input:focus { border-color: var(--border); background: var(--bg); }

.empty-state { color: var(--text-dim); font-size: 14px; padding: 10px 0 0; }
.empty-state.hidden { display: none; }

/* Booking detail page */

.booking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.booking-header h1 { font-size: 20px; margin: 0; }
.confirmation-alert {
  background: #fff4e5;
  border: 1px solid #f2b558;
  color: #8a5a12;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
}
.booking-header-actions { display: flex; align-items: center; gap: 14px; }
.booking-stage-pill {
  display: inline-block;
  margin-top: 10px;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.booking-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 720px) { .booking-grid { grid-template-columns: 1fr; } }

.info-list dt { color: var(--text-dim); font-size: 11px; text-transform: uppercase; margin-top: 12px; }
.info-list dt:first-child { margin-top: 0; }
.info-list dd { margin: 2px 0 0; font-size: 15px; font-weight: 600; }

dd.contact-value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px !important;
  font-weight: 500 !important;
  color: var(--text);
}
.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
}
.copy-btn:hover { color: var(--accent); background: var(--accent-soft); }
.copy-btn.copied { color: #2e9e5b; }
.copy-btn svg { width: 13px; height: 13px; display: block; }

.value-input {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 6px;
  margin: 2px 0 0 -7px;
  background: transparent;
  width: 100%;
}
.value-input:hover { border-color: var(--border); }
.value-input:focus { border-color: var(--accent); background: var(--panel); outline: none; }
.value-input:disabled { color: var(--text-dim); cursor: wait; font-style: italic; }

.period-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.period-box { flex: 1; }
.period-box .label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; }
.period-box .value-input { font-size: 18px; font-weight: 700; }
.period-arrow { color: var(--text-dim); font-size: 20px; transform: rotate(90deg); }

.lineitems-table .qty-input, .lineitems-table .price-input {
  width: 70px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}
.price-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.price-input-wrap .price-suffix {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  white-space: nowrap;
}
.lineitems-table .desc-cell { min-width: 200px; }
.lineitems-table .drag-cell, .equip-table .drag-cell { width: 24px; padding-left: 4px; padding-right: 0; }
.lineitems-table .drag-handle, .equip-table .drag-handle {
  display: inline-flex;
  cursor: grab;
  color: var(--text-dim);
  padding: 4px;
  border-radius: 4px;
}
.lineitems-table .drag-handle:hover, .equip-table .drag-handle:hover { color: var(--text); background: var(--accent-soft); }
.lineitems-table .drag-handle svg, .equip-table .drag-handle svg { width: 14px; height: 14px; display: block; }
.lineitems-table tr.dragging, .equip-table tr.dragging { opacity: .4; }
.lineitems-table tr.drag-over-top td, .equip-table tr.drag-over-top td { box-shadow: inset 0 2px 0 var(--accent); }
.lineitems-table tr.drag-over-bottom td, .equip-table tr.drag-over-bottom td { box-shadow: inset 0 -2px 0 var(--accent); }
.lineitems-table tr.car-row { background: var(--accent-soft); font-weight: 700; }
.lineitems-table tr.car-row td { border-bottom: 2px solid var(--border); }
.lineitems-table tr.pending-row { opacity: .55; }
.lineitems-table tr.payment-row td { border-bottom: none; font-weight: 700; }
.lineitems-table .avail-note { font-size: 11px; color: var(--text-dim); }
.lineitems-table .avail-note.low { color: var(--busy-border); font-weight: 700; }
.equip-status-badge-row { margin-top: 4px; }
.equip-status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.equip-status-badge.ok { background: var(--avail); color: var(--avail-border); }
.equip-status-badge.zero { background: var(--border); color: var(--text-dim); }
.equip-status-badge.short { background: var(--busy); color: var(--busy-border); }
.lineitems-table tfoot td {
  border-bottom: none;
  border-top: 2px solid var(--border);
  font-weight: 700;
  font-size: 16px;
  padding-top: 12px;
}
.lineitems-table tfoot tr:not(:first-child) td {
  border-top: none;
  font-weight: 400;
  font-size: 13px;
  padding-top: 6px;
  color: var(--text-dim);
}

.add-line-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.add-line-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
}
.add-line-row select, .add-line-row input {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
}
.add-line-row input[type="text"] { width: 180px; }
.add-line-row input[type="number"] { width: 90px; }

.search-input {
  width: 100%;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  margin-bottom: 8px;
  box-sizing: border-box;
}
.equip-avail-list { display: flex; flex-direction: column; gap: 2px; }
.equip-avail-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.equip-avail-row:last-child { border-bottom: none; }
.equip-avail-name { font-weight: 700; flex: 1 1 auto; min-width: 120px; }
.equip-avail-price { color: var(--text-dim); font-size: 13px; }
.equip-avail-count { font-size: 12px; color: var(--text-dim); min-width: 130px; }

.pdf-history-list { display: flex; flex-direction: column; gap: 2px; }
.pdf-history-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.pdf-history-row:last-child { border-bottom: none; }
.pdf-history-seq { color: var(--text-dim); font-size: 13px; min-width: 28px; }
.pdf-history-date { font-weight: 700; flex: 1 1 auto; }
.pdf-history-size { color: var(--text-dim); font-size: 13px; min-width: 70px; }
.equip-avail-count.low { color: var(--busy-border); font-weight: 700; }
.equip-avail-btn-slot { min-width: 64px; display: flex; justify-content: flex-end; }
.added-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--avail-border);
  white-space: nowrap;
}

/* Puts the car name on its own line under the section title instead of
   an all-caps run-on ("VEHICLE & CONTRACT — TOYOTA LAND CRUISER…") that
   wraps awkwardly once the car name is long, especially on narrow screens. */
.panel-title-name {
  display: block;
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
  margin-top: 2px;
}

/* Lets a wide table (line items, equipment, cars, pricing rules) scroll
   horizontally within its own card instead of blowing out the width of
   the whole page on narrow screens. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
/* Floor widths so columns scroll instead of squeezing illegibly narrow
   once the card is narrower than the table wants to be. */
.table-scroll .equip-table { min-width: 480px; }
.table-scroll .lineitems-table { min-width: 620px; }

/* ============================================================
   Mobile layout (phones, narrow tablets)
   ============================================================ */
@media (max-width: 760px) {
  /* Calendar top bar: stack left/center/right into their own full-width,
     wrapping rows instead of cramming logo, nav links, date controls and
     filters into a single line. */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 12px;
  }
  .topbar-left, .topbar-center, .topbar-right {
    width: 100%;
    flex-wrap: wrap;
  }
  .topbar-center { justify-content: center; }
  .brand-logo { height: 28px; margin-right: 8px; }
  .range-label { min-width: 0; }
  .search { flex: 1 1 100%; width: 100%; }

  /* Let the whole page scroll instead of confining scroll to .timeline-scroll, so the
     topbar/legend scroll out of view as you scroll down into the calendar — trades the
     always-visible controls of desktop for more visible calendar height on a small screen,
     per explicit request. (Desktop keeps the header pinned — see the un-scoped rule above
     this media query and its comment for why that matters there: a sticky in-calendar date
     header needs .timeline-scroll to be the one true scrolling ancestor. Here there's only
     one scroll container either way — body — so that constraint doesn't apply.) */
  body { overflow-y: auto; height: auto; min-height: 100%; }
  .timeline-scroll { overflow-x: auto; overflow-y: visible; flex: none; min-height: auto; }

  /* Car/equipment name column: narrower so more of the day grid fits on screen. Long names
     scroll sideways inside their own cell (swipe on the name) instead of being cut off with
     an ellipsis; the scrollbar is hidden since it would eat the single row's height. */
  .car-cell, .equip-cell {
    font-size: var(--text-sm); padding: 0 8px;
    overflow-x: auto; overflow-y: hidden; text-overflow: clip; white-space: nowrap;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .car-cell::-webkit-scrollbar, .equip-cell::-webkit-scrollbar { display: none; }

  /* Availability dropdown: anchor to the viewport instead of the button
     that opens it, so it can't run off the edge of a narrow screen. */
  .avail-panel {
    position: fixed;
    top: 96px;
    left: 12px;
    right: 12px;
    width: auto;
    max-height: calc(100vh - 116px);
    overflow-y: auto;
  }

  /* Deal detail panel: full-width sheet instead of a fixed 360px sidebar,
     which on a phone would already cover almost the whole screen anyway
     while leaving cramped margins. */
  .deal-panel { width: 100%; }
  .deal-panel-scroll { padding: 18px; }
  .deal-panel-footer { padding: 12px 18px; }

  /* Secondary pages (Equipment / Cars / Contracts / Booking) */
  .page-content-inner, .page-content-inner-wide {
    padding: 16px 12px 40px;
  }
  .panel-card { padding: 16px; }

  .equip-form input, .equip-form select,
  .add-line-row input[type="text"],
  .add-line-row input[type="number"] {
    width: 100%;
  }
  .equip-form label, .add-line-row label { flex: 1 1 100%; }

  .equip-avail-row, .pdf-history-row {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  .booking-header-actions { flex-wrap: wrap; }
}
