/* sitemanager — design system v2
   Geist + Geist Mono. Off-white surface. Tighter radii, compact density.
   Hardware-accelerated transforms only. */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-soft: #f4f4f3;
  --surface-hover: #f7f7f5;
  --border: #e6e6e3;
  --border-strong: #d8d8d4;
  --text: #0a0a0a;
  --text-2: #3f3f46;
  --text-muted: #71717a;

  --axians: #0284c7;       /* sky-600 */
  --axians-soft: #e0f2fe;
  --encom: #e11d48;        /* rose-600 */
  --encom-soft: #ffe4e6;

  --positive: #047857;
  --positive-soft: #ecfdf5;
  --negative: #b91c1c;
  --negative-soft: #fef2f2;

  --amber: #b45309;
  --amber-soft: #fffbeb;

  --shadow-sm: 0 1px 0 rgba(10,10,10,0.04);
  --shadow-md: 0 6px 18px -10px rgba(10,10,10,0.16), 0 2px 4px -2px rgba(10,10,10,0.05);
  --shadow-lg: 0 24px 48px -24px rgba(10,10,10,0.22), 0 4px 12px -6px rgba(10,10,10,0.08);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --font-sans: 'Geist', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }

/* TOPBAR ---------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(250, 250, 249, 0.82);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 12px 24px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.brand-dot {
  width: 10px; height: 10px;
  background: var(--text);
  border-radius: 3px;
  display: inline-block;
  position: relative;
}
.brand-dot::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 4px;
  border: 1px solid var(--text);
  opacity: 0.18;
  animation: brandPulse 2.6s var(--ease) infinite;
}
@keyframes brandPulse {
  0%, 100% { transform: scale(1); opacity: 0.18; }
  50% { transform: scale(1.18); opacity: 0; }
}
.brand-name { font-size: 15px; }
.topnav {
  display: flex;
  gap: 2px;
  justify-self: start;
}
.topnav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}
.topnav a:hover { color: var(--text); background: var(--surface-soft); }
.topnav a.is-active {
  background: var(--text);
  color: var(--bg);
}
.userbox {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}
.user-name { color: var(--text-2); font-weight: 500; }
.link-muted {
  color: var(--text-muted);
  font-size: 13px;
  transition: color 0.18s var(--ease);
}
.link-muted:hover { color: var(--text); }

/* PAGE ------------------------------------------------------ */
.page {
  max-width: 1480px;
  margin: 0 auto;
  padding: 32px 24px 96px;
}
.page-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 24px;
  margin-bottom: 24px;
}
.page-head-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.page-title {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.03em;
  line-height: 1;
  font-weight: 600;
}
.page-sub {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* FILTERBAR ------------------------------------------------- */
.filterbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  min-width: 240px;
  flex: 0 1 320px;
  color: var(--text-muted);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.search-field:focus-within {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(10,10,10,0.06);
}
.search-field input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  color: var(--text);
  font-size: 13px;
  width: 0;
}

.filter-group {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  box-shadow: var(--shadow-sm);
}
.chip {
  border: 0;
  background: transparent;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s var(--ease), background 0.2s var(--ease), transform 0.18s var(--ease);
}
.chip:hover { color: var(--text); }
.chip:active { transform: scale(0.97); }
.chip.is-active {
  background: var(--text);
  color: var(--bg);
}
.chip-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.chip-dot-axians { background: var(--axians); }
.chip-dot-encom  { background: var(--encom); }

/* BUTTON ---------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 13px;
  letter-spacing: -0.005em;
  transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}
.btn-primary {
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 4px 14px -8px rgba(10,10,10,0.45), inset 0 1px 0 rgba(255,255,255,0.06);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0) scale(0.985); }
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-soft); color: var(--text); }
.btn-ghost:active { transform: scale(0.985); }
.btn-xs { padding: 5px 10px; font-size: 12px; }

/* TABLE ----------------------------------------------------- */
.table-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  position: relative;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
  table-layout: fixed;
}

/* col widths — sum to 100% with table-layout:fixed (active sites: 11 cols) */
.sites-table .col-name      { width: 22%; }
.sites-table .col-num        { width: 9%; }
.sites-table .col-phase      { width: 6.6%; }
/* archived: 7 cols — set via td defaults */

