/* ============================================================
   LAYOUT — sidebar, topbar, bottom bar, footer
   ============================================================ */

:root {
  /* ── Layout ───────────────────────────────────────────── */
  --sidebar-w:           240px;
  --sidebar-w-collapsed: 72px;
  --topbar-h:            56px;
  --bottombar-h:         60px;
  --footer-h:            40px;
  --transition:          0.3s cubic-bezier(0.2, 0.8, 0.2, 1);

  /* ── Brand WAS (override dinamico via Template.php+env) ─ */
  --accent:          #5B3CF5;
  --accent-dark:     #3D3DF2;
  --accent-end:      #7F40FF;
  --accent-light:    #ede9fe;
  --accent-text:     #3730a3;
  --accent-gradient: linear-gradient(135deg, #3D3DF2 0%, #7F40FF 100%);

  /* ── Palette semantica ────────────────────────────────── */
  --color-bg:      #f5f4ff;
  --color-surface: #ffffff;
  --color-border:  rgba(0,0,0,0.08);

  --color-text-1:  #344050;
  --color-text-2:  #5e6e82;
  --color-text-3:  #748194;
  --color-text-4:  #9da9bb;

  /* ── Status ───────────────────────────────────────────── */
  --color-success:    #00864e;
  --color-success-bg: #ccf6e4;
  --color-danger:     #e63757;
  --color-danger-bg:  #fdd8df;
  --color-warning:    #f5803e;
  --color-warning-bg: #fde3d1;
  --color-info:       #27bcfd;
  --color-info-bg:    #d0f2ff;

  /* ── Radius ───────────────────────────────────────────── */
  --radius-sm:   4px;
  --radius-md:   6px;
  --radius-lg:   6px;
  --radius-pill: 160px;

  /* ── Shadow ───────────────────────────────────────────── */
  --shadow-card: 0 7px 14px 0 rgba(65,69,88,.07), 0 3px 6px 0 rgba(0,0,0,.04);
  --shadow-sm:   0 2px 4px rgba(0,0,0,.04);

  /* ── Alias retrocompatibilità ─────────────────────────── */
  --bg-color:   var(--color-bg);
  --box-shadow: var(--shadow-card);
}

/* ── Base ─────────────────────────────────────────────────── */

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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg-color);
  font-family: 'Inter', var(--bs-font-sans-serif);
  font-size: 14px;
  color: var(--color-text-2);
}

/* ── Layout principale ────────────────────────────────────── */

/* Pagina con sidebar (utente loggato) */
body.has-sidebar {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  min-height: 100dvh;
  transition: grid-template-columns var(--transition);
}

body.has-sidebar.sidebar-collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* Pagina pubblica (login ecc.) */
body.is-public .g-main {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Il contenuto occupa lo spazio rimanente e centra verticalmente */
body.is-public .g-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

/* Rimuove min-vh-100 sulle pagine pubbliche per evitare overflow */
body.is-public .g-content .min-vh-100 {
  min-height: unset !important;
}

/* ── Sidebar ──────────────────────────────────────────────── */

.g-sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow: hidden;
  transition: width var(--transition);
  z-index: 100;
}

.sidebar-collapsed .g-sidebar {
  width: var(--sidebar-w-collapsed);
}

/* Brand */
.g-sidebar-header {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.g-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  overflow: hidden;
}

.g-brand-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
}

.g-brand-name {
  font-family: 'Outfit', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-1);
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition);
}

.g-brand-name img {
    height: 24px;
}

.sidebar-collapsed .g-brand-name {
  opacity: 0;
}

/* Nav */
.g-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}

.g-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.g-nav-section {
  padding: 12px 14px 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition);
}

.sidebar-collapsed .g-nav-section {
  opacity: 0;
}

.g-nav-item {
  margin: 1px 6px;
}

.g-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--color-text-2);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  transition: color var(--transition);
}

.g-nav-link:hover {
  color: var(--accent);
}

.g-nav-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(91,60,245,0.25);
}

.g-nav-item.active .g-nav-link {
  color: var(--accent);
  font-weight: 600;
}

.g-nav-icon {
  width: 16px;
  text-align: center;
  flex-shrink: 0;
  font-size: 16px;
}

.g-nav-label {
  font-size: 13px;
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition);
}

.sidebar-collapsed .g-nav-label {
  opacity: 0;
}

/* Footer sidebar */
.g-sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  overflow: hidden;
}

.g-user-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

