#app { display: flex; min-height: 100vh; }
#public-container { min-height: 100vh; width: 100%; }
#auth-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; width: 100%; background: var(--bg-secondary); }
#shell-container { display: flex; width: 100%; min-height: 100vh; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: var(--z-sidebar);
  transition: width var(--transition-normal);
  overflow: hidden;
}
.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.sidebar-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  min-height: 60px;
}

/* Accordion: clicking the Amezay logo collapses/expands the whole left menu */
#sidebar.collapsed { width: var(--sidebar-collapsed-width, 72px); }
#sidebar.collapsed .sidebar-nav,
#sidebar.collapsed .nav-section-bottom,
#sidebar.collapsed .sidebar-footer { display: none; }
#sidebar.collapsed .sidebar-header { padding: 16px 18px; justify-content: center; }
#sidebar.collapsed .logo-text { display: none; }
#sidebar.collapsed + #main-area { margin-left: var(--sidebar-collapsed-width, 72px); }
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  cursor: pointer;
  border-radius: 8px;
  padding: 2px;
  transition: opacity 0.15s;
}
.sidebar-logo:hover { opacity: 0.8; }
.logo-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  color: #fff;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 800;
  flex-shrink: 0;
}
.logo-text {
  color: var(--text-primary);
}

/* Sidebar Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.nav-section {
  padding: 4px 12px;
}
.nav-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 12px 4px;
}
.nav-section-title-link {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  transition: color 0.15s;
}
.nav-section-title-link:hover { color: var(--color-primary, #6366f1); }
.nav-section-title-link::after { content: '\203A'; font-size: 14px; color: var(--text-muted); }
/* Accordion nav sections — one open at a time */
.nav-acc-title {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  transition: color 0.15s;
  user-select: none;
}
.nav-acc-title:hover { color: var(--color-primary, #6366f1); }
.nav-acc-caret { font-size: 11px; color: var(--text-muted); }
.nav-acc-caret::before { content: '\25BE'; } /* ▾ */
.nav-acc-closed > .nav-acc-title .nav-acc-caret::before { content: '\25B8'; } /* ▸ */
.nav-acc-closed > .nav-acc-body { display: none; }
.nav-acc-body { display: block; }

/* Applications accordion — CORE / APPS / MODULES groups */
.apps-groups { display: flex; flex-direction: column; gap: 2px; }
.apps-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 8px 2px;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
.apps-group-title:hover { color: var(--color-primary, #6366f1); }
.apps-group-caret { font-size: 10px; }
.apps-group-caret::before { content: '\25BE'; }
.apps-group.group-closed .apps-group-caret::before { content: '\25B8'; }
.apps-group.group-closed .apps-group-body { display: none; }
.apps-group-count { margin-left: auto; font-size: 10px; color: var(--text-muted); }
.nav-empty { padding: 2px 12px 6px; color: var(--text-muted); font-size: 12px; }

.nav-item-app { position: relative; padding-right: 30px; }
.nav-item-action {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  padding: 0;
}
.nav-item-app:hover .nav-item-action,
.nav-item-action:focus { opacity: 1; }
.nav-item-action:hover { background: var(--sidebar-hover); }
.nav-item-remove:hover { background: rgba(220, 38, 38, 0.15); }
.nav-item-gallery {
  margin-top: 6px;
  border-top: 1px solid var(--border-color);
  padding-top: 8px;
  font-size: 13px;
  color: var(--color-primary, #6366f1);
}

/* Purchased-app groups (with module sub-units) */
.nav-products { display: flex; flex-direction: column; gap: 2px; }
.nav-product { display: flex; flex-direction: column; }
.nav-product .nav-item-product { padding-right: 34px; cursor: pointer; }
.nav-product-caret {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.nav-product-closed > .nav-item-product .nav-product-caret { transform: translateY(-50%) rotate(-90deg); }
.nav-product-modules { display: flex; flex-direction: column; gap: 1px; padding-left: 26px; }
.nav-product-closed > .nav-product-modules { display: none; }
.nav-item-module { font-size: 12.5px; min-height: 30px; border-left: 2px solid var(--border-color); margin-left: 6px; padding-left: 8px; }
.nav-item-module.active { border-left-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.nav-icon-module { font-size: 12px; width: 16px; text-align: center; }
.nav-item-product.active .nav-label { color: var(--color-primary, #6366f1); }

/* Applications gallery page — grouped CORE / APPS / MODULES */
.gallery-group { margin-bottom: 26px; }
.gallery-group-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}
.gallery-group-count { color: var(--text-muted); font-size: 12px; font-weight: 500; }
.app-card-desc {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
  max-height: 2.8em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.app-card-app { cursor: pointer; }
.app-card-static { opacity: 0.85; }
.app-card-app:hover { border-color: var(--color-primary, #6366f1); }
.app-remove-btn { margin-top: 4px; }
.app-add-btn { margin-top: 4px; }
/* SAI pinned at the top of the menu — always visible */
.nav-item-pinned {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 4px;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  border-radius: 8px;
  margin: 1px 0;
  font-size: 14px;
}
.nav-item:hover {
  background: var(--sidebar-hover);
}
.nav-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
  font-weight: 500;
}
.nav-icon {
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.nav-label {
  flex: 1;
}
.nav-section-bottom {
  margin-top: auto;
  border-top: 1px solid var(--sidebar-border);
  padding-top: 8px;
}
.sidebar-logout {
  color: var(--color-danger, #dc2626);
}
.sidebar-logout:hover {
  background: rgba(220, 38, 38, 0.08);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: default;
}
.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}
.sidebar-user-info {
  flex: 1;
  min-width: 0;
}
.sidebar-user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user-role {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-version {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
  text-align: center;
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px dashed var(--sidebar-border);
}
.sidebar-lang-switch {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.sidebar-lang-switch:hover {
  background: var(--bg-hover);
}

/* Main Area */
#main-area {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition-normal);
}

/* Header */
#header {
  height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: var(--z-header);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}
.bc-home { font-weight: 500; }
.bc-sep { color: var(--text-muted); margin: 0 2px; }
.bc-link { cursor: pointer; transition: color 0.15s; }
.bc-link:hover { color: var(--color-primary); }
.bc-current { color: var(--text-primary); font-weight: 500; }
.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--bg-hover); }
.lang-toggle {
  font-size: 12px;
  font-weight: 600;
}
.header-version {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  user-select: none;
}
.header-user {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.15s;
}
.header-user:hover { transform: scale(1.05); }
.header-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
}
.header-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Header dropdown */
.header-user-dropdown {
  position: fixed;
  top: 56px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 220px;
  z-index: 1000;
  padding: 8px;
}
.dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
}
.dropdown-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}
.dropdown-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.account-avatar-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.account-avatar-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 20px;
  overflow: hidden;
  flex-shrink: 0;
}
.account-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.form-hint {
  font-size: 12px;
  color: var(--text-muted, #888);
  margin-top: 6px;
}
.dropdown-user-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}
.dropdown-user-email {
  font-size: 12px;
  color: var(--text-muted);
}
.dropdown-divider {
  height: 1px;
  background: var(--border-color);
  margin: 4px 8px;
}
.dropdown-item {
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
}
.dropdown-item:hover { background: var(--bg-hover); }

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

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
}

/* Mobile */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2); }
  #main-area { margin-left: 0; }
  .mobile-menu { display: flex !important; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  #header { padding: 0 12px; gap: 8px; }
  #content { padding: 16px; }
  .header-breadcrumb { font-size: 13px; min-width: 0; }
  .bc-home, .bc-sep { flex-shrink: 0; }
  .page-title { font-size: 20px; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  #header .lang-toggle, #header .theme-toggle { display: none; }
}
@media (min-width: 769px) {
  .mobile-menu { display: none; }
}
