/* ============================================================
   app.css  —  Gestionale magazzino
   v3 — aggiunto .modal-overlay per centrare le modali
   ============================================================ */

/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f4f3f0;
  --bg-card:     #ffffff;
  --bg-sidebar:  #0f1117;
  --bg-input:    #f9f8f6;

  --text-pri:    #111219;
  --text-sec:    #5c5c6b;
  --text-muted:  #9898a6;
  --text-inv:    #e8e7e3;

  --accent:      #1a56db;
  --accent-lt:   #dbeafe;
  --accent-dk:   #1240a8;

  --ok:          #059669;
  --ok-lt:       #d1fae5;
  --warn:        #d97706;
  --warn-lt:     #fef3c7;
  --danger:      #dc2626;
  --danger-lt:   #fee2e2;
  --info:        #0891b2;
  --info-lt:     #e0f2fe;

  --border:      #e2e1dc;
  --border-dk:   #c8c7c0;

  --radius-sm:   4px;
  --radius:      8px;
  --radius-lg:   12px;

  --shadow-sm:   0 1px 3px rgba(0,0,0,.07);
  --shadow:      0 2px 8px rgba(0,0,0,.09);
  --shadow-lg:   0 8px 24px rgba(0,0,0,.12);

  --sidebar-w:   224px;
  --topbar-h:    56px;
  --t:           150ms ease;
}

html { font-size: 15px; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-weight: 400;
  line-height: 1.55;
  color: var(--text-pri);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout app ───────────────────────────────────────── */
.body--app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar__logo { font-size: 1.4rem; color: var(--accent); line-height: 1; }

.sidebar__name {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-inv);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.sidebar__nav {
  flex: 1;
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  color: rgba(232,231,227,.55);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 400;
  transition: background var(--t), color var(--t);
}

.nav-link:hover { background: rgba(255,255,255,.07); color: var(--text-inv); }

.nav-link--active {
  background: rgba(26,86,219,.18);
  color: #93b4ff;
  font-weight: 500;
}

.nav-icon { font-size: 1rem; width: 1.1rem; text-align: center; flex-shrink: 0; }

.sidebar__user {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.07);
}

.sidebar__user-name {
  display: block;
  font-size: .8rem;
  color: rgba(232,231,227,.6);
  margin-bottom: .3rem;
  font-family: 'DM Mono', monospace;
}

.btn-logout {
  background: none;
  border: 1px solid rgba(255,255,255,.15);
  color: rgba(232,231,227,.5);
  border-radius: var(--radius-sm);
  padding: .3rem .75rem;
  font-size: .8rem;
  cursor: pointer;
  transition: border-color var(--t), color var(--t);
}
.btn-logout:hover { border-color: rgba(255,255,255,.35); color: var(--text-inv); }

