/* ===== Variables (palette coordinata con logo tondo bianco/nero) ===== */
:root {
  /* Background chiaro neutro e superfici bianche per valorizzare il logo tondo su fondo bianco */
  --color-bg: #f5f5f5;
  --color-surface: #ffffff;
  /* Testo principale quasi nero per massimo contrasto sul bianco del logo */
  --color-text: #111827;
  --color-text-muted: #6b7280;
  /* Primario in linea con la scritta nera del logo */
  --color-primary: #111827;
  --color-primary-hover: #000000;
  /* Accento grigio freddo molto leggero per piccoli dettagli */
  --color-accent: #4b5563;
  /* Bordo neutro chiaro per card, frame del logo e tabelle */
  --color-border: #e5e7eb;
  --color-error: #c0392b;
  --color-success: #27ae60;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-logo: 0 4px 20px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --radius-full: 50%;
  --header-h: 56px;
  --footer-h: 120px;
  /* Touch-friendly min size (WCAG / Apple HIG) */
  --touch-min: 44px;
  /* Safe area for notched devices (PWA fullscreen) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

body.page-home {
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
}

/* ===== Layout: sticky footer ===== */
.site-main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
}

body.page-home .site-main {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0.75rem 1rem;
}

body.page-home .page-home-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.site-footer {
  margin-top: auto;
  background: var(--color-primary);
  color: #e8e8e8;
  padding: 1.25rem 1.5rem;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
  font-size: 0.9rem;
}

body.page-home .site-footer {
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + var(--safe-bottom));
  font-size: 0.85rem;
}

/* ===== Header ===== */
.site-header {
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: var(--safe-top);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem 0 1.5rem;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--color-text);
  font-weight: 600;
}

.site-logo {
  display: block;
  height: auto;
  width: auto;
}

.site-logo-header {
  max-height: 44px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  object-position: left center;
}

