/* ============================================================
   AgenziaHub — App-style theme
   ============================================================ */

:root {
  --sidebar-w: 252px;
  --topbar-h: 60px;
  /* Defaults = Moderna Indigo (overridden per-agenzia via _UiThemeVars) */
  --sidebar-from: #1e1b4b;
  --sidebar-to: #2d2a5e;
  --sidebar-text: rgba(255,255,255,0.62);
  --sidebar-text-active: #fff;
  --sidebar-accent: #818cf8;
  --sidebar-active-bg: rgba(129,140,248,0.18);
  --sidebar-hover-bg: rgba(255,255,255,0.06);
  --bg: #f1f5f9;
  --surface: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1), 0 8px 24px rgba(0,0,0,0.06);
  --radius-sm: 8px;
  --radius-md: 12px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --primary: #6366f1;
  --primary-rgb: 99,102,241;
  --accent: #818cf8;
  --accent-rgb: 129,140,248;
}

/* ---- Base ---- */
html {
  font-size: 14px;
  position: relative;
  min-height: 100%;
  box-sizing: border-box;
}
@media (min-width: 768px) { html { font-size: 15px; } }
*, *::before, *::after { box-sizing: inherit; }

body {
  background: var(--bg);
  color: #1e293b;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  margin: 0;
}

/* ---- App shell ---- */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: linear-gradient(175deg, var(--sidebar-from) 0%, var(--sidebar-to) 100%);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1000;
  transition: transform var(--transition);
  box-shadow: 4px 0 24px rgba(0,0,0,0.18);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Brand */
.sidebar-header {
  padding: 22px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: #fff;
}

.brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.45);
}

.brand-name {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.module-switcher {
  display: flex;
  gap: 6px;
  margin-top: 14px;
}

.module-switcher-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none;
  color: rgba(255,255,255,0.55);
  background: rgba(255,255,255,0.06);
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.module-switcher-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.12);
}

.module-switcher-btn.active {
  color: #fff;
  background: color-mix(in srgb, var(--primary) 35%, transparent);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

.module-switcher-btn i {
  font-size: 0.85rem;
}

/* Section labels */
.sidebar-section-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  padding: 16px 20px 4px;
}

/* Nav items */
.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 4px 12px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  line-height: 1.4;
}

.sidebar-link i {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  transition: color var(--transition);
}

.sidebar-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
  text-decoration: none;
}

.sidebar-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
}

.sidebar-link.active i {
  color: var(--sidebar-accent);
}

.sidebar-link-logout {
  color: rgba(252, 165, 165, 0.75) !important;
}
.sidebar-link-logout:hover {
  color: #fca5a5 !important;
  background: rgba(239,68,68,0.12) !important;
}

/* Notification badge */
.sidebar-notif-badge {
  margin-left: auto;
  background: #ef4444;
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  min-width: 18px;
  text-align: center;
  line-height: 1.4;
}

/* Bottom section (account) */
.sidebar-bottom {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 8px;
  flex-shrink: 0;
}

/* User card */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin: 6px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  min-width: 0;
}

.user-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.user-info { min-width: 0; }

.user-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255,255,255,0.88);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.62rem;
  color: rgba(255,255,255,0.38);
}

/* ---- Mobile overlay ---- */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  backdrop-filter: blur(2px);
}

@media (max-width: 767px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0 !important; }
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* Top bar */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.topbar-toggle {
  background: none;
  border: none;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: #64748b;
  font-size: 1.25rem;
  cursor: pointer;
  transition: all var(--transition);
  display: none;
  align-items: center;
  line-height: 1;
}

@media (max-width: 767px) {
  .topbar-toggle { display: flex; }
}

.topbar-toggle:hover { background: #f1f5f9; color: #1e293b; }

.topbar-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #1e293b;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-module-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  margin-right: 4px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  background: color-mix(in srgb, var(--primary) 10%, white);
  border: 1px solid color-mix(in srgb, var(--primary) 28%, white);
  transition: background 0.15s, color 0.15s;
}

.topbar-module-link:hover {
  background: color-mix(in srgb, var(--primary) 16%, white);
  color: color-mix(in srgb, var(--primary) 85%, black);
}

@media (max-width: 576px) {
  .topbar-module-link span {
    display: none;
  }
  .topbar-module-link {
    padding: 6px 10px;
  }
}

