:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #172922;
  background: #f5f8f5;
  font-synthesis: none;
  --ink: #172922;
  --muted: #586c62;
  --green: #18563d;
  --deep-green: #0e2d24;
  --line: #e1e9e3;
  --surface: #fff;
  --muted-surface: #f5f8f5;
  --lime: #c6eea2;
  --radius: 16px;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 300px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #58996f;
  outline-offset: 3px;
}
p, h1, h2, h3 { margin: 0; }
a { color: var(--green); }
svg { flex: none; }

.sr-only, .skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
}

.skip-link:focus {
  position: fixed;
  z-index: 10;
  top: 10px;
  left: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 8px;
}

.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  align-self: start;
  position: sticky;
  top: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 38px;
  padding: 26px 16px 20px;
  background: var(--deep-green);
  color: #eef7ef;
}

.brand { display: flex; align-items: center; gap: 11px; }
.sidebar .brand { padding: 0 4px; }
.brand-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 43px;
  height: 43px;
  border-radius: 13px;
  background: var(--lime);
  color: #15382a;
}
.brand strong { display: block; font-size: 1.03rem; letter-spacing: -.03em; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font-size: .81rem; }
.sidebar .brand small { color: #b8cec0; }

.nav { display: grid; gap: 5px; }
.nav button {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 13px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #c7dad0;
  font-weight: 600;
  font-size: .92rem;
  text-align: left;
}
.nav button:hover { background: #1b4033; color: #fff; }
.nav button[aria-current] { background: #274c3c; border-color: #385b49; color: #eaffdc; }
.nav button[aria-current] svg { color: var(--lime); }
.sidebar-bottom {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  border-top: 1px solid #315246;
  padding: 17px 8px 0;
  font-size: .82rem;
  color: #cbe2d5;
}
.sidebar-dot { width: 7px; height: 7px; border-radius: 50%; background: #a8d67e; }

.workspace { min-width: 0; }
.topbar {
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar-title { font-weight: 700; font-size: .94rem; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.role-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #edf2ee;
  border-radius: 10px;
}
.role-switch button {
  border: 0;
  border-radius: 8px;
  min-height: 34px;
  padding: 5px 11px;
  background: transparent;
  color: #506659;
  font-size: .85rem;
  font-weight: 650;
  white-space: nowrap;
}
.role-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 1px 3px #1e423119;
}
.avatar {
  display: inline-grid;
  flex: none;
  place-items: center;
  border-radius: 50%;
  color: #265742;
  background: #e4f1e6;
  font-size: .76rem;
  font-weight: 750;
}
.avatar--top { width: 36px; height: 36px; }
.avatar--table { width: 37px; height: 37px; }

.main-content { width: min(100%, 1420px); margin: 0 auto; padding: 32px 32px 56px; }
.page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}
h1 { font-size: clamp(1.75rem, 3vw, 2.4rem); line-height: 1.12; letter-spacing: -.045em; }
.page-heading p { margin-top: 9px; color: var(--muted); font-size: 1rem; }
h2 { font-size: 1.08rem; line-height: 1.25; letter-spacing: -.02em; }
h3 { font-size: 1rem; line-height: 1.3; letter-spacing: -.02em; }

.btn {
  min-height: 43px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: .9rem;
  white-space: nowrap;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #114730; }
.btn-primary:disabled { background: #e1e9e2; color: #516458; }
.btn-secondary { background: var(--surface); color: var(--green); border-color: #cfddd2; }
.btn-secondary:hover:not(:disabled) { background: #f0f7f0; }
.btn-danger { background: #a02d23; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #812218; }
.btn-danger:disabled { background: #f3e4e1; color: #7d453c; }
.btn-danger-outline { background: var(--surface); color: #9b3026; border-color: #edd7d2; }
.btn-danger-outline:hover:not(:disabled) { background: #fbedeb; }
.btn-small { min-height: 36px; padding: 5px 10px; font-size: .87rem; }
.text-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  padding: 5px 0;
  color: var(--green);
  font-weight: 700;
  font-size: .87rem;
  text-align: left;
}
.text-button:hover { text-decoration: underline; text-underline-offset: 3px; }

.card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px #20342807;
  overflow: hidden;
}
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.summary-card { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.summary-icon, .machine-icon, .dispense-icon, .hero-icon {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 39px;
  height: 39px;
  border-radius: 11px;
  background: #eaf4e9;
  color: var(--green);
}
.summary-label { font-size: .87rem; color: var(--muted); font-weight: 600; line-height: 1.25; }
.summary-card strong { display: block; font-size: 1.8rem; line-height: 1; letter-spacing: -.055em; }
.dashboard-grid, .settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(255px, .45fr); gap: 18px; align-items: start; }
.machine-list { display: grid; gap: 12px; min-width: 0; }
.card-header {
  min-height: 62px;
  padding: 17px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 9px;
}
.card-header .text-button { flex: none; }
.machine-preview { display: flex; gap: 11px; align-items: center; margin: 0 20px; padding: 15px 12px; border-radius: 10px; background: #f4f8f4; }
.machine-preview p { color: var(--muted); margin-top: 3px; font-size: .83rem; }
.machine-summary { margin: 15px 20px; padding: 0; }
.machine-summary div { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; font-size: .9rem; }
.machine-summary div + div { border-top: 1px solid var(--line); }
.machine-summary dt { color: var(--muted); }
.machine-summary dd { margin: 0; font-weight: 700; white-space: nowrap; }
.machine-card > .btn { margin: 0 20px 20px; width: calc(100% - 40px); }
.qr-card-notice {
  padding: 9px 11px;
  border: 1px solid #f1d9ad;
  border-radius: 8px;
  background: #fff5e4;
  color: #69451d;
  font-size: .9rem;
  line-height: 1.4;
}
.machine-card > .qr-card-notice { margin: 0 20px 13px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 7px;
  background: #e9f5e5;
  color: #235238;
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-badge > span:first-child { width: 6px; height: 6px; border-radius: 50%; background: #4b9c61; }
.status-badge--busy { background: #fff0d9; color: #704512; }
.status-badge--busy > span:first-child { background: #c17b23; }

.table-scroll { overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; text-align: left; }
.table thead { background: #f4f8f4; color: #51675b; }
.table th, .table td { padding: 12px 14px; vertical-align: middle; }
.table thead th { font-size: .83rem; font-weight: 650; padding-top: 11px; padding-bottom: 11px; }
.table th:first-child { padding-left: 20px; }
.table th:last-child, .table td:last-child { padding-right: 20px; }
.table tbody tr + tr { border-top: 1px solid #ebf0ec; }
.table tbody th { font-weight: 700; }
.table td .text-button { white-space: nowrap; }
.operation, .member-name { display: flex; align-items: center; gap: 9px; }
.member-actions { display: flex; justify-content: flex-end; gap: 8px; }
.member-email { overflow-wrap: anywhere; }
.member-balance { white-space: nowrap; }
.operation small { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; margin-top: 3px; }
.movement-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: #e9f4eb;
  color: var(--green);
}
.movement--erogazione { color: #3e5960; background: #eef2f2; }
.movement--rimborso { color: #715523; background: #f8f0df; }
.align-right { text-align: right; }
.date-cell { white-space: nowrap; }
.amount { font-weight: 750; white-space: nowrap; }
.amount--positive { color: #176846; }
.muted, .plain-meta { color: var(--muted); }
.plain-meta { font-size: .9rem; white-space: nowrap; }
.empty { padding: 26px 20px; color: var(--muted); }

.filterbar { display: flex; align-items: center; gap: 14px; justify-content: space-between; padding: 16px 20px; }
.filterbar label { font-size: .9rem; font-weight: 650; }
.search-field {
  position: relative;
  display: flex;
  align-items: center;
  width: min(100%, 330px);
}
.search-field svg { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search-field input { padding-left: 38px; }
input, select {
  min-height: 42px;
  width: 100%;
  border: 1px solid #cddbd0;
  border-radius: 9px;
  padding: 8px 11px;
  background-color: #fff;
  color: var(--ink);
  font-size: 1rem;
}
input::placeholder { color: #60756a; }
select {
  appearance: none;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, #38614d 50%),
    linear-gradient(135deg, #38614d 50%, transparent 50%);
  background-position: calc(100% - 17px) 54%, calc(100% - 12px) 54%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.filterbar select { width: auto; min-width: 140px; }

.statistics-controls { display: flex; flex-wrap: wrap; gap: 12px 18px; padding: 16px 20px; margin-bottom: 22px; }
.statistics-controls label { display: grid; flex: 0 1 195px; gap: 6px; min-width: 0; font-size: .9rem; font-weight: 650; }
.statistics-members .card-header { flex-wrap: wrap; }
.statistics-members .search-field { width: min(100%, 255px); }

.settings-card .card-header { border-bottom: 1px solid var(--line); }
.machine-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 12px; border-bottom: 1px solid var(--line); }
.settings-form { padding: 0 20px; }
.settings-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 17px 0;
}
.settings-row + .settings-row, .settings-footer { border-top: 1px solid var(--line); }
.settings-row > div:first-child { display: flex; gap: 12px; align-items: flex-start; }
.settings-row svg { color: var(--green); }
.settings-row label { font-weight: 700; }
.settings-row p, .settings-footer p, .settings-qr p { margin-top: 5px; color: var(--muted); font-size: .9rem; line-height: 1.45; }
.settings-footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 17px 0 20px; }
.settings-footer p { margin: 0; }
.unit-field { display: flex; align-items: center; gap: 7px; width: 106px; flex: none; color: var(--muted); }
.unit-field input { min-width: 0; }
.settings-qr { padding: 20px; }
.settings-qr .summary-icon { margin-bottom: 11px; }
.settings-qr .btn { margin-top: 14px; }
.settings-qr .qr-card-notice { margin-top: 10px; color: #69451d; }

.member-hero {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border-radius: var(--radius);
  background: linear-gradient(110deg, #102f25 18%, #18513a);
  color: #fbfdf9;
  margin-bottom: 20px;
}
.member-hero-inner { position: relative; z-index: 1; padding: 23px 26px 27px; }
.hero-icon { background: #396449; color: #f1f9e9; margin-bottom: 12px; }
.member-hero h2 { color: #d4ebdc; font-size: 1rem; }
.balance { display: flex; align-items: baseline; gap: 10px; margin: 3px 0 7px; }
.balance strong { color: #cdf4a9; font-size: clamp(3rem, 8vw, 4.6rem); line-height: 1; letter-spacing: -.06em; }
.balance span { color: #e0efdd; font-size: 1.05rem; }
.member-hero p { color: #d9ebdf; font-size: .92rem; }
.field-art { position: absolute; inset: 0 0 0 46%; overflow: hidden; pointer-events: none; }
.field-art i { position: absolute; display: block; border: 2px solid #b5e58e38; border-radius: 43% 57% 52% 48%; inset: -45% -15% -65% 0; transform: rotate(-35deg); }
.field-art i:nth-child(2) { inset: -26% -10% -45% 14%; border-color: #b5e58e26; }
.field-art i:nth-child(3) { inset: -12% -5% -34% 26%; border-color: #b5e58e1a; }
.member-grid { display: grid; grid-template-columns: minmax(270px, .7fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.dispense-content { display: grid; justify-items: start; gap: 10px; padding: 0 20px 20px; }
.dispense-icon { width: 52px; height: 52px; }
.dispense-content p { color: var(--muted); line-height: 1.4; }
.dispense-test { width: 100%; margin: 0; padding: 8px 12px 10px; border: 1px solid var(--line); border-radius: 10px; }
.dispense-test legend { padding: 0 5px; color: var(--muted); font-size: .88rem; font-weight: 700; }
.dispense-test label { display: flex; align-items: center; gap: 8px; font-size: .93rem; }
.dispense-test input { flex: none; width: 1.1rem; height: 1.1rem; min-height: 0; padding: 0; accent-color: var(--green); }
.dispense-btn { width: 100%; min-height: 50px; font-size: 1rem; }
.dispense-content .dispense-caption { font-size: .83rem; }
.dispense-progress { padding: 9px 11px; border-left: 3px solid #c17b23; border-radius: 5px; background: #fff5e4; }
.dispense-content > button[hidden] { display: none; }
.dispense-reviews { margin-bottom: 20px; }
.dispense-review-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.machine-identifier { margin: 0 20px 10px; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }

.entry, .loading { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.entry { background: radial-gradient(ellipse at 30% 35%, #d4e8d5, #f5f8f5 73%); }
.entry-card { width: min(100%, 430px); padding: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 16px 55px #14332012; }
.entry-card h1 { margin-top: 22px; }
.entry-card > p { margin: 8px 0 18px; color: var(--muted); line-height: 1.5; }
.entry-card form { display: grid; gap: 9px; }
.entry-card form label { font-weight: 650; }
.entry-card form .btn { margin-top: 8px; }
.entry-card > .text-button { margin-top: 14px; }

dialog {
  width: min(calc(100% - 30px), 455px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 18px 75px #0f2b2670;
}
dialog::backdrop { background: #0b231bb0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 8px; color: var(--green); background: #edf5ee; }
.icon-button:hover { background: #dcece0; }
.dialog-form { display: grid; gap: 15px; padding: 20px; }
.dialog-form p { line-height: 1.45; color: var(--muted); }
.dialog-form label { display: grid; gap: 6px; font-weight: 650; }
.dialog-form footer { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-form .form-error { color: #922f22; }
.qr-content { display: grid; justify-items: center; gap: 12px; padding: 18px 20px 20px; }
.qr-content img { display: block; max-width: 100%; height: auto; }
.qr-version { color: var(--muted); font-size: .92rem; font-weight: 700; }
.qr-address { overflow-wrap: anywhere; text-align: center; }
.qr-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.qr-reminder {
  display: grid;
  justify-items: start;
  gap: 9px;
  width: 100%;
  padding: 13px;
  border: 1px solid #f1d9ad;
  border-radius: 10px;
  background: #fff5e4;
  color: #69451d;
}
.qr-reminder p { font-size: .9rem; line-height: 1.45; }
.qr-reminder strong { display: block; margin-bottom: 3px; }
.qr-reminder .form-error { color: #922f22; }
.qr-footer { width: 100%; padding-top: 9px; border-top: 1px solid var(--line); text-align: center; }
.qr-feedback { color: var(--muted); font-size: .9rem; text-align: center; }
.qr-feedback:empty { display: none; }
#notification { position: fixed; right: 14px; bottom: 14px; z-index: 5; max-width: min(400px, calc(100% - 28px)); }
.toast { display: flex; align-items: center; gap: 9px; padding: 13px 15px; border-radius: 10px; color: #fff; background: #18452f; box-shadow: 0 5px 22px #172c2a30; font-size: .9rem; font-weight: 650; }
.toast--error { background: #892e21; }

@media (max-width: 1120px) {
  .shell { grid-template-columns: 190px minmax(0, 1fr); }
  .topbar, .main-content { padding-inline: 24px; }
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
  .machine-card { max-width: none; }
}

@media (max-width: 800px) {
  .shell { display: block; }
  .sidebar { min-height: 0; position: static; padding: 12px 15px; gap: 12px; }
  .sidebar .brand { padding: 0; }
  .brand-icon { width: 36px; height: 36px; border-radius: 10px; }
  .brand-icon svg { width: 20px; height: 20px; }
  .sidebar-bottom { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 5px; }
  .nav button { width: auto; padding: 8px; font-size: .85rem; gap: 5px; }
  .nav button svg { width: 15px; height: 15px; }
  .topbar { min-height: 58px; padding-inline: 15px; }
  .main-content { padding: 22px 15px 42px; }
  .summary-grid { gap: 10px; }
  .summary-card { padding: 12px; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 580px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .member-grid { grid-template-columns: minmax(0, 1fr); }
  .page-heading { align-items: flex-start; }
  .page-heading p { line-height: 1.35; }
  .page-heading > .btn { margin-top: 2px; padding-inline: 9px; }
  .topbar-actions { gap: 8px; }
  .avatar--top { width: 31px; height: 31px; }
  .table th, .table td { padding-inline: 11px; }
  .table th:first-child { padding-left: 14px; }
  .table th:last-child, .table td:last-child { padding-right: 14px; }
  .card-header { padding-inline: 14px; }
  .filterbar { padding-inline: 14px; gap: 8px; }
  .table--members, .table--members tbody { display: block; }
  .table--members thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .table--members tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 5px 9px;
    padding: 12px 14px;
  }
  .table--members tbody tr:first-child { border-top: 1px solid var(--line); }
  .table--members th.member-identity, .table--members td { padding: 0; }
  .member-balance { grid-column: 2; grid-row: 1; }
  .member-email { grid-column: 1 / -1; padding-left: 46px !important; }
  .member-options { grid-column: 1 / -1; margin-top: 4px; }
}

@media print {
  body:has(dialog[open].dialog--qr) #app,
  body:has(dialog[open].dialog--qr) .skip-link,
  .dialog--qr .icon-button, .dialog--qr .qr-actions, .dialog--qr .qr-feedback,
  .dialog--qr .qr-reminder, .dialog--qr .qr-footer, #notification { display: none; }
  .dialog--qr[open] { position: static; inset: auto; display: block; width: 100%; border: 0; box-shadow: none; }
  .dialog--qr::backdrop { background: transparent; }
  .dialog--qr .dialog-head { justify-content: center; border: 0; }
  .dialog--qr .qr-content img { width: 55mm; height: 55mm; }
}
