/* ==========================================================================
   Gestionale – tema grafico (Bootstrap 5)
   ========================================================================== */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #e8efff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6e9f2;
  --bg: #f4f6fb;
  --sidebar-w: 252px;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.1);

  /* Personalizzazione Bootstrap 5.3 */
  --bs-primary: #2563eb;
  --bs-primary-rgb: 37, 99, 235;
  --bs-primary-text-emphasis: #1d4ed8;
  --bs-primary-bg-subtle: #e8efff;
  --bs-link-color-rgb: 37, 99, 235;
  --bs-link-hover-color-rgb: 29, 78, 216;
  --bs-body-font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --bs-body-color: #0f172a;
  --bs-body-bg: #f4f6fb;
  --bs-border-color: #e6e9f2;
  --bs-border-radius: 10px;
  --bs-border-radius-lg: 14px;
  --bs-focus-ring-color: rgba(37, 99, 235, 0.18);
}

body {
  background: var(--bg);
  color: var(--ink);
  font-size: 0.93rem;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.01em;
}

a {
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ------------------------------------------------------------- pulsanti */
.btn {
  --bs-btn-border-radius: 10px;
  font-weight: 600;
  font-size: 0.875rem;
}

.btn-sm {
  --bs-btn-border-radius: 9px;
  font-size: 0.82rem;
}

.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-dark);
  --bs-btn-hover-border-color: var(--brand-dark);
  --bs-btn-active-bg: var(--brand-dark);
  --bs-btn-active-border-color: var(--brand-dark);
  --bs-btn-disabled-bg: #9db9f7;
  --bs-btn-disabled-border-color: #9db9f7;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}

.btn-outline-primary {
  --bs-btn-color: var(--brand);
  --bs-btn-border-color: #bcd0fb;
  --bs-btn-hover-bg: var(--brand-soft);
  --bs-btn-hover-color: var(--brand-dark);
  --bs-btn-hover-border-color: var(--brand);
  --bs-btn-active-bg: var(--brand);
  --bs-btn-active-color: #fff;
  --bs-btn-active-border-color: var(--brand);
}

.btn-light {
  --bs-btn-bg: #ffffff;
  --bs-btn-border-color: var(--line);
  --bs-btn-hover-bg: #f6f8fd;
  --bs-btn-hover-border-color: #d7dce8;
}

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

.app-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* -------------------------------------------------------------- sidebar */
.sidebar {
  width: var(--sidebar-w);
  position: fixed;
  inset: 0 auto 0 0;
  overflow-y: auto;
  z-index: 1030;
  color: #b9c4d9;
  background:
    radial-gradient(420px 260px at -10% 0%, rgba(37, 99, 235, 0.35), transparent 60%),
    linear-gradient(180deg, #0e1730 0%, #142042 55%, #16224a 100%);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.05rem 1.1rem;
  color: #fff;
  font-weight: 800;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar-brand .bi {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  font-size: 1.05rem;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.45);
}

.sidebar-nav {
  padding: 0.55rem 0 2rem;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.12rem 0.6rem;
  padding: 0.56rem 0.85rem;
  border-radius: 9px;
  color: #b9c4d9;
  font-weight: 500;
  font-size: 0.885rem;
  border: 0;
}

.sidebar-nav .nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-decoration: none;
}

.sidebar-nav .nav-link.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.95), rgba(79, 70, 229, 0.95));
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.35);
}

.sidebar-nav .nav-link .bi {
  width: 1.05rem;
  text-align: center;
  opacity: 0.92;
}

.nav-section {
  padding: 1.05rem 1.5rem 0.35rem;
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: #6b7a99;
}

/* --------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  padding: 0.7rem 1.4rem;
  background: rgba(255, 255, 255, 0.87);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
}

/* ---------------------------------------------------------------- card */
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  font-size: 0.93rem;
  padding: 0.8rem 1rem;
}

.card-body {
  padding: 1rem;
}

.kpi-card {
  transition: box-shadow 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: #d7ddf0;
}

.kpi-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 13px;
  font-size: 1.25rem;
}

.kpi-card .fs-3,
.kpi-card .fs-4 {
  letter-spacing: -0.02em;
}

.chart-box {
  position: relative;
  height: 300px;
}

/* -------------------------------------------------------------- tabelle */
.table {
  --bs-table-hover-bg: #f7f9ff;
  margin-bottom: 0;
}

.table thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: #667085;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td {
  border-color: #eef0f6;
}

.table > :not(caption) > * > * {
  vertical-align: middle;
}

.table-sm > :not(caption) > * > * {
  padding: 0.5rem 0.55rem;
}

