/* ================================================================
   RT BOTIQUE — Control Panel — stylesheet
   Palette dal logo Botique:
   - Antracite     #1a1a1a  sfondo principale
   - Pannello      #232323  cards/blocchi
   - Pannello+     #2c2c2c  hover/elevation
   - Border        #333333
   - Oro           #C8985A  accent primario
   - Oro chiaro    #D4A971
   - Avorio        #E8DCC4  highlight delicati
   - Testo bright  #EFEFEF
   - Testo normale #B5B5B5
   - Testo dimmed  #7A7A7A
   - Verde         #5BC890  utile/positivo
   - Rosso         #E26B6B  perdita/critico
================================================================ */

:root {
  --bg:        #1a1a1a;
  --panel:     #232323;
  --panel-2:   #2c2c2c;
  --border:    #333333;
  --gold:      #C8985A;
  --gold-2:    #D4A971;
  --ivory:     #E8DCC4;
  --text:      #EFEFEF;
  --text-2:    #B5B5B5;
  --text-3:    #7A7A7A;
  --pos:       #5BC890;
  --neg:       #E26B6B;
  --warn:      #E5C16A;
  --shadow:    0 6px 18px rgba(0,0,0,0.35);
  --radius:    12px;
  --radius-sm: 8px;
  --space:     16px;
  --space-2:   24px;
  --space-3:   32px;
  --transition: 180ms cubic-bezier(.4,0,.2,1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

/* ===== SPLASH ===== */
.splash {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.splash-inner { text-align: center; }
.splash-logo { width: 80px; height: 80px; animation: pulse 1.6s ease-in-out infinite; }
.splash-text { color: var(--text-2); margin-top: 16px; font-size: 14px; letter-spacing: 0.02em; }

@keyframes pulse {
  0%, 100% { opacity: 0.7; transform: scale(0.96); }
  50%      { opacity: 1; transform: scale(1.04); }
}

/* ===== ERROR BANNER ===== */
.error-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--neg);
  color: white;
  padding: 12px 24px;
  text-align: center;
  font-weight: 500;
  z-index: 200;
  box-shadow: var(--shadow);
}

/* ===== HEADER ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo {
  width: 42px;
  height: 42px;
}
.logo-large {
  width: 56px;
  height: 56px;
}
.logo-img {
  height: 56px;
  width: auto;
  display: block;
}
.header-titles { display: flex; flex-direction: column; }
.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.subtitle {
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.month-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
}
.month-selector select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}
.month-selector select:hover {
  border-color: var(--gold);
}
.user-chip {
  background: var(--bg);
  color: var(--gold);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
}

/* ===== BUTTONS ===== */
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}
.btn:hover {
  background: var(--bg);
  border-color: var(--gold);
  color: var(--gold);
}
.btn-secondary {}
.btn-close {
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 28px;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.btn-close:hover { background: var(--panel-2); color: var(--text); }

/* ===== MAIN LAYOUT ===== */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px;
}