.data-table thead th {
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table thead .thead-top th { border-bottom: 0; padding-bottom: 6px; }
.data-table thead .thead-sub th {
  font-size: 10.5px;
  letter-spacing: 0.05em;
  padding: 0 14px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.data-table thead th.th-group {
  color: var(--text-2);
  font-weight: 600;
  letter-spacing: 0.08em;
}
.data-table thead th.th-center { text-align: center; }
.data-table thead th.th-num    { text-align: right; }
.data-table thead th.th-derived { color: var(--text-2); background: rgba(244,244,243,0.55); }
.data-table thead th.th-name { padding-left: 22px; }

/* sortable headers */
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  user-select: none;
  transition: color 0.18s var(--ease);
}
.th-num .th-sort { flex-direction: row-reverse; }
.th-sort:hover { color: var(--text); }
.th-sort .sort-icon {
  width: 10px;
  height: 10px;
  color: var(--text-muted);
  opacity: 0.45;
  transition: opacity 0.18s var(--ease), color 0.18s var(--ease), transform 0.2s var(--ease);
}
.th-sort.is-asc  .sort-icon { opacity: 1; color: var(--text); transform: rotate(180deg); }
.th-sort.is-desc .sort-icon { opacity: 1; color: var(--text); transform: rotate(0deg); }

.data-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  background: var(--surface);
  position: relative;
  transition: background 0.2s var(--ease);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-table tbody tr:nth-child(even) td { background: #fbfbfa; }
.data-table tbody tr:hover td { background: var(--surface-hover); }
.data-table tbody tr:last-child td { border-bottom: 0; }

.cell-num   { text-align: right; }
.cell-phase { text-align: center; padding-left: 6px !important; padding-right: 6px !important; }
.cell-derived { background: rgba(244,244,243,0.55) !important; }

/* macro left strip and Sito padding alignment */
.data-table .cell-name { padding-left: 22px; }
.site-row .cell-name::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: transparent;
}
.site-row.macro-axians .cell-name::before { background: var(--axians); }
.site-row.macro-encom  .cell-name::before { background: var(--encom); }

.site-name {
  display: block;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.012em;
  color: var(--text);
}
.site-macro {
  display: inline-block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.macro-axians .site-macro { color: var(--axians); }
.macro-encom  .site-macro { color: var(--encom); }

/* AMOUNT cell */
.amount-wrap {
  display: block;
  position: relative;
  width: 100%;
  text-align: right;
}
.amount {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  line-height: 1;
}
.amount-val { font-variant-numeric: tabular-nums; }

.cell-derived .amount-val { color: var(--text-2); }
.cell-delta { font-weight: 500; }
.cell-delta.is-positive .amount-val { color: var(--positive); }
.cell-delta.is-negative .amount-val { color: var(--negative); }
.cell-delta.is-zero .amount-val { color: var(--text-muted); }

/* + button — absolutely positioned at the LEFT of the cell, revealed on row hover */
.cell-editable .plus-btn {
  position: absolute;
  left: 6px;
  top: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 50%;
  color: var(--text-2);
  opacity: 0;
  transform: translateY(-50%) scale(0.85);
  transition: transform 0.18s var(--ease-spring), background 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease), opacity 0.15s var(--ease);
}
.site-row:hover .cell-editable .plus-btn,
.cell-editable:focus-within .plus-btn,
.cell-editable .plus-btn.is-open { opacity: 1; transform: translateY(-50%) scale(1); }
.cell-editable .plus-btn:hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  transform: translateY(-50%) scale(1.08);
}
.cell-editable .plus-btn:active { transform: translateY(-50%) scale(0.92); }
.cell-editable .plus-btn.is-open { background: var(--text); color: var(--bg); border-color: var(--text); }

/* PHASE chips */
.phase-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  padding: 0;
  border-radius: 7px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  transition: transform 0.18s var(--ease-spring), background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
  position: relative;
  vertical-align: middle;
}
.phase-mark {
  width: 14px;
  height: 14px;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.18s var(--ease), transform 0.28s var(--ease-spring);
  pointer-events: none;
}
.phase-chip:hover { border-color: var(--text); color: var(--text); }
.phase-chip:active { transform: scale(0.92); }
.phase-chip.is-on {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}
.phase-chip.is-on .phase-mark { opacity: 1; transform: scale(1); }

