:root {
  --bg: #f5f6f8;
  --card-bg: #fff;
  --text: #222;
  --muted: #666;
  --primary: #2a6ef2;
  --primary-hover: #1f54c9;
  --error: #dc3545;
  --error-bg: #fee;
  --error-text: #721c24;
  --radius: 12px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

body {
  margin: 0;
  padding: 0;
  font-family: "Inter", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ========================================
   HEADER
   ======================================== */

.app-header {
  background: #fff;
  padding: 16px 0;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100; /* 🔧 AUMENTATO DA 50 A 100 per stare sopra Handsontable */
}

.app-header .logo {
  height: 70px;
  width: auto;
}

.app-header .logo-text {
  font-weight: 600;
  font-size: 1.3rem;
}

/* ========================================
   LAYOUT
   ======================================== */

.container {
  width: 90%;
  max-width: 900px;
  margin: 32px auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.card {
  background: var(--card-bg);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card h2 {
  margin-top: 0;
}

.result-card {
  background: var(--card-bg);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.result-card h2 {
  margin-top: 0;
  margin-bottom: 12px;
}

.result-card h3 {
  margin: 0;
  font-size: 18px;
  color: var(--muted);
}

.sub-section {
  position: relative;
  margin-top: 20px;
}

/* ========================================
   FORM
   ======================================== */

.form-group {
  margin-bottom: 20px;
}

label {
  font-weight: 600;
  margin-bottom: 6px;
  display: block;
}

input,
select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #ccc;
  font-size: 15px;
}

/* ========================================
   BUTTONS
   ======================================== */

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: 0.2s;
}

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

.secondary-btn {
  background: #e8e8e8;
  color: #333;
  border: none;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  opacity: 0.7;
  font-size: 13px;
}

#downloadBtn {
  margin-top: 16px;
}

/* ========================================
   DROPZONE
   ======================================== */

.dropzone {
  background: #fafafa;
  border: 2px dashed #bbb;
  padding: 24px;
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: 0.2s;
}

.dropzone.dragover {
  background: #eef3ff;
  border-color: var(--primary);
}

.file-name {
  margin-top: 10px;
  font-size: 14px;
  color: var(--muted);
}

/* ========================================
   ERROR BOX
   ======================================== */

.error-box {
  background-color: var(--error-bg);
  border: 2px solid var(--error);
  color: var(--error-text);
  padding: 0;
  border-radius: 8px;
  margin: 20px 0;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(220, 53, 69, 0.15);
}

.error-header {
  background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--error);
}

.error-header h3 {
  color: var(--error-text);
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.error-header h3::before {
  content: "⚠";
  font-size: 1.3rem;
  color: var(--error);
}

.copy-btn {
  background: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  color: var(--error-text);
  border: 2px solid var(--error);
  border-radius: 6px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.6);
  border-color: #a71d2a;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.copy-btn:active {
  transform: translateY(0) scale(0.98);
}

.copy-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  transition: stroke 0.2s;
}

.copy-btn.success {
  background: rgba(40, 167, 69, 0.2);
  border-color: #28a745;
  color: #155724;
}

#errorContent {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.9rem;
  padding: 20px;
  word-break: break-word;
  line-height: 1.6;
  background: rgba(255, 255, 255, 0.4);
}

/* ========================================
   PREVIEW
   ======================================== */

.preview-box {
  margin-top: 20px;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  padding: 16px;
  transition: 0.2s;
}

.preview-box.collapsed #preview-container {
  display: none;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.preview-header button {
  font-size: 14px;
  padding: 6px 12px;
}

.table-container {
  margin-top: 12px;
  height: 450px;
  overflow: hidden;
  border: 1px solid #ddd;
  border-radius: 8px;
  position: relative;
  z-index: 1; /* 🔧 AGGIUNTO per stare sotto l'header */
}

/* ========================================
   SEARCH OVERLAY
   ======================================== */

