:root {
  --primary: #b8860b;
  --primary-hover: #d4a017;
  --primary-dim: rgba(184, 134, 11, 0.12);
  --primary-light: rgba(184, 134, 11, 0.08);
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --text: #1a1a2e;
  --text-dim: #5c6370;
  --text-muted: #9ca3af;
  --border: #e2e5ea;
  --border-strong: #d1d5db;
  --danger: #dc3545;
  --success: #198754;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 10% 10%, rgba(184, 134, 11, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 90% 90%, rgba(184, 134, 11, 0.04) 0%, transparent 50%);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: hidden;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* Layout */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  position: sticky;
  top: 0;
  z-index: 100;
  isolation: isolate;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
}

.logo span {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.2;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.logo-img {
  height: 42px;
  width: auto;
  object-fit: contain;
  display: block;
}

.nav-links { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

.app-header.nav-open .nav-toggle span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.app-header.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
.app-header.nav-open .nav-toggle span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}
.nav-links a { color: var(--text-dim); font-size: 0.9rem; font-weight: 500; }
.nav-links a.active, .nav-links a:hover { color: var(--primary); }

.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(184,134,11,0.25); }

.btn-outline {
  background: var(--bg-card);
  color: var(--primary);
  border: 1px solid var(--border-strong);
}
.btn-outline:hover { background: var(--primary-light); border-color: var(--primary); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: rgba(0,0,0,0.04); }

.btn-lg { padding: 0.85rem 1.75rem; font-size: 1rem; }
.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.8rem; }
.btn-icon {
  width: 44px; height: 44px; padding: 0; border-radius: 50%;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.btn-icon:hover { background: var(--primary-light); border-color: var(--primary); }
.btn-icon.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-icon.danger { background: var(--danger); color: #fff; border-color: var(--danger); }

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
  font-weight: 500;
}

input, textarea, select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

textarea { resize: vertical; min-height: 80px; }

input[type="checkbox"] { width: auto; margin-right: 0.5rem; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 1.25rem;
}

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.auth-logo-banner {
  margin: -2.5rem -2.5rem 1.75rem;
  background: #ffffff;
  padding: 1.25rem 1.5rem;
  line-height: 0;
  border-bottom: 1px solid var(--border);
}

.auth-logo-full {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

.auth-card h1 {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
  color: var(--primary);
}

.auth-card .subtitle {
  color: var(--text-dim);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }

/* Dashboard */
.hero-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 2.5rem;
}

.section-title {
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.8rem;
}

.meeting-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.meeting-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

.meeting-card .title { font-size: 1.05rem; font-weight: 600; color: var(--text); }
.meeting-card .meta { font-size: 0.85rem; color: var(--text-dim); }
.meeting-card .status {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.status-live { background: #dcfce7; color: var(--success); }
.status-scheduled { background: var(--primary-light); color: var(--primary); }
.status-ended { background: #f3f4f6; color: var(--text-muted); }

.meeting-card .actions { display: flex; gap: 0.5rem; margin-top: auto; flex-wrap: wrap; }

/* Admin table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th,
.data-table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: var(--bg);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table tr:hover td { background: var(--primary-light); }
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-admin { background: var(--primary-light); color: var(--primary); }
.badge-user { background: #f3f4f6; color: var(--text-dim); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
  opacity: 0; visibility: hidden;
  transition: all 0.2s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.modal h2 { margin-bottom: 1.5rem; font-size: 1.35rem; color: var(--text); }

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.invite-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.invite-row input { flex: 1; min-width: 0; }
.invite-row .invite-name { max-width: 140px; flex: 0 1 140px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.cal-event-row {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.hero-section {
  padding-top: 4rem;
  text-align: center;
}

.hero-section h1 {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  margin-bottom: 1rem;
  color: var(--primary);
}

.hero-section .hero-sub {
  font-size: clamp(1rem, 2.5vw, 1.15rem);
  color: var(--text-dim);
  max-width: 600px;
  margin: 0 auto 2.5rem;
}

.hero-section .hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 4rem;
}

/* Meeting room — video area scura, pannelli chiari */
.meet-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: 1fr auto;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
}

.meet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 250;
  border: none;
  padding: 0;
  cursor: pointer;
}

.video-area {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  overflow: hidden;
  background: #2d3748;
}

.video-grid {
  display: grid;
  gap: 4px;
  width: 100%;
  height: 100%;
  padding: 4px;
}

.video-grid.layout-1 { grid-template-columns: 1fr; }
.video-grid.layout-2 { grid-template-columns: 1fr 1fr; }
.video-grid.layout-3 { grid-template-columns: repeat(3, 1fr); }
.video-grid.layout-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.video-tile {
  position: relative;
  background: #1e293b;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

.video-tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  background: #0f172a;
}

.video-tile .avatar-placeholder {
  position: relative;
  z-index: 0;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(184,134,11,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: var(--primary-hover);
}

.video-tile .tile-label {
  position: absolute;
  z-index: 2;
  bottom: 8px; left: 8px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  display: flex; align-items: center; gap: 6px;
}

.video-tile .tile-label .muted-icon { color: #fca5a5; }

.sidebar-panel {
  grid-column: 2;
  grid-row: 1 / 3;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.panel-tabs button {
  flex: 1;
  padding: 0.85rem;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  border-bottom: 2px solid transparent;
}
.panel-tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--bg-card);
}

.panel-tabs button.lobby-has-waiting {
  color: var(--primary);
  animation: lobby-pulse 1.5s ease-in-out infinite;
}

.lobby-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: #b91c1c;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}

@keyframes lobby-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.panel-content { flex: 1; overflow-y: auto; padding: 1rem; }

.chat-messages { display: flex; flex-direction: column; gap: 0.75rem; }
.chat-msg .sender { font-size: 0.8rem; font-weight: 600; color: var(--primary); }
.chat-msg .text { font-size: 0.9rem; color: var(--text); }
.chat-msg.system .text { font-style: italic; color: var(--text-muted); font-size: 0.85rem; }

.chat-input-area {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  background: var(--bg);
}
.chat-input-area input { flex: 1; }

.participant-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.participant-item .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--primary); font-size: 0.85rem;
}
.participant-item .info { flex: 1; }
.participant-item .name { font-size: 0.9rem; font-weight: 500; }
.participant-item .role { font-size: 0.75rem; color: var(--text-muted); }

.meet-controls {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.meet-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
  color: #fff;
  z-index: 10;
}

.reactions-bar {
  display: flex;
  gap: 0.25rem;
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.5rem;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.2s;
}
.reactions-bar.show {
  opacity: 1;
  pointer-events: auto;
}
.reactions-bar button {
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; padding: 0.25rem 0.5rem;
  border-radius: 4px;
}
.reactions-bar button:hover { background: var(--primary-light); }

.reaction-float {
  position: absolute;
  font-size: 2rem;
  animation: floatUp 2s ease-out forwards;
  pointer-events: none;
  z-index: 50;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-120px); }
}

