:root {
  --bg: #f7f7f8;
  --card-bg: #ffffff;
  --border: #e6e6e8;
  --text: #17171a;
  --text-muted: #8a8a91;
  --text-faint: #b4b4ba;
  --accent: #17171a;
  --success: #1f9d55;
  --success-bg: #e8f7ee;
  --danger: #d6373f;
  --danger-bg: #fdecec;
  --info: #2b6ff0;
  --info-bg: #eaf1fe;
  --warning: #b8790a;
  --warning-bg: #fdf3e0;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 25, 0.04), 0 1px 8px rgba(20, 20, 25, 0.03);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }

/* ---------- LOGIN ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-card form { margin-top: 24px; display: flex; flex-direction: column; gap: 8px; }

.login-card label { font-size: 13px; font-weight: 500; color: var(--text-muted); }

.login-card input {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 8px;
}

.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.error-msg { color: var(--danger); font-size: 13px; margin: 0 0 8px; }

/* ---------- BRAND ---------- */
.brand { display: flex; align-items: center; gap: 12px; }

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.brand h1 { font-size: 16px; margin: 0; font-weight: 700; }
.brand p { font-size: 11px; margin: 0; color: var(--text-muted); letter-spacing: 0.04em; }

/* ---------- BUTTONS ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #2b2b30; }
.btn-block { width: 100%; margin-top: 4px; }

/* ---------- APP SHELL ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
}

.sidebar .brand { padding: 4px 4px 20px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.depositi-label { font-size: 10px; letter-spacing: 0.06em; color: var(--text-faint); font-weight: 600; }
.depositi-value { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.btn-logout {
  margin-top: 14px;
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}
.btn-logout:hover { background: var(--bg); color: var(--text); }

/* ---------- CONTENT ---------- */
.content { flex: 1; padding: 32px 40px; max-width: 1600px; width: 100%; }

.page-eyebrow { font-size: 11px; letter-spacing: 0.08em; color: var(--text-faint); font-weight: 600; }
.page-title { font-size: 30px; font-weight: 800; margin: 4px 0 28px; }

/* ---------- STAT CARDS ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.stat-icon {
  background: var(--bg);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.stat-value { font-size: 28px; font-weight: 800; margin-top: 10px; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- PANELS ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1.4fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 16px; margin-bottom: 16px; }

.deposito-row-totale {
  background: var(--accent) !important;
  color: #fff;
}
.deposito-row-totale .deposito-name { color: #fff; font-weight: 600; }
.deposito-row-totale .deposito-qty { color: #fff; }

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 14px;
}

.panel-title.warning { color: var(--warning); }

.deposito-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 500;
}

.deposito-qty { font-weight: 700; font-size: 16px; }

.movimenti-list { display: flex; flex-direction: column; gap: 12px; }

.movimento-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.movimento-info { display: flex; flex-direction: column; gap: 4px; }

.movimento-desc { font-size: 13px; font-weight: 600; }
.movimento-meta { font-size: 12px; color: var(--text-muted); }
.movimento-qty { font-size: 15px; font-weight: 700; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  width: fit-content;
}

.badge-carico { background: var(--success-bg); color: var(--success); }
.badge-scarico { background: var(--danger-bg); color: var(--danger); }
.badge-trasferimento { background: var(--info-bg); color: var(--info); }

.empty-msg { color: var(--text-muted); font-size: 13px; }

.low-stock-panel { margin-top: 16px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
}

.placeholder-panel {
  background: var(--card-bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- PAGE HEADER / TOOLBAR ---------- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}
.page-header .page-title { margin-bottom: 0; }

.toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }

.input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--card-bg);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#prodotti-search, #fornitori-search { flex: 1; min-width: 220px; }
.select { min-width: 180px; }

.btn-secondary { background: var(--card-bg); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #188046; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b52d34; }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #1f5bd0; }

.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.modal-sm { max-width: 420px; }
.field-hint { font-size: 12px; color: var(--text-muted); margin: 8px 0 0; display: block; }

/* ---------- BACKUP & STRUMENTI ---------- */
.tool-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tool-icon {
  width: 40px;
  height: 40px;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.tool-card h3 { font-size: 15px; margin: 4px 0 0; }
.tool-card p { font-size: 13px; color: var(--text-muted); margin: 0 0 6px; flex: 1; }

.btn-block { width: 100%; text-align: center; display: inline-block; text-decoration: none; box-sizing: border-box; }

.backup-auto-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; font-size: 14px; }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: 0.2s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }

.backup-auto-fields { padding-top: 4px; }

/* ---------- TABLE ---------- */
.table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .cell-muted { color: var(--text-muted); font-size: 12px; }
.data-table .cell-strong { font-weight: 700; }

.price-cell { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.price-sub { font-size: 11px; color: var(--text-muted); }
.th-sub { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text-faint); }

.iva-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--warning);
  background: var(--warning-bg);
  padding: 2px 7px;
  border-radius: 6px;
  margin-left: 6px;
  vertical-align: middle;
}