.topbar-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: #64748b;
  text-decoration: none;
  font-size: 1.05rem;
  transition: all var(--transition);
  position: relative;
}

.topbar-icon:hover { background: #f1f5f9; color: #1e293b; }

.topbar-notif-badge {
  position: absolute;
  top: 5px; right: 5px;
  width: 8px; height: 8px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid white;
}

/* Content */
.content-alerts { padding: 16px 24px 0; }

.content-area {
  flex: 1;
  padding: 20px 24px 48px;
}

/* ============================================================
   AUTH PAGES (login, setup)
   ============================================================ */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(165deg, rgba(15, 23, 42, 0.62) 0%, rgba(28, 25, 23, 0.78) 100%),
    url("/img/landing-real-estate-office.jpg") center / cover no-repeat;
  background-color: #1c1917;
}

.auth-wrapper main { width: 100%; }

.auth-wrapper .card {
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.96);
}

/* ============================================================
   COMPONENTS
   ============================================================ */

/* Cards */
.card {
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
  background: var(--surface);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  background: transparent;
  border-bottom: 1px solid #f1f5f9;
  font-weight: 600;
  padding: 14px 20px;
  border-radius: var(--radius-md) var(--radius-md) 0 0 !important;
}

.card-body { padding: 20px; }
.card-footer { background: transparent; border-top: 1px solid #f1f5f9; padding: 12px 20px; }

/* Buttons */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.84rem;
  transition: all var(--transition);
}

.btn:focus, .btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.25);
  outline: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 78%, black));
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.3);
}

.btn-primary:hover, .btn-primary:focus {
  background: linear-gradient(135deg, var(--accent), var(--primary));
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.4);
  transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }

