/* =====================================================================
   ISP Billing – Mondo Hi-Tech
   Foglio di stile principale (mobile-first, bianco/blu)
   ===================================================================== */

:root {
  --blue-900: #004a63;
  --blue-800: #006080;
  --blue-700: #0080a8;      /* colore primario (logo "MONDO") */
  --blue-600: #0092bf;
  --blue-500: #00a8d8;      /* accento (globo) */
  --blue-400: #00b0e0;
  --blue-100: #d9eef7;
  --blue-50:  #eef7fb;
  --gray-900: #1f2a30;
  --gray-700: #505858;      /* grigio logo "HI-TECH" */
  --gray-500: #6b7680;
  --gray-400: #98a3ad;
  --gray-300: #cfd8df;
  --gray-200: #e3e9ee;
  --gray-100: #f1f5f8;
  --white:    #ffffff;
  --green:    #1f9d55;
  --green-bg: #e3f5ea;
  --red:      #d13b3b;
  --red-bg:   #fbe7e7;
  --orange:   #e08a1e;
  --orange-bg:#fdf0dc;
  --yellow-bg:#fff7d6;
  --purple:   #6f4bd1;
  --purple-bg:#ece6fb;

  --bg:       #f4f8fb;
  --text:     var(--gray-900);
  --muted:    var(--gray-500);
  --border:   var(--gray-200);
  --radius:   12px;
  --radius-sm: 8px;
  --shadow:   0 1px 2px rgba(0, 74, 99, .06), 0 4px 14px rgba(0, 74, 99, .06);
  --shadow-lg: 0 10px 40px rgba(0, 74, 99, .18);

  --sidebar-w: 264px;
  --topbar-h: 60px;
  --bottomnav-h: 60px;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  font-size: 16px;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
img, svg { max-width: 100%; height: auto; display: inline-block; vertical-align: middle; }
svg.ico { width: 20px; height: 20px; flex: 0 0 20px; vertical-align: -4px; }
a { color: var(--blue-700); text-decoration: none; }
a:hover { color: var(--blue-800); text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; color: var(--blue-900); font-weight: 700; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; } h4 { font-size: .95rem; }
p { margin: 0 0 .9rem; }
code, pre, kbd { font-family: var(--mono); font-size: .86em; }
code { background: var(--blue-50); color: var(--blue-900); padding: .1em .4em; border-radius: 5px; }
pre {
  background: #0d2a36; color: #d8eef7; padding: 1rem; border-radius: var(--radius-sm);
  overflow-x: auto; -webkit-overflow-scrolling: touch; font-size: .82rem; line-height: 1.5;
  margin: .5rem 0 1rem; position: relative;
}
pre code { background: transparent; color: inherit; padding: 0; font-size: inherit; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
table { border-collapse: collapse; width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}
.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--blue-800) 0%, var(--blue-700) 55%, var(--blue-600) 100%);
  color: #fff;
  z-index: 60;
  transform: translateX(-100%);
  transition: transform .25s ease;
  display: flex; flex-direction: column;
  padding-top: var(--sat);
  padding-left: var(--sal);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-lg);
}
.sidebar.open { transform: translateX(0); }
.sidebar__brand {
  display: flex; align-items: center; gap: .7rem;
  padding: 1rem 1.1rem; height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
}
.sidebar__brand img { height: 34px; width: auto; }
.sidebar__close {
  margin-left: auto; background: none; border: 0; color: var(--blue-700); font-size: 1.5rem; line-height: 1;
  padding: .25rem .5rem; border-radius: 6px;
}
.sidebar__close:hover { background: var(--blue-50); }
.sidebar__section { padding: 1rem .85rem .25rem; font-size: .68rem; letter-spacing: .09em; text-transform: uppercase; opacity: .7; }
.sidebar nav { padding: .5rem .6rem 1.5rem; }
.sidebar a.nav-link {
  display: flex; align-items: center; gap: .7rem;
  padding: .62rem .8rem; margin: .1rem 0; border-radius: 10px;
  color: rgba(255,255,255,.92); font-weight: 500; font-size: .93rem;
  transition: background .15s;
}
.sidebar a.nav-link:hover { background: rgba(255,255,255,.12); text-decoration: none; color: #fff; }
.sidebar a.nav-link.active { background: var(--white); color: var(--blue-800); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.sidebar a.nav-link .ico { width: 20px; height: 20px; flex: 0 0 20px; opacity: .95; }
.sidebar__footer { margin-top: auto; padding: 1rem; font-size: .75rem; opacity: .75; }
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(0, 40, 60, .45); z-index: 55;
  opacity: 0; pointer-events: none; transition: opacity .25s; backdrop-filter: blur(2px);
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding-top: var(--sat);
  box-shadow: 0 1px 0 rgba(0,74,99,.04);
}
.topbar__inner {
  height: var(--topbar-h); display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem; padding-left: calc(1rem + var(--sal)); padding-right: calc(1rem + var(--sar));
}
.topbar__brand img { height: 32px; width: auto; }
.topbar__title { font-weight: 700; color: var(--blue-900); font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 10px; border: 0; background: transparent; color: var(--blue-800);
  touch-action: manipulation;
}
.icon-btn:hover { background: var(--blue-50); }
.icon-btn svg { width: 24px; height: 24px; }
.user-menu { position: relative; }
.user-menu__btn {
  display: inline-flex; align-items: center; gap: .55rem; border: 1px solid var(--border); background: #fff;
  padding: .3rem .6rem .3rem .3rem; border-radius: 999px; max-width: 220px;
}
.user-menu__btn:hover { border-color: var(--blue-500); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--blue-700); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; flex: 0 0 32px;
}
.user-menu__name { font-size: .85rem; font-weight: 600; color: var(--blue-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); min-width: 200px; padding: .4rem; z-index: 70;
  display: none;
}
.dropdown.show { display: block; }
.dropdown a, .dropdown button {
  display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left; padding: .6rem .7rem; border-radius: 6px;
  border: 0; background: none; color: var(--text); font-size: .9rem;
}
.dropdown a:hover, .dropdown button:hover { background: var(--blue-50); text-decoration: none; }
.dropdown .danger { color: var(--red); }
.dropdown hr { margin: .3rem 0; }

