:root {
  --ink: #ffffff;
  --panel: #f6f5f2;
  --panel-2: #eeece5;
  --line: #d9d5c9;
  --text: #1b1f23;
  --text-dim: #6c7075;
  --brass: #a8791c;
  --brass-soft: #8a6a1d;
  --ok: #4c9a6a;
  --danger: #c1533b;
  --radius: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;
  --mono: 'Space Mono', 'Courier New', monospace;
  --sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

/* ---- Header: barra fluttuante moderna ---- */
.plaque-header {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 10px rgba(27,31,35,.04);
  padding: 18px 24px;
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.plaque-header .brand {
  font-family: var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--brass-soft);
}

.plaque-header h1 {
  font-size: 22px;
  margin: 4px 0 0;
  font-weight: 600;
}

.header-actions { display: flex; gap: 10px; align-items: center; }

/* ---- Buttons ---- */
button, .btn {
  font-family: var(--sans);
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
button:hover, .btn:hover { border-color: var(--brass); }
button.primary {
  background: var(--brass);
  border-color: var(--brass);
  color: #1a1305;
  font-weight: 600;
}
button.primary:hover { background: var(--brass-soft); }
button.ghost { background: transparent; }
button.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ---- Cards / panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 10px rgba(27,31,35,.03);
  padding: 22px;
  margin-bottom: 20px;
}
.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-dim);
  margin: 0 0 16px;
  font-family: var(--mono);
}

/* ---- Room grid ---- */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.room-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(27,31,35,.03);
  padding: 16px;
  cursor: pointer;
  transition: border-color .15s ease, transform .1s ease, box-shadow .15s ease;
}
.room-card:hover { border-color: var(--brass); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(27,31,35,.08); }
.room-card.selected { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass); }
.room-card .room-number {
  font-family: var(--mono);
  color: var(--brass-soft);
  font-size: 12px;
  letter-spacing: .08em;
}
.room-card h3 { margin: 6px 0 4px; font-size: 16px; }
.room-card .meta { color: var(--text-dim); font-size: 13px; }
.room-card .rate { font-family: var(--mono); color: var(--text); margin-top: 10px; font-size: 14px; }

/* ---- Day timeline (elemento distintivo: striscia oraria stile targa prenotazione porta) ---- */
.timeline {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  height: 64px;
  display: flex;
}
.timeline .hour-slot {
  flex: 1;
  position: relative;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  padding: 4px 6px;
  border-right: 1px solid var(--line);
}
.timeline .hour-slot:last-child { border-right: none; }
.timeline .booked-block {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--brass);
  opacity: .85;
  border-left: 2px solid var(--brass-soft);
}
.timeline .booked-block.mine { background: var(--ok); border-left-color: #7fd19f; }

/* ---- Form ---- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-family: var(--mono);
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 14px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brass);
}
.row { display: flex; gap: 12px; }
.row > .field { flex: 1; }

/* ---- Booking list ---- */
.booking-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  gap: 12px;
  flex-wrap: wrap;
}
.booking-row:last-child { border-bottom: none; }
.booking-row .info { font-size: 14px; }
.booking-row .room { color: var(--brass-soft); font-family: var(--mono); font-size: 12px; }
.tag {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.tag.paid { background: rgba(76,154,106,.15); color: var(--ok); }
.tag.pending { background: rgba(201,162,39,.15); color: var(--brass-soft); }
.tag.free { background: rgba(76,154,106,.15); color: var(--ok); }
.tag.cancelled { background: rgba(193,83,59,.15); color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 14px;
}

.msg { padding: 10px 14px; border-radius: var(--radius); font-size: 14px; margin-bottom: 14px; }
.msg.error { background: rgba(193,83,59,.12); color: #e28d7c; border: 1px solid rgba(193,83,59,.4); }
.msg.success { background: rgba(76,154,106,.12); color: #8fd6ab; border: 1px solid rgba(76,154,106,.4); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; }
.stat-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat-box .num { font-family: var(--mono); font-size: 26px; color: var(--brass-soft); }
.stat-box .label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--text-dim); font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  padding: 9px 18px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--panel);
  transition: border-color .15s ease, color .15s ease;
}
.tab:hover { border-color: var(--brass); }
.tab.active { color: var(--brass-soft); border-color: var(--brass); font-weight: 600; background: var(--ink); }