/* ── Main ─────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  flex-shrink: 0;
}

.topbar__title { font-size: 1rem; font-weight: 500; letter-spacing: .01em; }
.topbar__mag { display: flex; align-items: center; gap: .5rem; }
.topbar__mag-label { font-size: .8rem; color: var(--text-muted); }

.page-content { flex: 1; overflow-y: auto; padding: 1.75rem; }

/* ── Cards ────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.card--flat { box-shadow: none; }

.card__title {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ── KPI ──────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
}

.stat-card--warn::before   { background: var(--warn); }
.stat-card--danger::before { background: var(--danger); }
.stat-card--ok::before     { background: var(--ok); }

.stat-label {
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.stat-value {
  font-size: 2rem;
  font-weight: 300;
  font-family: 'DM Mono', monospace;
  line-height: 1.2;
  margin-top: .15rem;
}

.stat-value--warn   { color: var(--warn); }
.stat-value--danger { color: var(--danger); }
.stat-value--ok     { color: var(--ok); }

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

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

thead th {
  padding: .65rem 1rem;
  text-align: left;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background var(--t); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

tbody td { padding: .7rem 1rem; color: var(--text-pri); vertical-align: middle; }

td.mono { font-family: 'DM Mono', monospace; font-size: .8rem; color: var(--text-sec); }
td.num  { font-family: 'DM Mono', monospace; text-align: right; font-weight: 500; }

/* ── Badge ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge--ok     { background: var(--ok-lt);    color: #065f46; }
.badge--warn   { background: var(--warn-lt);   color: #78350f; }
.badge--danger { background: var(--danger-lt); color: #7f1d1d; }
.badge--info   { background: var(--info-lt);   color: #0e4f63; }
.badge--muted  { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.badge--super  { background: var(--accent-lt); color: var(--accent-dk); font-size: .65rem; }

/* ── Form ─────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group--full { grid-column: 1 / -1; }

label { font-size: .78rem; font-weight: 500; color: var(--text-sec); letter-spacing: .02em; }

.input, .select, .textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .55rem .75rem;
  font-family: inherit;
  font-size: .875rem;
  color: var(--text-pri);
  transition: border-color var(--t), box-shadow var(--t);
  width: 100%;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}

.input--mono { font-family: 'DM Mono', monospace; font-size: .85rem; }
.select--sm  { padding: .35rem .6rem; font-size: .8rem; }
.textarea    { resize: vertical; min-height: 80px; }

.form-hint  { font-size: .75rem; color: var(--text-muted); }
.form-error { font-size: .75rem; color: var(--danger); }

.checkbox-group { display: flex; align-items: center; gap: .5rem; padding: .55rem 0; }
.checkbox-group input[type=checkbox] { width: 1rem; height: 1rem; accent-color: var(--accent); flex-shrink: 0; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background var(--t), opacity var(--t), transform var(--t);
  text-decoration: none;
  white-space: nowrap;
}

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

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

.btn--ghost { background: transparent; color: var(--text-sec); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--bg); color: var(--text-pri); }

.btn--sm   { padding: .35rem .75rem; font-size: .8rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Filter bar ───────────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: flex-end;
  margin-bottom: 1.25rem;
}

.filter-bar .input,
.filter-bar .select { min-width: 160px; flex: 1; max-width: 260px; }

/* ── Empty state ──────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state__icon { font-size: 2.5rem; margin-bottom: .5rem; }
.empty-state__text { font-size: .9rem; }

/* ── Toast ────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1.1rem;
  border-radius: var(--radius);
  background: var(--text-pri);
  color: var(--text-inv);
  font-size: .85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
  max-width: 340px;
}

.toast--ok     { background: var(--ok); }
.toast--danger { background: var(--danger); }
.toast--warn   { background: var(--warn); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Spinner ──────────────────────────────────────────── */
.spinner {
  width: 1.1rem; height: 1.1rem;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}

.spinner--dark { border: 2px solid var(--border); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login ────────────────────────────────────────────── */
.body--login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-sidebar);
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo  { font-size: 2rem; color: var(--accent); margin-bottom: .25rem; }
.login-title { font-size: 1.25rem; font-weight: 600; margin-bottom: .25rem; }
.login-sub   { font-size: .85rem; color: var(--text-muted); margin-bottom: 2rem; }
.login-form  { display: flex; flex-direction: column; gap: 1rem; }

.login-error {
  background: var(--danger-lt);
  color: #7f1d1d;
  border-radius: var(--radius);
  padding: .6rem .9rem;
  font-size: .85rem;
}

/* ── Utility ──────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-ok     { color: var(--ok); }
.text-warn   { color: var(--warn); }

.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }

.flex        { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-1       { gap: .5rem; }
.gap-2       { gap: 1rem; }
.ml-auto     { margin-left: auto; }

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

.section-title { font-size: .875rem; font-weight: 600; color: var(--text-pri); }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
  .body--app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { height: auto; flex-direction: row; flex-wrap: wrap; position: static; }
  .sidebar__nav { flex-direction: row; flex-wrap: wrap; padding: .5rem; }
  .sidebar__user { display: none; }
  .page-content { padding: 1rem; }
}

/* ── Modali centrate ──────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .45);
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-overlay > div {
  max-height: 90vh;
  overflow-y: auto;
  margin: auto;
  width: 100%;
}

.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
}

.modal-box--wide { max-width: 660px; }