.logo-placeholder {
  display: none;
  padding: 0.35rem 0.75rem;
  background: var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.site-logo:not([src]) + .logo-placeholder,
.logo-placeholder.show { display: inline-block; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* ===== Buttons (touch-friendly) ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1rem;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  color: #fff;
}

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

.btn-ghost:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

/* ===== Hero (Home) — logo tondo, occupa 100% viewport ===== */
body.page-home .hero {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1rem;
  min-height: 0;
  background: linear-gradient(180deg, var(--color-surface) 0%, var(--color-bg) 100%);
  border-radius: 0 0 var(--radius) var(--radius);
}

.hero {
  text-align: center;
  padding: 2.5rem 1rem 3.5rem;
  background: linear-gradient(180deg, var(--color-surface) 0%, var(--color-bg) 100%);
  border-radius: 0 0 var(--radius) var(--radius);
}

.hero-content {
  max-width: 560px;
  margin: 0 auto;
}

.hero-logo-wrap {
  /*display: inline-flex;*/
  align-items: center;
  justify-content: center;
  width: 160px;
  height: 160px;
  margin: 0 auto 1.75rem;
  border-radius: var(--radius-full);
  overflow: hidden;
  /* Fondo bianco pieno per il logo rotondo 300x332 */
  background: #ffffff;
  box-shadow: var(--shadow-logo);
  border: 4px solid var(--color-border);
}

.hero-logo-wrap .hero-logo {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  /* Mantiene il rapporto 300x332 dentro al cerchio, senza tagliare i bordi del logo */
  object-fit: contain;
  display: block;
}

body.page-home .hero-claim {
  font-size: clamp(1.25rem, 3vw, 1.65rem);
  margin: 0 0 0.5rem;
}

.hero-claim {
  font-size: clamp(1.4rem, 3.5vw, 1.85rem);
  font-weight: 600;
  color: var(--color-primary);
  margin: 0 0 0.6rem;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

.hero-sub {
  font-size: 0.95rem;
  color: var(--color-text-muted);
  margin: 0;
  max-width: 32em;
  margin-left: auto;
  margin-right: auto;
}

body.page-home .hero-logo-wrap {
  width: clamp(100px, 22vmin, 140px);
  height: clamp(100px, 22vmin, 140px);
  margin-bottom: 1rem;
}

body.page-home .hero-sub {
  font-size: 0.9rem;
}

/* ===== Messages ===== */
body.page-home .messages {
  flex-shrink: 0;
  margin: 0.5rem auto;
}

.messages {
  max-width: 560px;
  margin: 0 auto 2rem;
}

/* Slide "Lavoro definitivo" in homepage: sempre visibile sotto la hero */
body.page-home .home-slide-definitivo {
  flex-shrink: 0;
  max-width: 560px;
  width: 100%;
  margin: 0.75rem auto 0;
  padding: 0 0 0.5rem;
}

.home-slide-definitivo {
  max-width: 560px;
  margin: 1.5rem auto 0;
  padding: 0;
}

.home-slide-definitivo .carousel-home,
body.page-home .home-slide-definitivo .carousel-home {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  background: var(--color-bg);
  min-height: 140px;
}

.home-slide-definitivo .carousel-counter {
  font-size: 0.8rem;
  opacity: 0.9;
}

.message {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin: 0 0 0.5rem;
  background: var(--color-surface);
  border-left: 4px solid var(--color-accent);
}

.message-error { border-left-color: var(--color-error); }
.message-success { border-left-color: var(--color-success); }
.message-warning { border-left-color: #f39c12; }

/* ===== Modal ===== */
/* ===== Modal (fullscreen on small screens) ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: calc(1rem + var(--safe-top)) calc(1rem + var(--safe-right)) calc(1rem + var(--safe-bottom)) calc(1rem + var(--safe-left));
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal-visible {
  opacity: 1;
  visibility: visible;
}

body.modal-open { overflow: hidden; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-box {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

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

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

@media (max-width: 480px) {
  .modal-box {
    max-width: none;
    max-height: none;
    height: 100%;
    border-radius: 0;
  }
  .modal {
    padding: 0;
    align-items: stretch;
  }
}

/* ===== Login form ===== */
.login-form {
  padding: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.form-group input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  min-height: var(--touch-min);
  font-size: 16px; /* evita zoom su iOS */
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(107, 91, 79, 0.2);
}

.form-error {
  color: var(--color-error);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.form-actions .btn { flex: 1; }

/* ===== Footer ===== */
.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* ===== Breakpoints: tablet 768px, phone 480px ===== */
@media (max-width: 768px) {
  .site-main { padding: 1rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-title { font-size: 1.35rem; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .footer-inner { grid-template-columns: 1fr; text-align: center; }
  .header-inner { padding: 0 1rem; }
  .hero { padding: 2rem 1rem 3rem; }
  .hero-claim { font-size: 1.35rem; }
}

@media (max-width: 480px) {
  .header-actions { gap: 0.35rem; }
  .header-actions .btn { padding: 0.5rem 0.75rem; font-size: 0.85rem; }
  .site-logo-header { max-height: 38px; max-width: 140px; }
  .hero-logo-wrap { width: 130px; height: 130px; margin-bottom: 1.25rem; }
}

.footer-contacts {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.footer-contacts a {
  color: #d4cfc4;
  text-decoration: none;
}

.footer-contacts a:hover { text-decoration: underline; }

.footer-center { text-align: right; }
@media (max-width: 640px) { .footer-center { text-align: center; } }

.footer-disclaimer {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.85);
}

.footer-copy {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.7);
}

/* ===== Area riservata: page layout ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title { margin: 0; font-size: 1.5rem; font-weight: 600; color: var(--color-primary); }

/* ===== Orders list table ===== */
.orders-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.orders-table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 0.95rem;
}

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

.orders-table th {
  background: var(--color-bg);
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.orders-table tbody tr {
  transition: background 0.15s;
}

.orders-table tbody tr:hover {
  background: #f5f5f5;
}

.orders-table tbody tr a {
  display: block;
  text-decoration: none;
  color: inherit;
}

.orders-table .num { font-weight: 500; color: var(--color-primary); }
.orders-table .date { white-space: nowrap; }
.orders-table .stato {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
}

.stato-preso { background: #ecf0f1; color: #5c5c5c; }
.stato-lavorazione { background: #fff3cd; color: #856404; }
.stato-attesa { background: #cce5ff; color: #004085; }
.stato-concluso { background: #d4edda; color: #155724; }

.orders-table .totale { font-weight: 600; white-space: nowrap; }

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

/* Lista ordini: layout a card su mobile/tablet */
@media (max-width: 640px) {
  .table-wrap { overflow-x: visible; }
  .orders-table { min-width: 0; }
  .orders-table thead { display: none; }
  .orders-table tbody tr {
    display: block;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    transition: background 0.15s;
  }
  .orders-table tbody tr:hover { background: #f9f9f9; }
  .orders-table tbody tr:last-child { margin-bottom: 0; }
  .orders-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0;
    border: none;
    gap: 0.75rem;
  }
  .orders-table tbody td::before {
    content: attr(data-label);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    flex-shrink: 0;
  }
  .orders-table tbody td.num {
    padding-top: 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.35rem;
  }
  .orders-table tbody td.num::before { display: none; }
  .orders-table tbody td.num a {
    font-size: 1.1rem;
    padding: 0.5rem 0;
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
  }
  .orders-table tbody tr:has(.orders-empty) {
    padding: 1.5rem;
    text-align: center;
  }
  .orders-table tbody tr:has(.orders-empty) td {
    display: block;
    justify-content: center;
  }
  .orders-table tbody tr:has(.orders-empty) td::before { display: none; }
}

/* ===== Order detail (read-only) ===== */
.detail-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.detail-card h3 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: var(--color-primary);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem 1.5rem;
}

.detail-item {
  margin: 0;
}

.detail-item strong {
  display: block;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 0.2rem;
}

.detail-item span { font-size: 0.95rem; }

.articoli-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.articoli-table th,
.articoli-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.articoli-table th {
  background: var(--color-bg);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

@media (max-width: 640px) {
  .detail-card { padding: 1rem; }
  .articoli-table { font-size: 0.9rem; }
  .articoli-table th,
  .articoli-table td { padding: 0.5rem 0.6rem; }
  .documenti-list a { min-height: var(--touch-min); padding: 0.35rem 0; }
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
  padding: 0.5rem 0;
  min-height: var(--touch-min);
  color: var(--color-accent);
  text-decoration: none;
  font-size: 0.95rem;
  -webkit-tap-highlight-color: transparent;
}

.back-link:hover { text-decoration: underline; }

/* ===== Carousel immagini ===== */
.carousel {
  position: relative;
  max-width: 100%;
  background: var(--color-bg);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
}

.carousel-inner {
  position: relative;
  width: 100%;
  height: 100%;
}

.carousel-slide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.carousel-slide.active {
  opacity: 1;
  visibility: visible;
  z-index: 1;
}

.carousel-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.carousel-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.2s;
}

.carousel-btn:hover {
  background: rgba(0,0,0,0.75);
}

.carousel-prev { left: 0.5rem; }
.carousel-next { right: 0.5rem; }

.carousel-counter {
  position: absolute;
  bottom: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  padding: 0.25rem 0.5rem;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.85rem;
  border-radius: 4px;
}

@media (max-width: 480px) {
  .carousel-btn {
    width: var(--touch-min);
    height: var(--touch-min);
    font-size: 1.25rem;
    -webkit-tap-highlight-color: transparent;
  }
  .carousel-prev { left: 0.35rem; }
  .carousel-next { right: 0.35rem; }
}

/* ===== Documenti ===== */
.documenti-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.documenti-list li {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}

.documenti-list li:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.documenti-list a {
  color: var(--color-accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.documenti-list a:hover { text-decoration: underline; }

.documenti-list a::before {
  content: "📄";
  font-size: 1rem;
}

/* ===== PWA & iOS ottimizzazioni ===== */
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  -webkit-overflow-scrolling: touch;
  -webkit-touch-callout: none;
}
.pwa-standalone body {
  overflow-x: hidden;
  overscroll-behavior-y: none;
}
.pwa-standalone .site-main {
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 768px) {
  .btn, .header-actions a, .back-link, .dashboard-nav-item {
    -webkit-tap-highlight-color: transparent;
  }
  input, select, textarea {
    font-size: 16px;
  }
}
