/* ============================================
   ELETTROMECCANICA MARANZAN - CSS UNIFICATO
   ============================================ */

/* ===== RESET GLOBALE ===== */
* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

/* ===== VARIABILI CSS ===== */
:root {
  /* Colori base */
  --bg: #ffffff;
  --fg: #222222;

  /* Bordi */
  --border: #dddddd;
  --border-strong: #000000;

  /* Input e panel */
  --input-bg: #ffffff;
  --panel-bg: #ffffff;

  /* Pulsanti */
  --btn-primary-bg: #000000;
  --btn-primary-fg: #ffffff;
  --btn-secondary-bg: #f5f5f5;
  --btn-secondary-fg: #222222;

  /* Tastiera magazzino */
  --key-bg: #ffffff;
  --key-active: #f0f0f0;

  /* Stati */
  --error: #b00020;
  --success: #00A86B;
  --placeholder: #9aa0a6;
}

/* ===== DARK MODE ===== */
@media (prefers-color-scheme: dark) {
  /* Dark mode per private e riparazioni */
  body:not(.theme-light) {
    --bg: #000000;
    --fg: #ffffff;
    --border: #2a2b2d;
    --border-strong: #6a6b6d;
    --input-bg: #1a1a1a;
    --panel-bg: #000000;
    --btn-primary-bg: #ffffff;
    --btn-primary-fg: #000000;
    --btn-secondary-bg: #2a2a2a;
    --btn-secondary-fg: #ffffff;
    --placeholder: #8a8f98;
    --error: #ff4d4f;
    --key-bg: #000000;
    --key-active: #222427;
  }

  /* Dark mode specifico per magazzino */
  body.touch-app:not(.theme-light) {
    --bg: #000000;
    --fg: #ffffff;
    --panel-bg: #000000;
    --border: #2a2b2d;
    --border-strong: #6a6b6d;
    --key-bg: #000000;
    --key-active: #222427;
    --placeholder: #8a8f98;
    --error: #ff4d4f;
  }
}

/* Manual force dark per magazzino */
body.touch-app.theme-dark {
  --bg: #000000;
  --fg: #ffffff;
  --panel-bg: #000000;
  --border: #2a2b2d;
  --border-strong: #6a6b6d;
  --key-bg: #000000;
  --key-active: #222427;
  --placeholder: #8a8f98;
  --error: #ff4d4f;
}

/* ===== BODY BASE ===== */
body {
  font-family: Helvetica, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 18px;
  line-height: 1.5;
}

/* Controlli form ereditano font */
button, input {
  font: inherit;
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== TOAST NOTIFICATION ===== */
.toast {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top, 0));
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.toast.success {
  background: var(--success);
  color: #ffffff;
}

.toast.error {
  background: var(--error);
  color: #ffffff;
}

.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-20px);
}


/* ============================================
   HOMEPAGE PUBBLICA (index.html)
   ============================================ */

.homepage {
  padding: calc(0.3em + env(safe-area-inset-top, 0)) 0.3em calc(0.3em + env(safe-area-inset-bottom, 0));
  flex: 1;
}

body:has(.homepage) {
  background: #fafafa;
  color: #222;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  font-size: clamp(11px, 3.5vw, 18px);
  -webkit-text-size-adjust: 100%;
}

.contenitore {
  max-width: 100vw;
  padding: 0 0.2em;
  font-size: clamp(11px, 3.5vw, 18px);
}

.homepage p {
  font-size: clamp(11px, 3.5vw, 18px);
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.homepage a {
  color: inherit;
  text-decoration: underline;
}

#conferma-piva {
  font-size: clamp(11px, 3.5vw, 18px);
  color: green;
  margin-left: 0.5em;
  display: none;
  white-space: nowrap;
}

.footer {
  font-size: clamp(11px, 3.5vw, 18px);
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.2;
  font-weight: normal;
  letter-spacing: normal;
  padding: 0.2em;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-text-size-adjust: 100%;
}

.footer p {
  margin: 0;
  font-size: clamp(11px, 3.5vw, 18px);
}


/* ============================================
   PRIVATE HUB (private.html)
   ============================================ */

.hub {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 0) 1rem env(safe-area-inset-bottom, 0);
}

.menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  width: 100%;
  max-width: 600px;
}

.menu-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.menu-item {
  font-size: 18px;
  color: var(--fg);
  text-decoration: none;
  text-align: center;
  transition: opacity 0.2s ease;
}

.menu-item.main-item {
  text-decoration: underline;
  font-weight: normal;
}

.menu-item.sub-item {
  text-decoration: none;
  font-weight: normal;
  font-size: 13.5px;
}

.menu-item:hover,
.menu-item:active {
  opacity: 0.6;
}

@media (min-width: 768px) {
  .menu {
    gap: 2.5rem;
  }
}


/* ============================================
   MAGAZZINO (magazzino.html)
   ============================================ */

