/* ============================================
   GRAPH Suite — Layout & Structure
   ACG Suite — Design System Centralizzato
   ============================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border-color: hsl(var(--border));
}

body {
  font-family: var(--font-primary);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "rlig" 1, "calt" 1;
}

a { color: hsl(var(--primary)); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: hsl(var(--border)); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground)); }

/* ---- App Layout ---- */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: hsl(var(--card));
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
  flex-shrink: 0;
}

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

.sidebar-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid hsl(var(--border));
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: hsl(var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsl(var(--primary-foreground));
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-weight: 600;
  font-size: 18px;
  color: hsl(var(--foreground));
}

.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-version,
.sidebar.collapsed .nav-section-title {
  display: none;
}

.sidebar-toggle {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsl(var(--muted-foreground));
  transition: all 0.2s;
}

.sidebar-toggle:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.sidebar.collapsed .sidebar-toggle {
  margin: 0 auto;
}

/* ---- Sidebar Navigation ---- */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.nav-section {
  margin-bottom: 8px;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  padding: 8px 12px 4px;
  letter-spacing: 0.05em;
}

/* Nav Group (collassabile) */
.nav-group-toggle {
  cursor: pointer;
}
.nav-group-toggle:hover {
  background: hsl(var(--accent));
}
.nav-group-items {
  overflow: hidden;
  transition: max-height 0.25s ease;
}
.nav-group-items .nav-item {
  padding-left: 20px;
  font-size: calc(var(--sidebar-font-size, 14px) - 1px);
}
.nav-group-arrow {
  transition: transform 0.2s;
}
.nav-group-arrow.collapsed {
  transform: rotate(-90deg);
}
.sidebar.collapsed .nav-group-items {
  display: none !important;
}
.sidebar.collapsed .nav-group-arrow {
  display: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: hsl(var(--muted-foreground));
  font-weight: 500;
  font-size: var(--sidebar-font-size, 14px);
  transition: all 0.2s;
  margin-bottom: 2px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.nav-item:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.nav-item.active {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 10px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid hsl(var(--border));
  flex-shrink: 0;
}

.sidebar-version {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  text-align: center;
}

/* Sidebar app tags (compat) */
.sidebar__footer {
  margin: 0;
  padding: 12px;
  border-top: 1px solid hsl(var(--border));
  font-size: 10px;
}
.sidebar__footer-title {
  font-weight: 700;
  margin-bottom: 4px;
  color: hsl(var(--foreground));
}
.sidebar__apps {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.sidebar__app-tag {
  padding: 1px 6px;
  border-radius: 8px;
  background: hsl(var(--info-light));
  color: hsl(var(--primary));
  font-size: 9px;
  font-weight: 600;
}

/* ---- Main Content Area ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

/* ---- Header (inside main-content) ---- */
.header {
  height: var(--header-height);
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.header-left,
.header__brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-title {
  display: flex;
  flex-direction: column;
}

.header-title h1,
.header__title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 8px;
  color: hsl(var(--foreground));
}

.header-subtitle,
.header__subtitle {
  font-size: 14px;
  color: hsl(var(--muted-foreground));
}

/* Compat: old header classes */
.header__logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: hsl(var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: hsl(var(--primary-foreground));
  font-size: 13px;
  letter-spacing: 1px;
}

.header__right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header__user {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: hsl(var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsl(var(--primary-foreground));
  font-weight: 700;
  font-size: 12px;
}

.header__mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: hsl(var(--foreground));
  cursor: pointer;
  padding: 4px;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: hsl(var(--muted-foreground));
}
.breadcrumb-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.breadcrumb-item.active {
  color: hsl(var(--foreground));
  font-weight: 500;
}
.breadcrumb-separator {
  color: hsl(var(--muted-foreground));
}

/* Search Box */
.search-box {
  position: relative;
  width: 280px;
}
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  font-size: 13px;
  background: hsl(var(--muted) / 0.3);
  color: hsl(var(--foreground));
  transition: all 0.2s;
  font-family: inherit;
}
.search-box input:focus {
  outline: none;
  border-color: hsl(var(--primary));
  background: hsl(var(--background));
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1);
}
.search-box input::placeholder {
  color: hsl(var(--muted-foreground));
}
.search-box .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: hsl(var(--muted-foreground));
  pointer-events: none;
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-separator {
  width: 1px;
  height: 32px;
  background: hsl(var(--border));
  margin: 0 8px;
}

