/* ====================================================================
   AR Revenue Channel Manager
   Interfaccia da gestionale: densa, leggibile a lungo, senza decorazione.
   Chi la usa ci passa la giornata dentro.
   ==================================================================== */

:root {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --border:    #e2e8f0;
  --border-2:  #cbd5e1;
  --text:      #0f172a;
  --text-2:    #475569;
  --text-3:    #94a3b8;

  --accent:    #0284c7;
  --accent-d:  #0369a1;
  --ok:        #059669;
  --ok-bg:     #ecfdf5;
  --warn:      #d97706;
  --warn-bg:   #fffbeb;
  --err:       #dc2626;
  --err-bg:    #fef2f2;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.04);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Barra superiore ------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  height: 52px;
  padding: 0 20px;
  background: #0f172a;
  color: #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand { display: flex; align-items: center; gap: 9px; color: #fff; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  background: #38bdf8; color: #0f172a;
  border-radius: 5px; font-size: 12px; font-weight: 800;
}
.brand-text { font-size: 14px; letter-spacing: -.01em; }

.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a {
  padding: 6px 11px;
  border-radius: var(--radius);
  color: #94a3b8;
  font-size: 13px;
  white-space: nowrap;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #e2e8f0; text-decoration: none; }
.nav a.active { background: rgba(56,189,248,.15); color: #7dd3fc; font-weight: 500; }

.user { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.user-name { color: #cbd5e1; }
.badge-role {
  background: rgba(255,255,255,.1);
  color: #94a3b8;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: .04em;
}

/* --- Struttura ------------------------------------------------------ */

.main { padding: 20px; max-width: 1600px; margin: 0 auto; }
.main-wide { max-width: none; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.02em; }
.page-head .sub { color: var(--text-2); font-size: 13px; margin-top: 3px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.card-body { padding: 16px; }
.card-body-flush { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* --- Indicatori ----------------------------------------------------- */

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
  font-weight: 600;
}
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; }
.kpi-note { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* --- Tabelle -------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-2);
  font-weight: 600;
  white-space: nowrap;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.muted { color: var(--text-3); }

.table-scroll { overflow-x: auto; }

/* --- Pulsanti ------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-d); border-color: var(--accent-d); }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.18); color: #cbd5e1; }
.btn-ghost:hover { background: rgba(255,255,255,.08); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Moduli --------------------------------------------------------- */

.field { margin-bottom: 13px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 4px;
}
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=url], select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  font: inherit;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(2,132,199,.25);
  outline-offset: -1px;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 70px; }
.field-inline { display: flex; align-items: center; gap: 7px; }
.field-inline label { margin: 0; font-weight: 500; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 130px; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 3px; }

.filters {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 120px; }

/* --- Etichette ------------------------------------------------------ */

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.badge-ok    { background: var(--ok-bg);   color: var(--ok); }
.badge-warn  { background: var(--warn-bg); color: var(--warn); }
.badge-err   { background: var(--err-bg);  color: var(--err); }
.badge-muted { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

.chan-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}

/* --- Messaggi ------------------------------------------------------- */

.flash-wrap { max-width: 1600px; margin: 14px auto 0; padding: 0 20px; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 8px;
  border: 1px solid;
}
.flash-success { background: var(--ok-bg);   color: #065f46; border-color: #a7f3d0; }
.flash-error   { background: var(--err-bg);  color: #991b1b; border-color: #fecaca; }
.flash-info    { background: #eff6ff;        color: #1e40af; border-color: #bfdbfe; }

.empty { text-align: center; padding: 50px 20px; color: var(--text-2); }
.empty h2 { font-size: 16px; margin: 0 0 6px; color: var(--text); }
.empty p { margin: 0 0 16px; font-size: 13px; }

/* ====================================================================
   CALENDARIO — la schermata centrale
   ==================================================================== */

.cal-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 210px);
}

.cal { border-collapse: separate; border-spacing: 0; font-size: 12px; }

/* La prima colonna resta visibile mentre si scorre di lato: senza, dopo
   dieci giorni non si sa piu' quale riga si sta guardando. */
.cal th.sticky-l, .cal td.sticky-l {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--surface);
  border-right: 2px solid var(--border-2);
  min-width: 190px;
  max-width: 190px;
}
.cal thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--surface-2);
  padding: 5px 4px;
  text-align: center;
  min-width: 58px;
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
  border-bottom: 1px solid var(--border-2);
}
.cal thead th.sticky-l { z-index: 6; text-align: left; padding-left: 12px; }
.cal thead th.weekend { background: #eef2ff; color: #3730a3; }
.cal thead th.today   { background: #0284c7; color: #fff; }
.cal th .dow { display: block; font-weight: 500; opacity: .75; }
.cal th .dnum { display: block; font-size: 13px; font-weight: 700; }

.cal tbody td { padding: 0; text-align: center; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.cal tbody td.weekend { background: #f5f7ff; }
.cal tbody td.past    { background: #f8fafc; opacity: .55; }

.row-room > td.sticky-l { font-weight: 650; background: #f8fafc; }
.row-room td { background: #fcfdfe; }
.row-plan > td.sticky-l { padding-left: 24px; color: var(--text-2); font-size: 11px; }

.room-label { display: block; padding: 7px 12px; line-height: 1.3; }
.room-label small { display: block; color: var(--text-3); font-weight: 400; font-size: 10px; }

/* Le celle sono input diretti: nel lavoro reale si tabula da una all'altra,
   aprire una finestra per ogni giorno sarebbe insostenibile. */
.cell {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 6px 2px;
  text-align: center;
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: inherit;
}
.cell:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: #fff; }
.cell:disabled { color: var(--text-2); }

.cell-avail { font-weight: 650; }
.cell-avail.zero { color: var(--err); background: var(--err-bg); }
.cell-avail.low  { color: var(--warn); }
.cell-rate { color: var(--text); }
.cell-closed { background: repeating-linear-gradient(45deg, #fee2e2, #fee2e2 4px, #fecaca 4px, #fecaca 8px); }

.cell-saving { background: #fef9c3 !important; }
.cell-saved  { background: #dcfce7 !important; transition: background .8s; }
.cell-error  { background: #fee2e2 !important; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); padding: 10px 2px 0; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: block; }

/* --- Pannello modifica massiva -------------------------------------- */

.bulk { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.bulk summary {
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 7px;
}
.bulk summary::-webkit-details-marker { display: none; }
.bulk summary::before { content: '▸'; color: var(--text-3); }
.bulk[open] summary::before { content: '▾'; }
.bulk[open] summary { border-bottom: 1px solid var(--border); }
.bulk-body { padding: 16px; }

.dow-picker { display: flex; gap: 5px; flex-wrap: wrap; }
.dow-picker label {
  padding: 5px 9px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  user-select: none;
  margin: 0;
}
.dow-picker input { display: none; }
.dow-picker input:checked + span { color: var(--accent); }
.dow-picker label:has(input:checked) { background: #e0f2fe; border-color: var(--accent); }

.check-list { display: grid; gap: 5px; max-height: 190px; overflow-y: auto; padding: 9px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.check-list label { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 400; margin: 0; cursor: pointer; }

.apply-row { display: flex; align-items: center; gap: 9px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.apply-row:last-child { border-bottom: 0; }
.apply-row > label:first-child { display: flex; align-items: center; gap: 6px; min-width: 168px; font-size: 12px; font-weight: 500; margin: 0; cursor: pointer; }
.apply-row input[type=number], .apply-row select { max-width: 130px; }

/* --- Prenotazioni nel calendario ------------------------------------ */

.bk-strip { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 12px; font-size: 11px; }
.bk-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 10px; }
  .nav { order: 3; width: 100%; }
  .main { padding: 12px; }
}

@media print {
  .topbar, .bulk, .filters, .btn { display: none !important; }
  .cal-wrap { max-height: none; overflow: visible; border: 0; }
}