body.touch-app {
  font-family: -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: clamp(8px, 2.5vw, 18px);
  -webkit-user-select: none;
  user-select: none;
}

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

#results-area {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  padding-bottom: 180px;
  padding-top: 6px;
}

.block {
  margin-bottom: 0;
}

.block h3 {
  margin: 0;
  padding-left: 6px;
  font-weight: 600;
  font-size: 18px;
}

.block p,
.block div {
  font-size: 18px;
  padding-left: 6px !important;
  margin: 0;
}

#top-results h3,
#suggestions h3 {
  font-size: 18px !important;
}

.table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 18px;
  -webkit-user-select: text;
  user-select: text;
}

.table tr + tr td {
  border-top: 1px solid var(--border);
}

.table td {
  padding: 6px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.table .td-codice {
  text-align: left;
  font-weight: 500;
  width: 30%;
}

.table .td-desc {
  text-align: left;
  width: 55%;
}

.table .td-scaffale {
  text-align: right;
  width: 15%;
  white-space: nowrap;
}

.input-zone {
  position: fixed;
  left: 0;
  right: 0;
  bottom: env(safe-area-inset-bottom, 0);
  background: var(--panel-bg);
  padding: 0.3rem 0.2rem 0.3rem;
  border-top: 1px solid var(--panel-bg);
  z-index: 10;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.input-container {
  flex: 1;
  position: relative;
}

.code-input {
  width: 100%;
  font-size: 16px;
  line-height: 1.2;
  padding: 10px 12px;
  padding-right: 2.8em;
  border: 1px solid var(--border-strong);
  background: var(--panel-bg);
  color: var(--fg);
  border-radius: 14px;
}

.menu-inside {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.menu-inside svg {
  display: block;
}

.kbd-toggle {
  font-size: 16px;
  line-height: 1;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  background: var(--panel-bg);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-flow: row;
  gap: 6px;
}

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: var(--key-bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  touch-action: manipulation;
  user-select: none;
  aspect-ratio: 1 / 1;
  min-height: 54px;
}

.key:active {
  background: var(--key-active);
}

.code-input::placeholder {
  color: var(--placeholder);
  opacity: 1;
}

.code-input::-webkit-input-placeholder {
  color: var(--placeholder);
  opacity: 1;
}

.code-input::-moz-placeholder {
  color: var(--placeholder);
  opacity: 1;
}

.code-input:-ms-input-placeholder {
  color: var(--placeholder);
  opacity: 1;
}

.code-input.error::placeholder {
  color: var(--error);
  opacity: 1;
}

.code-input.error::-webkit-input-placeholder {
  color: var(--error);
  opacity: 1;
}

.code-input.error::-moz-placeholder {
  color: var(--error);
  opacity: 1;
}

.code-input.error:-ms-input-placeholder {
  color: var(--error);
  opacity: 1;
}

.long-press-indicator {
  position: fixed;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(0, 122, 255, 0.2);
  border: 3px solid rgba(0, 122, 255, 0.6);
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
  z-index: 9999;
  transition: transform 0.2s ease;
}

.long-press-indicator.active {
  transform: translate(-50%, -50%) scale(1);
  animation: long-press-fill 2.5s linear forwards;
}

.long-press-indicator.complete {
  background: rgba(0, 122, 255, 0.8);
  border-color: rgba(0, 122, 255, 1);
  animation: long-press-complete 0.3s ease forwards;
}

@keyframes long-press-fill {
  from {
    background: rgba(0, 122, 255, 0.2);
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    background: rgba(0, 122, 255, 0.6);
    transform: translate(-50%, -50%) scale(1.2);
  }
}

@keyframes long-press-complete {
  0% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
  }
}

.app,
#results-area,
.contenitore {
  touch-action: pan-y;
}

@media (min-width: 768px) {
  .app {
    max-width: 800px;
    margin: 0 auto;
  }

  #results-area,
  .input-zone {
    max-width: 800px;
    margin: 0 auto;
  }

  .input-zone {
    bottom: env(safe-area-inset-bottom, 0);
  }
}


/* ============================================
   RIPARAZIONI E FORMS
   (riparazioni-*.html, magazzino-nuovo.html, magazzino-dettaglio.html)
   ============================================ */

.app:not(.touch-app) {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(0.3em + env(safe-area-inset-top, 0)) 1rem calc(0.3em + env(safe-area-inset-bottom, 0));
  max-width: 800px;
  margin: 0 auto;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  font-size: 24px;
  font-weight: 600;
  margin: 0;
}

.counter {
  font-size: 14px;
  color: var(--success);
  margin-top: 0.5rem;
  font-weight: 500;
}

/* Coda inserimenti */
.coda-container {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.coda-container.hidden {
  display: none;
}

.coda-container h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 1rem 0;
  text-align: center;
}

.coda-lista {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.empty-queue {
  text-align: center;
  color: var(--border-strong);
  font-size: 14px;
  padding: 2rem 0;
}

.coda-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: background 0.2s ease;
}

.coda-item:hover {
  background: var(--btn-secondary-bg);
}

.coda-item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.coda-item-codice {
  font-weight: 600;
  font-size: 16px;
}

.coda-item-desc {
  font-size: 14px;
  color: var(--border-strong);
}

.coda-item-scaff {
  font-size: 13px;
  color: var(--border-strong);
  font-family: 'Courier New', monospace;
}

.coda-item-remove {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--btn-secondary-bg);
  color: var(--fg);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.coda-item-remove:hover {
  background: var(--error);
  color: #ffffff;
  border-color: var(--error);
}

.coda-actions {
  display: flex;
  gap: 1rem;
}

.coda-actions button {
  flex: 1;
}

/* Form */
.form-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
}

.form-group label {
  font-size: 16px;
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  font-size: 16px;
  padding: 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--fg);
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--fg);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  margin: 0;
}

