/* Gestionale Stampa 3D — tipografia & variabili */
@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap");

:root {
  --bg: #0c0f14;
  --bg-elevated: #141a24;
  --bg-card: #1a2230;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8edf5;
  --text-muted: #8b95a8;
  --accent: #3dd6c6;
  --accent-dim: rgba(61, 214, 198, 0.15);
  --accent-hover: #5ae8d9;
  --warning: #f0b429;
  --danger: #f07178;
  --success: #7fd962;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  font-family: var(--font);
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(61, 214, 198, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(100, 120, 255, 0.06), transparent);
  color: var(--text);
  line-height: 1.5;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button,
.btn,
a.nav-item,
.modal-close,
.btn-icon {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(61, 214, 198, 0.15);
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.field textarea {
  min-height: 80px;
  resize: vertical;
}

.field-hint {
  margin: 0.35rem 0 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.gf-image-preview-wrap {
  margin-top: 0.65rem;
}

.gf-image-preview {
  max-width: 100%;
  max-height: 200px;
  width: auto;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: contain;
  background: var(--bg-elevated);
}

.product-extras-details {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  background: var(--bg-elevated);
}

.product-extras-details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.product-extras-body {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.product-extras-body .field:last-child {
  margin-bottom: 0;
}

.product-photo-cell,
.th-photo {
  width: 72px;
  vertical-align: middle;
}

.product-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
}

.product-thumb-placeholder {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.15rem;
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #0a0e12;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--text-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-danger {
  background: rgba(240, 113, 120, 0.15);
  color: var(--danger);
  border-color: rgba(240, 113, 120, 0.35);
}

.btn-danger:hover {
  background: rgba(240, 113, 120, 0.25);
}

.btn-block {
  width: 100%;
  margin-top: 0.5rem;
}

.btn-sm {
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  min-height: 40px;
}

/* --- App layout --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(0.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.75rem
    max(1rem, env(safe-area-inset-left));
  background: rgba(12, 15, 20, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent), #6b8cff);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  color: #0a0e12;
}

.app-brand h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.app-brand span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 1.25rem 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  background: none;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-left-color: var(--accent);
}

.nav-icon {
  font-size: 1.1rem;
  opacity: 0.9;
}

.main {
  flex: 1;
  padding: 1.5rem 2rem max(2rem, env(safe-area-inset-bottom));
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.view-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 2;
}

.view-header .btn.btn-primary {
  position: relative;
  z-index: 3;
}

.view-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.view-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Azioni rapide (dashboard / mobile) */
.quick-actions {
  margin-bottom: 1.75rem;
}

.quick-actions-title {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

.quick-action {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 52px;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(61, 214, 198, 0.12);
  transition: background 0.15s, border-color 0.15s;
}

.quick-action:active {
  background: var(--bg-elevated);
  border-color: var(--accent);
}

.quick-action .qa-icon {
  font-size: 1.15rem;
  opacity: 0.85;
}

@media (min-width: 769px) {
  .quick-actions-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* --- Stats --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card .label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  font-family: var(--mono);
  margin-top: 0.35rem;
  color: var(--accent);
}

/* --- Tables & cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.data-table th,
table.data-table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.data-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--bg-elevated);
}

table.data-table tr:last-child td {
  border-bottom: none;
}

table.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

table.data-table .mono {
  font-family: var(--mono);
  font-size: 0.85rem;
}

.empty-state {
  padding: 3rem 2rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state p {
  margin: 0 0 1rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-pending,
.badge-bozza,
.badge-draft {
  background: rgba(240, 180, 41, 0.2);
  color: var(--warning);
}

.badge-in_progress,
.badge-inviato,
.badge-sent {
  background: rgba(100, 160, 255, 0.2);
  color: #8cb4ff;
}

.badge-completed,
.badge-accept,
.badge-accettato,
.badge-accepted {
  background: rgba(127, 217, 98, 0.2);
  color: var(--success);
}

.badge-shipped,
.badge-spedito {
  background: rgba(61, 214, 198, 0.2);
  color: var(--accent);
}

.badge-cancelled,
.badge-rifiutato,
.badge-rejected,
.badge-cancellato,
.badge-canceled {
  background: rgba(240, 113, 120, 0.2);
  color: var(--danger);
}

.badge-expired,
.badge-scaduto {
  background: rgba(139, 149, 168, 0.25);
  color: var(--text-muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99990;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
  overscroll-behavior: contain;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: min(90vh, 90dvh);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: scale(0.96);
  transition: transform 0.2s;
}

.modal-backdrop.open .modal {
  transform: scale(1);
}

.modal.modal-wide {
  max-width: 720px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* Line items builder */
.line-items {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--bg-elevated);
}

.line-item-row {
  display: grid;
  grid-template-columns: 1fr 70px 100px 36px;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}

.line-item-row:last-child {
  margin-bottom: 0;
}

.line-item-row .field {
  margin-bottom: 0;
}

.line-item-row input,
.line-item-row select {
  padding: 0.45rem 0.5rem;
  font-size: 0.88rem;
}

.btn-icon {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  line-height: 1;
}

.line-total-preview {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--accent);
  margin-top: 0.75rem;
  text-align: right;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom));
  right: max(1rem, env(safe-area-inset-right));
  left: auto;
  max-width: calc(100vw - 2rem - env(safe-area-inset-left) - env(safe-area-inset-right));
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast-container .toast {
  pointer-events: auto;
}

.toast {
  padding: 0.85rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: slideIn 0.25s ease;
}

.toast.error {
  border-color: rgba(240, 113, 120, 0.5);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 15, 20, 0.7);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--text-muted);
}