.price-preview-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}
.price-preview-iva { opacity: 0.85; font-size: 13px; }
.price-preview-iva strong { font-size: 15px; }
.mode-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.mode-tag.auto { color: var(--success); border-color: var(--success-bg); background: var(--success-bg); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  padding: 6px;
  border-radius: 6px;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }
.icon-btn.success:hover { background: var(--success-bg); color: var(--success); }
.icon-btn.info:hover { background: var(--info-bg); color: var(--info); }

/* ---------- OROLOGIO SIDEBAR ---------- */
.sidebar-clock {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  white-space: nowrap;
}

/* ---------- APPUNTAMENTI ---------- */
.panel-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel-title-row .panel-title { margin-bottom: 0; }
.panel-title-row .icon-btn {
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  padding: 5px 10px;
}

.appuntamenti-panel { margin-top: 16px; }
.appuntamenti-list { display: flex; flex-direction: column; gap: 10px; }

.appuntamento-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.appuntamento-data {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}
.appuntamento-ora { font-size: 11px; font-weight: 500; color: var(--text-muted); }
.appuntamento-info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.appuntamento-titolo { font-size: 13px; font-weight: 600; }
.appuntamento-note { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty-msg { padding: 30px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ---------- FORNITORI CARDS ---------- */
.fornitori-list { display: flex; flex-direction: column; gap: 14px; }

.fornitore-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.fornitore-card-head { display: flex; justify-content: space-between; align-items: flex-start; }
.fornitore-name { font-size: 16px; font-weight: 700; }
.fornitore-piva { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.fornitore-meta { font-size: 13px; color: var(--text-muted); margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }

.fornitore-rappresentante {
  margin-top: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}
.fornitore-rappresentante .label { font-size: 10px; letter-spacing: 0.05em; color: var(--text-faint); font-weight: 700; margin-bottom: 4px; }

.fornitore-sconti { margin-top: 12px; }
.fornitore-sconti .label { font-size: 10px; letter-spacing: 0.05em; color: var(--text-faint); font-weight: 700; margin-bottom: 6px; }
.sconto-chip {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  margin-right: 6px;
}

/* ---------- MODALS ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 25, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 28px 28px;
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-header h3 { margin: 0; font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-close:hover { color: var(--text); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: 13px; font-weight: 500; color: var(--text-muted); margin-bottom: 5px; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 18px 0 10px;
}
.form-section-label:first-child { margin-top: 0; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- PREZZO BOX (dentro la modale Prodotto) ---------- */
.price-box {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.price-box-label { font-size: 10px; letter-spacing: 0.05em; color: var(--text-faint); font-weight: 700; margin-bottom: 10px; }

.toggle-group { display: flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 14px; }
.toggle-btn {
  flex: 1;
  padding: 9px;
  border: none;
  background: var(--card-bg);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
}
.toggle-btn.active { background: var(--accent); color: #fff; }

.price-preview {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
}
.price-preview strong { font-size: 18px; }

/* ============================================================
   RESPONSIVE — tablet e mobile
   ============================================================ */

/* Tablet: barra laterale più stretta, layout a 2 colonne diventa 1 */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .three-col { grid-template-columns: 1fr; }
  .content { padding: 24px 20px; max-width: 100%; }
  .sidebar { width: 200px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile: la sidebar diventa una barra orizzontale in alto, scrollabile */
@media (max-width: 680px) {
  .app-shell { flex-direction: column; min-height: 100vh; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    padding: 10px 12px;
    gap: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar .brand {
    border-bottom: none;
    padding: 0;
    margin: 0 8px 0 0;
    flex-shrink: 0;
  }
  .brand h1 { font-size: 14px; }
  .brand p { display: none; }
  .brand-icon { width: 34px; height: 34px; font-size: 16px; }

  .nav {
    flex-direction: row;
    flex: 0 0 auto;
    gap: 4px;
  }
  .nav-item {
    white-space: nowrap;
    padding: 8px 10px;
    font-size: 13px;
  }
  .nav-icon { display: none; }

  .sidebar-footer {
    border-top: none;
    margin: 0 0 0 auto;
    padding: 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
  }
  .depositi-label, .depositi-value { display: none; }
  .btn-logout { margin-top: 0; width: auto; padding: 8px 10px; white-space: nowrap; }

  .content { padding: 18px 14px; }
  .page-title { font-size: 22px; }
  .page-eyebrow { font-size: 10px; }

  .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-header .btn { width: 100%; }
  .header-actions { flex-direction: column; }
  .header-actions .btn { width: 100%; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 20px; margin-top: 6px; }
  .stat-head { font-size: 10px; }

  .toolbar { flex-direction: column; }
  .toolbar .input, .toolbar .select { width: 100%; min-width: 0; }

  .table-wrap { border-radius: var(--radius-sm); }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 9px 10px; }

  .fornitore-card { padding: 14px; }
  .fornitore-card-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .row-actions { align-self: flex-end; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 20px 18px 24px;
  }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }

  .login-card { padding: 24px; }
}

/* Schermi molto piccoli */
@media (max-width: 420px) {
  .stat-grid { grid-template-columns: 1fr; }
  .nav-item { padding: 8px; font-size: 12px; }
}