.section { margin-bottom: 40px; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.section h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
  color: var(--text);
}
.section-meta {
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

/* ===== KPI CARDS ===== */
.cards-grid {
  display: grid;
  gap: 16px;
}
.cards-grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.cards-grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--gold);
  opacity: 0.4;
  transition: var(--transition);
}
.card:hover {
  border-color: var(--gold);
  background: var(--panel-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.card:hover::before { opacity: 1; }

.card-label {
  font-size: 12px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-bottom: 8px;
}
.card-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.card-value.positive { color: var(--pos); }
.card-value.negative { color: var(--neg); }
.card-value.gold     { color: var(--gold); }
.card-sub {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 6px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.card-sub .delta-pos { color: var(--pos); }
.card-sub .delta-neg { color: var(--neg); }
.card-drill-hint {
  position: absolute;
  bottom: 8px; right: 12px;
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.04em;
}

/* ===== CHART ===== */
.chart-wrapper {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  height: 360px;
}

/* ===== TABLE ===== */
.table-wrapper {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 600px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead th {
  text-align: left;
  padding: 12px 16px;
  background: var(--panel-2);
  color: var(--text-2);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 1;
}
.data-table thead th.numeric { text-align: right; }
.data-table thead th:hover { color: var(--gold); }
.data-table thead th.sort-asc::after  { content: ' ▴'; color: var(--gold); }
.data-table thead th.sort-desc::after { content: ' ▾'; color: var(--gold); }

.data-table tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.data-table tbody tr:hover { background: var(--panel-2); }
.data-table tbody td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody td.positive { color: var(--pos); }
.data-table tbody td.negative { color: var(--neg); }
.data-table tbody td.dimmed   { color: var(--text-3); }

/* Occupazione bar inline */
.occ-bar {
  display: inline-block;
  width: 50px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
  vertical-align: middle;
  margin-right: 8px;
}
.occ-bar-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
}

/* ===== FOOTER ===== */
.footer {
  display: flex;
  justify-content: space-between;
  padding: 16px 32px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}
.footer .dot { margin: 0 6px; }
.footer-left { display: flex; gap: 4px; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 24px;
  animation: fadeIn 180ms ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 800px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: slideUp 220ms cubic-bezier(.4,0,.2,1);
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

/* Drill-down content */
.drill-section { margin-bottom: 20px; }
.drill-section:last-child { margin-bottom: 0; }
.drill-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.drill-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.drill-table th, .drill-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.drill-table th {
  color: var(--text-3);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.drill-table td.numeric, .drill-table th.numeric { text-align: right; font-variant-numeric: tabular-nums; }

.drill-tree-node { padding-left: 16px; border-left: 2px solid var(--border); margin: 4px 0; }
.drill-tree-node.l1 { padding-left: 0; border-left: none; }

details.drill-collapse {
  margin: 6px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}
details.drill-collapse > summary {
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
details.drill-collapse > summary::-webkit-details-marker { display: none; }
details.drill-collapse > summary::before {
  content: '▸';
  color: var(--gold);
  margin-right: 8px;
  transition: var(--transition);
}
details.drill-collapse[open] > summary::before { transform: rotate(90deg); }
details.drill-collapse > .drill-collapse-body { padding: 12px 14px; border-top: 1px solid var(--border); }

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-3);
  font-style: italic;
}

/* ===== v0.2 — Record cards (drill profondo) ===== */
.modal-subtitle {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 12px;
  font-style: italic;
}

.drill-help {
  font-size: 12px;
  color: var(--text-3);
  margin: 6px 0 12px 0;
  line-height: 1.5;
}

.record-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px !important;
}

.record-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: var(--transition);
}
.record-card:hover {
  border-color: var(--gold);
}

.record-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.record-desc {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  flex: 1;
  min-width: 0;
}
.record-amounts {
  display: flex;
  gap: 12px;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  flex-shrink: 0;
}
.record-amounts .amount-pos { color: var(--pos); }
.record-amounts .amount-neg { color: var(--neg); }
.record-amounts .amount-tot {
  font-size: 13px;
  font-weight: 600;
  border-left: 1px solid var(--border);
  padding-left: 12px;
}

.record-meta {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.record-attachment {
  font-size: 11px;
  color: var(--gold);
  text-decoration: none;
  align-self: flex-start;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: var(--transition);
}
.record-attachment:hover {
  background: var(--panel-2);
  border-color: var(--gold);
}

.simple-list {
  list-style: none;
  margin: 0;
  padding: 8px 0 8px 4px;
  font-size: 12px;
  color: var(--text-2);
  columns: 2;
  column-gap: 16px;
}
.simple-list li {
  padding: 3px 0;
  break-inside: avoid;
}

/* ===== v0.3 Period toggle (YTD ↔ Mese) ===== */
.period-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
}
.period-btn {
  background: transparent;
  color: var(--text-3);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: var(--transition);
}
.period-btn:hover {
  color: var(--text);
  border-color: var(--gold);
}
.period-btn.active {
  background: var(--gold);
  color: var(--bg);
  border-color: var(--gold);
}
.period-meta {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.02em;
  margin-left: 8px;
}

/* ===== v0.3 Card big (per Ricavo netto principale + Utile finale) ===== */
.card.card-big {
  grid-column: span 2;
}
.card.card-big .card-value {
  font-size: 36px;
}
.card.card-big .card-label {
  font-size: 13px;
}
@media (max-width: 768px) {
  .card.card-big {
    grid-column: span 1;
  }
  .card.card-big .card-value {
    font-size: 28px;
  }
}

/* ===== v0.3 IVA summary footer in modal drill ===== */
.iva-summary {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.iva-label {
  color: var(--text-3);
  letter-spacing: 0.02em;
}
.iva-value {
  color: var(--ivory);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .main { padding: 20px 16px; }
  .header { padding: 14px 16px; flex-wrap: wrap; gap: 12px; }
  .header-right { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .footer { flex-direction: column; gap: 8px; padding: 16px; }
  .modal { max-height: 92vh; }
  .modal-head, .modal-body { padding: 16px; }
  .data-table { font-size: 12px; }
  .data-table thead th, .data-table tbody td { padding: 8px 10px; }
}
