/* ─── ManxDeals design tokens (shared with treecassyn.com) ─────── */
:root {
  --manx: #cf142b;
  --manx-dark: #a60f22;
  --manx-deep: #7c0a18;
  --gold: #f2b705;

  --background: #faf8f7;
  --foreground: #1c1917;
  --surface: #ffffff;
  --surface-2: #f5f1ef;
  --border: #e7e0dd;
  --muted: #78716c;

  --ok: #047857;
  --warn: #b45309;
  --danger: #cf142b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #110d0d;
    --foreground: #f5f0ee;
    --surface: #1c1717;
    --surface-2: #262020;
    --border: #332b2b;
    --muted: #a39a96;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
}

/* Thin Manx red accent bar across the very top, like ManxDeals */
.top-accent {
  height: 4px;
  background: linear-gradient(90deg, var(--manx-deep), var(--manx), var(--gold));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}

.brand { display: flex; align-items: center; gap: 12px; height: 56px; }

.brand-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 12px;
  background: var(--manx);
  color: #fff;
  box-shadow: 0 2px 6px color-mix(in srgb, var(--manx) 30%, transparent);
  flex-shrink: 0;
}
.triskelion { width: 20px; height: 20px; }

.brand-text h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; white-space: nowrap; }
.brand-text .manx { color: var(--manx); }
.brand-text .fares { color: var(--foreground); }
.tagline { margin: 1px 0 0; font-size: 9px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }

.container { max-width: 1400px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---------------- Search card ---------------- */
.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(28, 25, 23, 0.06);
  padding: 18px 20px;
}
#search-form {
  display: grid;
  grid-template-columns: minmax(200px, 2fr) minmax(200px, 2fr) repeat(4, minmax(58px, 74px)) minmax(84px, auto) auto;
  gap: 12px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; }
.field select, .field input {
  height: 38px; padding: 0 10px; width: 100%;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); font-size: 14px; color: var(--foreground);
  -webkit-appearance: none; appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2378716c' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--manx); outline-offset: 1px; }

.btn {
  border: none; border-radius: 10px; padding: 0 20px; height: 38px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn-primary { background: var(--manx); color: #fff; }
.btn-primary:hover { background: var(--manx-dark); }
.btn-primary:disabled { background: color-mix(in srgb, var(--manx) 55%, var(--surface)); cursor: wait; }

/* ---------------- Progress ---------------- */
.progress-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 18px; margin-top: 16px;
}
.progress-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; margin-bottom: 8px; color: var(--muted); }
.progress-meta #progress-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-meta #progress-count { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.progress-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--manx-deep), var(--manx), var(--gold)); transition: width 0.4s ease; }

/* ---------------- Summary ---------------- */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 16px;
  min-height: 78px;
  display: flex; flex-direction: column; justify-content: center; gap: 3px;
}
.stat-value {
  display: block;
  font-size: 17px; font-weight: 700; color: var(--foreground);
  line-height: 1.25;
  overflow-wrap: break-word;
}
.stat-label { font-size: 12px; color: var(--muted); }

