:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #273549;
  --border-color: #334155;
  --border-focus: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #0ea5e9;
  --primary-hover: #0284c7;
  --accent: #10b981;
  --accent-glow: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Layout */
.app-container {
  display: flex;
  flex: 1;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background-color: #111827;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  flex-shrink: 0;
}

/* Mobile Menu Trigger & Backdrop */
.mobile-menu-btn {
  display: none;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--border-color);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.mobile-menu-btn:hover, .mobile-menu-btn:active {
  background: rgba(56, 189, 248, 0.15);
  border-color: #38bdf8;
  color: #38bdf8;
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  margin-left: auto;
  transition: color 0.2s;
}

.sidebar-close-btn:hover {
  color: #fff;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #0ea5e9, #10b981);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.25rem;
  color: #fff;
  box-shadow: 0 0 15px rgba(14, 165, 233, 0.4);
}

.brand-title h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.brand-title span {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
}

.nav-item button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.nav-item button:hover {
  background-color: var(--bg-card);
  color: var(--text-main);
}

.nav-item.active button {
  background: linear-gradient(90deg, rgba(14, 165, 233, 0.15), rgba(16, 185, 129, 0.08));
  border-color: rgba(14, 165, 233, 0.4);
  color: #38bdf8;
  font-weight: 600;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

.sidebar-footer {
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.status-badge-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  color: var(--accent);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-dark);
  overflow-y: auto;
}

/* Header */
.top-header {
  height: 70px;
  border-bottom: 1px solid var(--border-color);
  background-color: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-info h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.header-info p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.server-pills {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.pill {
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pill.active {
  border-color: rgba(16, 185, 129, 0.4);
  background-color: var(--accent-glow);
  color: #34d399;
}

/* Page Content Body */
.content-body {
  padding: 2rem;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.25s ease forwards;
}

.tab-pane.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards & Grids */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  position: relative;
}

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

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-top: 0.5rem;
}

.stat-label {
  font-size: 0.825rem;
  color: var(--text-muted);
}

.stat-tag {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  background-color: rgba(56, 189, 248, 0.1);
  color: #38bdf8;
}

/* Infrastructure Specs List */
.specs-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.spec-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-md);
  background-color: rgba(15, 23, 42, 0.5);
  font-size: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.spec-item .spec-label {
  color: var(--text-muted);
  font-weight: 500;
}

.spec-item .spec-val {
  color: #fff;
  font-weight: 600;
  font-family: monospace;
}

/* Upload Dropzone */
.dropzone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  background-color: rgba(15, 23, 42, 0.4);
  cursor: pointer;
  transition: all 0.25s ease;
  margin-bottom: 1.5rem;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background-color: rgba(14, 165, 233, 0.08);
}

.dropzone svg {
  width: 48px;
  height: 48px;
  stroke: var(--primary);
  margin-bottom: 0.75rem;
}

.dropzone p {
  color: var(--text-main);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.dropzone span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Catalog cards */
.catalog-card {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.25rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: transform 0.2s, border-color 0.2s;
}

.catalog-card:hover {
  transform: translateY(-2px);
  border-color: rgba(56, 189, 248, 0.4);
}

.pdf-icon {
  min-width: 58px;
  height: 52px;
  padding: 3px 4px;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.72rem;
  text-align: center;
  line-height: 1.15;
  word-break: break-word;
  flex-shrink: 0;
}

.catalog-details {
  flex: 1;
}

.catalog-title {
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 0.2rem;
}

.catalog-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 1rem;
}

