/* ─── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --sidebar-bg: #1c1008;
  --ink: #1a1005;
  --muted: #7a6e64;
  --line: #e8ddd3;
  --brand: #f97316;
  --brand-2: #fb923c;
  --brand-dark: #c2410c;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --shadow-sm: 0 2px 8px rgba(87,52,18,.08);
  --shadow: 0 8px 28px rgba(87,52,18,.12);
  --shadow-lg: 0 20px 60px rgba(87,52,18,.16);
  --radius: 20px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --sidebar-w: 260px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
body {
  font-family: 'DM Sans', system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; background: transparent; }
table { width: 100%; border-collapse: collapse; }
.hidden { display: none !important; }

/* ─── App shell ──────────────────────────────────────────────────────────────── */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg); color: #fff;
  padding: 20px 14px; display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 0 8px; }
.logo {
  width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; font-size: 20px;
  box-shadow: 0 6px 14px rgba(249,115,22,.35);
}
.brand h1 { font-size: 15px; font-weight: 800; letter-spacing: -.01em; color: #fff; }
.brand p { font-size: 11px; color: #f5bfa0; margin-top: 2px; }
.nav { display: grid; gap: 3px; }
.nav button {
  color: #d4b8a8; text-align: left; padding: 10px 12px;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  transition: .15s; white-space: nowrap; width: 100%;
}
.nav button:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav button.active { background: rgba(249,115,22,.22); color: #fff; font-weight: 700; }
.side-card {
  margin-top: auto; background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1); padding: 12px;
  border-radius: var(--radius-sm); font-size: 12px;
}
.side-card small { color: #f5bfa0; display: block; font-size: 11px; }
#householdStatus { color: #f5bfa0; font-size: 11px; margin-top: 2px; }
#syncStatus { font-size: 11px; color: #f5bfa0; margin-top: 6px; }

/* ─── Main ───────────────────────────────────────────────────────────────────── */
.main { padding: 24px 28px; max-width: 1300px; width: 100%; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar h2 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.status { display: flex; gap: 7px; align-items: center; color: var(--muted); font-size: 12px; margin-top: 3px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ─── Sections ───────────────────────────────────────────────────────────────── */
.section { display: none; animation: fadeIn .18s ease; }
.section.active { display: block; }
@keyframes fadeIn { from { opacity:0; transform:translateY(3px); } to { opacity:1; transform:none; } }

/* ─── Grid ───────────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.flex-wrap { flex-wrap: wrap; }

/* ─── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 20px;
}
.card h3 { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.card-soft {
  background: rgba(249,115,22,.04); border: 1px solid rgba(249,115,22,.13);
  border-radius: var(--radius); padding: 16px;
}

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 18px; background: var(--bg); }
.auth-card { width: min(440px,100%); }
.auth-intro { margin-bottom: 14px; }
.auth-intro h2 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 4px; }
.auth-intro p { font-size: 13px; }
.auth-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.auth-actions .btn { justify-content: center; }
.auth-link {
  width: max-content; justify-self: center; color: var(--brand-dark);
  font-weight: 700; font-size: 13px; padding: 4px 8px; border-radius: 8px;
}
.auth-link:hover { background: #fff1e6; }

/* ─── Metric cards ───────────────────────────────────────────────────────────── */
.metric-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s;
}
.metric-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.metric-icon { font-size: 22px; margin-bottom: 8px; }
.metric-label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-size: 24px; font-weight: 800; margin: 4px 0 2px; letter-spacing: -.02em; }
.metric-sub { font-size: 12px; color: var(--muted); }

/* ─── Typography ─────────────────────────────────────────────────────────────── */
.muted { color: var(--muted); }
.green-text { color: var(--green); }
.danger-text { color: var(--red); }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff1e6; color: #9a3412; border: 1px solid #fed7aa;
  border-radius: 999px; padding: 3px 9px; font-size: 11px; font-weight: 700;
}
.status-badge { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-closed { background: var(--green-soft); color: #166534; }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  background: var(--brand); color: #fff; border-radius: var(--radius-sm);
  padding: 10px 15px; font-weight: 700; font-size: 14px;
  box-shadow: 0 3px 12px rgba(249,115,22,.25); transition: .15s;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--brand-dark); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.btn.secondary:hover { background: var(--bg); box-shadow: var(--shadow); }
.btn.danger { background: var(--red); box-shadow: 0 3px 12px rgba(220,38,38,.2); }
.btn.danger:hover { background: #b91c1c; }
.btn.green { background: var(--green); box-shadow: 0 3px 12px rgba(21,128,61,.2); }
.btn.green:hover { background: #166534; }
.btn.small { padding: 6px 10px; border-radius: var(--radius-xs); font-size: 12px; }

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form { display: grid; gap: 11px; }
.form-row { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 9px; align-items: end; }
.field { display: grid; gap: 5px; }
.field label { font-size: 11px; font-weight: 700; color: #6b4c37; letter-spacing: .03em; text-transform: uppercase; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-xs);
  padding: 9px 11px; background: var(--surface); color: var(--ink); font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(249,115,22,.1);
}
.field textarea { min-height: 80px; resize: vertical; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ─── Sync banner ────────────────────────────────────────────────────────────── */
.sync-banner {
  background: var(--amber-soft); border: 1px solid #fde68a; border-radius: var(--radius-sm);
  padding: 10px 16px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  font-size: 13px; color: #78350f;
}

/* ─── Shopping layout ────────────────────────────────────────────────────────── */
.shopping-layout { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: 14px; align-items: start; }
.sticky-total { position: sticky; top: 20px; }
.total-box {
  background: var(--sidebar-bg); color: #fff;
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-lg);
}
.total-box .metric-value { font-size: 34px; font-weight: 900; margin: 6px 0 4px; }
.place-total-row { display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid rgba(255,255,255,.1); padding-top: 7px; margin-top: 7px; font-size: 13px; }
.place-total-row span { color: #f5bfa0; }
.place-total-row strong { color: #fff; }

/* ─── Location tabs ──────────────────────────────────────────────────────────── */
.location-tabs { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 12px; }
.location-tab {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; font-size: 13px; cursor: pointer; transition: .15s; white-space: nowrap;
}
.location-tab:hover { border-color: var(--brand); color: var(--brand); }
.location-tab.active { background: var(--sidebar-bg); color: #fff; border-color: var(--sidebar-bg); }
.location-tab.active small { color: #f5bfa0; }
.location-tab.btn-add-place { color: var(--brand); border-color: rgba(249,115,22,.3); background: rgba(249,115,22,.05); }
.place-remove {
  display: inline-grid; place-items: center; width: 17px; height: 17px;
  border-radius: 50%; background: rgba(220,38,38,.12); color: var(--red);
  font-weight: 900; font-size: 12px; line-height: 1;
}
.location-tab.active .place-remove { background: rgba(255,255,255,.2); color: #fff; }

/* ─── Quick add row ──────────────────────────────────────────────────────────── */
.quick-row { display: grid; grid-template-columns: 1fr 150px auto; gap: 8px; align-items: end; }
.quick-row input { border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 10px 12px; }
.quick-row input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(249,115,22,.1); }

/* ─── Item rows ──────────────────────────────────────────────────────────────── */
.item {
  display: grid; grid-template-columns: 28px 1fr auto;
  gap: 10px; align-items: start; padding: 12px;
  border: 1px solid var(--line); border-radius: 14px; margin-bottom: 7px;
  background: var(--surface); transition: .13s;
}
.item.clickable { cursor: pointer; }
.item.clickable:hover { box-shadow: var(--shadow-sm); border-color: var(--brand); }
.item:hover { box-shadow: var(--shadow-sm); }
.item.done { opacity: .58; background: #f8fafc; }
.item.done .item-title { text-decoration: line-through; }
.item input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--green); cursor: pointer; margin-top: 2px; }
.item-icon { font-size: 18px; line-height: 1; padding-top: 2px; }
.item-body { min-width: 0; }
.item-title { font-weight: 700; font-size: 14px; word-break: break-word; }
.item-meta { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.item-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.item-price { font-weight: 800; font-size: 14px; white-space: nowrap; }
.price-hint { display: inline-flex; margin-left: 5px; background: #ecfdf5; color: #166534; border: 1px solid #bbf7d0; border-radius: 999px; padding: 1px 6px; font-weight: 700; font-size: 10px; }
.done-badge { display: inline-flex; margin-left: 5px; background: #e2e8f0; color: #475569; border-radius: 999px; padding: 1px 6px; font-size: 10px; }
.brand-badge { display: inline-flex; margin-left: 5px; background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; border-radius: 999px; padding: 1px 7px; font-size: 10px; font-weight: 700; }

/* ─── Category accordion ─────────────────────────────────────────────────────── */
.cat-accordion { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--surface); overflow: hidden; }
.cat-summary {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  cursor: pointer; list-style: none; user-select: none;
  font-weight: 700; background: #fdfaf7;
  transition: background .13s;
}
.cat-summary:hover { background: #fdf3ec; }
.cat-summary::-webkit-details-marker { display: none; }
.cat-arrow { color: var(--brand); font-size: 12px; transition: transform .2s; flex-shrink: 0; }
.cat-accordion[open] .cat-arrow { transform: rotate(90deg); }
.cat-name { flex: 1; font-size: 14px; }
.cat-meta { font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.cat-items { padding: 10px 12px 12px; display: grid; gap: 6px; background: #fafaf9; }
.cat-items .item { margin-bottom: 0; }

/* ─── Session header ─────────────────────────────────────────────────────────── */
.session-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.session-title { font-size: 18px; font-weight: 800; margin: 6px 0 4px; }

/* ─── Detail form accordion ──────────────────────────────────────────────────── */
.detail-form-accordion > summary { list-style: none; }
.detail-form-accordion > summary::-webkit-details-marker { display: none; }

/* ─── Purchase mode ──────────────────────────────────────────────────────────── */
.purchase-totals { display: grid; grid-template-columns: repeat(3,auto) auto; gap: 10px; align-items: center; }
.purchase-totals > div { background: rgba(249,115,22,.07); border: 1px solid rgba(249,115,22,.15); border-radius: 13px; padding: 10px 14px; }
.purchase-totals small { display: block; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.purchase-totals strong { font-size: 20px; font-weight: 800; display: block; margin-top: 2px; }

.purchase-item {
  display: grid; grid-template-columns: 50px 1fr 130px auto;
  align-items: center; gap: 10px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); transition: .13s;
}
.purchase-item.done { opacity: .55; background: #f8faf8; border-color: #d1fae5; }
.pm-check-label { display: grid; place-items: center; cursor: pointer; }
.pm-check-input { display: none; }
.pm-check-box {
  width: 42px; height: 42px; border-radius: 13px;
  border: 2px solid #e5c9b5; background: var(--surface);
  display: grid; place-items: center; font-size: 20px; font-weight: 900; color: #fff;
  transition: .15s;
}
.pm-check-input:checked + .pm-check-box { background: var(--green); border-color: var(--green); }
.pm-info strong { font-size: 14px; display: block; }
.pm-info small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.pm-price-col { text-align: right; }
.pm-price-col small { display: block; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.pm-price-col strong { font-size: 17px; font-weight: 800; display: block; margin: 2px 0; }
.pm-price-input { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 6px 8px; text-align: right; font-weight: 700; font-size: 14px; margin-top: 4px; }
.pm-price-input:focus { outline: none; border-color: var(--brand); }
.pm-actions { display: flex; gap: 5px; }

.purchase-accordion { margin-bottom: 10px; }
.purchase-accordion .cat-items { padding: 10px; }
.purchase-accordion .pm-check-box { background: var(--surface); }

/* ─── History ────────────────────────────────────────────────────────────────── */
.history-card { margin-bottom: 10px; padding: 0; overflow: hidden; }
.history-summary {
  display: flex; align-items: center; gap: 12px; padding: 16px 18px;
  cursor: pointer; list-style: none; background: var(--surface);
}
.history-summary::-webkit-details-marker { display: none; }
.history-summary:hover { background: #fdf8f4; }
.history-main { flex: 1; min-width: 0; }
.history-price { text-align: right; flex-shrink: 0; }
.history-price strong { display: block; font-size: 18px; font-weight: 800; }
.history-price small { font-size: 12px; color: var(--muted); }
.history-detail { padding: 14px 18px 18px; border-top: 1px solid var(--line); background: #fdfaf7; }

/* ─── Templates ──────────────────────────────────────────────────────────────── */
.template-row {
  display: grid; grid-template-columns: 22px 1fr 65px 65px 85px;
  gap: 7px; align-items: center; padding: 8px 10px;
  border-radius: 10px; background: var(--surface); margin-bottom: 5px;
  cursor: pointer; border: 1px solid transparent;
}
.template-row:hover { border-color: var(--line); }
.template-row input[type="checkbox"] { accent-color: var(--brand); width: 18px; height: 18px; }
.template-row input:not([type="checkbox"]) {
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 7px; font-size: 13px; width: 100%;
}

/* ─── Analytics ──────────────────────────────────────────────────────────────── */
.mini-metrics { gap: 10px; }
.mini-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; background: #fffaf5; }
.mini-card strong { display: block; font-size: 20px; font-weight: 800; margin: 5px 0 2px; }
.mini-card small { display: block; color: var(--muted); font-size: 12px; }
.bars { display: grid; gap: 11px; }
.bar-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; font-size: 13px; }
.bar-head span { color: var(--muted); }
.bar-track { height: 9px; border-radius: 999px; background: #f0e8e0; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .4s ease; }
.insight { border: 1px solid rgba(249,115,22,.14); background: rgba(249,115,22,.04); border-radius: 13px; padding: 13px; }
.insight strong { display: block; margin-bottom: 3px; font-size: 13px; }
.insight p { margin: 0; color: var(--muted); font-size: 12px; }
.insight-list { display: grid; gap: 9px; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 9px 7px; text-align: left; font-size: 13px; }
.table th { font-size: 10px; color: #7c5b45; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }

/* ─── Family ─────────────────────────────────────────────────────────────────── */
.family-layout { display: grid; grid-template-columns: minmax(0,1.15fr) minmax(280px,.85fr); gap: 14px; align-items: start; margin-bottom: 14px; }
.family-card { padding: 18px; }
.family-card-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.family-card-head h3 { margin-bottom: 3px; }
.family-card-head .muted { font-size: 13px; }
.family-list { display: grid; gap: 9px; }
.family-house {
  display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; align-items: center;
  padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.family-house.is-active { border-color: rgba(249,115,22,.38); background: #fffaf5; box-shadow: var(--shadow-sm); }
.family-house-body { min-width: 0; }
.family-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.family-create-form { margin-top: 14px; padding-top: 14px; border-top: 1px solid rgba(249,115,22,.14); }
.family-divider { margin: 14px 0; border: 0; border-top: 1px solid var(--line); }
.family-members-card { margin-top: 14px; }
.family-stats { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.family-stats span {
  display: inline-flex; gap: 5px; align-items: baseline; padding: 6px 9px;
  border: 1px solid var(--line); border-radius: 999px; background: #fffaf5;
  color: var(--muted); font-size: 12px; font-weight: 700;
}
.family-stats strong { color: var(--ink); }
.copy-box { margin-top: 13px; padding: 13px; border: 1px dashed #fed7aa; border-radius: 13px; background: #fff7ed; }
.copy-box strong { display: block; font-size: 1.3rem; color: #431407; margin-top: 3px; letter-spacing: .04em; }

/* ─── Modal ──────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(26,16,5,.5);
  display: grid; place-items: center; padding: 20px; z-index: 100;
  backdrop-filter: blur(4px); animation: fadeIn .15s ease;
}
.modal-card {
  width: min(760px,100%); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(10px); opacity:0; } to { transform:none; opacity:1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.modal-body { padding: 20px; flex: 1; overflow-y: auto; }
.modal-body h3 { margin-bottom: 12px; }
.close { background: #fff1e6; color: #9a3412; border-radius: 9px; padding: 6px 12px; font-size: 12px; font-weight: 700; }
/* Botões fixos no modal */
.modal-sticky-top { position: sticky; top: 0; background: var(--surface); z-index: 2; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.modal-sticky-bottom { position: sticky; bottom: 0; background: var(--surface); z-index: 2; padding-top: 12px; border-top: 1px solid var(--line); margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; right: 18px; bottom: 22px;
  background: var(--sidebar-bg); color: #fff;
  padding: 12px 18px; border-radius: 13px;
  box-shadow: var(--shadow-lg); z-index: 200;
  max-width: 340px; font-size: 14px; font-weight: 500;
  transform: translateY(10px); opacity: 0;
  transition: transform .22s ease, opacity .22s ease;
  pointer-events: none;
}
.toast--visible { transform: none; opacity: 1; }

/* ─── Empty state ────────────────────────────────────────────────────────────── */
.empty {
  border: 1px dashed var(--line); border-radius: 13px;
  padding: 22px; text-align: center; color: var(--muted); background: var(--bg);
  font-size: 14px;
}

/* ─── FAB + Bottom bar ───────────────────────────────────────────────────────── */
.fab {
  display: none; position: fixed; right: 16px; bottom: 82px; z-index: 60;
  background: var(--brand); color: #fff; border-radius: 999px;
  padding: 13px 17px; font-weight: 800; font-size: 15px;
  box-shadow: 0 8px 22px rgba(249,115,22,.35); transition: .15s;
}
.fab:hover { transform: scale(1.05); }
.bottom-total {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 55;
  background: var(--sidebar-bg); color: #fff;
  border-top: 1px solid rgba(255,255,255,.1);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 36px rgba(0,0,0,.18);
  align-items: center; justify-content: space-between; gap: 10px;
}
.bottom-total small { display: block; color: #f5bfa0; font-weight: 700; font-size: 10px; text-transform: uppercase; }
.bottom-total strong { font-size: 20px; font-weight: 900; display: block; }
.bottom-total span { font-size: 12px; color: #f5bfa0; }

/* ─── Mobile appbar ──────────────────────────────────────────────────────────── */
.mobile-appbar { display: none; }
.mobile-backdrop { display: none; }

/* ─── Print ──────────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar .btn, .topbar .actions, .fab, .bottom-total, .mobile-appbar,
  .location-tabs button.btn-add-place, .place-remove, .actions { display: none !important; }
  .app-shell { display: block; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  .main { max-width: none; padding: 0; }
}

/* ─── Responsive ≤ 900px ─────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  body { padding-bottom: 80px; }
  .app-shell { display: block; padding-top: 62px; }

  /* Mobile appbar */
  .mobile-appbar {
    display: flex; position: fixed; top: 0; left: 0; right: 0; height: 62px; z-index: 80;
    align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px;
    background: var(--sidebar-bg); color: #fff;
    box-shadow: 0 3px 16px rgba(26,16,5,.22);
  }
  .mobile-appbar strong { font-size: 15px; font-weight: 800; display: block; }
  .mobile-appbar small { font-size: 10px; color: #f5bfa0; display: block; }
  .mobile-menu-btn { border-radius: 11px; font-size: 20px; background: rgba(255,255,255,.1); color: #fff; height: 38px; width: 38px; display: grid; place-items: center; }
  .mobile-new-btn { border-radius: 11px; font-weight: 700; height: 38px; padding: 0 13px; color: #fff; background: var(--brand); font-size: 13px; }

  /* Sidebar drawer */
  .mobile-backdrop { display: block; position: fixed; inset: 0; z-index: 78; background: rgba(0,0,0,.32); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.menu-open .mobile-backdrop { opacity: 1; pointer-events: auto; }
  .sidebar { position: fixed !important; top: 0; left: 0; bottom: 0; height: 100dvh !important; width: min(80vw, 290px); z-index: 79; border-radius: 0 18px 18px 0; transform: translateX(-105%); transition: transform .22s ease; }
  body.menu-open .sidebar { transform: translateX(0); }

  /* Main */
  .main { padding: 12px 12px 96px; }
  .topbar { margin-bottom: 14px; }
  .topbar h2 { font-size: 20px; }
  .topbar .actions { gap: 6px; }
  .topbar #newSessionBtn, .topbar #quickFairBtn { display: none; }

  /* Grid → coluna única */
  .grid.cols-4, .grid.cols-3, .grid.cols-2,
  .shopping-layout, .form-row, .purchase-totals { grid-template-columns: 1fr !important; gap: 9px; }
  .purchase-totals { display: grid !important; }

  /* Card */
  .card { padding: 14px; }
  .card h3 { font-size: 15px; }
  .auth-actions { grid-template-columns: 1fr; }

  /* Inputs maiores para toque */
  .field input, .field select, .field textarea { font-size: 16px; min-height: 44px; }

  /* Quick row → coluna */
  .quick-row { grid-template-columns: 1fr !important; gap: 8px; }
  .quick-row input, .quick-row .btn { width: 100%; min-height: 46px; }

  /* Location tabs scroll horizontal */
  .location-tabs { flex-wrap: nowrap !important; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .location-tabs::-webkit-scrollbar { display: none; }
  .location-tab { flex-shrink: 0; }

  /* Item rows */
  .item { grid-template-columns: 26px 1fr !important; }
  .item-right { grid-column: 2; flex-direction: row; align-items: center; justify-content: space-between; }

  /* Hide desktop sidebar total */
  .sticky-total { display: none; }
  .fab { display: flex !important; align-items: center; justify-content: center; }
  .bottom-total { display: flex !important; }

  /* Purchase */
  .purchase-item { grid-template-columns: 44px 1fr !important; }
  .pm-price-col { grid-column: 2; display: flex; align-items: center; gap: 10px; }
  .pm-price-col small { display: none; }
  .pm-actions { grid-column: 2; justify-content: flex-end; }

  /* Modal bottom sheet on mobile */
  .modal { padding: 0; align-items: flex-end; place-items: end center; }
  .modal-card { width: 100%; max-height: 92dvh; border-radius: 20px 20px 0 0; }

  /* Toast above bottom bar */
  .toast { left: 10px; right: 10px; bottom: 84px; max-width: none; border-radius: 13px; z-index: 90; }

  /* History */
  .history-summary { flex-wrap: wrap; }
  .history-price { width: 100%; text-align: left; }

  /* Family */
  .family-layout { grid-template-columns: 1fr; gap: 10px; }
  .family-card { padding: 14px; }
  .family-card-head { flex-direction: column; gap: 8px; }
  .family-house { grid-template-columns: 1fr; align-items: stretch; }
  .family-actions { justify-content: flex-start; }
  .family-actions .btn { min-height: 36px; }
  .family-stats { justify-content: flex-start; }

  /* Actions wrap */
  .actions { gap: 6px; }
  .session-header { flex-direction: column; }
}

/* ─── Hide FAB/bottom on auth ────────────────────────────────────────────────── */
body.auth-visible .bottom-total,
body.auth-visible .fab { display: none !important; }