.content {
  flex: 1;
  padding: 1rem;
  padding-left: calc(1rem + var(--sal));
  padding-right: calc(1rem + var(--sar));
  padding-bottom: calc(1rem + var(--bottomnav-h) + var(--sab));
  max-width: 1400px; width: 100%; margin: 0 auto;
}

/* Bottom navigation (mobile) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--white); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--bottomnav-h) + var(--sab)); padding-bottom: var(--sab);
  box-shadow: 0 -2px 12px rgba(0,74,99,.08);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .66rem; color: var(--gray-500); font-weight: 600; touch-action: manipulation;
}
.bottom-nav a svg { width: 24px; height: 24px; }
.bottom-nav a.active { color: var(--blue-700); }
.bottom-nav a:hover { text-decoration: none; }

@media (max-width: 640px) {
  .user-menu__name { display: none; }
  .user-menu__btn { padding: .2rem; border: 0; }
  .btn { white-space: normal; }
  .page-header .actions { width: 100%; }
}

/* Desktop */
@media (min-width: 1024px) {
  .sidebar { transform: none; box-shadow: none; }
  .sidebar__close { display: none; }
  .sidebar-backdrop { display: none; }
  .main { margin-left: var(--sidebar-w); }
  .topbar__brand, .menu-btn { display: none; }
  .bottom-nav { display: none; }
  .content { padding: 1.5rem 2rem; padding-bottom: 2rem; }
}

/* ---------- Page header ---------- */
.page-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem;
}
.page-header h1 { margin: 0; }
.page-header .sub { color: var(--muted); font-size: .9rem; margin: 0; width: 100%; }
.page-header .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.breadcrumb { font-size: .82rem; color: var(--muted); margin-bottom: .5rem; }
.breadcrumb a { color: var(--blue-700); }