.phase-chip.phase-final { border-style: dashed; }
.phase-chip.phase-final.is-locked {
  cursor: not-allowed;
  opacity: 0.4;
}
.phase-chip.phase-final:not(.is-locked) {
  border-style: solid;
  border-color: var(--positive);
  color: var(--positive);
}
.phase-chip.phase-final:not(.is-locked):hover {
  background: var(--positive);
  color: white;
  border-color: var(--positive);
}

/* TFOOT ----------------------------------------------------- */
.row-totals th,
.row-totals td {
  padding: 14px 14px;
  background: var(--surface-soft);
  border-top: 1px solid var(--border-strong);
  border-bottom: 0;
  font-size: 12.5px;
  font-weight: 500;
  vertical-align: middle;
}
.row-totals .cell-name {
  color: var(--text-2);
  font-size: 11.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding-left: 22px;
}
.row-totals .amount-val { color: var(--text); font-weight: 600; }
.row-totals .cell-delta.is-positive .amount-val { color: var(--positive); }
.row-totals .cell-delta.is-negative .amount-val { color: var(--negative); }
.row-totals .cell-totals-meta {
  text-align: right;
  color: var(--text-muted);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.row-totals .cell-totals-meta span { color: var(--text-2); font-weight: 600; }

/* row exit animation when archived */
.site-row.is-leaving td {
  animation: rowFade 0.55s var(--ease) forwards;
}
@keyframes rowFade {
  0% { opacity: 1; transform: translateX(0); }
  40% { opacity: 0.4; transform: translateX(8px); }
  100% { opacity: 0; transform: translateX(40px); padding-top: 0; padding-bottom: 0; line-height: 0; font-size: 0; border-bottom-width: 0; }
}
.site-row.is-hidden { display: none; }
.site-row.is-new td { animation: rowEnter 0.55s var(--ease) backwards; }
@keyframes rowEnter {
  0% { opacity: 0; transform: translateY(-4px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* numeric flash on update */
.amount-val.flash { animation: flashUp 0.7s var(--ease); }
@keyframes flashUp {
  0% { color: var(--positive); transform: translateY(-2px); }
  100% { color: inherit; transform: translateY(0); }
}

/* EMPTY STATE ---------------------------------------------- */
.empty-row td { padding: 44px 16px !important; background: var(--surface) !important; }
.empty-row td::before { display: none; }
.empty-state { text-align: center; }
.empty-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.012em;
  color: var(--text);
}
.empty-sub {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}
.empty-sub em { font-style: normal; font-weight: 500; color: var(--text); }

/* MODAL ----------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,10,10,0.32);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 24px;
  animation: fadeIn 0.18s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: modalIn 0.4s var(--ease-spring);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-card h2 {
  margin: 6px 0 18px;
  font-size: 20px;
  letter-spacing: -0.02em;
  font-weight: 600;
}
.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.modal-close:hover { background: var(--surface-soft); color: var(--text); }

/* FORMS ----------------------------------------------------- */
.form-stack { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; }
.field .label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: -0.005em;
}
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field input:not([type]) {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  font: inherit;
  color: var(--text);
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.field input:focus-visible {
  outline: none;
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(10,10,10,0.07);
}
.field .helper {
  font-size: 11.5px;
  color: var(--text-muted);
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.radio-row { display: flex; gap: 8px; }
.radio-pill {
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
  font-size: 13px;
  font-weight: 500;
}
.radio-pill input { position: absolute; opacity: 0; pointer-events: none; }
.radio-pill:has(input:checked) {
  border-color: var(--text);
  background: var(--surface-soft);
}
.radio-pill:hover { border-color: var(--text); }
.radio-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.radio-dot-axians { background: var(--axians); }
.radio-dot-encom  { background: var(--encom); }

.alert {
  padding: 11px 13px;
  border-radius: var(--radius-md);
  font-size: 13px;
}
.alert-error {
  background: var(--encom-soft);
  color: #881337;
  border: 1px solid #fecdd3;
}

/* AUTH ------------------------------------------------------ */
.auth-shell {
  min-height: calc(100dvh - 80px);
  display: grid;
  place-items: center;
  padding: 36px 0;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-md);
}
.auth-title {
  margin: 6px 0 4px;
  font-size: 24px;
  letter-spacing: -0.02em;
  font-weight: 600;
}
.auth-sub {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 13px;
}

/* POPOVER --------------------------------------------------- */
.popover {
  position: fixed;
  z-index: 90;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  width: 240px;
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 8px;
  transform-origin: top right;
  animation: popIn 0.28s var(--ease-spring);
  text-align: left;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.popover-label {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.popover-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 7px 10px;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.popover-row:focus-within {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(10,10,10,0.07);
}
.popover-currency {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 13px;
}
.popover-row input {
  flex: 1;
  border: 0;
  font: inherit;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
  width: 0;
  text-align: left;
}
.popover input[type="text"] {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 12.5px;
  background: var(--surface);
}
.popover input[type="text"]:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 3px rgba(10,10,10,0.07); }
.popover-actions { display: flex; justify-content: flex-end; gap: 6px; }

/* TOAST ----------------------------------------------------- */
.toast-stack {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 80;
  display: grid;
  gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--text);
  color: var(--bg);
  padding: 12px 16px;
  padding-right: 18px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  min-width: 270px;
  max-width: 380px;
  font-size: 13px;
  animation: toastIn 0.45s var(--ease-spring);
}
.toast.is-leaving { animation: toastOut 0.35s var(--ease) forwards; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut { to { opacity: 0; transform: translateX(40px) scale(0.98); } }
.toast-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toast-msg { color: var(--bg); }
.toast-msg strong { color: white; font-weight: 600; }
.toast-link {
  color: white;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 12.5px;
}
.toast-error { background: var(--negative); }

/* USERS table extras --------------------------------------- */
.users-table .cell-name { padding-left: 16px; }
.users-table .cell-name::before { display: none; }
.users-table .user-email {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.users-table .cell-actions { text-align: right; }
.cell-actions { text-align: right; padding-right: 16px !important; }
.col-action { width: 110px; }
.th-action { padding: 0 !important; }
.reopen-btn svg { display: inline-block; }

.modal-confirm h2 { margin-bottom: 8px; }
.modal-confirm .modal-body {
  margin: 0 0 18px;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.55;
}
.modal-confirm .modal-body em {
  font-style: normal;
  font-weight: 600;
  color: var(--text);
}
.self-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
}
.status-pill .status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
}
.status-on  { background: var(--positive-soft); color: var(--positive); }
.status-on  .status-dot { background: var(--positive); }
.status-off { background: var(--negative-soft); color: var(--negative); }
.status-off .status-dot { background: var(--negative); }
.user-row.is-leaving td { animation: rowFade 0.5s var(--ease) forwards; }

/* ACTIVITY LOG -------------------------------------------- */
.log-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 8px 0;
  box-shadow: var(--shadow-md);
}
.activity { list-style: none; padding: 0; margin: 0; }
.activity-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 14px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.activity-item:last-child { border-bottom: 0; }
.activity-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-top: 7px;
  background: var(--text);
  position: relative;
}
.activity-dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0.18;
}
.dot-blue    { background: var(--axians); color: var(--axians); }
.dot-green   { background: var(--positive); color: var(--positive); }
.dot-amber   { background: var(--amber); color: var(--amber); }
.dot-rose    { background: var(--encom); color: var(--encom); }
.dot-neutral { background: var(--text-muted); color: var(--text-muted); }
.activity-line {
  margin: 0;
  font-size: 13.5px;
  letter-spacing: -0.005em;
  color: var(--text-2);
}
.activity-line strong { color: var(--text); font-weight: 600; }
.activity-line em { font-style: normal; font-family: var(--font-mono); font-size: 12.5px; color: var(--text-2); }
.activity-meta {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 11.5px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.site-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  background: var(--surface-soft);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.site-pill.macro-axians { color: var(--axians); border-color: rgba(2,132,199,0.25); }
.site-pill.macro-encom  { color: var(--encom);  border-color: rgba(225,29,72,0.25); }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.pager-info { color: var(--text-muted); font-size: 12.5px; }

/* RESPONSIVE / SCROLL ------------------------------------- */
.table-shell { overflow-x: auto; }
.sites-table { min-width: 1180px; }

/* Sticky first column on horizontal scroll */
.sites-table thead th.th-name,
.sites-table tbody .cell-name,
.sites-table tfoot .cell-name {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
}
.sites-table tfoot .cell-name { background: var(--surface-soft); }
.sites-table tbody tr:hover .cell-name { background: var(--surface-hover); }
.sites-table thead th.th-name {
  z-index: 3;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--border);
}
.sites-table tbody .cell-name,
.sites-table tfoot .cell-name { box-shadow: 1px 0 0 var(--border); }

