/* ══════════════════════════════════════════════════════════════
   Viatja AI · fonaments
   Tokens, tipografia, controls i carcassa de navegació.
   Cap color literal fora d'aquest fitxer: tot passa per tokens,
   perquè el mode fosc sigui una redefinició i no una reescriptura.
   ══════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light dark;

  /* superfícies */
  --bg: #f4f2ef;
  --card: #ffffff;
  --sunk: #eae7e1;
  --raised: #ffffff;

  /* tinta */
  --text: #1d1a17;
  --text-soft: #4a453e;
  --muted: #777066;
  --line: #e0dbd3;
  --hairline: #eeebe5;

  /* identitat */
  --primary: #b9472a;
  --primary-hover: #9c3a21;
  --primary-ink: #ffffff;
  --primary-wash: #fbeee9;
  --primary-line: #f0d8ce;

  /* semàntica: comprovat · estimat · per confirmar · alerta */
  --ok: #1f6149;
  --ok-wash: #e3efe9;
  --est: #8a5a06;
  --est-wash: #f8eeda;
  --wait: #4c6579;
  --wait-wash: #e7eef2;
  --danger: #a3302a;
  --danger-wash: #f8e6e4;
  --warn: #8a5a06;

  --focus: #2d67d4;
  --shadow-sm: 0 1px 2px rgba(29, 26, 23, .05);
  --shadow: 0 1px 2px rgba(29, 26, 23, .05), 0 10px 26px -20px rgba(29, 26, 23, .5);
  --shadow-lg: 0 -6px 30px -12px rgba(29, 26, 23, .22);

  --r: 16px;
  --r-sm: 11px;
  --r-lg: 22px;

  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --display: ui-serif, "New York", Iowan Old Style, Georgia, serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --gutter: 18px;
  --tabbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --card: #1e1b18;
    --sunk: #191614;
    --raised: #241f1b;
    --text: #f0ece6;
    --text-soft: #cdc6bc;
    --muted: #989186;
    --line: #302b25;
    --hairline: #262220;
    --primary: #e5794f;
    --primary-hover: #f08c63;
    --primary-ink: #1d1a17;
    --primary-wash: #2d1d16;
    --primary-line: #43291f;
    --ok: #6fbe9d;
    --ok-wash: #14291f;
    --est: #d9a441;
    --est-wash: #2a2113;
    --wait: #9ab3c4;
    --wait-wash: #16232a;
    --danger: #e8776a;
    --danger-wash: #2f1715;
    --warn: #d9a441;
    --focus: #7aa5ff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 26px -20px rgba(0, 0, 0, .9);
    --shadow-lg: 0 -6px 30px -12px rgba(0, 0, 0, .75);
  }
}

/* ── base ─────────────────────────────────────────────── */
* { box-sizing: border-box; }

/* Qualsevol display d'una classe (flex, grid) guanya a [hidden] per
   especificitat; això el torna a fer autoritatiu a tota l'app. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* barra inferior + botó flotant, perquè res no quedi mai tapat */
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 68px);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.012em; line-height: 1.22; text-wrap: balance; }
h2 { font-size: 20px; }
h3 { font-size: 16.5px; }
h4 { font-size: 15px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

a { color: var(--primary); text-underline-offset: 2px; }

img { max-width: 100%; }

progress { width: 100%; height: 6px; border: 0; border-radius: 99px; background: var(--sunk); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--sunk); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 99px; }