.badge {
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-success {
  background-color: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.badge-info {
  background-color: rgba(14, 165, 233, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(14, 165, 233, 0.4);
}

.badge-warning {
  background-color: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

/* Table Controls */
.table-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 260px;
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.5rem;
  background-color: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--border-focus);
}

.search-box svg {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  stroke: var(--text-dim);
}

.filter-select {
  padding: 0.75rem 1.25rem;
  background-color: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
}

/* Data Table */
.table-container {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow-card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.data-table th {
  background-color: rgba(15, 23, 42, 0.8);
  padding: 0.9rem 1rem;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tr:hover td {
  background-color: var(--bg-card-hover);
}

.table-compact th {
  padding: 0.5rem 0.35rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

.table-compact td {
  padding: 0.4rem 0.35rem;
  font-size: 0.78rem;
}

.price-tag {
  font-family: monospace;
  font-weight: 700;
  color: #38bdf8;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-group {
  display: flex;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-decoration: none;
}

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

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

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

.btn-secondary:hover {
  background-color: #334155;
}

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

.btn-accent:hover {
  background-color: #059669;
}

/* Form controls */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.form-input, .form-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background-color: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.9rem;
  outline: none;
}

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

/* Simulation Result Card */
.match-card {
  background-color: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
}

.match-card.best {
  border-color: rgba(16, 185, 129, 0.6);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.1);
}

.match-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.match-score {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  background-color: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.match-prices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  padding: 0.75rem;
  background-color: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
}

.price-item {
  display: flex;
  flex-direction: column;
}

.price-item span {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

.price-item strong {
  font-size: 1rem;
  color: #fff;
  font-family: monospace;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.toast {
  padding: 1rem 1.5rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  color: #fff;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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

/* Drag and Drop Zone */
.dropzone {
  border: 2px dashed rgba(56, 189, 248, 0.4);
  border-radius: var(--radius-md);
  padding: 2.25rem 1.5rem;
  text-align: center;
  background: rgba(15, 23, 42, 0.4);
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.dropzone:hover {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.05);
  transform: translateY(-2px);
}

.dropzone.dragover {
  border-color: #34d399;
  background: rgba(16, 185, 129, 0.1);
  box-shadow: 0 0 20px rgba(52, 211, 153, 0.2);
  transform: scale(1.01);
}

.dropzone.has-file {
  border-color: #34d399;
  background: rgba(16, 185, 129, 0.05);
}

.progress-bar-container {
  width: 100%;
  height: 9px;
  background: #1e293b;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #34d399);
  transition: width 0.3s ease;
  border-radius: 6px;
}

/* ========================================================
   RESPONSIVE DESIGN (TABLET & SMARTPHONE HORIZONTAL/VERTICAL)
   ======================================================== */

/* Table Scrollbar & Touch Optimization */
.table-container {
  -webkit-overflow-scrolling: touch;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: thin;
  scrollbar-color: #38bdf8 #1e293b;
}

.table-container::-webkit-scrollbar {
  height: 6px;
}

.table-container::-webkit-scrollbar-track {
  background: #0f172a;
  border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
  background: #38bdf8;
}

/* TABLET & PICCOLI SCHERMI (<= 1024px) */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    max-width: 82vw;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 12px 0 35px rgba(0, 0, 0, 0.65);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

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

  body.sidebar-open {
    overflow: hidden;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .sidebar-close-btn {
    display: block;
  }

  .top-header {
    padding: 0.65rem 1.25rem;
    height: auto;
    min-height: 62px;
  }

  .content-body {
    padding: 1.25rem 1rem;
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .grid-3 {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .grid-2 {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* SMARTPHONE & SCHERMI MOBILI MEDI (<= 768px) */
@media (max-width: 768px) {
  .top-header {
    padding: 0.5rem 0.85rem;
    gap: 0.5rem;
  }

  .header-info h2 {
    font-size: 1.05rem;
    line-height: 1.2;
  }

  .header-info p {
    display: none;
  }

  .server-pills {
    gap: 0.35rem;
  }

  .pill {
    padding: 0.25rem 0.55rem;
    font-size: 0.7rem;
  }

  #pill-server-ip {
    display: none;
  }

  .content-body {
    padding: 0.85rem 0.65rem;
  }

  .card {
    padding: 1.1rem 0.9rem;
    border-radius: var(--radius-md);
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
    margin-bottom: 0.85rem;
  }

  .card-title {
    font-size: 0.95rem;
  }

  .stat-value {
    font-size: 1.6rem;
  }

  /* Evita auto-zoom fastidioso su browser mobili/iOS impostando font-size minimo 16px */
  .search-box input,
  .filter-select,
  .form-input,
  .form-textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .table-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .search-box {
    width: 100%;
    min-width: 0;
  }

  .filter-select {
    width: 100%;
  }

  .btn {
    min-height: 42px;
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
  }

  .match-card {
    padding: 0.9rem;
  }

  .match-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  .match-prices {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    padding: 0.6rem;
  }

  .price-item strong {
    font-size: 0.9rem;
  }

  .data-table th, .data-table td {
    padding: 0.65rem 0.75rem;
    font-size: 0.8rem;
  }

  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
  }

  .toast {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1rem;
  }

  /* Parametri Finanziari Live & Sliders */
  #container-sliders-computo {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* SMARTPHONE VERTICALI COMPATTI (<= 480px) */
@media (max-width: 480px) {
  .brand-title h1 {
    font-size: 1rem;
  }

  .grid-4 {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .match-prices {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }

  .btn-group {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }

  .pagination {
    flex-direction: column;
    gap: 0.75rem;
    text-align: center;
  }

  /* Griglie numeriche su schermi stretti */
  .card div[style*="grid-template-columns: repeat(auto-fit"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.6rem !important;
  }
}