.btn-outline-primary {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-outline-primary:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Forms */
.form-control, .form-select {
  border-radius: var(--radius-sm);
  border-color: #e2e8f0;
  font-size: 0.875rem;
  transition: all var(--transition);
}

.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

.form-label {
  font-weight: 500;
  font-size: 0.8rem;
  color: #475569;
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* Alerts */
.alert {
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.875rem;
}

.alert-success { background: #f0fdf4; color: #166534; border-left: 4px solid #22c55e; }
.alert-danger  { background: #fef2f2; color: #991b1b; border-left: 4px solid #ef4444; }
.alert-warning { background: #fffbeb; color: #92400e; border-left: 4px solid #f59e0b; }
.alert-info    { background: #eff6ff; color: #1e40af; border-left: 4px solid #3b82f6; }

/* Tables */
.table { font-size: 0.875rem; }

.table th {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #64748b;
}

/* Calendar grid: appointment blocks stay clickable above later rows */
.calendar-grid tbody tr {
  position: relative;
}

.calendar-grid tbody tr:has(.appt-item) {
  z-index: 1;
}

.calendar-grid tbody tr:has(.appt-item:hover),
.calendar-grid tbody tr:has(.appt-item:focus-within) {
  z-index: 5;
}

.calendar-grid .appt-item {
  z-index: 10;
}

/* Status badge on colored appointment blocks (grid/week) */
.appt-item .appt-status-badge {
  flex-shrink: 0;
  font-size: 0.65rem;
  line-height: 1.1;
  padding: 2px 5px;
  background: rgba(255, 255, 255, 0.94) !important;
  color: #0f172a !important;
  border: 1px solid rgba(15, 23, 42, 0.18);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.appt-status-inattesa {
  border-left: 3px solid #ffc107;
}

.appt-status-confermato {
  border-left: 3px solid #198754;
}

.appt-status-completato {
  border-left: 3px solid #6c757d;
}

.appt-status-cancellato {
  border-left: 3px solid #dc3545;
}

.appt-status-nonpresentato {
  border-left: 3px solid #212529;
}

/* Badges */
.badge {
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.68rem;
  padding: 4px 8px;
}

/* Headings */
h1, .h1 { font-size: 1.45rem; font-weight: 700; color: #0f172a; }
h2, .h2 { font-size: 1.2rem;  font-weight: 700; color: #0f172a; }
h3, .h3 { font-size: 1.05rem; font-weight: 600; color: #1e293b; }
h4, .h4 { font-size: 0.95rem; font-weight: 600; color: #1e293b; }
h5, .h5 { font-size: 0.875rem; font-weight: 600; color: #1e293b; }

/* Assistant panel */
.assistant-root {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1080;
}

.assistant-fab {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 8px 24px rgba(var(--primary-rgb), 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}

.assistant-fab:hover {
  transform: translateY(-1px);
  color: #fff;
}

.assistant-panel {
  position: absolute;
  right: 0;
  bottom: 4rem;
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(32rem, calc(100vh - 6rem));
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.assistant-panel.open {
  display: flex;
}

.assistant-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

.assistant-messages {
  flex: 1;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 12rem;
}

.assistant-msg {
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.assistant-msg-user {
  align-self: flex-end;
  background: color-mix(in srgb, var(--primary) 12%, white);
  color: color-mix(in srgb, var(--primary) 55%, #0f172a);
  max-width: 92%;
}

.assistant-msg-bot {
  align-self: flex-start;
  background: #f1f5f9;
  color: #0f172a;
  max-width: 92%;
}

.assistant-form {
  padding: 0.75rem;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}

.assistant-action-card {
  align-self: stretch;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font-size: 0.85rem;
}

.assistant-action-title {
  font-weight: 700;
  color: #92400e;
  margin-bottom: 0.25rem;
}

.assistant-action-summary {
  color: #78350f;
  margin-bottom: 0.5rem;
}

.assistant-action-buttons {
  display: flex;
  gap: 0.5rem;
}

.assistant-candidates {
  margin: 0.5rem 0;
  padding: 0.65rem;
  border: 1px dashed var(--bs-border-color);
  border-radius: 0.5rem;
  background: rgba(13, 110, 253, 0.04);
}

.assistant-candidates-title {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--bs-secondary-color);
}

.assistant-candidate-btn {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 0.35rem;
  white-space: normal;
}

.assistant-candidate-btn:last-child {
  margin-bottom: 0;
}

.assistant-nav-card {
  align-self: stretch;
  background: #eff6ff;
  border: 1px solid #93c5fd;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font-size: 0.85rem;
}

.assistant-nav-title {
  font-weight: 700;
  color: #1e40af;
  margin-bottom: 0.25rem;
}

.assistant-nav-summary {
  color: #1e3a8a;
  margin-bottom: 0.5rem;
}

.assistant-nav-buttons {
  display: flex;
  gap: 0.5rem;
}

.team-photo-preview {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.team-photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.team-photo-preview i {
  font-size: 2.5rem;
}

/* Super-admin platform shell */
.platform-auth-body {
  min-height: 100vh;
  background: linear-gradient(145deg, #0f172a 0%, #1e293b 45%, #334155 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.platform-auth-shell {
  width: min(26rem, 100%);
}

.platform-auth-brand {
  color: #f8fafc;
}

.platform-auth-brand i {
  font-size: 2rem;
}

.platform-auth-card {
  border: none;
  border-radius: 14px;
}

.platform-body {
  margin: 0;
  background: #f1f5f9;
}

.platform-shell {
  display: flex;
  min-height: 100vh;
}

.platform-sidebar {
  width: 260px;
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  flex-shrink: 0;
}

.platform-sidebar-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
  padding: 0 0.25rem;
}

.platform-sidebar-brand i {
  font-size: 1.5rem;
  color: var(--accent);
}

.platform-brand-title {
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.platform-brand-sub {
  font-size: 0.75rem;
  opacity: 0.65;
}

.platform-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.platform-nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 0.9rem;
}

.platform-nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.platform-nav-link.active {
  background: rgba(99, 102, 241, 0.25);
  color: #fff;
}

.platform-sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 1rem;
}

.platform-user {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.platform-user-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.platform-user-name {
  font-size: 0.85rem;
  color: #fff;
}

.platform-user-role {
  font-size: 0.72rem;
  opacity: 0.65;
}

.platform-main {
  flex: 1;
  padding: 1.5rem 2rem;
  overflow-x: auto;
}

.platform-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.platform-page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  color: #0f172a;
}

.platform-page-sub {
  margin: 0.25rem 0 0;
  color: #64748b;
  font-size: 0.9rem;
}

.platform-stat-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem 1.1rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.platform-stat-label {
  font-size: 0.78rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.platform-stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.2;
  margin-top: 0.25rem;
}

.platform-help {
  background: #fff;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  color: #475569;
  font-size: 0.88rem;
}

@media (max-width: 768px) {
  .platform-shell {
    flex-direction: column;
  }

  .platform-sidebar {
    width: 100%;
  }

  .platform-main {
    padding: 1rem;
  }
}