.checkbox-label span {
  user-select: none;
}

/* Autocomplete */
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 10;
  display: none;
}

.autocomplete-list.show {
  display: block;
}

.autocomplete-item {
  padding: 0.75rem;
  cursor: pointer;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover {
  background: var(--btn-secondary-bg);
}

/* Attrezzi */
.attrezzo-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1rem;
  position: relative;
}

.attrezzo-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.attrezzo-label {
  font-weight: 500;
  font-size: 16px;
}

.btn-remove {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 20px;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.attrezzo-item input {
  margin-bottom: 0.5rem;
}

/* Buttons */
button {
  font-family: inherit;
  font-size: 16px;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  cursor: pointer;
  transition: opacity 0.2s;
}

button:active {
  opacity: 0.7;
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  border-color: var(--btn-primary-bg);
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-fg);
  border-color: var(--border-strong);
}

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

.form-actions button {
  flex: 1;
}

/* Popup */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

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

.popup-content {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 2rem;
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.popup-content h2 {
  margin: 0 0 1rem 0;
  font-size: 20px;
  text-align: center;
}

#popup-riepilogo {
  margin-bottom: 1.5rem;
  font-size: 16px;
  line-height: 1.6;
}

#popup-riepilogo p {
  margin: 0.5rem 0;
}

#popup-riepilogo strong {
  font-weight: 600;
}

.popup-actions {
  display: flex;
  gap: 1rem;
}

.popup-actions button {
  flex: 1;
}

/* Controlli archivio */
.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.search-box {
  display: flex;
  gap: 0.5rem;
}

.search-box input {
  flex: 1;
  font-size: 16px;
  padding: 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--fg);
}

.toggle-group {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
}

.toggle-btn {
  flex: 1;
  padding: 0.75rem;
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-fg);
  border: none;
  border-right: 1px solid var(--border-strong);
  cursor: pointer;
  font-size: 16px;
}

.toggle-btn:last-child {
  border-right: none;
}

.toggle-btn.active {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
}

/* Tabella archivio responsive */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table thead {
  border-bottom: 2px solid var(--border-strong);
}

.table th {
  text-align: left;
  padding: 0.75rem 0.5rem;
  font-weight: 600;
}

.table tbody tr {
  cursor: pointer;
  transition: background 0.2s;
}

.table tbody tr:hover {
  background: var(--btn-secondary-bg);
}

.table .td-numero {
  width: 20%;
  text-align: left;
}

.table .td-data {
  width: 20%;
  text-align: left;
}

.table .td-cliente {
  width: 40%;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table .td-stato {
  width: 20%;
  text-align: left;
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
}

.badge.completato-si {
  background: var(--success);
  color: white;
}

.badge.completato-no {
  background: var(--error);
  color: white;
}

@media (max-width: 768px) {
  .table {
    font-size: 14px;
  }

  .table th,
  .table td {
    padding: 0.5rem 0.25rem;
  }
}

/* Empty message */
.empty-message {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--fg);
  opacity: 0.6;
}

.empty-message.hidden {
  display: none;
}

.empty-message p {
  margin: 0;
  font-size: 18px;
}

/* Dettaglio scheda */
.detail-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.detail-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.detail-label {
  font-size: 14px;
  color: var(--fg);
  opacity: 0.7;
}

.detail-value {
  font-size: 18px;
  font-weight: 500;
}

.attrezzi-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.attrezzo-card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.attrezzo-card h4 {
  margin: 0 0 0.5rem 0;
  font-size: 16px;
}

.attrezzo-card p {
  margin: 0;
  font-size: 14px;
  opacity: 0.8;
}

/* Navigation buttons */
.nav-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  align-items: center;
  justify-content: center;
}

.nav-btn {
  padding: 0.75rem 1rem;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 50px;
}

.nav-btn.burger {
  font-size: 16px;
}