/* ---------------- Legend ---------------- */
.legend {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px;
  margin-top: 16px; font-size: 12px; color: var(--muted);
}
.legend-scale { flex: 1 1 140px; max-width: 260px; min-width: 120px; height: 12px; border-radius: 999px; background: linear-gradient(90deg, #16a34a, var(--gold), var(--manx)); }
.legend-min, .legend-max { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------------- Year grid / heatmap ---------------- */
.results { margin-top: 20px; }
/* 3 fixed columns on wide screens so day cells have enough width for prices */
.year-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 1120px) {
  .year-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.month-block {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px;
  overflow: hidden;  /* keep day cells inside the rounded corners */
}
.month-title { margin: 0 0 10px; font-size: 15px; font-weight: 700; color: var(--foreground); }
.month-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; font-size: 11px; text-align: center; }
.month-days .dow { color: var(--muted); font-weight: 600; padding: 2px 0 4px; }
.day-cell {
  border-radius: 8px; padding: 3px 1px; min-height: 46px; min-width: 0;
  cursor: pointer; position: relative; transition: transform 0.08s ease;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  overflow: hidden;
}
.day-cell:hover { transform: scale(1.06); box-shadow: 0 2px 6px rgba(28, 25, 23, 0.25); z-index: 2; }
.day-cell:active { transform: scale(0.96); }
.day-cell.blank { background: transparent; cursor: default; }
.day-cell.blank:hover, .day-cell.blank:active { transform: none; box-shadow: none; }
.day-cell .dnum { font-weight: 600; font-size: 12px; line-height: 1.2; }
.day-cell .dfare { font-weight: 700; font-size: 11px; line-height: 1.2; white-space: nowrap; }
.day-cell .dfare.na { color: var(--muted); font-weight: 500; text-decoration: line-through; }
.day-cell .dfare.none { color: color-mix(in srgb, var(--muted) 55%, transparent); font-weight: 500; }
.day-cell.sold-out .dnum { text-decoration: line-through; }
.day-cell.today { outline: 2px solid var(--manx); outline-offset: 1px; }
/* Price-change badge on heatmap cells */
.day-cell .delta {
  font-size: 9px; font-weight: 700; line-height: 1.2;
  font-variant-numeric: tabular-nums;
  padding: 0 3px; border-radius: 6px; margin-top: 1px;
}
.day-cell .delta.up { color: #7c0a18; background: color-mix(in srgb, #cf142b 22%, transparent); }
.day-cell .delta.down { color: #065f46; background: color-mix(in srgb, #16a34a 22%, transparent); }

/* ---------------- Day panel ---------------- */
.day-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(28, 25, 23, 0.18);
  padding: 18px 18px 40px; overflow-y: auto; z-index: 50;
  transform: translateX(105%); transition: transform 0.25s ease;
  display: none;
}
.day-panel.open { transform: translateX(0); }
.day-panel-head { display: flex; align-items: flex-start; gap: 10px; }
.day-panel-head-text { flex: 1; min-width: 0; }
.day-panel-head h3 { margin: 0; font-size: 18px; }
.day-route { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.day-hint { margin: 12px 0 10px; font-size: 12px; color: var(--muted); }
.day-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 0 12px; padding: 8px 0;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.day-age { font-size: 12px; color: var(--muted); }
.refresh-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--foreground);
  border-radius: 9px; padding: 6px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.refresh-btn:hover { border-color: var(--manx); color: var(--manx); }
.refresh-btn:disabled { opacity: 0.6; cursor: wait; }

/* Price history in the day panel */
.day-history { margin: 0 0 12px; }
.history-summary { font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.history-summary.up { color: var(--danger); }
.history-summary.down { color: var(--ok); }
.history-summary.flat { color: var(--muted); font-weight: 500; }
.sparkline { display: block; width: 100%; height: auto; }
.spark-wrap { position: relative; }
.spark-dot { fill: transparent; cursor: pointer; }
.spark-dot:hover { fill: var(--manx); }
.spark-tip {
  position: absolute; transform: translate(-50%, -100%);
  background: var(--foreground); color: var(--background);
  font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: 7px;
  pointer-events: none; white-space: nowrap; z-index: 5;
  box-shadow: 0 2px 8px rgba(28, 25, 23, 0.2);
}
.spark-tip.hidden { display: none; }
.day-close {
  flex-shrink: 0;
  border: none; background: var(--surface-2); color: var(--foreground);
  border-radius: 10px; font-size: 20px; line-height: 1; width: 34px; height: 34px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.day-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

/* Each sailing card: departure time on the left, fare options on the right. */
.sailing-item {
  border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px;
  display: grid;
  grid-template-columns: minmax(62px, auto) 1fr;
  align-items: start;
  gap: 6px 14px;
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.sailing-item:hover { border-color: color-mix(in srgb, var(--manx) 45%, var(--border)); box-shadow: 0 4px 12px rgba(28, 25, 23, 0.1); }
.sailing-time { font-weight: 700; font-size: 15px; line-height: 1.25; font-variant-numeric: tabular-nums; padding-top: 2px; }
.sailing-time small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; margin-top: 1px; }

/* Fare options inside a sailing: name | price | Book */
.sailing-fares { display: flex; flex-direction: column; min-width: 0; }
.fare-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 4px 10px;
  padding: 6px 0;
}
.fare-row:first-child { padding-top: 0; }
.fare-row + .fare-row { border-top: 1px dashed var(--border); }
.fare-row .fname { font-size: 11px; color: var(--muted); line-height: 1.3; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.fare-delta {
  font-size: 9px; font-weight: 700; line-height: 1.2;
  font-variant-numeric: tabular-nums;
  padding: 0 4px; border-radius: 6px; align-self: flex-start;
}
.fare-delta.up { color: #7c0a18; background: color-mix(in srgb, #cf142b 22%, transparent); }
.fare-delta.down { color: #065f46; background: color-mix(in srgb, #16a34a 22%, transparent); }
/* Uniform price size/alignment: tabular numbers so digits line up vertically. */
.fare-row .fprice {
  font-weight: 800; font-size: 16px; color: var(--foreground);
  line-height: 1.2; white-space: nowrap;
  font-variant-numeric: tabular-nums;
  text-align: right; min-width: 64px;
}
.fare-row .fprice.off { color: var(--ok); }
.fare-row .fprice.na { color: color-mix(in srgb, var(--muted) 60%, transparent); font-weight: 500; text-decoration: line-through; font-size: 13px; min-width: 64px; }
.sailing-action { display: flex; align-items: center; }
.book-btn {
  display: inline-block; text-decoration: none; text-align: center;
  background: var(--manx); color: #fff; border-radius: 9px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
}
.book-btn:hover { background: var(--manx-dark); }
.no-results { color: var(--muted); font-size: 13px; padding: 10px 2px; }

/* ---------------- Misc ---------------- */
.hidden { display: none !important; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 16px 40px; }
.footer a { color: var(--manx); }

/* ---------------- Tablet ---------------- */
@media (max-width: 1080px) {
  #search-form {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  #search-form .field:nth-child(3),
  #search-form .field:nth-child(4),
  #search-form .field:nth-child(5),
  #search-form .field:nth-child(6) { grid-column: span 1; }
  #search-form .field:nth-child(7) { grid-column: 1 / -1; }
  #search-form .field-actions { grid-column: 1 / -1; }
  .field select, .field input { height: 42px; }
}

/* ---------------- Phone ---------------- */
@media (max-width: 720px) {
  .topbar { padding: 0 16px; }
  .brand-text h1 { font-size: 16px; }

  .container { padding: 14px 12px 50px; }

  /* Search form: route/vehicle full width, numbers in a 2x2 grid, full-width button */
  .search-card { padding: 14px 14px 16px; }
  #search-form {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  #search-form .field:first-child,
  #search-form .field:nth-child(2) { grid-column: 1 / -1; }
  #search-form .field:nth-child(7) { grid-column: 1 / -1; }  /* Year */
  #search-form .field-actions { grid-column: 1 / -1; }
  .field select, .field input { height: 46px; font-size: 16px; }  /* prevent iOS zoom */
  .field-actions .btn { width: 100%; height: 46px; font-size: 16px; }

  /* Heatmap: single column */
  .year-grid { grid-template-columns: 1fr; gap: 14px; }
  .month-block { padding: 12px; }
  .day-cell { min-height: 52px; }
  .day-cell .dnum { font-size: 12px; }
  .day-cell .dfare { font-size: 12px; }

  /* Summary stats: 2-up */
  .summary { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 10px 12px; min-height: 84px; }
  .stat-value { font-size: 15px; }

  /* Day panel: full-width sheet */
  .day-panel { width: 100%; padding: 16px 14px 40px; }
  .sailing-item { grid-template-columns: minmax(56px, auto) 1fr; gap: 6px 10px; padding: 12px 12px; }
  .fare-row .fprice { font-size: 15px; }
  .fare-row .fname { font-size: 11px; }
  .book-btn { padding: 8px 14px; }
}