.g-user-name {
  font-size: 12px;
  color: var(--color-text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transition: opacity var(--transition);
}

.sidebar-collapsed .g-user-name {
  opacity: 0;
}

.g-logout {
  color: var(--color-text-4);
  font-size: 14px;
  text-decoration: none;
  flex-shrink: 0;
  padding: 4px;
  border-radius: 4px;
  transition: color var(--transition);
}

.g-logout:hover {
  color: var(--color-danger);
}

/* ── Area principale ──────────────────────────────────────── */

.g-main {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ── Topbar ───────────────────────────────────────────────── */

.g-topbar {
  position: sticky;
  top: 0;
  z-index: 90;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: env(safe-area-inset-top, 0px) 16px 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* Logomark — visibile solo su mobile: su desktop il brand è già nella sidebar */
.g-topbar-brand {
  display: none;
  flex-shrink: 0;
}

.g-topbar-brand-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  display: block;
}

/* Toggle sidebar */
.g-sidebar-toggle {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-3);
  flex-shrink: 0;
  font-size: 18px;
  transition: background var(--transition);
}

.g-sidebar-toggle:hover {
  background: var(--color-bg);
}

/* Titolo e breadcrumb */
.g-page-info {
  flex: 1;
  min-width: 0;
}

.g-page-title {
  font-family: 'Outfit', sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-1);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-breadcrumb {
  font-size: 11px;
  color: var(--color-text-4);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-breadcrumb-tenant {
  color: var(--accent);
  font-weight: 500;
}

.g-env-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: #fff3cd;
  color: #856404;
}

/* Azioni topbar */
.g-topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Switcher tenant (solo dev/globale) — pulsante icona nel cluster azioni;
   la <select> reale resta nel DOM ma invisibile, il pulsante ne apre il
   picker nativo (vedi tenant-switch.js). Il nome del tenant attivo è nel
   breadcrumb, quindi qui basta un'icona con un pallino di stato. */
.g-tenant-switcher {
  position: relative;
}

.g-tenant-switcher-select {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  pointer-events: none;
}

.g-tenant-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  border: 1.5px solid #fff;
}

.g-icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-3);
  position: relative;
  font-size: 18px;
  transition: background var(--transition);
}

.g-icon-btn:hover {
  background: var(--color-bg);
}

.g-notify-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-danger);
  border: 1.5px solid #fff;
}

/* Avatar */
.g-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 0.5px solid rgba(0, 0, 0, 0.1);
}

.g-avatar-btn {
  cursor: pointer;
  border: 0.5px solid rgba(0, 0, 0, 0.1);
}

/* ── Dropdown utente (topbar) ─────────────────────────────── */

.g-user-dropdown {
  min-width: 240px;
  padding: 8px;
}

.g-user-dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 12px;
  white-space: normal;
}

.g-avatar-lg {
  width: 44px;
  height: 44px;
  font-size: 15px;
}

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

.g-user-dropdown-name {
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-1);
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-user-dropdown-email {
  font-size: 12px;
  color: var(--color-text-3);
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-user-dropdown .dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  font-size: 13px;
}

.g-user-dropdown .dropdown-item i {
  font-size: 16px;
  width: 16px;
  text-align: center;
}

/* ── Contenuto pagina ─────────────────────────────────────── */

.g-content {
  flex: 1;
  padding: 20px 16px;
  overflow-y: auto;
  background: var(--bg-color);
}

/* Card */

.card {
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  background: var(--color-surface);
}

.card-header {
  border: 0;
  background: transparent;
}

/* ── Footer ───────────────────────────────────────────────── */

.g-footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 11px;
  color: var(--color-text-4);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ── Bottom bar mobile ────────────────────────────────────── */

.g-bottombar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottombar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
  z-index: 200;
  justify-content: space-around;
  align-items: center;
}

.g-bb-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 20px;
  border-radius: 8px;
  color: var(--color-text-4);
  text-decoration: none;
  transition: color var(--transition);
}

.g-bb-item.active,
.g-bb-item:hover {
  color: var(--accent);
}

.g-bb-icon {
  font-size: 20px;
}
.g-bb-label {
  font-size: 10px;
  font-weight: 500;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 768px) {
  body.has-sidebar {
    grid-template-columns: 1fr;
  }

  .g-sidebar {
    display: none;
  }

  .g-sidebar-toggle {
    display: none;
  }

  .g-topbar-brand {
    display: flex;
  }

  .g-bottombar {
    display: flex;
  }

  /* Spazio per la bottom bar */
  .g-main {
    padding-bottom: var(--bottombar-h);
  }
  body.is-public .g-main {
    padding-bottom: 0;
  }

  /* Copyright/versione: superfluo su mobile, la bottombar occupa già la fascia */
  .g-footer {
    display: none;
  }
}

/* Avatar con foto: nasconde il bg colorato e mostra solo l'img */
.g-avatar.has-photo {
  background: transparent !important;
  padding: 0;
  overflow: hidden;
}

.g-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  pointer-events: none; /* il click va sul button padre */
}

/* Form logout nel dropdown — allineato come un normale dropdown-item */
#logoutForm {
  margin: 0;
  padding: 0;
}

#logoutForm .dropdown-item {
  border: none;
  background: none;
  cursor: pointer;
}