.loading-overlay.hidden {
  display: none;
}

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem max(0.5rem, env(safe-area-inset-left)) 0.5rem
      max(0.5rem, env(safe-area-inset-right));
    gap: 0.35rem;
    scrollbar-width: none;
  }

  .sidebar::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    flex: 0 0 auto;
    min-height: 48px;
    padding: 0.65rem 1rem;
    border-left: none;
    border-radius: var(--radius-sm);
    justify-content: center;
    white-space: nowrap;
    font-size: 0.88rem;
  }

  .nav-item.active {
    border-left: none;
  }

  .app-shell {
    flex-direction: column;
  }

  .main {
    padding: 1rem max(1rem, env(safe-area-inset-left)) max(1.5rem, env(safe-area-inset-bottom))
      max(1rem, env(safe-area-inset-right));
  }

  .view-header {
    flex-direction: column;
    align-items: stretch;
  }

  .view-header .btn {
    width: 100%;
    order: -1;
    min-height: 50px;
    font-size: 1rem;
  }

  .view-header h2 {
    font-size: 1.35rem;
  }

  .app-brand h1 {
    font-size: 1rem;
    line-height: 1.2;
  }

  .app-brand span {
    font-size: 0.68rem;
    line-height: 1.3;
  }

  .app-logo {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  /* Evita zoom iOS su focus negli input (<16px) */
  .field input,
  .field textarea,
  .field select,
  .line-item-row input,
  .line-item-row select {
    font-size: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-card .value {
    font-size: 1.4rem;
  }

  table.data-table {
    font-size: 0.85rem;
  }

  table.data-table th,
  table.data-table td {
    padding: 0.75rem 0.65rem;
  }

  table.data-table .btn {
    width: auto;
    min-height: 40px;
    margin: 0.15rem 0.15rem 0.15rem 0;
  }

  .modal-backdrop {
    align-items: flex-end;
    justify-content: stretch;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .modal {
    max-height: min(92vh, 92dvh);
    border-radius: var(--radius) var(--radius) 0 0;
    margin: 0;
    transform: translateY(104%);
  }

  .modal-backdrop.open .modal {
    transform: translateY(0);
  }

  .modal.modal-wide {
    max-width: none;
  }

  .modal-footer {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .modal-footer .btn {
    flex: 1 1 auto;
    min-width: calc(50% - 0.25rem);
    min-height: 48px;
  }

  .line-item-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
  }

  .line-item-row:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
  }

  .line-item-row .field {
    width: 100%;
  }

  .line-item-row .btn-icon {
    align-self: flex-end;
  }

  .line-total-preview {
    text-align: left;
    font-size: 1.05rem;
  }

  #btn-add-line {
    width: 100%;
    min-height: 48px;
  }

  .toast-container {
    left: max(1rem, env(safe-area-inset-left));
    right: max(1rem, env(safe-area-inset-right));
  }

  .toast {
    font-size: 0.95rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-backdrop,
  .toast {
    transition: none !important;
    animation: none !important;
  }
}
