/* ── Variabili ── */
:root {
  --primary:      #2563eb;
  --primary-dark: #1d4ed8;
  --secondary:    #64748b;
  --success:      #10b981;
  --warning:      #f59e0b;
  --danger:       #ef4444;
  --info:         #06b6d4;
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --text:         #1e293b;
  --text-muted:   #94a3b8;
  --border:       #e2e8f0;
  --nav-h:        60px;
  --bottom-nav-h: 64px;
  --radius:       12px;
}

/* ── Reset/Base ── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
  padding-bottom: var(--bottom-nav-h);
}

a { text-decoration: none; color: inherit; }

/* ── Offline bar ── */
.offline-bar {
  display: none;
  position: fixed;
  top: env(safe-area-inset-top, 0px); left: 0;
  width: 100%;
  background: #ef4444;
  color: #fff;
  text-align: center;
  padding: 6px;
  font-size: .8rem;
  z-index: 9999;
}
.offline-bar.visible { display: block; }
body.offline .app-navbar { top: calc(2rem + env(safe-area-inset-top, 0px)); }

/* ── Top Navbar ── */
.app-navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: env(safe-area-inset-top, 0px) 1rem 0;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(37,99,235,.3);
}
.app-navbar .brand {
  display: flex;
  align-items: center;
  gap: .45rem;
  flex: 1;
  min-width: 0;
}
.app-navbar .brand-name {
  font-size: .875rem;
  font-weight: 700;
  letter-spacing: -.3px;
  line-height: 1.2;
  word-break: break-word;
  overflow-wrap: break-word;
}
.app-navbar .nav-actions { display: flex; gap: .5rem; align-items: center; }
.app-navbar .btn-icon {
  background: transparent;
  border: none;
  color: #fff;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background .15s;
}
.app-navbar .btn-icon:hover { background: rgba(255,255,255,.15); }