.muted { color: var(--muted); }
.fineprint { font-size: 12px; line-height: 1.45; color: var(--muted); }
.kicker,
.recommendation-kicker {
  display: block;
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 3px;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.empty {
  padding: 18px 16px;
  border-radius: var(--r-sm);
  background: var(--sunk);
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

/* ── accessibilitat ───────────────────────────────────── */
.skip-link {
  position: fixed; z-index: 1000; top: 12px; left: 12px;
  padding: 10px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-weight: 700;
  transform: translateY(-180%); transition: transform 160ms ease;
}
.skip-link:focus { transform: translateY(0); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px;
}
button:disabled, [aria-disabled="true"] { cursor: not-allowed; opacity: .5; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (forced-colors: active) {
  .primary, .secondary, .ghost, .tab, .suggestion, .panel, .chat, .summary, .seg-button {
    border: 1px solid ButtonText;
  }
}

/* ── controls ─────────────────────────────────────────── */
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.primary, .secondary, .ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 16px; border-radius: var(--r-sm);
  font-size: 14.5px; font-weight: 600; line-height: 1.2;
  border: 1px solid transparent; transition: background-color 140ms ease, border-color 140ms ease;
  min-height: 44px;
}
.primary { background: var(--primary); color: var(--primary-ink); box-shadow: var(--shadow-sm); }
.primary:hover:not(:disabled) { background: var(--primary-hover); }
.secondary { background: var(--card); color: var(--text); border-color: var(--line); }
.secondary:hover:not(:disabled) { border-color: var(--muted); }
.ghost { background: transparent; color: var(--text-soft); border-color: var(--line); }
.ghost:hover:not(:disabled) { background: var(--sunk); }
.danger-quiet { color: var(--danger); font-size: 13.5px; font-weight: 600; padding: 10px 12px; }
.linklike {
  color: var(--primary); font: inherit; text-decoration: underline;
  text-underline-offset: 2px; padding: 0; min-height: 0;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label,
label > span:first-child { font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.field-help, .helper-note { font-size: 11.5px; line-height: 1.4; color: var(--muted); }

input[type="text"], input[type="number"], input[type="date"], input[type="time"],
input[type="email"], input[type="url"], input:not([type]), select, textarea {
  width: 100%; padding: 11px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-size: 15px; min-height: 44px;
  appearance: none; -webkit-appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); }

fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin: 0; }
legend { font-size: 12.5px; font-weight: 600; color: var(--text-soft); padding: 0 6px; }

details > summary {
  cursor: pointer; list-style: none; padding: 13px 0;
  font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 8px;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::after {
  content: "›"; margin-left: auto; color: var(--muted);
  font-size: 19px; line-height: 1; transition: transform 160ms ease;
}
details[open] > summary::after { transform: rotate(90deg); }

/* ── carcassa: capçalera ──────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--hairline);
}
.appbar-brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; }
.appbar-name { letter-spacing: -.01em; }
.logo { width: 26px; height: 26px; border-radius: 8px; overflow: hidden; display: block; flex: none; }
.logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.appbar-actions { margin-left: auto; display: flex; gap: 7px; }
.appbar-button {
  padding: 7px 12px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: var(--sunk); color: var(--text-soft); min-height: 34px;
}
.appbar-button:hover { background: var(--line); }

/* ── carcassa: pantalles ──────────────────────────────── */
main { display: block; }
.section { display: none; padding: 4px var(--gutter) 28px; max-width: 780px; margin: 0 auto; }
.section.active { display: block; }

.screen-head { padding: 16px 0 12px; }
.screen-title {
  font-family: var(--display); font-weight: 600;
  font-size: clamp(27px, 7vw, 33px); letter-spacing: -.018em; line-height: 1.08;
}
.screen-sub { margin: 5px 0 0; font-size: 13.5px; color: var(--muted); line-height: 1.45; }
.screen-head-back { display: flex; align-items: flex-start; gap: 10px; }
.back-button {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  background: var(--sunk); color: var(--text); font-size: 22px; line-height: 1;
  display: grid; place-items: center; margin-top: 2px;
}

/* ── carcassa: barra inferior ─────────────────────────── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 2px; padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  display: grid; justify-items: center; gap: 2px;
  padding: 6px 2px; border-radius: 10px;
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  min-height: 44px; align-content: center;
}
.tab-icon { font-size: 17px; line-height: 1; }
.tab.active { color: var(--primary); }
.tab-hidden { display: none; }
.tab { position: relative; }
.tab-count {
  position: absolute; top: 2px; left: 50%; margin-left: 4px;
  min-width: 15px; padding: 0 4px; border-radius: 99px;
  background: var(--primary); color: var(--primary-ink);
  font-size: 9.5px; font-weight: 700; line-height: 15px; text-align: center;
}
.tab-count:empty, .tab-count[data-empty="true"] { display: none; }

/* ── carcassa: botó flotant de l'assistent ────────────── */
.fab {
  position: fixed; right: var(--gutter); z-index: 45;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  display: flex; align-items: center; gap: 7px;
  height: 44px; padding: 0 16px 0 13px; border-radius: 22px;
  background: var(--text); color: var(--bg);
  font-size: 13.5px; font-weight: 600;
  box-shadow: 0 6px 20px -8px rgba(0, 0, 0, .55);
}
.fab span { font-size: 15px; }

/* ── carcassa: control segmentat ──────────────────────── */
.seg {
  display: grid; grid-auto-flow: column; gap: 3px;
  background: var(--sunk); padding: 3px; border-radius: 12px;
  margin: 14px 0 16px; position: sticky; top: calc(env(safe-area-inset-top) + 54px); z-index: 30;
}
.seg-button {
  padding: 9px 6px; border-radius: 9px;
  font-size: 13px; font-weight: 600; color: var(--muted); min-height: 40px;
}
.seg-button[aria-current="true"] { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }
.seg-panel { display: flex; flex-direction: column; gap: 16px; }

/* ── carcassa: superfícies ────────────────────────────── */
.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px; box-shadow: var(--shadow-sm);
}
.spaced-panel { margin-top: 0; }
.panel-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel-link {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 15px 16px; border-radius: var(--r);
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.panel-link strong { display: block; font-size: 14.5px; font-weight: 600; }
.panel-link small { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.panel-link-chev { margin-left: auto; color: var(--muted); font-size: 20px; line-height: 1; }

.grid, .discover-grid, .profile-grid, .brief-grid {
  display: grid; gap: 11px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.two { display: grid; gap: 16px; }
.full-grid-row { grid-column: 1 / -1; }

/* ── descobrir: el brief i el panell d'afinar ─────────── */
.brief {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 13px;
}
.brief-grid { grid-template-columns: repeat(3, 1fr); }
.brief-wide { grid-column: 1 / -1; }
@media (max-width: 400px) { .brief-grid { grid-template-columns: repeat(2, 1fr); } }

.discover-actions { display: flex; gap: 9px; }
.discover-actions .primary { flex: 1 1 auto; }
.refine-toggle { flex: none; }
.refine-count {
  display: inline-grid; place-items: center; min-width: 19px; height: 19px;
  margin-left: 7px; padding: 0 5px; border-radius: 99px;
  background: var(--primary); color: var(--primary-ink);
  font-size: 11px; font-weight: 700;
}
.refine-panel {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px; box-shadow: var(--shadow-sm);
}
.refine-note { font-size: 12.5px; color: var(--muted); margin: 0; }

/* ── estats globals ───────────────────────────────────── */
.status {
  display: none; margin: 0 var(--gutter) 8px; padding: 11px 14px;
  border-radius: var(--r-sm); font-size: 13.5px; font-weight: 500;
  background: var(--ok-wash); color: var(--ok);
}
.status.show { display: block; }
.status.error { background: var(--danger-wash); color: var(--danger); }
.network-status {
  margin: 0 var(--gutter) 8px; padding: 11px 14px; border-radius: var(--r-sm);
  background: var(--est-wash); color: var(--est); font-size: 13px;
}

/* ── diàlegs ──────────────────────────────────────────── */
dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(88vh, 900px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--card); color: var(--text);
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, .55);
  overflow: auto;
}
dialog::backdrop { background: rgba(20, 18, 16, .5); backdrop-filter: blur(2px); }
dialog > div { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.install-modal-head { display: flex; align-items: flex-start; gap: 12px; }
.install-modal-head h2 { font-family: var(--display); font-size: 21px; }
.close-modal {
  margin-left: auto; width: 32px; height: 32px; flex: none; border-radius: 50%;
  background: var(--sunk); color: var(--muted); font-size: 17px; line-height: 1;
  display: grid; place-items: center;
}

/* ── peu ──────────────────────────────────────────────── */
.footer {
  max-width: 780px; margin: 0 auto; padding: 24px var(--gutter) 8px;
  border-top: 1px solid var(--hairline);
  font-size: 11.5px; line-height: 1.55; color: var(--muted);
}
.footer nav { display: flex; gap: 16px; margin-top: 10px; }

/* ── escriptori ───────────────────────────────────────── */
@media (min-width: 900px) {
  :root { --gutter: 28px; }
  body { padding-bottom: 0; }
  .section { max-width: 940px; padding-bottom: 40px; }
  .footer { max-width: 940px; padding-bottom: 40px; }
  .tabs {
    position: sticky; top: 0; bottom: auto;
    max-width: 940px; margin: 0 auto 4px;
    grid-template-columns: repeat(4, max-content);
    justify-content: start; gap: 4px;
    padding: 8px var(--gutter);
    border-top: 0; border-bottom: 1px solid var(--line);
    background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tab { grid-auto-flow: column; justify-items: start; align-items: center; gap: 7px; padding: 8px 14px; font-size: 13.5px; }
  .tab.active { background: var(--primary-wash); }
  .fab { bottom: 24px; }
  .two { grid-template-columns: 1fr 1fr; align-items: start; }
  .seg { max-width: 420px; top: 8px; }
}

/* ── fila d'accions del viatge ────────────────────────── */
.trip-actions { display: flex; flex-wrap: wrap; gap: 8px; }
/* Un <details> tancat ha d'amagar el contingut: .trip-actions guanyava a la regla del navegador. */
details:not([open]) > .trip-actions { display: none; }
.trip-actions .share-trip { flex: 1 1 auto; min-width: 130px; }
@media (min-width: 620px) { .trip-actions .share-trip { flex: 0 0 auto; min-width: 0; } }

/* ── seccions del viatge que hereten .panel ───────────── */
.accommodation-panel, .packing-panel, .readiness-panel, .reservations-panel, .logistics-panel { min-width: 0; }