/* ---------- Cards ---------- */
.card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 1rem; overflow: hidden;
}
.card__header {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .85rem 1rem; border-bottom: 1px solid var(--border); background: #fff;
}
.card__header h2, .card__header h3 { margin: 0; font-size: 1rem; }
.card__header .actions { margin-left: auto; display: flex; gap: .4rem; flex-wrap: wrap; }
.card__body { padding: 1rem; }
.card__footer { padding: .75rem 1rem; border-top: 1px solid var(--border); background: var(--gray-100); }
.card--flush .card__body { padding: 0; }
.card--blue { background: linear-gradient(135deg, var(--blue-800), var(--blue-500)); color: #fff; border: 0; }
.card--blue h2, .card--blue h3 { color: #fff; }

/* KPI tiles */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 640px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .kpi-grid { grid-template-columns: repeat(6, 1fr); } }
.kpi {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .2rem; position: relative; overflow: hidden;
  min-height: 92px;
}
.kpi::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--blue-500); }
.kpi.green::after { background: var(--green); } .kpi.red::after { background: var(--red); }
.kpi.orange::after { background: var(--orange); } .kpi.gray::after { background: var(--gray-400); }
.kpi.purple::after { background: var(--purple); }
.kpi__label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.kpi__value { font-size: 1.5rem; font-weight: 800; color: var(--blue-900); line-height: 1.1; }
.kpi__sub { font-size: .75rem; color: var(--muted); }
.kpi a { color: inherit; }

