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

:root {
  /* Tema chiaro — usato da login, lobby (testo/form), dashboard, invito.
     La schermata di chiamata e l'anteprima camera restano SEMPRE scure
     (colori scritti diretti, non da queste variabili) per leggibilità
     dei controlli sopra il video, come nelle altre app di videochiamata. */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #3b82f6;
  --green: #22c55e;
  --orange: #f97316;
  --red: #ef4444;
}

html, body {
  height: 100%;
  background:
    radial-gradient(ellipse 900px 600px at 50% -10%, rgba(59,130,246,0.07), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ===== SCREEN / CARD (login, lobby, dashboard) ===== */
.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card h1 { font-size: 22px; font-weight: 800; }
.card h2 { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.sub { font-size: 13px; color: var(--muted); margin-top: -6px; }

label { font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 4px; }

input[type="text"], input[type="password"], input[type="email"], input[type="date"], input[type="time"], input[type="number"] {
  width: 100%;
  background: #ffffff;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
input::placeholder { color: #9ca3af; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }

.row-2 { display: flex; gap: 12px; }
.row-2 > div { flex: 1; }

.btn-primary {
  margin-top: 6px;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  display: block;
}
.btn-primary:active { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-ghost {
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.12);
  background: rgba(0,0,0,0.035);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn-ghost svg { flex-shrink: 0; }
.btn-ghost:active { opacity: 0.75; }
.btn-ghost.small { padding: 6px 12px; font-size: 12px; }
.btn-ghost.danger { color: var(--red); border-color: rgba(239,68,68,0.35); }

.error { color: var(--red); font-size: 13px; min-height: 16px; }

/* ===== LOBBY (anteprima prima di entrare in stanza) ===== */
.page-brand {
  position: fixed;
  top: 28px;
  left: 32px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}
.page-brand .brand-mark { width: 30px; height: 30px; border-radius: 8px; }

.lobby-wrap {
  width: 100%;
  max-width: 1040px;
  display: flex;
  align-items: center;
  gap: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.08);
}

.lobby-preview {
  position: relative;
  flex: 1 1 520px;
  max-width: 600px;
  aspect-ratio: 16 / 9;
  border-radius: 20px;
  overflow: hidden;
  background: #0b0b0e;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);
}

#preview-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #17181c;
  color: rgba(255,255,255,0.3);
}

.preview-controls {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  z-index: 2;
}

.preview-ctrl-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(20,20,20,0.75);
  color: #f0f0f0; /* sempre chiaro: il pulsante sta sempre sopra il video scuro */
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: background 0.15s;
}
.preview-ctrl-btn:hover { background: rgba(255,255,255,0.15); }
.preview-ctrl-btn.off { background: var(--red); border-color: transparent; }
.preview-ctrl-btn:disabled { opacity: 0.4; cursor: default; }

.preview-error {
  position: absolute;
  bottom: 70px;
  left: 12px;
  right: 12px;
  text-align: center;
  font-size: 12px;
  color: rgba(255,255,255,0.55);
}

.lobby-info {
  flex: 1 1 320px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.lobby-eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.lobby-info h1 { font-size: 30px; font-weight: 800; line-height: 1.25; margin-bottom: 10px; }

.lobby-time {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: #f4f5f7;
  border-radius: 999px;
  padding: 8px 16px;
  margin-bottom: 28px;
}
.lobby-time svg { margin-right: 7px; flex-shrink: 0; }

.lobby-label { margin-top: 0; margin-bottom: 8px; }
#lobby-name { margin-bottom: 18px; }

.lobby-device-select {
  width: 100%;
  background: #ffffff;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  margin-bottom: 14px;
}
.lobby-device-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
.lobby-device-select:disabled { opacity: 0.5; }

@media (max-width: 760px) {
  .lobby-wrap { flex-direction: column; gap: 24px; padding: 18px; border-radius: 20px; }
  .lobby-preview { max-width: 100%; width: 100%; }
  .lobby-info { width: 100%; }
  .lobby-info h1 { font-size: 24px; }
}

/* ===== DASHBOARD (admin) ===== */
#dashboard-screen { align-items: flex-start; }
#dashboard-screen.screen { display: block; padding: 32px 24px; }

.dashboard-inner { max-width: 1080px; margin: 0 auto; }

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(59,130,246,0.15);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.login-card { text-align: center; }
.login-card .brand-mark { width: 44px; height: 44px; margin: 0 auto 2px; }

.topbar {
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar .brand { display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 20px; font-weight: 800; line-height: 1.2; }
.topbar-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 860px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}
.form-card, .list-card { margin: 0; max-width: none; width: 100%; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.quota-badge, .role-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: rgba(59,130,246,0.1);
  color: #2563eb;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.users-card { max-width: none; margin-top: 24px; }
.user-create-form {
  display: grid;
  grid-template-columns: 1fr 1.25fr 150px auto;
  gap: 10px;
  align-items: center;
  margin-top: 6px;
}
.user-create-form .btn-primary { margin: 0; white-space: nowrap; }
.user-row {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.user-row.inactive { opacity: 0.58; }
.user-summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; }
.user-summary > span { color: var(--muted); }
.role-badge { padding: 3px 8px; margin-left: 5px; }
.user-controls {
  display: grid;
  grid-template-columns: 150px minmax(220px, 1fr) auto auto;
  align-items: end;
  gap: 10px;
  margin-top: 10px;
}
.user-controls label { display: flex; flex-direction: column; gap: 5px; margin: 0; }
.user-controls .active-control { flex-direction: row; align-items: center; align-self: center; white-space: nowrap; }
.user-controls .save-user { align-self: center; justify-content: center; }
.user-row-error { margin-top: 5px; }

@media (max-width: 760px) {
  .user-create-form, .user-controls { grid-template-columns: 1fr; }
  .user-summary { align-items: flex-start; flex-direction: column; }
}

.card h2 { display: flex; align-items: center; gap: 8px; }
.card-icon {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.appt-card {
  display: flex;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 10px;
  transition: border-color 0.15s;
}
.appt-card:hover { border-color: rgba(0,0,0,0.18); }

.appt-date-badge {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 10px;
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
}
.appt-date-badge .day   { font-size: 18px; font-weight: 800; color: #1d4ed8; }
.appt-date-badge .month { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--accent); }

.appt-date-badge.lg { width: 64px; height: 64px; border-radius: 14px; }
.appt-date-badge.lg .day   { font-size: 24px; }
.appt-date-badge.lg .month { font-size: 11px; }

.appt-body { flex: 1; min-width: 0; }
.appt-title { font-size: 15px; font-weight: 700; }
.appt-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.appt-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.appt-actions .btn-ghost { gap: 5px; }
.appt-actions svg { flex-shrink: 0; }

.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
}
.empty-state svg { margin-bottom: 10px; opacity: 0.45; }
.empty-state p { font-size: 13px; }

/* ===== PAGINA INVITO (pubblica, per chi riceve il link) ===== */
.invite-screen { align-items: center; }
.invite-card-v2 {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.12);
}

.invite-hero {
  position: relative;
  height: 142px;
  background: linear-gradient(135deg, #4f7df3, #7c6ff0 55%, #a76ff0);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 24px 0;
  text-align: center;
}
.invite-hero-heading {
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
}
.invite-hero-heading h1 {
  color: #fff;
  font-size: 29px;
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: -0.02em;
  text-align: center;
}
.invite-hero-heading h1 strong { font-weight: 800; }
.invite-hero-icon {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 68px;
  height: 68px;
  border-radius: 20px;
  background: var(--surface);
  color: #4f6df3;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, 34px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}

.invite-body {
  padding: 48px 40px 36px;
  text-align: center;
}

.invite-title-v2 {
  width: 100%;
  max-width: 430px;
  margin: 12px auto 0;
  font-size: 36px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.invite-meta-chip {
  display: inline-block;
  margin-top: 14px;
  margin-bottom: 26px;
  padding: 8px 16px;
  border-radius: 999px;
  background: #f4f5f7;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.btn-primary.lg { padding: 15px; font-size: 16px; }

.invite-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 0 20px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.invite-divider::before, .invite-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.invite-cal-row {
  display: flex;
  justify-content: center;
  gap: 28px;
}
.cal-icon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}
.cal-icon-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}
.cal-icon-btn:hover .cal-icon-circle { transform: translateY(-3px); }
.cal-icon-circle.blue   { background: rgba(66,133,244,0.14);  color: #4285F4; }
.cal-icon-circle.indigo { background: rgba(0,120,212,0.14);   color: #0078D4; }
.cal-icon-circle.green  { background: rgba(59,130,246,0.14);  color: #3b82f6; }

@media (max-width: 480px) {
  .invite-screen { align-items: flex-start; padding-top: 30px; }
  .invite-hero { height: 132px; padding-top: 21px; }
  .invite-hero-heading h1 { font-size: 24px; }
  .invite-body { padding: 44px 22px 30px; }
  .invite-title-v2 { font-size: 30px; }
  .invite-cal-row { gap: 18px; }
}

/* ===== CALL SCREEN (stanza videochiamata) ===== */
#call-screen {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: #000;
}

#remote-grid {
  position: absolute;
  inset: 0;
  display: grid;
  background: #000;
  gap: 2px;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
#remote-grid.count-2 { grid-template-columns: 1fr 1fr; }
#remote-grid.count-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#remote-grid.count-3 .remote-cell:nth-child(3) { grid-column: 1 / 3; }
#remote-grid.count-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.remote-cell { position: relative; background: #111; overflow: hidden; }
.remote-cell video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* Schermo condiviso: va mostrato per intero, mai ritagliato ai bordi */
.remote-cell.is-screen { background: #000; }
.remote-cell.is-screen video { object-fit: contain; }

/* Modalità presentazione: mentre qualcuno condivide lo schermo (grande, in
   #remote-grid), le webcam di tutti gli altri diventano piccole miniature —
   posizionate inizialmente sul bordo destro (MAI al centro, per non coprire
   la condivisione), ma libere da trascinare ovunque con il mouse/dito. */
#thumb-strip {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none; /* il contenitore non deve bloccare i click sullo schermo condiviso */
}
#thumb-strip.hidden { display: none !important; }
#thumb-strip .remote-cell {
  position: fixed;
  width: 160px;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  cursor: grab;
  touch-action: none;
  pointer-events: auto;
}
#thumb-strip .remote-cell:active { cursor: grabbing; }
#thumb-strip .remote-cell-label { font-size: 11px; padding: 1px 6px; }
@media (max-width: 700px) {
  #thumb-strip .remote-cell { width: 110px; }
}
.remote-cell-label {
  position: absolute;
  bottom: 8px;
  left: 10px;
  z-index: 2;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  background: rgba(0,0,0,0.5);
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}

#call-name-badge {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 50;
  background: rgba(0,0,0,0.6);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  pointer-events: none;
}

#local-pip {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: 50;
  width: 200px;
  aspect-ratio: 16/9;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.12);
  background: #111;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  cursor: grab;
  touch-action: none;
}
#local-pip:active { cursor: grabbing; }
#local-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

#controls-bar {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  gap: 16px;
}
#controls-bar button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(20,20,20,0.88);
  color: #f0f0f0; /* sempre chiaro: i controlli stanno sempre sopra il video scuro */
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background 0.2s, transform 0.1s;
}
#controls-bar button:hover  { background: rgba(255,255,255,0.15); }
#controls-bar button:active { transform: scale(0.92); }
#mute-btn.muted    { background: var(--red); border-color: transparent; }
#camera-btn.muted  { background: var(--red); border-color: transparent; }
#speaker-btn.muted { background: var(--red); border-color: transparent; }
#screenshare-btn.active { background: var(--accent); border-color: transparent; }
#hangup-btn        { background: var(--red); border-color: transparent; }
#hangup-btn:hover  { background: #dc2626 !important; }

/* ===== TOAST ===== */
#toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(30,30,30,0.95);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  color: rgba(255,255,255,0.8);
  white-space: nowrap;
  pointer-events: none;
}
#toast.hidden { display: none !important; }

@media (max-width: 480px) {
  #local-pip { width: 120px; bottom: 90px; right: 12px; }
  #controls-bar button { width: 46px; height: 46px; }
}