/* KPI BAR --------------------------------------------------- */
.kpi-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.kpi-tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, rgba(10,10,10,0.018), transparent 60%);
  pointer-events: none;
}
.kpi-label {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
}
.kpi-value {
  margin: 6px 0 0;
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.1;
}
.kpi-unit {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* DATE PILL + POPOVER --------------------------------------- */
.date-pill {
  background: var(--surface) !important;
  border: 1px solid var(--border);
  color: var(--text-2) !important;
  padding: 6px 14px !important;
}
.date-pill:hover { border-color: var(--text); color: var(--text) !important; }
.date-popover {
  position: fixed;
  z-index: 90;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  width: 280px;
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 12px;
  animation: popIn 0.28s var(--ease-spring);
}
.date-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.date-presets button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 7px 4px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.date-presets button:hover { border-color: var(--text); color: var(--text); }
.date-presets button.is-active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.date-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.date-range .field { gap: 4px; }
.date-range .label { font-size: 10.5px; }
.date-range input[type="date"] {
  padding: 7px 10px !important;
  font-size: 12.5px;
  font-family: var(--font-mono);
}

/* SITE DETAIL PAGE ------------------------------------------ */
.detail-head { gap: 18px; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
  transition: color 0.18s var(--ease);
}
.back-link:hover { color: var(--text); }
.detail-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.detail-name { display: inline-block; }
.detail-name[contenteditable="true"] {
  outline: none;
  border-bottom: 2px solid var(--text);
  padding-bottom: 2px;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 8px;
  color: var(--text-2);
  transition: all 0.18s var(--ease);
}
.icon-btn:hover { border-color: var(--text); color: var(--text); }
.icon-btn-danger:hover { border-color: var(--negative); color: var(--negative); }
.macro-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
  transition: filter 0.18s var(--ease);
}
.macro-pill:hover { filter: brightness(0.95); }
.macro-pill .macro-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.macro-pill.macro-axians { background: var(--axians-soft); color: var(--axians); }
.macro-pill.macro-encom  { background: var(--encom-soft);  color: var(--encom); }