/* ── Main Content ── */
.app-content {
  margin-top: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
  padding: 1rem;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Bottom Navigation ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 1000;
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}
.bottom-nav .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: .65rem;
  font-weight: 500;
  color: var(--secondary);
  cursor: pointer;
  text-decoration: none;
  transition: color .15s;
  padding: 6px 0;
}
.bottom-nav .nav-item i { font-size: 1.2rem; }
.bottom-nav .nav-item.active { color: var(--primary); }
.bottom-nav .nav-item .badge-cart {
  position: relative;
}
.bottom-nav .nav-item .badge-cart .count {
  position: absolute;
  top: -6px; right: -8px;
  background: var(--danger);
  color: #fff;
  font-size: .55rem;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  overflow: hidden;
}
.card-header {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .95rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.card-body { padding: 1rem; }

/* ── Dashboard Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1rem;
  text-align: center;
}
.stat-card .stat-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  margin: 0 auto .5rem;
}
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-card .stat-label { font-size: .75rem; color: var(--text-muted); }

/* ── Search Bar ── */
.search-wrapper {
  position: relative;
  margin-bottom: .75rem;
}
.search-wrapper i {
  position: absolute;
  left: .85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}
.search-input {
  width: 100%;
  padding: .65rem .75rem .65rem 2.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .9rem;
  outline: none;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── List Items ── */
.list-item {
  display: flex;
  align-items: center;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: .75rem;
  transition: background .1s;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--bg); }
.list-item .item-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}
.list-item .item-body { flex: 1; min-width: 0; }
.list-item .item-title {
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item .item-sub {
  font-size: .78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item .item-actions { display: flex; gap: .25rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success   { background: var(--success); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-outline   { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-sm        { padding: .3rem .65rem; font-size: .78rem; border-radius: 6px; }
.btn-icon-sm {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  cursor: pointer;
  font-size: .85rem;
  transition: background .15s;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .75rem 0;
}
.page-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: .85rem;
  transition: background .15s;
}
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:hover:not(.active) { background: var(--bg); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-info { font-size: .8rem; color: var(--text-muted); margin: 0 .5rem; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  top: calc(var(--nav-h) + env(safe-area-inset-top, 0px) + .75rem);
  right: .75rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: calc(100vw - 1.5rem);
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  padding: .75rem 1rem;
  border-radius: 10px;
  font-size: .85rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  animation: toastIn .25s ease;
  max-width: 340px;
  pointer-events: auto;
}
.toast.removing { animation: toastOut .25s ease forwards; }
.toast-success { background: #d1fae5; color: #065f46; border-left: 3px solid var(--success); }
.toast-error   { background: #fee2e2; color: #991b1b; border-left: 3px solid var(--danger); }
.toast-warning { background: #fef3c7; color: #92400e; border-left: 3px solid var(--warning); }
.toast-info    { background: #e0f2fe; color: #0c4a6e; border-left: 3px solid var(--info); }
.toast i       { font-size: 1rem; flex-shrink: 0; margin-top: .05rem; }
.toast-body    { flex: 1; }
.toast-title   { font-weight: 600; margin-bottom: 1px; }
.toast-msg     { font-size: .8rem; opacity: .85; }
.toast-close   { background: none; border: none; cursor: pointer; opacity: .5; padding: 0; font-size: .9rem; }

@keyframes toastIn  { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: translateX(0); } }
@keyframes toastOut { from { opacity:1; transform: translateX(0); } to { opacity:0; transform: translateX(20px); } }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fadeIn .2s ease;
}
@media (min-width: 576px) {
  .modal-backdrop { align-items: center; padding: 1rem; }
}
.modal-sheet {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp .25s ease;
}
@media (min-width: 576px) {
  .modal-sheet { border-radius: var(--radius); max-height: 90vh; }
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-title   { font-size: 1rem; font-weight: 700; }
.modal-close   { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); }
.modal-body    { padding: 1.25rem; }

@keyframes fadeIn  { from { opacity:0 } to { opacity:1 } }
@keyframes slideUp { from { transform: translateY(30px); opacity:0 } to { transform: translateY(0); opacity:1 } }

/* ── Detail rows ── */
.detail-row {
  display: flex;
  flex-direction: column;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.detail-value { font-size: .9rem; font-weight: 500; margin-top: 2px; }

/* ── Cart ── */
.cart-fab {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + .75rem);
  right: 1rem;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--warning);
  color: #fff;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(245,158,11,.4);
  z-index: 900;
  transition: transform .15s;
}
.cart-fab:hover { transform: scale(1.08); }
.cart-count {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: .6rem;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

.cart-item {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item-top    { display: flex; align-items: center; gap: .5rem; }
.cart-item-bottom { display: flex; align-items: center; gap: .5rem; padding-left: calc(46px + .5rem); }
.cart-item-body { flex: 1; min-width: 0; }
.cart-item-name { font-size: .88rem; font-weight: 600; }
.cart-item-sub  { font-size: .78rem; color: var(--text-muted); }
.cart-item-qty   { display: flex; align-items: center; gap: .35rem; flex-shrink: 0; }
.cart-item-price { flex: 1; text-align: right; font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item-actions { display: flex; gap: .4rem; width: 68px; justify-content: flex-end; flex-shrink: 0; }
.riga-input {
  width: 46px;
  text-align: center;
  font-size: .78rem;
  font-weight: 700;
  padding: .2rem .25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-muted);
  flex-shrink: 0;
}
.riga-input:focus { outline: none; border-color: var(--primary); color: var(--text); }
.qty-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem;
}
.qty-input::-webkit-inner-spin-button,
.qty-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.qty-input { -moz-appearance: textfield; }
.cart-item .qty-input { text-align: right; }
.qty-input {
  width: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .2rem;
  font-size: .85rem;
}

/* ── Form ── */
.form-group { margin-bottom: 1rem; }
.form-label { font-size: .8rem; font-weight: 600; color: var(--secondary); margin-bottom: .3rem; display: block; }
.form-control {
  width: 100%;
  padding: .6rem .85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  outline: none;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
}
.badge-primary { background: #dbeafe; color: var(--primary); }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }

/* ── Login Page ── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}
.login-logo-img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 20px;
  margin: 0 auto .6rem;
  display: block;
}
.login-logo p  { font-size: .8rem; color: var(--text-muted); margin: 0; }
.btn-login {
  width: 100%;
  padding: .85rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  color: #fff;
  cursor: pointer;
  margin-top: .5rem;
  transition: opacity .15s, transform .1s;
}
.btn-login:hover { opacity: .92; }
.btn-login:active { transform: scale(.98); }
.btn-login:disabled { opacity: .6; cursor: not-allowed; }

/* ── Responsive Desktop ── */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .bottom-nav { display: none; }
  .sidebar {
    position: fixed;
    top: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
    left: 0;
    bottom: 0;
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1rem .75rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    overflow-y: auto;
  }
  .sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem .85rem;
    border-radius: 8px;
    font-size: .88rem;
    font-weight: 500;
    color: var(--secondary);
    cursor: pointer;
    text-decoration: none;
    transition: background .12s, color .12s;
  }
  .sidebar .nav-item i { width: 18px; text-align: center; }
  .sidebar .nav-item:hover { background: var(--bg); color: var(--text); }
  .sidebar .nav-item.active { background: #dbeafe; color: var(--primary); font-weight: 600; }
  /* nav-group (accordion) */
  .sidebar .nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .sidebar .nav-group-toggle .nav-group-arrow {
    margin-left: auto;
    font-size: .7rem;
    transition: transform .2s;
  }
  .sidebar .nav-group-toggle .nav-group-arrow.rotated { transform: rotate(180deg); }
  .sidebar .nav-group-children {
    overflow: hidden;
    max-height: 0;
    transition: max-height .25s ease;
  }
  .sidebar .nav-group-children.open { max-height: 300px; }
  .sidebar .nav-subitem {
    padding: .45rem .75rem .45rem 2.6rem;
    font-size: .82rem;
  }
  .app-content {
    margin-left: 220px;
    max-width: none;
    padding: 1.5rem;
  }
  .cart-fab { bottom: 1.5rem; right: 1.5rem; }
}
@media (max-width: 767px) {
  .sidebar { display: none; }
}

/* ── Settings menu (mobile nav-group modal) ── */
.settings-menu { display: flex; flex-direction: column; gap: .5rem; padding: .25rem 0; }
.settings-menu-item {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .85rem 1rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: .95rem;
  font-weight: 500;
  background: var(--bg);
  transition: background .12s;
}
.settings-menu-item:hover { background: #dbeafe; color: var(--primary); }
.settings-menu-item i { width: 20px; text-align: center; color: var(--primary); }

/* ── Spinner ── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  gap: .75rem;
  color: var(--text-muted);
  font-size: .85rem;
}

/* ── Signature pad ── */
.signature-wrapper {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}
.signature-wrapper canvas {
  display: block;
  width: 100%;
  height: 120px;
  touch-action: none;
  cursor: crosshair;
}
.signature-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: .85rem;
  pointer-events: none;
  gap: .4rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: .75rem; display: block; opacity: .4; }
.empty-state p { font-size: .9rem; }

/* ── Section title ── */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── Quick actions ── */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .5rem;
  margin-bottom: 1.25rem;
}
.quick-btn {
  flex: 0 0 calc((100% - 1rem) / 3);
}
.quick-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem .5rem;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
  transition: box-shadow .15s, transform .1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
}
.quick-btn:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); transform: translateY(-1px); }
.quick-btn i { font-size: 1.5rem; }
.quick-btn span { font-size: .78rem; font-weight: 600; color: var(--text); line-height: 1.2; }

/* ── Logo drop zone (profilo.php) ── */
.logo-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  transition: border-color .2s, background .2s;
  text-align: center;
}
.logo-drop-zone.drag-over {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}