.grid { display: grid; gap: 1rem; }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-2-1 { grid-template-columns: 2fr 1fr; }
  .grid-1-2 { grid-template-columns: 1fr 2fr; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem .95rem; border-radius: 9px; border: 1px solid transparent;
  font-weight: 600; font-size: .9rem; line-height: 1.2; white-space: nowrap;
  background: var(--blue-700); color: #fff; cursor: pointer; touch-action: manipulation;
  transition: background .15s, box-shadow .15s, transform .05s; min-height: 40px;
  -webkit-appearance: none; appearance: none;
}
.btn:hover { background: var(--blue-800); color: #fff; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.btn-outline { background: #fff; color: var(--blue-700); border-color: var(--blue-700); }
.btn-outline:hover { background: var(--blue-50); color: var(--blue-800); }
.btn-light { background: var(--gray-100); color: var(--gray-900); border-color: var(--border); }
.btn-light:hover { background: var(--gray-200); color: var(--gray-900); }
.btn-success { background: var(--green); } .btn-success:hover { background: #17824a; }
.btn-danger { background: var(--red); } .btn-danger:hover { background: #b02f2f; }
.btn-danger-outline { background: #fff; color: var(--red); border-color: var(--red); }
.btn-danger-outline:hover { background: var(--red-bg); color: var(--red); }
.btn-warning { background: var(--orange); } .btn-warning:hover { background: #c47716; }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; min-height: 32px; border-radius: 7px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-lg { padding: .75rem 1.3rem; font-size: 1rem; min-height: 48px; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; gap: .35rem; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; line-height: 1.4;
  background: var(--gray-100); color: var(--gray-700);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success, .badge-active, .badge-paid, .badge-online, .badge-closed { background: var(--green-bg); color: var(--green); }
.badge-danger, .badge-expired, .badge-overdue, .badge-reject, .badge-urgent { background: var(--red-bg); color: var(--red); }
.badge-warning, .badge-suspended, .badge-unpaid, .badge-high, .badge-in_progress { background: var(--orange-bg); color: var(--orange); }
.badge-info, .badge-open, .badge-draft { background: var(--blue-100); color: var(--blue-800); }
.badge-muted, .badge-cancelled, .badge-inactive, .badge-low { background: var(--gray-100); color: var(--gray-500); }
.badge-purple, .badge-admin { background: var(--purple-bg); color: var(--purple); }
.badge-normal { background: var(--blue-50); color: var(--blue-700); }

/* ---------- Alerts / flash ---------- */
.alert {
  display: flex; gap: .6rem; align-items: flex-start; padding: .8rem 1rem; border-radius: var(--radius-sm);
  margin-bottom: 1rem; border: 1px solid transparent; font-size: .92rem;
}
.alert svg { width: 20px; height: 20px; flex: 0 0 20px; margin-top: 1px; }
.alert-success { background: var(--green-bg); color: #155c34; border-color: #b7e4c7; }
.alert-danger { background: var(--red-bg); color: #8f2323; border-color: #f2bcbc; }
.alert-warning { background: var(--orange-bg); color: #7a4a07; border-color: #f5d8a8; }
.alert-info { background: var(--blue-100); color: var(--blue-900); border-color: #a9d9ed; }
.alert .close { margin-left: auto; background: none; border: 0; font-size: 1.2rem; line-height: 1; color: inherit; opacity: .6; }
.flash-stack { position: relative; z-index: 1; }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: .9rem 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); } .form-grid.cols-4 { grid-template-columns: repeat(4, 1fr); } }
.form-grid .span-2 { grid-column: span 1; }
@media (min-width: 640px) { .form-grid .span-2 { grid-column: span 2; } .form-grid .span-all { grid-column: 1 / -1; } }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field label, .label { font-size: .82rem; font-weight: 600; color: var(--blue-900); }
.field .hint { font-size: .76rem; color: var(--muted); }
.field .req { color: var(--red); }
.input, .select, .textarea,
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"],
input[type="search"], input[type="tel"], input[type="url"], input[type="time"], input[type="datetime-local"], select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  background: #fff; font-size: 16px; /* evita lo zoom automatico su iOS */
  line-height: 1.3; min-height: 44px; color: var(--text);
  -webkit-appearance: none; appearance: none; transition: border-color .15s, box-shadow .15s;
}
@media (min-width: 640px) {
  .input, .select, .textarea,
  input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"],
  input[type="search"], input[type="tel"], input[type="url"], input[type="time"], input[type="datetime-local"], select, textarea { font-size: .92rem; min-height: 42px; }
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(0,168,216,.2); }
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--gray-100); color: var(--gray-500); }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230080a8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2.2rem;
}
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--blue-700); vertical-align: middle; }
.check { display: flex; align-items: center; gap: .55rem; font-size: .9rem; min-height: 42px; }
.input-group { display: flex; gap: .4rem; }
.input-group > * { min-width: 0; }
.input-group .btn { flex: 0 0 auto; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.is-invalid { border-color: var(--red) !important; }
.error-text { color: var(--red); font-size: .78rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .9rem 1rem 1rem; margin: 0 0 1rem; min-width: 0; }
legend { padding: 0 .4rem; font-weight: 700; color: var(--blue-800); font-size: .9rem; }

/* Filters bar */
.filters { display: grid; gap: .6rem; grid-template-columns: 1fr; margin-bottom: 1rem; }
@media (min-width: 640px) { .filters { grid-template-columns: 2fr 1fr 1fr auto; align-items: end; } }
.filters .field label { font-size: .75rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; font-size: .9rem; }
.table th, .table td { padding: .7rem .85rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table th { background: var(--blue-50); color: var(--blue-900); font-weight: 700; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.table tbody tr:hover { background: #f8fbfd; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn { margin-left: .2rem; }
.table a.strong { font-weight: 600; color: var(--blue-800); }
.table .muted { color: var(--muted); font-size: .82rem; }
.table-empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.table-empty svg { width: 42px; height: 42px; opacity: .35; margin-bottom: .5rem; }

/* Responsive "card" tables on small screens */
@media (max-width: 767px) {
  .table-responsive thead { display: none; }
  .table-responsive, .table-responsive tbody, .table-responsive tr, .table-responsive td { display: block; width: 100%; }
  .table-responsive tr { border: 1px solid var(--border); border-radius: var(--radius-sm); margin: .6rem .75rem; background: #fff; padding: .35rem 0; box-shadow: var(--shadow); }
  .table-responsive td { border: 0; padding: .4rem .9rem; display: grid; grid-template-columns: 38% 1fr; align-items: center; column-gap: 1rem; text-align: right !important; }
  .table-responsive td::before { content: attr(data-label); grid-column: 1; grid-row: 1; align-self: start; padding-top: .15rem; font-weight: 700; color: var(--blue-900); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; text-align: left; }
  .table-responsive td > * { grid-column: 2; min-width: 0; }
  .table-responsive td > input, .table-responsive td > select { text-align: left; }
  .table-responsive td.actions { display: flex; justify-content: flex-end; gap: .3rem; }
  .table-responsive td.actions::before { content: none; }
  .table-responsive td:empty { display: none; }
  .table-responsive td.primary { font-weight: 600; }
  .table-responsive tbody tr:hover { background: #fff; }
}

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; padding: .75rem 1rem; font-size: .85rem; color: var(--muted); }
.pagination .pages { display: flex; gap: .25rem; flex-wrap: wrap; }
.pagination .pages a, .pagination .pages span { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px; padding: 0 .5rem; border-radius: 8px; border: 1px solid var(--border); background: #fff; color: var(--blue-800); font-weight: 600; }
.pagination .pages span.current { background: var(--blue-700); color: #fff; border-color: var(--blue-700); }
.pagination .pages a:hover { background: var(--blue-50); text-decoration: none; }

/* ---------- Definition lists / details ---------- */
.dl { display: grid; grid-template-columns: 1fr; gap: .35rem .9rem; margin: 0; font-size: .92rem; }
@media (min-width: 640px) { .dl { grid-template-columns: max-content 1fr; } }
.dl dt { font-weight: 600; color: var(--blue-900); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding-top: .15rem; }
.dl dd { margin: 0 0 .4rem; word-break: break-word; }
@media (min-width: 640px) { .dl dd { margin-bottom: 0; padding: .1rem 0 .35rem; border-bottom: 1px dashed var(--border); } .dl dt { padding: .1rem 0; border-bottom: 1px dashed var(--border); } }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--border); margin-bottom: 1rem; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: .6rem .9rem; font-weight: 600; font-size: .88rem; color: var(--muted); white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabs a.active { color: var(--blue-700); border-bottom-color: var(--blue-700); }
.tabs a:hover { text-decoration: none; color: var(--blue-800); }

/* ---------- Auth page ---------- */
.auth {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 1.25rem;
  padding-top: calc(1.25rem + var(--sat)); padding-bottom: calc(1.25rem + var(--sab));
  background: radial-gradient(1200px 600px at 10% -10%, var(--blue-100), transparent 60%), radial-gradient(900px 500px at 110% 110%, var(--blue-100), transparent 55%), var(--bg);
}
.auth__card { width: 100%; max-width: 420px; background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg); padding: 2rem 1.6rem; border: 1px solid var(--border); }
.auth__logo { text-align: center; margin-bottom: 1.4rem; }
.auth__logo img { max-height: 60px; }
.auth__title { text-align: center; color: var(--blue-900); font-size: 1.15rem; margin-bottom: 1.3rem; }
.auth__footer { text-align: center; color: var(--muted); font-size: .78rem; margin-top: 1.4rem; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.text-right { text-align: right; } .text-center { text-align: center; }
.mono { font-family: var(--mono); font-size: .86em; }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.flex { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.flex-between { justify-content: space-between; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-100 { width: 100%; }
.strong { font-weight: 700; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--blue-900); }
.copy-btn { position: absolute; top: .5rem; right: .5rem; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 6px; padding: .25rem .5rem; font-size: .72rem; }
.copy-btn:hover { background: rgba(255,255,255,.25); }
.progress { height: 8px; background: var(--gray-200); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--blue-500); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--gray-400); margin-right: .35rem; }
.dot.online { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.chart-bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: .5rem; }
.chart-bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: .25rem; min-width: 0; }
.chart-bars .bar i { display: block; width: 100%; max-width: 38px; background: linear-gradient(180deg, var(--blue-500), var(--blue-700)); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.chart-bars .bar b { font-size: .62rem; color: var(--muted); font-weight: 600; }
.chart-bars .bar span { font-size: .6rem; color: var(--blue-900); font-weight: 700; white-space: nowrap; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .7rem; padding: .65rem 1rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; min-width: 0; }
.list li .title { font-weight: 600; color: var(--blue-900); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .meta { font-size: .78rem; color: var(--muted); }
.stat-row { display: flex; justify-content: space-between; padding: .45rem 0; border-bottom: 1px dashed var(--border); font-size: .9rem; }
.stat-row:last-child { border-bottom: 0; }
.stat-row b { color: var(--blue-900); }
.totals { margin-left: auto; width: 100%; max-width: 360px; }
.totals .stat-row.grand { font-size: 1.05rem; border-top: 2px solid var(--blue-700); border-bottom: 0; padding-top: .6rem; }
.tag-list { display: flex; flex-wrap: wrap; gap: .3rem; }
.search-results { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; z-index: 40; display: none; }
.search-results.show { display: block; }
.search-results div { padding: .55rem .75rem; cursor: pointer; font-size: .9rem; border-bottom: 1px solid var(--border); }
.search-results div:hover { background: var(--blue-50); }
.search-results div small { display: block; color: var(--muted); }
.rel { position: relative; }

/* Guide */
.guide-layout { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 1000px) { .guide-layout { grid-template-columns: 260px 1fr; align-items: start; } .guide-nav { position: sticky; top: calc(var(--topbar-h) + 1rem); } }
.guide-nav .list li { padding: .5rem .9rem; }
.guide-nav a { color: var(--gray-700); font-weight: 500; font-size: .88rem; }
.guide-nav a.active { color: var(--blue-700); font-weight: 700; }
.guide-content { font-size: .95rem; }
.guide-content h2 { margin-top: 1.75rem; padding-bottom: .35rem; border-bottom: 2px solid var(--blue-100); }
.guide-content h2:first-child { margin-top: 0; }
.guide-content h3 { margin-top: 1.3rem; color: var(--blue-800); }
.guide-content ul, .guide-content ol { padding-left: 1.3rem; }
.guide-content li { margin-bottom: .3rem; }
.guide-content table { font-size: .88rem; margin-bottom: 1rem; }
.guide-content table th, .guide-content table td { border: 1px solid var(--border); padding: .5rem .6rem; text-align: left; vertical-align: top; }
.guide-content table th { background: var(--blue-50); }
.guide-content .note { border-left: 4px solid var(--blue-500); background: var(--blue-50); padding: .75rem 1rem; border-radius: 0 8px 8px 0; margin: 1rem 0; }
.guide-content .note.warn { border-color: var(--orange); background: var(--orange-bg); }
.guide-content .note.danger { border-color: var(--red); background: var(--red-bg); }
.guide-content .step { display: flex; gap: .8rem; margin: .8rem 0; }
.guide-content .step b.n { flex: 0 0 28px; height: 28px; border-radius: 50%; background: var(--blue-700); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; }
.guide-pager { display: flex; justify-content: space-between; gap: .5rem; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Error pages */
.error-page { text-align: center; padding: 4rem 1rem; }
.error-page .code { font-size: 5rem; font-weight: 800; color: var(--blue-100); line-height: 1; }

/* ---------- Print (fatture) ---------- */
.print-only { display: none; }
@media print {
  .sidebar, .topbar, .bottom-nav, .no-print, .sidebar-backdrop { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0 !important; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
  .print-only { display: block; }
  a { color: inherit; text-decoration: none; }
}
.invoice-print { background: #fff; padding: 1.5rem; max-width: 900px; margin: 0 auto; font-size: .92rem; }
.invoice-print .head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 3px solid var(--blue-700); padding-bottom: 1rem; margin-bottom: 1rem; }
.invoice-print .head img { max-height: 56px; }
.invoice-print .parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.25rem; }
@media (max-width: 560px) { .invoice-print .parties { grid-template-columns: 1fr; } }
.invoice-print .box { border: 1px solid var(--border); border-radius: 8px; padding: .75rem 1rem; }
.invoice-print .box h4 { margin-bottom: .4rem; color: var(--blue-700); text-transform: uppercase; font-size: .72rem; letter-spacing: .06em; }
.invoice-print table.items th { background: var(--blue-700); color: #fff; padding: .55rem .7rem; text-align: left; font-size: .78rem; }
.invoice-print table.items td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); }
.invoice-print .foot { margin-top: 1.5rem; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: .75rem; }

/* Reduce motion */
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } html { scroll-behavior: auto; } }

/* =====================================================================
   Area clienti (portale pubblico)
   ===================================================================== */
body.portal { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.portal-header { background: var(--white); border-bottom: 1px solid var(--border); padding-top: var(--sat); position: sticky; top: 0; z-index: 20; box-shadow: 0 1px 0 rgba(0,74,99,.04); }
.portal-header__inner { max-width: 1040px; margin: 0 auto; padding: .6rem 1rem; display: flex; align-items: center; gap: 1rem; min-height: 64px; }
.portal-brand { display: inline-flex; align-items: center; gap: .75rem; color: var(--blue-900); font-weight: 700; }
.portal-brand img { height: 36px; width: auto; }
.portal-brand span { padding-left: .75rem; border-left: 2px solid var(--blue-100); font-size: .95rem; }
.portal-brand:hover { text-decoration: none; }
.portal-user { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.portal-user__name { font-size: .88rem; font-weight: 600; color: var(--blue-900); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 1.25rem 1rem calc(2rem + var(--sab)); padding-left: calc(1rem + var(--sal)); padding-right: calc(1rem + var(--sar)); }
.portal-footer { background: var(--white); border-top: 1px solid var(--border); padding: 1rem; padding-bottom: calc(1rem + var(--sab)); text-align: center; font-size: .8rem; color: var(--muted); display: flex; flex-direction: column; gap: .25rem; }
.portal-hero { background: linear-gradient(135deg, var(--blue-800), var(--blue-500)); color: #fff; border-radius: var(--radius); padding: 1.25rem 1.4rem; margin-bottom: 1.25rem; box-shadow: var(--shadow); }
.portal-hero h1 { color: #fff; margin: 0 0 .25rem; font-size: 1.4rem; }
.portal-hero p { margin: 0; opacity: .92; font-size: .92rem; }
.portal-login { max-width: 460px; margin: 1.5rem auto; }
.portal-login .card__body { padding: 1.6rem 1.5rem; }
.portal-login h1 { font-size: 1.3rem; text-align: center; }
.portal-login .intro { color: var(--muted); font-size: .92rem; text-align: center; margin-bottom: 1.2rem; }
.otp-input { font-size: 1.8rem !important; letter-spacing: .5em; text-align: center; font-family: var(--mono); min-height: 56px !important; }
.sub-card { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); margin-bottom: 1rem; overflow: hidden; }
.sub-card__head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); background: var(--blue-50); }
.sub-card__head h2 { margin: 0; font-size: 1.05rem; }
.sub-card__body { padding: 1rem 1.1rem; display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 820px) { .sub-card__body { grid-template-columns: 1.1fr 1fr; } }
.sub-expiry { display: flex; align-items: center; gap: .9rem; padding: .8rem 1rem; border-radius: var(--radius-sm); background: var(--gray-100); margin-bottom: .9rem; }
.sub-expiry.ok { background: var(--green-bg); } .sub-expiry.warn { background: var(--orange-bg); } .sub-expiry.bad { background: var(--red-bg); }
.sub-expiry b { font-size: 1.25rem; color: var(--blue-900); display: block; line-height: 1.1; }
.sub-expiry small { color: var(--muted); }
.recharge-box { border: 1px dashed var(--blue-500); border-radius: var(--radius-sm); padding: .9rem 1rem; background: #fbfdff; }
.recharge-box h3 { margin-bottom: .6rem; }
.recharge-options { display: grid; gap: .45rem; grid-template-columns: 1fr; margin-bottom: .75rem; }
@media (min-width: 480px) { .recharge-options { grid-template-columns: 1fr 1fr; } }
.recharge-option { position: relative; display: block; cursor: pointer; }
.recharge-option input { position: absolute; opacity: 0; width: 0; height: 0; }
.recharge-option span { display: flex; flex-direction: column; gap: .1rem; padding: .6rem .75rem; border: 2px solid var(--border); border-radius: var(--radius-sm); background: #fff; transition: border-color .15s, box-shadow .15s; min-height: 58px; justify-content: center; }
.recharge-option b { color: var(--blue-900); font-size: .95rem; }
.recharge-option small { color: var(--muted); font-size: .78rem; }
.recharge-option input:checked + span { border-color: var(--blue-700); box-shadow: 0 0 0 3px rgba(0,128,168,.15); background: var(--blue-50); }
.recharge-option input:focus-visible + span { outline: 2px solid var(--blue-500); outline-offset: 2px; }
.pay-methods { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .pay-methods { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); } }
.pay-method { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; background: #fff; display: flex; flex-direction: column; gap: .6rem; }
.pay-method h3 { margin: 0; display: flex; align-items: center; gap: .5rem; }
.pay-method .btn { margin-top: auto; }
.bank-box { background: var(--blue-50); border-radius: var(--radius-sm); padding: .75rem .9rem; font-size: .9rem; }
.bank-box div { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; border-bottom: 1px dashed var(--blue-100); flex-wrap: wrap; }
.bank-box div:last-child { border-bottom: 0; }
.bank-box b { font-family: var(--mono); text-align: right; word-break: break-all; }
.result-icon { width: 72px; height: 72px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 1rem; }
.result-icon.ok { background: var(--green-bg); color: var(--green); } .result-icon.ko { background: var(--red-bg); color: var(--red); }
.result-icon svg { width: 40px; height: 40px; }
@media (max-width: 640px) {
  .portal-brand span, .portal-user__name { display: none; }
  .portal-brand img { height: 32px; }
}