.hot-search-overlay {
  position: absolute;
  top: 72px;
  right: 30px;
  z-index: 10; /* 🔧 RIDOTTO DA 1000 A 10 (sopra tabella ma sotto header) */
  width: 180px;
  padding: 8px 15px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.3) !important;
  backdrop-filter: blur(5px);
  box-shadow: var(--shadow);
  outline: none;
  transition: all 0.3s ease;
}

.hot-search-overlay:focus {
  width: 280px;
  background: rgba(255, 255, 255, 1) !important;
  border-color: var(--primary);
}

/* ========================================
   HANDSONTABLE STYLES
   ======================================== */

.handsontable {
  font-family: "Inter", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  z-index: 1 !important; /* 🔧 AGGIUNTO per stare sotto l'header */
}

.handsontable thead th {
  background: #f8f9fa !important;
  color: var(--text) !important;
  font-weight: 600 !important;
  border-bottom: 2px solid #ddd !important;
  border-right: 1px solid #e0e0e0 !important;
  padding: 10px 8px !important;
  text-align: left !important;
}

.handsontable td {
  padding: 8px 10px !important;
  border-right: 1px solid #f0f0f0 !important;
  border-bottom: 1px solid #f0f0f0 !important;
  background: #fff !important;
}

.handsontable tbody tr:nth-child(even) td {
  background: #fafbfc !important;
}

.handsontable tbody tr:hover td {
  background: #f0f7ff !important;
}

.handsontable .ht_clone_left th {
  background: #f8f9fa !important;
  font-weight: 600 !important;
  color: var(--muted) !important;
  border-right: 2px solid #ddd !important;
  border-bottom: 1px solid #e0e0e0 !important;
}

.handsontable .ht_clone_top_left_corner th {
  background: #f8f9fa !important;
  border-right: 2px solid #ddd !important;
  border-bottom: 2px solid #ddd !important;
}

/* Search results highlight */
.handsontable td.htSearchResult,
.handsontable tbody tr:nth-child(even) td.htSearchResult {
  background-color: #b5d7ff !important;
  color: var(--primary) !important;
  font-weight: 800 !important;
  text-decoration: underline;
}

/* Selection styles */
.handsontable td.htReadOnly {
  cursor: text;
  color: #333;
}

.handsontable td.current,
.handsontable td.area {
  background-color: rgba(42, 110, 242, 0.15) !important;
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.handsontable .wtHolder {
  user-select: text;
  -webkit-user-select: text;
  -ms-user-select: text;
}

/* ========================================
   SCROLLBAR FIX
   ======================================== */

.handsontable .ht_clone_top,
.handsontable .ht_clone_top_left_corner,
.handsontable .ht_clone_left,
.handsontable .ht_clone_bottom,
.handsontable .ht_clone_bottom_left_corner {
  overflow: hidden !important;
}

.handsontable .ht_clone_top .wtHolder,
.handsontable .ht_clone_top_left_corner .wtHolder,
.handsontable .ht_clone_left .wtHolder,
.handsontable .ht_clone_bottom .wtHolder,
.handsontable .ht_clone_bottom_left_corner .wtHolder {
  overflow: hidden !important;
}

.handsontable .ht_master {
  overflow: visible !important;
}

.handsontable .ht_master .wtHolder {
  overflow: auto !important;
}

/* Custom scrollbar */
.handsontable .ht_master .wtHolder::-webkit-scrollbar {
  height: 12px;
  width: 12px;
}

.handsontable .ht_master .wtHolder::-webkit-scrollbar-thumb {
  background: #c0c0c0;
  border-radius: 6px;
  border: 2px solid #f5f6f8;
}

.handsontable .ht_master .wtHolder::-webkit-scrollbar-thumb:hover {
  background: #a0a0a0;
}

.handsontable .ht_master .wtHolder::-webkit-scrollbar-track {
  background: #f5f6f8;
  border-radius: 6px;
}

/* ========================================
   UTILITY
   ======================================== */

.hidden {
  display: none !important;
}

.full {
  width: 100%;
}

.loader {
  text-align: center;
  font-size: 18px;
}

.logout-container {
  text-align: center;
  margin-top: 40px;
  padding-bottom: 40px;
}

#preview-container.hidden + #searchTable {
  display: none !important;
}
