/* Cellar Intelligence Phase 4 styles. Loaded after app.css and uses
   the same design tokens (iOS grouped background, wineRed / winePurple,
   system font stack). All Phase 4 classes are prefixed p4- to stay
   clear of core styles. */

/* Home (Insights) segmented control spacing — the control itself is the
   shared .segmented/.seg from app.css (old app parity). */
.p4-segmented { margin: 12px 0 16px; }
.p4-section-title { display: flex; align-items: center; gap: 8px; font-size: 1.06rem; font-weight: 600; margin: 0 0 10px; }
.p4-section-ico { display: inline-flex; }
.p4-section-ico svg { width: 17px; height: 17px; fill: none; stroke: var(--red); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.p4-section-unit { font-size: 0.78rem; font-weight: 500; }

/* Home hero banner (old app): 3-stop brand gradient, radius 20, the
   logo centred on a white glow. */
.home-hero {
  background: var(--gradient-hero); border-radius: 20px; height: 180px;
  display: flex; align-items: center; justify-content: center;
  margin: 4px 0 16px; overflow: hidden;
}
.home-hero__logo {
  height: 120px; width: auto; max-width: 82%;
  filter: drop-shadow(0 0 16px rgba(255, 255, 255, 0.85)) drop-shadow(0 0 40px rgba(255, 255, 255, 0.5));
}

/* Drink / Buy heading blocks (old app). */
.tab-heading h2 { font-size: 1.4rem; margin: 4px 0 2px; }
.tab-heading p { margin: 0 0 12px; }

/* Drink Window mini-cards (old app drinkWindowCard): tinted icon
   circle + big count + caption. */
.dw-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.dw-card {
  flex: 1 1 120px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--bg); border-radius: 12px; padding: 14px 8px;
}
.dw-ico { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.dw-ico svg { width: 21px; height: 21px; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dw-ico--orange { background: rgba(255, 149, 0, 0.14); } .dw-ico--orange svg { stroke: #c77400; }
.dw-ico--green { background: rgba(52, 199, 89, 0.14); } .dw-ico--green svg { stroke: var(--green); fill: var(--green); }
.dw-ico--red { background: rgba(255, 59, 48, 0.12); } .dw-ico--red svg { stroke: #d70015; }
.dw-ico--grey { background: var(--fill); } .dw-ico--grey svg { stroke: var(--text-muted); }
.dw-num { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.dw-label { font-size: 0.75rem; color: var(--text-muted); text-align: center; }

/* AI Sommelier chat card (old app): white card, wineRed-tinted hairline
   border, soft shadow. */
.p4-chat {
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid rgba(155, 27, 48, 0.15);
  box-shadow: 0 6px 6px rgba(0, 0, 0, 0.06), 0 3px 3px rgba(0, 0, 0, 0.06);
  padding: 12px; margin: 14px 0;
}
.p4-chat-head { font-weight: 600; font-size: 1rem; margin-bottom: 6px; }
.p4-chat-caption { margin: 0 0 8px; font-size: 0.9rem; }
.p4-chat-messages { display: grid; gap: 8px; padding: 2px 0 10px; max-height: 340px; overflow-y: auto; }
.p4-chat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.p4-chat-send {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: 12px; padding: 11px 18px;
  background: var(--red); color: #fff;
}
.p4-chat-send[disabled] { opacity: 0.5; pointer-events: none; }

/* Insights stat row + drink-window cards */
/* Old app: the stats row is not a card — icon + big number + caption
   sitting directly on the background. */
.p4-stats-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0 4px; }
/* Stat text starts where card text starts: .card pads 18px, so the
   tiles pad the same on the left (UX audit walker 5). */
.p4-stat { flex: 1 1 120px; padding: 4px 0 4px 18px; }
.p4-stat__value { font-size: 1.4rem; font-weight: 700; }
.p4-stat__label { color: var(--text-muted); font-size: 0.85rem; font-weight: 600; }
.p4-win--early { border-top: 4px solid #e07b00; }
.p4-win--peak { border-top: 4px solid #1d7a3a; }
.p4-win--past { border-top: 4px solid var(--red); }

/* Charts */
.p4-donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.p4-legend { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.p4-legend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.p4-legend__swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.p4-bar-row { display: grid; grid-template-columns: 130px 1fr 44px; align-items: center; gap: 10px; padding: 4px 0; font-size: 0.9rem; }
.p4-bar-row__label { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p4-bar-track { background: var(--bg-card-hover); border-radius: 999px; height: 12px; overflow: hidden; }
.p4-bar-fill { height: 100%; border-radius: 999px; background: var(--red); }
.p4-bar-row__value { text-align: right; font-weight: 600; color: var(--text-muted); }
.p4-vbars { display: flex; align-items: flex-end; gap: 6px; min-height: 130px; padding-top: 10px; overflow-x: auto; }
.p4-vbar { flex: 1 0 30px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--text-muted); }
.p4-vbar__col { width: 70%; max-width: 44px; background: var(--gradient); border-radius: 6px 6px 0 0; min-height: 3px; }
.p4-vbar__value { font-weight: 700; color: var(--text); font-size: 0.8rem; }

/* Chat */
.p4-chat-list { max-height: 300px; overflow-y: auto; display: grid; gap: 8px; padding: 4px 0 10px; }
.p4-bubble { max-width: 85%; padding: 10px 14px; border-radius: 14px; background: var(--bg-card-hover); white-space: pre-wrap; word-wrap: break-word; }
.p4-bubble--user { justify-self: end; background: var(--red); color: #fff; }
.p4-bubble--assistant { justify-self: start; border: 1px solid var(--border); background: var(--bg-card); }
.p4-chat-form { display: flex; gap: 8px; }
.p4-chat-form input { flex: 1; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 12px; }

/* Selectable chips + option grids (tasting / learn) */
.p4-chip { font: inherit; font-size: 0.85rem; cursor: pointer; min-height: 38px; padding: 7px 14px; border-radius: 999px; background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); }
.p4-chip--on { background: rgba(155, 27, 48, 0.12); color: var(--red); border-color: rgba(155, 27, 48, 0.3); font-weight: 600; }
/* Difficulty tabs in Blind Tasting setup (tasting.js): these classes had
   no rules at all, so the buttons rendered as raw browser buttons while
   the price chips next to them were styled pills (UI-CHECK-2). Same
   tokens as .p4-chip so the two rows read as one control set. */
.p4-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 8px; }
.p4-tab { font: inherit; font-size: 0.85rem; cursor: pointer; min-height: 38px; padding: 7px 14px; border-radius: 999px; background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); }
.p4-tab--active { background: rgba(155, 27, 48, 0.12); color: var(--red); border-color: rgba(155, 27, 48, 0.3); font-weight: 600; }
.p4-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.p4-opt { font: inherit; cursor: pointer; text-align: center; padding: 12px 10px; border-radius: var(--radius-sm); background: var(--bg-card); border: 1px solid var(--border); color: var(--text); }
.p4-opt--sel { border-color: var(--purple); background: linear-gradient(135deg, rgba(155,27,48,0.08), rgba(107,47,160,0.08)); font-weight: 700; }
.p4-level-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.p4-level-row__label { flex: 0 0 84px; font-weight: 600; font-size: 0.9rem; }
.p4-levels { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }

/* Dot comparison rows */
.p4-dots-row { display: grid; grid-template-columns: 84px 1fr 1fr; gap: 10px; align-items: center; padding: 5px 0; font-size: 0.9rem; }
.p4-dots { display: inline-flex; gap: 4px; }
.p4-dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--border-hover); background: transparent; }
.p4-dot--on { background: var(--red); border-color: transparent; }
.p4-dot--ref { background: var(--text-muted); border-color: transparent; }

/* Stars */
.p4-stars { display: inline-flex; gap: 4px; }
.p4-star { font-size: 1.6rem; line-height: 1; background: none; border: none; cursor: pointer; color: var(--text-dim); padding: 2px; }
.p4-star--on { color: #e07b00; }

/* Nudges, handoff, score */
.p4-nudge { background: #fff7e8; border: 1px solid #e0a458; border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.p4-handoff { text-align: center; padding: 36px 10px; }
.p4-handoff .big { font-size: 2.6rem; }
.p4-score-total { font-family: var(--font-display); font-size: 2.4rem; font-weight: 700; }
.p4-score-bar { display: grid; grid-template-columns: 92px 1fr 40px; gap: 10px; align-items: center; font-size: 0.9rem; padding: 3px 0; }
.p4-winner { border-color: #e07b00; box-shadow: 0 0 0 2px rgba(224, 123, 0, 0.35); }

/* Recommendation cards */
.p4-rec-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin: 10px 0; background: var(--bg); }
.p4-rec-card__head { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; }
.p4-rec-card__price { color: var(--red); white-space: nowrap; }

/* Modal + toast (CSV import, generic) */
.p4-modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(26, 26, 46, 0.45); display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 24px 12px; }
.p4-modal { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); max-width: 560px; width: 100%; padding: 22px; }
.p4-toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 50; background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 0.9rem; font-weight: 600; box-shadow: 0 4px 18px rgba(0,0,0,0.25); }

/* Cellar toolbar injected by files.js */
.p4-cellar-tools { display: flex; gap: 8px; margin: 10px 0 0; flex-wrap: wrap; }

/* History rows */
.p4-history-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.p4-history-row:last-child { border-bottom: none; }

/* Bottom nav has six entries now; tighten on small screens */
@media (max-width: 520px) {
  .bottom-nav a { padding: 10px 5px; font-size: 0.78rem; }
}

/* AI Usage box in Settings: it had no styles at all, so the numbers ran
   together and Reset was a bare browser button. Card it like its
   neighbours and give the figures room. */
.p4-usage {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin: 0 0 16px;
}
.p4-usage .p4-heading { margin: 0 0 10px; }
.p4-usage-calls, .p4-usage-cost { margin: 0 0 6px; }
.p4-usage-calls-num, .p4-usage-cost-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.p4-usage-reset { margin-top: 8px; }
.p4-import-help { font-size: 0.85rem; line-height: 1.45; }

/* ===== fix-app-rollout: picker buttons + pairing form spacing =====
   Tasting "Choose a Wine" and Learn list rows are <button class="wine-card">:
   inline spans inside a button run together ("Cabernet SauvignonCaymus
   Vineyards…"). Stack the name/sub lines and make the button behave like
   the link cards in the core list. */
button.wine-card { width: 100%; text-align: left; font: inherit; cursor: pointer; }
button.wine-card .wine-card__name,
button.wine-card .wine-card__sub { display: block; }

/* AI pairing form (Insights > Drink): these classes had no styles at all,
   so the inputs rendered cramped with labels crowding the field edges.
   Mirror the core .field treatment; on wide screens the two fields and
   the button sit on one row. */
.p4-pairing-form { display: grid; gap: 12px; margin: 12px 0; }
.p4-field { display: block; margin: 0; }
.p4-field span { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.p4-field input {
  width: 100%; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 12px;
}
.p4-field input:focus { outline: none; border-color: var(--purple); }
.p4-pairing-btn {
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
  border: 1px solid transparent; border-radius: 12px; padding: 12px 22px;
  background: var(--red); color: #fff;
}
.p4-pairing-btn[disabled] { opacity: 0.5; pointer-events: none; }
@media (min-width: 900px) {
  .p4-pairing-form { grid-template-columns: 2fr 1fr auto; align-items: end; }
}

/* Finding 23: the Tasting "History" tap scrolls #blindHistory into
   view, but the heading landed hidden behind the app's chrome. The
   scroll margin leaves room so the anchored card lands fully
   visible. */
#blindHistory { scroll-margin-top: 90px; scroll-margin-bottom: 90px; }

/* Finding 17: the subtle "still syncing" line under a cached Home
   render — visible, but clearly secondary to the data above it. */
.p4-syncing { text-align: center; font-size: 0.85rem; opacity: 0.75; margin: 10px 0 0; }