.btn.danger { color: var(--negative); border-color: rgba(225,29,72,0.28); }
.btn.danger:hover { background: var(--encom-soft); }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.metric-card.metric-derived { background: var(--surface-soft); }
.metric-label {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.metric-value {
  margin: 6px 0 0;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.metric-margin.is-positive .amount-val { color: var(--positive); }
.metric-margin.is-negative .amount-val { color: var(--negative); }
.metric-margin.is-zero    .amount-val { color: var(--text-muted); }

.phase-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 28px;
}
.phase-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 12px;
  text-align: center;
  display: grid;
  gap: 6px;
  justify-items: center;
  box-shadow: var(--shadow-sm);
}
.phase-tile .phase-chip {
  width: 30px; height: 30px;
}
.phase-name {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
}
.phase-when {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
}
.phase-tile.is-on .phase-name { color: var(--text); }

.movements-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
}
.movements-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.movements-title {
  margin: 0;
  font-size: 15px;
  letter-spacing: -0.012em;
  font-weight: 600;
}
.movements-count {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.empty-padded { padding: 36px 18px; }
.movements-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.movement-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 14px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.movement-item:last-child { border-bottom: 0; }
.kind-pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kind-manodopera { background: rgba(180, 83, 9, 0.10); color: var(--amber); }
.kind-materiale  { background: rgba(2, 132, 199, 0.10); color: var(--axians); }
.kind-ricavi     { background: rgba(4, 120, 87, 0.10);  color: var(--positive); }

.movement-amount {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.movement-note {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-2);
  font-style: italic;
}
.movement-meta {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.meta-edited { color: var(--amber); }
.movement-actions {
  display: flex;
  gap: 4px;
  align-items: flex-start;
}
.movement-edit-form {
  display: grid;
  gap: 8px;
  background: var(--surface-soft);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 8px;
  grid-column: 1 / -1;
}

.kpi-bar.kpi-mobile-wrap {
  /* placeholder for mobile compaction below */
}

/* TOUCH (no hover) — show + button always */
@media (hover: none) {
  .cell-editable .plus-btn {
    opacity: 1 !important;
    transform: translateY(-50%) scale(1) !important;
  }
}

/* TABLET ----------------------------------------------- */
@media (max-width: 1100px) {
  .page { padding: 28px 18px 96px; }
  .topbar-inner { padding: 11px 18px; gap: 18px; }
}

/* MOBILE ----------------------------------------------- */
@media (max-width: 768px) {
  /* topbar: 2 righe, nav scrollabile */
  .topbar { backdrop-filter: saturate(160%) blur(18px); -webkit-backdrop-filter: saturate(160%) blur(18px); }
  .topbar-inner {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand   userbox"
      "nav     nav";
    row-gap: 6px;
    padding: 10px 14px;
  }
  .brand   { grid-area: brand; }
  .userbox { grid-area: userbox; gap: 10px; }
  .user-name { display: none; }
  .topnav {
    grid-area: nav;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 4px 14px;
  }
  .topnav::-webkit-scrollbar { display: none; }
  .topnav a { flex-shrink: 0; white-space: nowrap; }

  /* page header */
  .page { padding: 18px 14px 110px; }
  .page-head { grid-template-columns: 1fr; row-gap: 14px; margin-bottom: 16px; }
  .page-head-right { justify-content: flex-start; flex-wrap: wrap; gap: 10px; }
  .page-title { font-size: 24px; }
  .page-sub { font-size: 12.5px; }

  /* "Nuovo cantiere" → Floating Action Button */
  #new-site-btn {
    position: fixed;
    z-index: 55;
    bottom: 16px;
    right: 16px;
    padding: 13px 20px;
    border-radius: 999px;
    box-shadow: 0 16px 32px -10px rgba(10,10,10,0.45), inset 0 1px 0 rgba(255,255,255,0.08);
    font-weight: 600;
  }
  #new-user-btn {
    position: fixed;
    z-index: 55;
    bottom: 16px;
    right: 16px;
    padding: 13px 20px;
    border-radius: 999px;
    box-shadow: 0 16px 32px -10px rgba(10,10,10,0.45), inset 0 1px 0 rgba(255,255,255,0.08);
    font-weight: 600;
  }

  /* filterbar */
  .filterbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .search-field { width: 100%; flex: 1 1 100%; min-width: 0; }
  .filter-group {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    border-radius: 999px;
    width: max-content;
    max-width: 100%;
  }
  .filter-group::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; }

  /* TABLE → CARD LIST */
  .table-shell {
    background: transparent !important;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
  }
  .data-table {
    table-layout: auto;
    width: 100%;
    min-width: 0 !important;
  }
  .data-table thead,
  .data-table colgroup { display: none !important; }

  /* sticky first col reset */
  .sites-table thead th.th-name,
  .sites-table tbody .cell-name,
  .sites-table tfoot .cell-name {
    position: static;
    box-shadow: none !important;
  }

  /* every row becomes a card */
  .data-table tbody { display: block; }
  .data-table tbody tr {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px 8px;
    background: var(--surface) !important;
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
  }
  .data-table tbody tr:hover td { background: transparent !important; }
  .data-table tbody tr:nth-child(even) td { background: transparent !important; }

  .site-row.macro-axians { border-left-color: var(--axians); }
  .site-row.macro-encom  { border-left-color: var(--encom); }

  .data-table tbody td {
    background: transparent !important;
    border: 0 !important;
    padding: 6px 0 !important;
    grid-column: 1 / -1;
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    min-width: 0;
  }
  .data-table tbody td .amount {
    margin-left: auto;
  }

  /* Empty row card */
  .empty-row { padding: 32px 18px !important; display: block !important; }
  .empty-row td { display: block !important; text-align: center !important; }

  /* Site name (collapsible header of the card) */
  .site-row .cell-name {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 28px 4px 0 !important;
    margin: 0 !important;
    border: 0 !important;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: rgba(10, 10, 10, 0.05);
    position: relative;
  }
  .site-row .cell-name::before { display: none !important; }
  .site-row .cell-name::after {
    content: "";
    position: absolute;
    right: 4px;
    top: 50%;
    width: 8px; height: 8px;
    border-right: 1.8px solid var(--text-muted);
    border-bottom: 1.8px solid var(--text-muted);
    transform: translateY(-70%) rotate(45deg);
    transition: transform 0.28s var(--ease-spring);
    pointer-events: none;
  }
  .site-row.is-expanded .cell-name::after {
    transform: translateY(-25%) rotate(-135deg);
  }
  .site-row.is-expanded .cell-name {
    padding-bottom: 12px !important;
    border-bottom: 1px solid var(--border) !important;
    margin-bottom: 4px !important;
  }
  .site-name { font-size: 14.5px; }
  .site-macro {
    margin-top: 0;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-soft);
    font-size: 10px;
    letter-spacing: 0.06em;
  }
  .macro-axians .site-macro { background: var(--axians-soft); color: var(--axians); }
  .macro-encom  .site-macro { background: var(--encom-soft);  color: var(--encom); }

  /* COLLAPSED state: hide every cell except the name */
  .site-row:not(.is-expanded) > td:not(.cell-name) { display: none !important; }
  .site-row:not(.is-expanded) {
    grid-template-columns: 1fr;
    padding: 10px 14px;
  }

  /* tfoot row is always shown — no chevron, no toggle */
  .row-totals .cell-name { cursor: default; padding: 0 0 6px !important; }
  .row-totals .cell-name::after { display: none !important; }

  /* labels via ::before on each metric cell */
  .site-row .cell-num::before,
  .site-row .cell-derived::before,
  .site-row .cell-delta::before,
  .site-row .cell-date::before {
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 500;
    flex-shrink: 0;
  }
  .site-row .cell-num[data-kind="manodopera"]::before { content: "Manodopera"; }
  .site-row .cell-num[data-kind="materiale"]::before  { content: "Materiale"; }
  .site-row .cell-num[data-kind="ricavi"]::before     { content: "Ricavi"; }
  .site-row .cell-derived::before { content: "Totale costi"; }
  .site-row .cell-delta::before   { content: "Margine"; }
  .site-row .cell-date::before    { content: "Completato"; }
  .cell-derived { background: transparent !important; }

  /* + button always visible on mobile, inline */
  .cell-editable { position: relative; }
  .cell-editable .plus-btn {
    position: static !important;
    transform: scale(1) !important;
    opacity: 1 !important;
    width: 26px; height: 26px;
    margin-left: 8px;
    flex-shrink: 0;
  }
  .amount-wrap {
    display: inline-flex !important;
    align-items: center;
    gap: 0;
    width: auto !important;
    margin-left: auto;
    text-align: right;
  }
  .cell-editable .plus-btn:hover {
    transform: scale(1) !important;
  }

  /* Phases: 5 chips in one row, full grid */
  .site-row .cell-phase {
    grid-column: span 1;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 12px 0 0 !important;
    margin-top: 8px;
    border-top: 1px solid var(--border) !important;
    gap: 6px;
    font-size: 10.5px;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .site-row .cell-phase::before {
    content: "";
    display: none;
  }
  /* show phase label below the chip */
  .site-row .cell-phase[data-mlabel]::after {
    content: attr(data-mlabel);
    color: var(--text-muted);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 500;
    order: 2;
  }
  .phase-chip { width: 34px; height: 34px; }

  /* Action cell (Riapri) — full width below */
  .site-row .cell-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
    padding: 10px 0 0 !important;
    margin-top: 6px;
    border-top: 1px solid var(--border) !important;
  }

  /* TFOOT: end-of-list summary (not sticky on mobile to avoid clash with FAB) */
  .data-table tfoot {
    display: block;
    position: static;
    margin-top: 14px;
    margin-bottom: 8px;
  }
  .row-totals {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--text);
    color: var(--bg);
    border-radius: var(--radius-lg);
    padding: 12px 14px;
    box-shadow: 0 18px 36px -12px rgba(10,10,10,0.45);
    border: 0;
    gap: 4px 16px;
  }
  .row-totals th,
  .row-totals td {
    background: transparent !important;
    border: 0 !important;
    padding: 3px 0 !important;
    color: rgba(255,255,255,0.6);
    font-size: 11.5px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    text-align: left;
    text-transform: none;
    letter-spacing: 0;
  }
  .row-totals .cell-name {
    grid-column: 1 / -1;
    color: rgba(255,255,255,0.45) !important;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 10.5px !important;
    padding: 0 0 6px !important;
    border-bottom: 1px solid rgba(255,255,255,0.12) !important;
    margin-bottom: 4px;
  }
  .row-totals .amount-val { color: white !important; font-weight: 600; font-size: 13px; }
  .row-totals .cell-delta.is-positive .amount-val { color: #6ee7b7 !important; }
  .row-totals .cell-delta.is-negative .amount-val { color: #fda4af !important; }
  .row-totals td[data-mlabel]::before {
    content: attr(data-mlabel);
    color: rgba(255,255,255,0.55);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .row-totals .cell-totals-meta {
    grid-column: 1 / -1;
    color: rgba(255,255,255,0.5) !important;
    font-size: 10.5px !important;
    padding: 6px 0 0 !important;
    border-top: 1px solid rgba(255,255,255,0.1) !important;
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .row-totals .cell-totals-meta span { color: white !important; }

  /* USERS — card layout */
  .users-table tbody tr {
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
  }
  .users-table .user-row td {
    grid-column: 1 / -1;
  }
  .users-table .user-email::before { content: "Email"; }
  .users-table td.cell-num[data-mlabel]::before { content: attr(data-mlabel); }
  .users-table td.cell-date::before { content: "Aggiunto"; }
  .users-table td:nth-child(3)::before { content: "Cantieri aperti"; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
  .users-table td:nth-child(4)::before { content: "Movimenti"; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
  .users-table td:nth-child(5)::before { content: "Stato"; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }

  /* MODAL → BOTTOM SHEET */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal-card {
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 22px 18px calc(28px + env(safe-area-inset-bottom));
    animation: modalInSheet 0.4s var(--ease-spring);
  }
  @keyframes modalInSheet {
    from { opacity: 0; transform: translateY(48px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .modal-card h2 { font-size: 19px; }

  /* TOAST: bottom-anchored (sopra al FAB) */
  .toast-stack {
    top: auto;
    bottom: 86px;
    left: 12px;
    right: 12px;
  }
  .toast {
    min-width: 0;
    max-width: 100%;
    width: 100%;
  }

  /* POPOVER: max width on phone */
  .popover { max-width: calc(100vw - 24px); }

  /* ACTIVITY LOG */
  .activity-item { padding: 12px 16px; gap: 10px; }
  .activity-line { font-size: 13px; }
}

/* KPI bar + detail su mobile */
@media (max-width: 768px) {
  .kpi-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
  .kpi-tile { padding: 12px 14px; }
  .kpi-value { font-size: 19px; }

  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .metric-card { padding: 12px 14px; }
  .metric-value { font-size: 16px; }
  .metric-card:nth-child(5) { grid-column: 1 / -1; }

  .phase-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .phase-tile { padding: 12px 8px; }

  .movement-item { padding: 12px 16px; gap: 10px; grid-template-columns: auto 1fr; }
  .movement-actions { grid-column: 1 / -1; justify-content: flex-end; padding-top: 6px; }

  .detail-title-row { row-gap: 6px; }
  .detail-name { font-size: 22px; }

  .date-popover { width: calc(100vw - 24px); max-width: 320px; }

  .filterbar { flex-wrap: wrap; }
  .date-pill { flex-shrink: 0; }
}

/* Very small phones */
@media (max-width: 380px) {
  .site-row { grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 12px; }
  .phase-chip { width: 30px; height: 30px; }
  #new-site-btn, #new-user-btn { padding: 12px 16px; bottom: 14px; right: 14px; }
}
