:root {
  --sea:        #0f2e33;  /* petrolio profondo — inchiostro / header */
  --sea-deep:   #0a2226;
  --sea-2:      #1b4249;
  --amber:      #dd9330;  /* ambra baltica — accento */
  --amber-hi:   #f0b95c;
  --amber-glow: #ffdd9e;
  --paper:      #eef2f1;  /* luce fredda del nord — sfondo */
  --card:       #ffffff;
  --frost:      #d8e2e0;  /* bordi / divisori */
  --frost-2:    #e6ecea;
  --green:      #3d7c5a;  /* locali previsti */
  --ink:        #14282b;
  --muted:      #64797a;
  --danger:     #b1442f;

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --shadow: 0 1px 2px rgba(15,46,51,.06), 0 8px 24px rgba(15,46,51,.08);
  --shadow-lg: 0 12px 40px rgba(10,34,38,.28);
  --dock-h: 84px;
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  padding-bottom: calc(var(--dock-h) + var(--sab) + 12px);
}
h1, h2, h3 { margin: 0; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--sea);
  color: #eaf2f0;
  padding-top: env(safe-area-inset-top, 0px);
  box-shadow: 0 6px 24px rgba(10,34,38,.22);
}
.topbar__inner {
  max-width: 640px; margin: 0 auto;
  padding: 14px 18px 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background:
    radial-gradient(circle at 32% 28%, var(--amber-glow), var(--amber-hi) 34%, var(--amber) 62%, #a9691a 100%);
  box-shadow: inset 0 0 6px rgba(255,255,255,.5), 0 2px 8px rgba(221,147,48,.5);
}
.brand__text h1 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600; font-size: 24px; letter-spacing: .2px; line-height: 1;
}
.brand__text p {
  margin: 2px 0 0; font-size: 12px; letter-spacing: .14em;
  text-transform: uppercase; color: #9fc0bd; font-weight: 500;
}

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: rgba(255,255,255,.08); border-radius: 999px; padding: 4px;
}
.segmented__btn {
  border: 0; background: transparent; color: #a9c6c3;
  font-size: 15px; font-weight: 600; padding: 9px 10px; border-radius: 999px;
  transition: color .18s, background .18s;
}
.segmented__btn.is-active { background: var(--amber); color: #2a1a05; }

/* ---------- Content / views ---------- */
.content { max-width: 640px; margin: 0 auto; padding: 22px 16px 8px; }
.view { display: none; animation: rise .32s ease both; }
.view.is-active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.view__head { margin-bottom: 18px; }
.eyebrow {
  margin: 0 0 6px; font-size: 11px; font-weight: 700; letter-spacing: .18em;
  text-transform: uppercase; color: var(--amber);
}
.view__title {
  font-family: "Fraunces", Georgia, serif; font-weight: 600;
  font-size: 27px; line-height: 1.12; color: var(--sea);
}
.view__sub { margin: 8px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- Estimate (ledger) ---------- */
.group { margin-bottom: 18px; }
.group__head {
  display: flex; align-items: baseline; gap: 8px;
  padding: 0 4px 8px; border-bottom: 2px solid var(--sea);
  margin-bottom: 2px;
}
.group__flag { font-size: 18px; }
.group__city {
  font-family: "Fraunces", serif; font-weight: 600; font-size: 18px; color: var(--sea);
}
.group__country {
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.group__sum { margin-left: auto; font-family: "Space Mono", monospace; font-size: 13px; color: var(--muted); }

.ledger { background: var(--card); border-radius: var(--r-md); box-shadow: var(--shadow); overflow: hidden; }
.ledger__colhead {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 12px; padding: 9px 14px; font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); font-weight: 700;
  background: var(--frost-2);
}
.ledger__colhead span:not(:first-child) { text-align: right; min-width: 52px; }

.row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px;
  align-items: center; padding: 11px 14px;
  border-top: 1px solid var(--frost);
}
.row:first-of-type { border-top: 0; }
.row__name { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 500; }
.row__name .dot {
  width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: var(--green); box-shadow: 0 0 0 3px rgba(61,124,90,.14);
}
.row--generic .row__name { color: var(--muted); font-style: italic; font-weight: 400; }
.row__pp, .row__tot {
  font-family: "Space Mono", monospace; font-size: 14px; text-align: right; min-width: 52px;
}
.row__pp { color: var(--muted); }
.row__tot { color: var(--sea); font-weight: 700; }
.badge {
  font-family: "Inter"; font-size: 11px; font-weight: 700; color: var(--amber);
  background: rgba(221,147,48,.12); padding: 1px 7px; border-radius: 999px;
}

.total {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; padding: 16px 18px;
  background: var(--sea); color: #eaf2f0; border-radius: var(--r-md);
  box-shadow: var(--shadow);
}
.total__label { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: #9fc0bd; font-weight: 600; }
.total__value { font-family: "Space Mono", monospace; font-size: 24px; font-weight: 700; color: var(--amber-hi); }

/* ---------- Records ---------- */
.rec-summary {
  display: flex; gap: 10px; margin-bottom: 18px;
}
.stat {
  flex: 1; background: var(--card); border-radius: var(--r-md);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat__label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.stat__value { font-family: "Space Mono", monospace; font-size: 22px; font-weight: 700; color: var(--sea); margin-top: 4px; }
.stat--accent { background: var(--sea); }
.stat--accent .stat__label { color: #9fc0bd; }
.stat--accent .stat__value { color: var(--amber-hi); }

.rec-city { margin-bottom: 16px; }
.rec-city__head {
  display: flex; align-items: center; gap: 8px; padding: 0 4px 8px;
  border-bottom: 2px solid var(--sea); margin-bottom: 2px;
}
.rec-city__flag { font-size: 17px; }
.rec-city__name { font-family: "Fraunces", serif; font-weight: 600; font-size: 17px; color: var(--sea); }
.rec-city__sum { margin-left: auto; font-family: "Space Mono", monospace; font-size: 13px; color: var(--muted); }

.rec-list { background: var(--card); border-radius: var(--r-md); box-shadow: var(--shadow); overflow: hidden; }
.rec {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
  padding: 12px 14px; border-top: 1px solid var(--frost);
  position: relative;
}
.rec:first-child { border-top: 0; }
.rec__name { font-size: 15px; font-weight: 600; color: var(--ink); }
.rec__amount { font-family: "Space Mono", monospace; font-size: 16px; font-weight: 700; color: var(--sea); text-align: right; }
.rec__meta { font-size: 12.5px; color: var(--muted); }
.rec__meal {
  display: inline-block; font-size: 11px; font-weight: 700; color: var(--sea-2);
  background: var(--frost-2); padding: 1px 8px; border-radius: 999px; margin-right: 6px;
}
.rec__del {
  grid-column: 2; justify-self: end; margin-top: 2px;
  border: 0; background: transparent; color: var(--muted);
  font-size: 12px; padding: 2px 4px; opacity: .7;
}
.rec__del:hover, .rec__del:focus-visible { color: var(--danger); opacity: 1; }

.empty {
  text-align: center; padding: 48px 24px; background: var(--card);
  border-radius: var(--r-md); box-shadow: var(--shadow);
}
.empty__mark {
  width: 46px; height: 46px; border-radius: 50%; margin: 0 auto 14px;
  background: radial-gradient(circle at 32% 28%, var(--amber-glow), var(--amber) 70%);
  opacity: .85;
}
.empty h3 { font-family: "Fraunces", serif; font-weight: 600; color: var(--sea); font-size: 19px; }
.empty p { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

/* ---------- Dock + FAB ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  height: calc(var(--dock-h) + var(--sab));
  padding-bottom: var(--sab);
  display: flex; justify-content: center; align-items: flex-start;
  pointer-events: none;
  background: linear-gradient(to top, var(--paper) 40%, rgba(238,242,241,0));
}
.fab {
  pointer-events: auto;
  margin-top: 10px;
  width: 66px; height: 66px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 34% 28%, var(--amber-glow), var(--amber-hi) 30%, var(--amber) 60%, #b0711d 100%);
  box-shadow: 0 6px 18px rgba(221,147,48,.5), inset 0 1px 3px rgba(255,255,255,.6);
  transition: transform .12s ease, box-shadow .12s ease;
}
.fab:active { transform: scale(.93); box-shadow: 0 3px 10px rgba(221,147,48,.5); }
.fab svg { width: 28px; height: 28px; fill: none; stroke: #3a2408; stroke-width: 2.6; stroke-linecap: round; }

/* ---------- Sheet (popup) ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet__scrim { position: absolute; inset: 0; background: rgba(10,34,38,.5); backdrop-filter: blur(2px); animation: fade .2s ease; }
.sheet__panel {
  position: relative; width: 100%; max-width: 520px;
  background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 8px 20px calc(22px + var(--sab));
  box-shadow: var(--shadow-lg);
  animation: slideUp .28s cubic-bezier(.2,.8,.25,1);
  max-height: 92vh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet__grab { width: 40px; height: 4px; border-radius: 99px; background: var(--frost); margin: 4px auto 12px; }
.sheet__title { font-family: "Fraunces", serif; font-weight: 600; font-size: 22px; color: var(--sea); margin-bottom: 16px; }

.field { display: block; margin-bottom: 16px; }
.field__label { display: block; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }

.input {
  width: 100%; font-family: inherit; font-size: 16px; color: var(--ink);
  background: var(--card); border: 1.5px solid var(--frost); border-radius: var(--r-sm);
  padding: 13px 14px; -webkit-appearance: none; appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(221,147,48,.18); }

.select-wrap { position: relative; }
.select-wrap::after {
  content: ""; position: absolute; right: 16px; top: 50%; width: 9px; height: 9px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}

.combo { position: relative; }
.combo__list {
  list-style: none; margin: 6px 0 0; padding: 6px;
  position: absolute; left: 0; right: 0; z-index: 5;
  background: var(--card); border: 1.5px solid var(--frost); border-radius: var(--r-sm);
  box-shadow: var(--shadow); max-height: 210px; overflow-y: auto;
}
.combo__list[hidden] { display: none; }
.combo__item {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 11px 12px; border-radius: 8px; font-size: 15px;
}
.combo__item:hover, .combo__item.is-active { background: var(--frost-2); }
.combo__item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex: none; }
.combo__item .pp { font-family: "Space Mono", monospace; font-size: 12px; color: var(--muted); }
.combo__item--new { color: var(--sea); font-weight: 600; }
.combo__item--new .tag { font-size: 11px; font-weight: 700; color: var(--amber); background: rgba(221,147,48,.12); padding: 1px 7px; border-radius: 999px; }

.amount { display: flex; align-items: center; background: var(--card); border: 1.5px solid var(--frost); border-radius: var(--r-sm); padding-left: 14px; transition: border-color .15s, box-shadow .15s; }
.amount:focus-within { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(221,147,48,.18); }
.amount__sign { font-family: "Space Mono", monospace; font-size: 18px; color: var(--muted); font-weight: 700; }
.input--amount { border: 0; box-shadow: none; background: transparent; font-family: "Space Mono", monospace; font-size: 20px; font-weight: 700; }
.input--amount:focus { box-shadow: none; }

.meal { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.meal__btn {
  border: 1.5px solid var(--frost); background: var(--card); color: var(--muted);
  font-size: 14px; font-weight: 600; padding: 12px 8px; border-radius: var(--r-sm);
  transition: all .15s;
}
.meal__btn.is-active { border-color: var(--sea); background: var(--sea); color: #eaf2f0; }

.sheet__error { color: var(--danger); font-size: 13.5px; font-weight: 600; margin: 0 0 12px; }
.sheet__error[hidden] { display: none; }

.sheet__actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 6px; }
.btn { border: 0; border-radius: var(--r-sm); font-size: 16px; font-weight: 700; padding: 15px 16px; transition: transform .1s, filter .15s; }
.btn:active { transform: scale(.98); }
.btn--ghost { background: transparent; color: var(--muted); border: 1.5px solid var(--frost); }
.btn--primary { background: var(--amber); color: #2a1a05; box-shadow: 0 4px 14px rgba(221,147,48,.4); }
.btn--primary:disabled { filter: grayscale(.4) opacity(.6); box-shadow: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-h) + var(--sab) + 14px);
  transform: translateX(-50%); z-index: 70;
  background: var(--sea); color: #eaf2f0; font-size: 14px; font-weight: 600;
  padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease;
}
.toast[hidden] { display: none; }
.toast--error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; }
}

:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

@media (min-width: 560px) {
  .meal { grid-template-columns: repeat(3, 1fr); }
}