.lobby-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  background: var(--bg);
}
.lobby-screen h1 { font-size: 1.5rem; margin-bottom: 0.5rem; color: var(--text); }
.lobby-screen p { color: var(--text-dim); }

.pre-join {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--bg);
}
.pre-join-card {
  max-width: 720px;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: center;
}
.pre-join-preview {
  aspect-ratio: 16/9;
  background: #2d3748;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
}
.pre-join-preview video { width: 100%; height: 100%; object-fit: cover; }

.hidden { display: none !important; }

@media (max-width: 768px) {
  .logo span { display: none; }
  .logo-img { height: 36px; }

  .app-header {
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    flex-wrap: nowrap;
    gap: 0.75rem;
  }

  .nav-toggle { display: flex; }

  .app-header .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0.5rem 1rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 200;
  }

  .app-header.nav-open .nav-links { display: flex; }

  .app-header .nav-links a,
  .app-header .nav-links button,
  .app-header .nav-links span {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
  }

  .app-header .nav-links a:last-of-type,
  .app-header .nav-links button:last-of-type {
    border-bottom: none;
  }

  .app-header .nav-links .btn {
    width: 100%;
    justify-content: flex-start;
    margin-top: 0.25rem;
  }

  .container { padding: 1rem; }

  .hero-section { padding-top: 2rem; }

  .hero-actions {
    flex-direction: column;
  }

  .hero-actions .btn {
    width: 100%;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .page-header .btn { width: 100%; }

  .card { padding: 1.25rem; }

  .auth-page {
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top));
    align-items: flex-start;
  }

  .auth-card {
    padding: 1.5rem;
    margin-top: 0.5rem;
  }

  .auth-logo-banner {
    margin: -1.5rem -1.5rem 1.25rem;
    padding: 1rem 1.25rem;
  }

  input, textarea, select { font-size: 16px; }

  .modal {
    padding: 1.25rem;
    max-height: calc(100dvh - 2rem);
    border-radius: var(--radius);
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .btn {
    width: 100%;
  }

  .invite-row {
    flex-direction: column;
  }

  .invite-row .invite-name {
    max-width: none;
    flex: 1 1 auto;
  }

  .data-table { min-width: 640px; }

  .cal-event-row {
    flex-direction: column;
    align-items: stretch;
  }

  .cal-event-row .btn { width: 100%; }

  .pre-join {
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top));
    align-items: flex-start;
  }

  .pre-join-card {
    grid-template-columns: 1fr;
    gap: 1.25rem;
    padding: 1.25rem !important;
  }

  .meet-layout {
    display: flex;
    flex-direction: column;
    height: 100dvh;
  }

  .video-area {
    flex: 1;
    min-height: 0;
  }

  .meet-header {
    padding: 0.65rem 1rem;
    padding-top: calc(0.65rem + env(safe-area-inset-top));
    font-size: 0.9rem;
  }

  .meet-header #timer {
    margin-left: 0 !important;
    display: block;
    font-size: 0.8rem;
  }

  .sidebar-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: min(72vh, 520px);
    z-index: 300;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
  }

  .meet-layout.sidebar-open .sidebar-panel {
    transform: translateY(0);
  }

  .meet-layout.sidebar-open .meet-backdrop {
    display: block;
  }

  .meet-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 0.5rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  }

  .meet-controls .btn-icon {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
  }

  .reactions-bar {
    bottom: calc(88px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 2rem);
    flex-wrap: wrap;
    justify-content: center;
  }

  .video-grid.layout-2,
  .video-grid.layout-4 {
    grid-template-columns: 1fr 1fr;
  }

  .video-grid.layout-3 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: 1fr;
  }
}

@media (max-width: 380px) {
  .meet-controls .btn-icon {
    width: 44px;
    height: 44px;
  }

  .meet-controls {
    gap: 0.35rem;
  }
}
