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

:root {
  --sidebar-w: 220px;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e0e4ef;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --warning: #d97706;
  --warning-hover: #b45309;
  --text: #1e293b;
  --text-muted: #64748b;
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active: #ffffff;
  --sidebar-active-bg: #2563eb;
  --success-bg: #f0fdf4;
  --success-border: #86efac;
  --success-text: #166534;
  --error-bg: #fef2f2;
  --error-border: #fca5a5;
  --error-text: #991b1b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

#layout {
  display: flex;
  height: 100vh;
}

/* SIDEBAR */
#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

#logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
}

#app-title {
  color: #ffffff;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
}

#nav {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 12px 10px;
  gap: 2px;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--sidebar-text);
  text-align: left;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: rgba(255,255,255,0.07);
  color: #ffffff;
}

.nav-btn.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
}

.nav-btn-bottom {
  margin-top: auto;
}

/* MAIN CONTENT */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 36px;
}

.section { display: none; }
.section.active { display: block; }

h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 24px;
}

h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

/* IMPORT INFO */
#import-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
  color: var(--text-muted);
  line-height: 1.6;
}

#import-info h3 { color: var(--text); }

/* DROP ZONE */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 16px;
}

#drop-zone.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}

#drop-icon { display: block; font-size: 36px; margin-bottom: 10px; }

#drop-label {
  display: block;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

#drop-or { display: block; color: var(--text-muted); margin-bottom: 12px; }

#file-input { display: none; }

#browse-label {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 8px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}

#browse-label:hover { background: var(--primary-hover); }

#import-filename {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-weight: 500;
  color: var(--text);
}

/* IMPORT ACTIONS */
#import-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

/* BUTTONS */
.btn {
  border: none;
  border-radius: 6px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #475569; color: #fff; }
.btn-secondary:hover { background: #334155; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: var(--warning-hover); }
.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  text-decoration: underline;
}

/* ALERTS */
.alert {
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  line-height: 1.6;
}

.alert-success {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
}

.alert-error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
}

.alert ul { margin: 8px 0 0 18px; }
.alert ul li { margin-bottom: 2px; }

/* IMPORT DEBUG LOG */
#import-debug-log {
  background: #0f172a;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 16px;
  max-height: 400px;
  overflow-y: auto;
}

#import-debug-log h3 {
  color: #e2e8f0;
  margin-bottom: 10px;
}

#import-debug-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#import-debug-list li {
  font-family: "Consolas", "Monaco", monospace;
  font-size: 11.5px;
  color: #94a3b8;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* FATTURATO FILTERS */
#fatturato-filters {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  cursor: pointer;
}

/* MULTI SELECT */
.multi-select-wrapper { position: relative; }

.multi-select-btn {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  min-width: 120px;
  text-align: left;
}

.multi-select-popup {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 100;
  min-width: 200px;
  padding: 8px 0 4px;
}

#prestazioni-options {
  max-height: 220px;
  overflow-y: auto;
  padding: 0 8px;
}

.multi-select-popup label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.multi-select-popup label:hover { background: var(--bg); }

.popup-actions {
  display: flex;
  gap: 12px;
  padding: 8px 14px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* FIELD TOGGLE */
#field-toggle { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }

.toggle-btn {
  border: none;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

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

.toggle-btn:disabled,
.toggle-btn.disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

/* FATTURATO TABLE */
#fatturato-table-wrapper { overflow-x: auto; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#fatturato-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 13px;
}

#fatturato-table th,
#fatturato-table td {
  padding: 10px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#fatturato-table th:first-child,
#fatturato-table td:first-child {
  text-align: left;
  font-weight: 500;
}

#fatturato-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#fatturato-table tbody tr:hover { background: #f8fafc; }
#fatturato-table tbody tr:last-child td { border-bottom: none; }

#fatturato-tfoot td {
  font-weight: 700;
  background: #f1f5f9;
  border-top: 2px solid var(--border);
  border-bottom: none;
}

/* GRAFICI */
#grafici-filters {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

#grafici-filters-periodo,
#grafici-filters-anni {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

#grafici-container { }

#grafici-chart-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

#grafici-canvas {
  max-height: 480px;
}

#grafici-growth-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-top: 16px;
}

#grafici-growth-list h3 {
  margin-bottom: 12px;
}

.growth-rows {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.growth-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.growth-row:last-child { border-bottom: none; }

.growth-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.growth-name {
  flex: 1;
  color: var(--text);
}

.growth-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.growth-up { color: #16a34a; }
.growth-down { color: #dc2626; }

/* MAPPATURA */
#mappatura-toolbar {
  margin-bottom: 20px;
}

.prestazione-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.prestazione-group-header {
  background: #f8fafc;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.mapping-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

.mapping-row:last-child { border-bottom: none; }

.mapping-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
}

.mapping-name-input {
  flex: 1;
  border: 1px solid var(--primary);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 13px;
  color: var(--text);
  outline: none;
}

.mapping-prestazione-select {
  border: 1px solid var(--primary);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  min-width: 160px;
}

.btn-icon {
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon.delete:hover { color: var(--danger); }

/* UTILS */
.hidden { display: none !important; }
