:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-elev: #1c232c;
  --border: #30363d;
  --border-soft: #21262d;
  --text: #c9d1d9;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --brand: #ff5a8a;
  --brand-soft: rgba(255, 90, 138, 0.12);
  --shadow: 0 0 0 1px var(--border-soft), 0 8px 24px rgba(0,0,0,0.32);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; color: var(--text); font-weight: 600; }
h1 { font-size: 18px; letter-spacing: 0.2px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--text); }
p { margin: 0 0 8px; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand .dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--brand) 0%, #c4356a 70%);
  box-shadow: 0 0 0 2px rgba(255,90,138,0.18);
}

.brand-text h1 { color: var(--text); }
.subtitle {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-elev);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.err { background: var(--red); box-shadow: 0 0 8px var(--red); }
.status-dot.warn { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  min-height: calc(100vh - 220px);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 14px;
}
.panel-header h2 { color: var(--text); }
.panel-header .muted { font-size: 12px; }

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.form input, .form select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form input:focus, .form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88,166,255,0.18);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--brand);
  color: #0d1117;
  border-color: rgba(255,90,138,0.6);
  box-shadow: 0 0 16px rgba(255,90,138,0.32);
}

.btn-primary:hover { filter: brightness(1.08); }

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(13,17,23,0.4);
  border-top-color: #0d1117;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.panel-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

.panel-footer h3 {
  margin-bottom: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
}

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.filters select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
}

.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.library-item {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.library-item:hover {
  border-color: var(--accent);
  background: var(--bg);
}
.library-item .lib-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}
.library-item .lib-cliente {
  color: var(--text);
  font-weight: 600;
}
.library-item .lib-meta {
  color: var(--text-muted);
  margin-top: 4px;
  font-size: 11px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 60px 30px;
}

.empty-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-soft), transparent);
  border: 2px solid var(--brand);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  font-size: 24px;
}
.empty-icon::before {
  content: "+";
  color: var(--brand);
  font-size: 28px;
  font-weight: 600;
}

.empty-features {
  margin-top: 16px;
  text-align: left;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.8;
  max-width: 480px;
  padding-left: 18px;
}

.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.report-header h2 { font-size: 18px; color: var(--text); }
.report-header .muted { font-size: 12px; }

.badges { display: flex; gap: 8px; }
.badge {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-size: 11px;
  border-radius: 6px;
  color: var(--text-muted);
}
.badge.brand-badge {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.card h3 {
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.grid-2 .card { margin-bottom: 0; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}
th {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg);
}
tr:last-child td { border-bottom: none; }
td.brand-cell { color: var(--text); font-weight: 600; }
td.servizi-cell { color: var(--text-muted); }

.chart-wrap {
  position: relative;
  height: 280px;
}

.rec-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.rec-card {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--brand);
  padding: 14px;
  border-radius: 8px;
  font-size: 12px;
}

.rec-card .rec-id {
  display: inline-block;
  background: var(--brand-soft);
  color: var(--brand);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}

.rec-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px;
  margin-bottom: 4px;
  align-items: baseline;
}

.rec-row .label {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.rec-row .value {
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

.kpi {
  display: flex;
  gap: 24px;
}

.kpi-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-label {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.kpi-value {
  color: var(--brand);
  font-size: 22px;
  font-weight: 700;
  font-feature-settings: "tnum" 1;
}

.footer-meta {
  color: var(--text-muted);
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.footer-meta .sep { margin: 0 8px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 30px;
}
.modal[hidden] { display: none; }
#report-content[hidden] { display: none; }
.empty-state[hidden] { display: none; }

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 1100px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-elev);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.modal-close:hover { color: var(--text); border-color: var(--brand); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .rec-cards { grid-template-columns: 1fr; }
}