.hidden { display: none !important; }

.quota-row {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.quota-row .quota-row-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.quota-row .remove-quota-btn { font-size: 12px; padding: 4px 10px; }

.weekday-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.weekday-picker label {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
.weekday-picker input { width: auto; }

.calendar-room-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.calendar-room-row .room-label {
  width: 170px;
  flex-shrink: 0;
}
.calendar-room-row .room-label .name { font-size: 14px; font-weight: 600; }
.calendar-room-row .room-label .hours { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.calendar-room-row .timeline { flex: 1; }
.calendar-legend { display:flex; gap:16px; margin-bottom:16px; font-size:12px; color:var(--text-dim); align-items:center; }
.calendar-legend .swatch { display:inline-block; width:10px; height:10px; border-radius:2px; margin-right:5px; vertical-align:middle; }

/* ---- Timeline scrollabile (necessario su schermi stretti) ---- */
.timeline-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.timeline-scroll .timeline { min-width: 640px; }

/* ---- Tabelle scrollabili su mobile ---- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll table { min-width: 520px; }

/* ---- Menu profilo a tendina (client) ---- */
.profile-menu { position: relative; }
.profile-menu-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
  color: var(--text);
  background: transparent;
}
.profile-menu-trigger:hover { border-color: var(--line); }
.profile-menu-trigger .caret { font-size: 10px; color: var(--text-dim); }
.profile-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  z-index: 50;
}
.profile-dropdown h2 { margin-top: 0; }

/* ---- View switcher (giorno / settimana / mese) ---- */
.view-switcher { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.view-switcher button { padding: 7px 14px; font-size: 13px; }
.view-switcher button.active { background: var(--brass); border-color: var(--brass); color: #1a1305; font-weight: 600; }
.calendar-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.calendar-nav .current-label { font-family: var(--mono); font-size: 13px; color: var(--text-dim); min-width: 140px; }

/* ---- Vista GRID (agenda): righe = giorni, colonne = servizi, elenco prenotazioni ---- */
.agenda-table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.agenda-header-row, .agenda-day-row {
  display: grid;
}
.agenda-header-cell {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
}
.agenda-header-cell:last-child { border-right: none; }
.agenda-day-label {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 10px 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--brass-soft);
  font-weight: 600;
}
.agenda-day-label.today { color: var(--ok); }
.agenda-cell {
  background: var(--ink);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 6px;
  min-height: 44px;
}
.agenda-cell:last-child { border-right: none; }
.agenda-item {
  background: var(--panel-2);
  border-left: 3px solid var(--brass);
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 4px;
  font-size: 12px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agenda-item.mine { border-left-color: var(--ok); }
.agenda-item .t { font-family: var(--mono); color: var(--brass-soft); margin-right: 5px; }
.agenda-item.mine .t { color: var(--ok); }
.agenda-add {
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  text-align: center;
  border-radius: 4px;
  padding: 2px;
  opacity: 0;
  transition: opacity .1s ease, background .1s ease;
}
.agenda-cell:hover .agenda-add { opacity: 1; }
.agenda-add:hover { background: var(--panel-2); color: var(--brass); }

/* ---- Vista DAY: griglia oraria interattiva, click-to-book ---- */
.dgrid-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.dgrid {
  display: grid;
  min-width: 100%;
  width: max-content;
}
.dgrid-corner { background: var(--panel); border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); position: sticky; left: 0; z-index: 3; }
.dgrid-head {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
}
.dgrid-time {
  background: var(--panel);
  border-right: 1px solid var(--line);
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  padding: 2px 8px;
  position: sticky;
  left: 0;
  z-index: 2;
}
.dgrid-cell {
  background: var(--ink);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  cursor: pointer;
  transition: background .1s ease;
}
.dgrid-cell:hover { background: var(--panel-2); }
.dgrid-cell.disabled {
  background: repeating-linear-gradient(45deg, var(--ink), var(--ink) 5px, var(--line) 5px, var(--line) 6px);
  cursor: not-allowed;
  opacity: .5;
}
.dgrid-booking {
  background: var(--brass);
  color: #1a1305;
  border-radius: 6px;
  padding: 4px 8px;
  margin: 1px 3px;
  font-size: 12px;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(27,31,35,.15);
}
.dgrid-booking.mine { background: var(--ok); color: #fff; }
.dgrid-booking .t { font-family: var(--mono); font-size: 10px; display: block; opacity: .85; }

/* ---- Popup (modale) per creare/vedere una prenotazione ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27,31,35,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-box {
  background: var(--ink);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
}
.modal-box h2 { margin-top: 0; }
.modal-close { position: absolute; top: 14px; right: 14px; }

/* ---- Vista mese: griglia calendario ---- */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.month-weekday-label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-dim);
  text-align: center;
  padding-bottom: 4px;
}
.month-day-cell {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 90px;
  padding: 6px 8px;
  transition: border-color .15s ease;
}
.month-day-cell:hover { border-color: var(--brass); }
.month-day-cell.other-month { opacity: .35; }
.month-day-cell.today { border-color: var(--brass); }
.month-day-cell .date-num { font-family: var(--mono); font-size: 13px; cursor: pointer; display: inline-block; }
.month-day-cell .date-num:hover { color: var(--brass-soft); text-decoration: underline; }
.month-day-cell .count-badge {
  display: inline-block;
  margin-top: 6px;
  background: var(--brass);
  color: #1a1305;
  font-size: 11px;
  font-family: var(--mono);
  padding: 1px 6px;
  border-radius: 10px;
}
.month-booking-item {
  font-size: 11px;
  padding: 2px 5px;
  border-radius: 3px;
  background: var(--ink);
  border-left: 2px solid var(--brass);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.month-booking-item.mine { border-left-color: var(--ok); }
.month-booking-item .t { font-family: var(--mono); color: var(--brass-soft); margin-right: 4px; }
.month-more-link { font-size: 11px; color: var(--brass-soft); cursor: pointer; margin-top: 3px; display: inline-block; }
.month-more-link:hover { text-decoration: underline; }

/* ================= RESPONSIVE ================= */
@media (max-width: 640px) {
  .row { flex-direction: column; }
}

@media (max-width: 860px) {
  .wrap { padding: 0 14px 48px; }
  .plaque-header { padding: 18px 0 16px; margin-bottom: 20px; }
  .plaque-header h1 { font-size: 18px; }
  .header-actions { width: 100%; justify-content: space-between; }

  .tabs.main-tabs, .tabs.auth-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .tabs.main-tabs .tab, .tabs.auth-tabs .tab {
    white-space: nowrap;
    padding: 10px 12px;
  }

  .panel { padding: 14px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .rooms-grid { grid-template-columns: 1fr; }

  .calendar-room-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .calendar-room-row .room-label { width: 100%; }

  .profile-dropdown { width: 240px; right: -8px; }

  table { font-size: 13px; }
  th, td { padding: 8px 6px; }
}

@media (max-width: 480px) {
  .plaque-header .brand { font-size: 11px; }
  .booking-row { flex-direction: column; align-items: flex-start; }
  .booking-row > div:last-child { width: 100%; display: flex; justify-content: space-between; align-items: center; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .view-switcher { width: 100%; }
  .view-switcher button { flex: 1; }
}