.number-badge {
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------- form */
.form-label {
  font-weight: 600;
  font-size: 0.82rem;
  color: #3f4a5f;
  margin-bottom: 0.3rem;
}

.form-control,
.form-select {
  border-color: #d7dce8;
  border-radius: 10px;
  font-size: 0.9rem;
}

.form-control:focus,
.form-select:focus {
  border-color: #9db9f7;
  box-shadow: 0 0 0 0.22rem rgba(37, 99, 235, 0.13);
}

.form-text {
  font-size: 0.76rem;
}

.form-check-input:checked {
  background-color: var(--brand);
  border-color: var(--brand);
}

/* --------------------------------------------------------------- badge */
.badge {
  border-radius: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tag-chip {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.5;
  border: 1px solid transparent;
}

.tag-chip.bg-primary { background: #e5edff !important; color: #1d4ed8; border-color: #c7d9ff; }
.tag-chip.bg-success { background: #e7f6ec !important; color: #157347; border-color: #bfe6cd; }
.tag-chip.bg-danger { background: #fdecec !important; color: #b02a2a; border-color: #f5c2c2; }
.tag-chip.bg-warning { background: #fff6e0 !important; color: #9a6700; border-color: #f3ddad; }
.tag-chip.bg-info { background: #e6f4f8 !important; color: #0b6b82; border-color: #bde4ee; }
.tag-chip.bg-secondary { background: #eef0f4 !important; color: #475467; border-color: #d8dde6; }
.tag-chip.bg-dark { background: #e9eaee !important; color: #212529; border-color: #cfd2d9; }

/* ------------------------------------------------------------- avvisi */
.alert {
  border-radius: 12px;
  border: 1px solid transparent;
}

.alert-info { background: #eef4ff; border-color: #d8e5ff; color: #1e40af; }
.alert-success { background: #ecfdf3; border-color: #c9f0d8; color: #166534; }
.alert-warning { background: #fffaeb; border-color: #f7e3b0; color: #92400e; }
.alert-danger { background: #fef2f2; border-color: #f7cccc; color: #991b1b; }

/* ------------------------------------------------------------ documento */
.doc-lines input,
.doc-lines select {
  font-size: 0.875rem;
}

/* Larghezze minime delle colonne: senza, il browser le comprime e i campi
   diventano illeggibili. La tabella scorre in orizzontale se non ci stanno. */
.doc-lines .col-articolo { min-width: 240px; }
.doc-lines .col-descrizione { min-width: 260px; }
.doc-lines .col-sezione { min-width: 130px; }
.doc-lines .col-qta { min-width: 90px; }
.doc-lines .col-um { min-width: 100px; }
.doc-lines .col-prezzo { min-width: 120px; }
.doc-lines .col-sconto { min-width: 90px; }
.doc-lines .col-iva { min-width: 100px; }
.doc-lines .col-totale { min-width: 120px; }
.doc-lines .col-azioni { min-width: 56px; }
.doc-lines td input,
.doc-lines td select {
  min-width: 100%;
}

.doc-lines .line-total {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.doc-totals dt {
  font-weight: 500;
  color: var(--muted);
}

.doc-totals dd {
  font-variant-numeric: tabular-nums;
  text-align: right;
  margin-bottom: 0.25rem;
}

.doc-totals .grand-total {
  font-size: 1.15rem;
  font-weight: 800;
}

/* --------------------------------------------------------------- modali */
.modal-content {
  border: 0;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}

.modal-header {
  border-bottom: 1px solid var(--line);
}

.modal-footer {
  border-top: 1px solid var(--line);
}

.dropdown-menu {
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
}

.list-group-item {
  border-color: #eef0f4;
}

/* -------------------------------------------------------- lista vuota */
.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: #98a2b3;
}

.empty-state .bi {
  font-size: 2.2rem;
  display: block;
  margin-bottom: 0.5rem;
}

/* --------------------------------------------------- ricerca a digitazione */
.autocomplete-wrap {
  position: relative;
}

.autocomplete-menu {
  background: #fff;
  border: 1px solid #d8dde6;
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18);
  z-index: 1080;
  max-height: 300px;
  overflow-y: auto;
  padding: 0.3rem;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--ink);
}

.autocomplete-item:hover,
.autocomplete-item:focus {
  background: #f2f5fb;
  outline: none;
}

.autocomplete-item .ac-extra {
  color: #98a2b3;
  font-size: 0.75rem;
  white-space: nowrap;
}

.autocomplete-create {
  color: var(--brand);
  font-weight: 600;
  border-top: 1px solid #eef0f4;
  border-radius: 0 0 8px 8px;
}

.autocomplete-empty {
  padding: 0.5rem 0.6rem;
  color: #98a2b3;
  font-size: 0.8rem;
}

/* ---------------------------------------------------------------- login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  background:
    radial-gradient(1100px 520px at 12% -12%, rgba(37, 99, 235, 0.4), transparent 60%),
    radial-gradient(900px 520px at 112% 8%, rgba(124, 58, 237, 0.32), transparent 55%),
    linear-gradient(160deg, #0e1730, #1b2a4e);
}

.login-brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  font-size: 1.5rem;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.5);
}

.login-card {
  border: 0;
  border-radius: 18px;
  box-shadow: 0 30px 70px rgba(2, 6, 23, 0.45);
}

/* --------------------------------------------------------- responsive */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .app-main {
    margin-left: 0;
  }

  .sidebar-backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1029;
    background: rgba(15, 23, 42, 0.5);
  }
}

/* ------------------------------------------------ rifiniture per telefono */
@media (max-width: 767.98px) {
  body {
    font-size: 0.9rem;
  }

  .app-main > main {
    padding: 1rem 0.75rem !important;
  }

  .topbar {
    padding: 0.6rem 0.85rem;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .card-body {
    padding: 0.85rem;
  }

  .card-header {
    padding: 0.7rem 0.85rem;
  }

  .kpi-icon {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
    border-radius: 11px;
    font-size: 1.05rem;
  }

  .table-responsive {
    -webkit-overflow-scrolling: touch;
  }

  .modal-dialog {
    margin: 0.6rem;
  }

  .btn-group .btn {
    padding-left: 0.6rem;
    padding-right: 0.6rem;
  }
}

@supports (padding: env(safe-area-inset-left)) {
  @media (max-width: 767.98px) {
    .topbar {
      padding-left: max(0.85rem, env(safe-area-inset-left));
      padding-right: max(0.85rem, env(safe-area-inset-right));
    }
  }
}

.sidebar-backdrop {
  display: none;
}

/* -------------------------------------------------------------- stampa */
@media print {
  .no-print,
  .sidebar,
  .topbar {
    display: none !important;
  }

  .app-main {
    margin-left: 0;
  }

  body {
    background: #fff;
  }
}