/* Status Badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 9999px;
  background: hsl(var(--secondary));
  font-size: 13px;
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: hsl(var(--muted-foreground));
}
.status-dot.active {
  background: hsl(var(--success));
  animation: pulse 2s infinite;
}
.status-dot.error {
  background: hsl(var(--error));
}

/* Icon Button */
.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsl(var(--muted-foreground));
  transition: all 0.2s;
  font-size: 18px;
}
.icon-btn:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

/* ---- Content Area ---- */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* Compat: old layout classes */
.main-content__header { margin-bottom: 16px; }
.main-content__title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: hsl(var(--foreground));
}
.main-content__section-desc {
  font-size: 13px;
  color: hsl(var(--muted-foreground));
  margin-top: 4px;
}
.section-panel {
  background: hsl(var(--card));
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

/* Section management */
.section { display: none; }
.section.active { display: block; }

/* ---- Login Overlay ---- */
.login-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, hsl(var(--primary)) 0%, hsl(var(--primary) / 0.8) 100%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-overlay.hidden { display: none; }

.login-container {
  background: hsl(var(--card));
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.login-header {
  text-align: center;
  margin-bottom: 32px;
}
.login-field {
  margin-bottom: 20px;
}
.login-field label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: hsl(var(--foreground));
}
.login-field input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-sizing: border-box;
}
.login-field input:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1);
}
.login-btn {
  width: 100%;
  padding: 14px;
  background: hsl(var(--primary));
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-top: 8px;
}
.login-btn:hover { opacity: 0.9; }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.login-error {
  background: hsl(var(--destructive) / 0.1);
  color: hsl(var(--destructive));
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  text-align: center;
}

/* Compat: DOC login classes */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, hsl(var(--primary)) 0%, hsl(var(--primary) / 0.8) 100%);
}
.login-card {
  background: hsl(var(--card));
  border-radius: 16px;
  padding: 40px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.login-logo {
  font-size: 36px;
  font-weight: 800;
  color: hsl(var(--primary));
  text-align: center;
  letter-spacing: 4px;
  margin-bottom: 4px;
}
.login-subtitle {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  text-align: center;
  margin-bottom: 24px;
}

/* ---- Animations ---- */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.fade-in { animation: fadeIn 0.3s ease; }
.transition-colors { transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease; }
.transition-all { transition: all 0.2s ease; }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 50;
    transform: translateX(-100%);
    height: 100vh;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open,
  .sidebar--open {
    transform: translateX(0);
  }
  .header__mobile-toggle { display: block; }
  .search-box { display: none; }
}

@media (max-width: 768px) {
  .content { padding: 12px; }
  .section-panel { padding: 14px; }
  .header { padding: 0 16px; }
}

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 49;
}
.sidebar-overlay.active,
.sidebar-overlay--active { display: block; }

/* ---- Compat: BEM sidebar classes (for old apps) ---- */
.sidebar__group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  padding: 8px 12px 4px;
  letter-spacing: 0.05em;
}
.sidebar__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: hsl(var(--muted-foreground));
  font-weight: 500;
  font-size: var(--sidebar-font-size, 14px);
  transition: all 0.2s;
  margin-bottom: 2px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.sidebar__item:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}
.sidebar__item--active {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}
.sidebar__item--active .sidebar__icon { color: hsl(var(--primary)); }
.sidebar__icon {
  color: hsl(var(--muted-foreground));
  flex-shrink: 0;
  transition: color 0.15s;
}
.sidebar__item:hover .sidebar__icon { color: hsl(var(--primary)); }
