/*
 * PitStop -- public/css/rating.css
 * Structured 5-dimension rating capture overlay.
 *
 * Reuses the host theme tokens defined in base.css (--bg, --surface, --text,
 * --muted, --border, --radius, --great, --ok, --poor, --neutral, etc.). Each
 * token has a safe fallback so the sheet still renders if loaded standalone.
 * Tier classes (.tier-great / .tier-ok / .tier-poor / .tier-none) match the
 * map markers, list badges, and detail -- price is one meter of five, never
 * enlarged.
 */

.rating-scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim, rgba(0, 0, 0, 0.5));
  z-index: 900;
  animation: rating-fade 0.15s ease-out;
}

.rating-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 901;
  margin: 0 auto;
  max-width: var(--app-max-width, 480px);
  background: var(--surface, #ffffff);
  color: var(--text, #14181f);
  border-top-left-radius: var(--radius-lg, 18px);
  border-top-right-radius: var(--radius-lg, 18px);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.28);
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: rating-rise 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes rating-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rating-rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .rating-scrim, .rating-sheet { animation: none; }
}

/* grab handle */
.rating-sheet::before {
  content: '';
  display: block;
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--border, #d5dae2);
  margin: 0 auto 12px;
}

/* --- header --- */
.rating-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.rating-station {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
}
.rating-sub {
  font-size: 0.82rem;
  color: var(--muted, #69727f);
  margin-top: 2px;
}
.rating-close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--bg-subtle, #eef1f5);
  color: var(--muted, #69727f);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.rating-close:active { transform: scale(0.92); }

/* --- live overall --- */
.rating-overall {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius, 12px);
  margin-bottom: 14px;
  background: var(--tier-bg, var(--bg-subtle, #eef1f5));
  border: 1px solid var(--tier-line, transparent);
  transition: background 0.18s ease, border-color 0.18s ease;
}
.rating-overall-num {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
  color: var(--tier-fg, var(--text, #14181f));
}
.rating-overall-lbl {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted, #69727f);
}

/* --- the five co-equal dimension rows --- */
.rating-dims { display: flex; flex-direction: column; gap: 10px; }

.rating-dim {
  display: grid;
  /* 104px is what the longest real label needs: "Cleanliness" measures ~75px at
     0.9rem/600 plus the 1.05rem icon and its 6px gap (~97px total). Anything
     tighter pushes the text into the dot column. Value column trimmed 22->20 so
     the dots -- the precision targets in a moving car -- keep their width. */
  grid-template-columns: 104px 1fr 20px;
  align-items: center;
  gap: 8px;
}
.rating-dim-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text, #14181f);
}
.rating-dim-label i { flex: none; font-size: 1.05rem; color: var(--muted, #69727f); }
/* Safety net: a longer label than today's six ellipsizes instead of spilling
   over the dots. */
.rating-dim-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rating-scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.rating-dot {
  height: 48px;
  min-width: 0;
  border: 1.5px solid var(--border, #d5dae2);
  border-radius: 10px;
  background: var(--surface, #ffffff);
  cursor: pointer;
  padding: 0;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
  -webkit-tap-highlight-color: transparent;
}
.rating-dot:active { transform: scale(0.9); }
.rating-dot:disabled { opacity: 0.5; cursor: default; }
.rating-dot.is-on {
  background: var(--dot-fill, var(--neutral, #636e7d));
  border-color: var(--dot-fill, var(--neutral, #636e7d));
}
.rating-dim-val {
  text-align: right;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted, #69727f);
  font-variant-numeric: tabular-nums;
}

/* --- optional note --- */
.rating-note { margin: 14px 0 4px; }
.rating-note-input {
  width: 100%;
  box-sizing: border-box;
  height: 46px;
  padding: 0 14px;
  border: 1.5px solid var(--border, #d5dae2);
  border-radius: var(--radius, 12px);
  background: var(--surface, #ffffff);
  color: var(--text, #14181f);
  /* 16px is a floor, not a style choice: iOS Safari auto-zooms any focused
     input below it and never zooms back out on blur, which strands the driver
     in a magnified sheet. Do not shrink this. */
  font-size: 1rem;
}
.rating-note-input::placeholder { color: var(--muted, #69727f); }
.rating-note-input:focus {
  outline: none;
  border-color: var(--accent, #2f6fed);
}
.rating-note-input:disabled { opacity: 0.6; }

/* --- footer --- */
.rating-foot { margin-top: 14px; }
.rating-error {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--poor, #c63127);
  background: var(--poor-bg, rgba(210, 59, 59, 0.1));
  border-radius: var(--radius, 12px);
  padding: 9px 12px;
  margin-bottom: 10px;
}

.rating-submit {
  width: 100%;
  height: 54px;
  border: none;
  border-radius: var(--radius, 12px);
  font-size: 1.02rem;
  font-weight: 700;
  /* the tier modifiers below repaint --submit-bg, so the ink has to travel with
     it -- brand ink is the resting value, tier ink when a tier fill is on */
  color: var(--submit-ink, var(--brand-ink, #ffffff));
  background: var(--submit-bg, var(--accent, #2f6fed));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.06s ease;
}
.rating-submit:active:not(:disabled) { transform: scale(0.98); }
.rating-submit:disabled {
  background: var(--bg-subtle, #eef1f5);
  color: var(--muted, #69727f);
  cursor: default;
}

/* tier coloring -- shared with map/list/detail. The overall block paints its
   bg/fg; the submit button + lit dots paint their fill. price is never special. */
.rating-overall.tier-great { --tier-fg: var(--great, #197d46); --tier-bg: var(--great-bg, rgba(31, 157, 85, 0.12)); --tier-line: var(--great, #197d46); }
.rating-overall.tier-ok    { --tier-fg: var(--ok, #94640b);    --tier-bg: var(--ok-bg, rgba(201, 138, 20, 0.12));    --tier-line: var(--ok, #94640b); }
.rating-overall.tier-poor  { --tier-fg: var(--poor, #c63127);  --tier-bg: var(--poor-bg, rgba(210, 59, 59, 0.12));   --tier-line: var(--poor, #c63127); }
.rating-overall.tier-none  { --tier-fg: var(--muted, #69727f); --tier-bg: var(--bg-subtle, #eef1f5); --tier-line: transparent; }

.rating-dot.tier-great { --dot-fill: var(--great, #197d46); }
.rating-dot.tier-ok    { --dot-fill: var(--ok, #94640b); }
.rating-dot.tier-poor  { --dot-fill: var(--poor, #c63127); }
.rating-dot.tier-none  { --dot-fill: var(--neutral, #636e7d); }

.rating-submit.tier-great { --submit-bg: var(--great, #197d46); --submit-ink: var(--tier-ink, #ffffff); }
.rating-submit.tier-ok    { --submit-bg: var(--ok, #94640b);    --submit-ink: var(--tier-ink, #ffffff); }
.rating-submit.tier-poor  { --submit-bg: var(--poor, #c63127);  --submit-ink: var(--tier-ink, #ffffff); }
.rating-submit.tier-none  { --submit-bg: var(--accent, #2f6fed); --submit-ink: var(--brand-ink, #ffffff); }

/* --- submitting spinner --- */
.rating-spin {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  /* the spinner sits ON the submit button, so the leading arc rides the
     button's own ink -- a fixed white vanished on a dark-mode tier fill */
  border-top-color: currentColor;
  border-radius: 50%;
  animation: rating-spin 0.7s linear infinite;
}
@keyframes rating-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .rating-spin { animation-duration: 1.6s; }
}

/* --- confirm beat --- */
.rating-confirm {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 0 4px;
  animation: rating-pop 0.25s ease-out;
}
.rating-confirm-mark {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--great, #197d46);
  color: var(--tier-ink, #ffffff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
.rating-confirm-txt {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--great, #197d46);
}
@keyframes rating-pop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .rating-confirm { animation: none; } }

/* dark theme: tokens come from base.css; only the scrim needs a nudge if the
   host did not define one. */
@media (prefers-color-scheme: dark) {
  .rating-scrim { background: var(--scrim, rgba(0, 0, 0, 0.62)); }
}

/* the rating sheet is opened from the detail overlay (z 1200) -- it must sit above it */
#rate-root { position: fixed; inset: 0; z-index: 1300; }
