/* ============================================================================
   AVISECO SYSTEMS — App Switcher (comutator de aplicații)
   v1.2 · Necesită aviseco-tokens.css + aviseco-components.css încărcate ÎNAINTE.
   Vanilla CSS, fără build step. Prefix .avs-app-switcher. Zero hex, zero px
   hardcodați în afara proprietăților documentate de mai jos.
   ============================================================================ */

/* ---------- 0. PROPRIETĂȚI PROPRII (singurele dimensiuni locale) ----------
   Pe desktop panoul are exact lățimea meniului (100% din elementul-gazdă,
   adică sidebar-ul minus padding-ul lui): marginile lui coincid cu ale
   intrărilor de meniu de sub el; numele lungi primesc ellipsis. Toate cele
   trei se pot suprascrie din aplicație pe elementul <avs-app-switcher>. */
avs-app-switcher {
  --avs-app-switcher-width: 100%;
  --avs-app-switcher-max-h: 420px;
  --avs-app-switcher-icon: 32px;      /* iconul din declanșator */
  --avs-app-switcher-item-icon: 28px; /* iconul din listă, mai mic: rândul e lat cât meniul */
  display: block;
  position: relative;
}

/* ---------- 1. DECLANȘATOR (capul sidebar-ului) ----------
   Înlocuiește blocul icon + nume din capul sidebar-ului. Pe navy, folosește
   aceleași alb-transparent ca .avs-nav-item, ca să fie o singură familie de
   suprafețe în sidebar. */
.avs-app-switcher__trigger {
  display: flex; align-items: center; gap: var(--avs-space-3);
  width: 100%; min-height: 44px;
  padding: var(--avs-space-2) var(--avs-space-2);
  background: transparent; border: 0;
  border-radius: var(--avs-radius-md);
  color: var(--avs-white); font: inherit; text-align: left;
  cursor: pointer;
  transition: background var(--avs-motion-fast) var(--avs-ease);
}
.avs-app-switcher__trigger:hover { background: rgba(255,255,255,.10); }
.avs-app-switcher__trigger:active { background: rgba(255,255,255,.16); }
.avs-app-switcher__trigger[aria-expanded="true"] { background: rgba(149,207,241,.18); }
.avs-app-switcher__trigger:focus-visible {
  outline: 2px solid var(--avs-sky-400); outline-offset: 2px;
}
.avs-app-switcher__trigger:disabled { opacity: .5; cursor: not-allowed; }

.avs-app-switcher__trigger-icon {
  width: var(--avs-app-switcher-icon); height: var(--avs-app-switcher-icon);
  flex: 0 0 auto; display: grid; place-items: center;
  border-radius: var(--avs-radius-md);
  background: rgba(255,255,255,.10); overflow: hidden;
}
.avs-app-switcher__trigger-icon img { width: 100%; height: 100%; object-fit: contain; }
.avs-app-switcher__trigger-icon svg { width: 20px; height: 20px; }

.avs-app-switcher__trigger-text { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; }
.avs-app-switcher__trigger-name {
  font-size: var(--avs-text-base); font-weight: var(--avs-weight-semibold);
  line-height: var(--avs-lh-base);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.avs-app-switcher__trigger-hint {
  font-size: var(--avs-text-xs); line-height: var(--avs-lh-xs);
  color: var(--avs-sky-300); text-transform: uppercase; letter-spacing: .06em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.avs-app-switcher__chevron { flex: 0 0 auto; width: 16px; height: 16px; opacity: .7; }
.avs-app-switcher__trigger:hover .avs-app-switcher__chevron,
.avs-app-switcher__trigger[aria-expanded="true"] .avs-app-switcher__chevron { opacity: 1; }

/* ---------- 2. PANOU ----------
   Suprafață ridicată (bg-raised + shadow-lg), sub declanșator, aliniată
   stânga. Se deschide cu durata de dropdown (180ms).
   Tema: doar tokens de rol (bg-raised, border, text-*), deci panoul urmează
   automat tema activă în aplicația-gazdă: light/dark din aviseco-design ȘI
   brand-ul Claude Style din aviseco-claude-style (data-theme / data-brand
   pe <html>). Nicio regulă per temă aici. */
.avs-app-switcher__panel {
  position: absolute; top: calc(100% + var(--avs-space-1)); left: 0;
  width: var(--avs-app-switcher-width); max-width: calc(100vw - var(--avs-space-8));
  max-height: min(calc(var(--avs-app-switcher-max-h) + var(--avs-space-16)), calc(100vh - var(--avs-space-16)));
  z-index: var(--avs-z-dropdown);
  background: var(--avs-bg-raised); color: var(--avs-text-primary);
  border: 1px solid var(--avs-border);
  border-radius: var(--avs-radius-lg);
  box-shadow: var(--avs-shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(calc(-1 * var(--avs-space-1))); pointer-events: none;
  transition: opacity var(--avs-motion-base) var(--avs-ease),
              transform var(--avs-motion-base) var(--avs-ease);
}
.avs-app-switcher__panel[data-open="true"] { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- 3. CĂUTARE ---------- */
.avs-app-switcher__search {
  display: flex; align-items: center; gap: var(--avs-space-2);
  padding: var(--avs-space-2) var(--avs-space-3);
  border-bottom: 1px solid var(--avs-border);
}
.avs-app-switcher__search svg { width: 16px; height: 16px; color: var(--avs-text-tertiary); flex: 0 0 auto; }
.avs-app-switcher__search input {
  flex: 1 1 auto; min-width: 0; min-height: var(--avs-control-height);
  background: transparent; border: 0; color: var(--avs-text-primary);
  font: inherit; font-size: var(--avs-text-base);
}
.avs-app-switcher__search input::placeholder { color: var(--avs-text-tertiary); }
.avs-app-switcher__search input:focus { outline: none; }
.avs-app-switcher__search:focus-within { box-shadow: inset 0 -2px 0 var(--avs-border-focus); }

/* Tastă afișată (Esc) — o singură componentă în tot ecosistemul */
.avs-kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; padding: 0 var(--avs-space-1);
  font-family: var(--avs-font-sans); font-size: var(--avs-text-xs); font-weight: var(--avs-weight-medium);
  line-height: var(--avs-lh-xs);
  color: var(--avs-text-secondary);
  background: var(--avs-bg-subtle);
  border: 1px solid var(--avs-border-strong); border-bottom-width: 2px;
  border-radius: var(--avs-radius-sm);
}

/* ---------- 4. LISTĂ ---------- */
.avs-app-switcher__list {
  list-style: none; margin: 0; padding: var(--avs-space-2);
  max-height: var(--avs-app-switcher-max-h); overflow-y: auto; flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.avs-app-switcher__item {
  display: flex; align-items: center; gap: var(--avs-space-2);
  min-height: 44px; padding: var(--avs-space-2) var(--avs-space-2);
  border-radius: var(--avs-radius-md);
  color: var(--avs-text-primary); text-decoration: none;
  cursor: pointer;
  transition: background var(--avs-motion-fast) var(--avs-ease);
}
.avs-app-switcher__item:hover { background: var(--avs-bg-subtle); text-decoration: none; color: var(--avs-text-primary); }
.avs-app-switcher__item:active { background: var(--avs-border); }
.avs-app-switcher__item[data-active="true"] { background: var(--avs-bg-subtle); }
.avs-app-switcher__item:focus-visible {
  outline: 2px solid var(--avs-border-focus); outline-offset: -2px;
}
.avs-app-switcher__item[aria-current="true"] { font-weight: var(--avs-weight-medium); }

.avs-app-switcher__item-icon {
  width: var(--avs-app-switcher-item-icon); height: var(--avs-app-switcher-item-icon);
  flex: 0 0 auto; display: grid; place-items: center;
  border-radius: var(--avs-radius-md);
  background: var(--avs-bg-subtle); border: 1px solid var(--avs-border);
  color: var(--avs-text-secondary); overflow: hidden;
}
.avs-app-switcher__item-icon img { width: 18px; height: 18px; object-fit: contain; }
.avs-app-switcher__item-icon svg { width: 18px; height: 18px; }

.avs-app-switcher__item-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.avs-app-switcher__item-name {
  font-size: var(--avs-text-base); line-height: var(--avs-lh-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Descrierea (partea de după „ — " din numele aplicației în portal): rândul al
   doilea, mic și discret; lipsește la aplicațiile fără descriere. */
.avs-app-switcher__item-desc {
  font-size: var(--avs-text-xs); line-height: var(--avs-lh-xs);
  color: var(--avs-text-tertiary); font-weight: var(--avs-weight-regular);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.avs-app-switcher__item-check { width: 16px; height: 16px; flex: 0 0 auto; color: var(--avs-text-accent); }
.avs-app-switcher__item-ext { width: 16px; height: 16px; flex: 0 0 auto; color: var(--avs-text-tertiary); opacity: 0; transition: opacity var(--avs-motion-fast) var(--avs-ease); }
.avs-app-switcher__item:hover .avs-app-switcher__item-ext,
.avs-app-switcher__item[data-active="true"] .avs-app-switcher__item-ext { opacity: 1; }

/* Portalul: fixat ultimul, sub separator (decizie #5) */
.avs-app-switcher__separator {
  height: 1px; margin: var(--avs-space-2) var(--avs-space-1); background: var(--avs-border);
}

/* ---------- 4b. UNDE SE DESCHID APLICAȚIILE (v1.2) ----------
   Sub listă, mereu vizibil cât timp lista e încărcată: un control segmentat
   cu două opțiuni. Lista se micșorează (are min-height: 0), deci zona asta
   nu e tăiată când panoul atinge înălțimea maximă. */
.avs-app-switcher__prefs {
  flex: 0 0 auto;
  display: flex; flex-direction: column; gap: var(--avs-space-1);
  padding: var(--avs-space-2) var(--avs-space-3) var(--avs-space-3);
  border-top: 1px solid var(--avs-border);
}
.avs-app-switcher__prefs[hidden] { display: none; }
.avs-app-switcher__prefs-label {
  font-size: var(--avs-text-xs); line-height: var(--avs-lh-xs); color: var(--avs-text-tertiary);
}
.avs-app-switcher__prefs-options {
  display: flex; gap: 2px; padding: 2px;
  background: var(--avs-bg-subtle); border: 1px solid var(--avs-border);
  border-radius: var(--avs-radius-md);
}
.avs-app-switcher__pref {
  flex: 1 1 0; min-width: 0; min-height: 32px; padding: 0 var(--avs-space-2);
  background: transparent; border: 0; border-radius: var(--avs-radius-sm);
  color: var(--avs-text-secondary); font: inherit; font-size: var(--avs-text-sm); line-height: var(--avs-lh-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
  transition: background var(--avs-motion-fast) var(--avs-ease), color var(--avs-motion-fast) var(--avs-ease);
}
.avs-app-switcher__pref:hover { color: var(--avs-text-primary); }
.avs-app-switcher__pref[aria-pressed="true"] {
  background: var(--avs-bg-raised); color: var(--avs-text-primary);
  font-weight: var(--avs-weight-medium); box-shadow: var(--avs-shadow-sm);
}
.avs-app-switcher__pref:focus-visible { outline: 2px solid var(--avs-border-focus); outline-offset: -2px; }
.avs-app-switcher__prefs-error { font-size: var(--avs-text-xs); line-height: var(--avs-lh-xs); color: var(--avs-danger); }
.avs-app-switcher__prefs-error[hidden] { display: none; }

/* ---------- 5. STĂRI: loading / error / empty ---------- */
.avs-app-switcher__state {
  padding: var(--avs-space-4) var(--avs-space-3);
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--avs-space-2);
  font-size: var(--avs-text-sm); color: var(--avs-text-secondary);
}
.avs-app-switcher__state-title { font-weight: var(--avs-weight-medium); color: var(--avs-text-primary); }
.avs-app-switcher__state[data-kind="error"] .avs-app-switcher__state-title { color: var(--avs-danger); }

.avs-app-switcher__skeleton { display: flex; flex-direction: column; gap: 2px; padding: var(--avs-space-2); }
.avs-app-switcher__skeleton-row {
  display: flex; align-items: center; gap: var(--avs-space-2);
  min-height: 44px; padding: var(--avs-space-2) var(--avs-space-2);
}
.avs-app-switcher__skeleton-row::before {
  content: ""; width: var(--avs-app-switcher-item-icon); height: var(--avs-app-switcher-item-icon);
  border-radius: var(--avs-radius-md); background: var(--avs-bg-subtle);
}
.avs-app-switcher__skeleton-row::after {
  content: ""; height: 12px; flex: 0 0 55%;
  border-radius: var(--avs-radius-sm); background: var(--avs-bg-subtle);
}
.avs-app-switcher__skeleton-row:nth-child(2)::after { flex-basis: 40%; }
.avs-app-switcher__skeleton-row:nth-child(3)::after { flex-basis: 65%; }

/* Acțiunile din stările error/empty (Reîncearcă, Deschide portalul) */
.avs-app-switcher__actions { display: flex; gap: var(--avs-space-2); flex-wrap: wrap; }
.avs-app-switcher__actions .avs-btn svg { width: 16px; height: 16px; }

/* ---------- 5b. VARIANTĂ PE BARA SUPERIOARĂ (variant="topbar") ----------
   Pentru aplicațiile/profilurile fără sidebar (ex. interfața de șofer din
   CarLogix: .avs-topbar + .avs-topnav). Declanșatorul stă pe suprafață, nu pe
   navy, deci ia culorile de rol ale suprafeței; panoul are lățime fixă, nu a
   gazdei (gazda e doar cât brandul). */
avs-app-switcher[variant="topbar"] { --avs-app-switcher-width: 320px; display: inline-block; width: auto; }
avs-app-switcher[variant="topbar"] .avs-app-switcher__trigger {
  width: auto; min-height: var(--avs-control-height); color: var(--avs-text-primary);
}
avs-app-switcher[variant="topbar"] .avs-app-switcher__trigger:hover { background: var(--avs-bg-subtle); }
avs-app-switcher[variant="topbar"] .avs-app-switcher__trigger:active { background: var(--avs-border); }
avs-app-switcher[variant="topbar"] .avs-app-switcher__trigger[aria-expanded="true"] { background: var(--avs-bg-subtle); }
avs-app-switcher[variant="topbar"] .avs-app-switcher__trigger:focus-visible { outline-color: var(--avs-border-focus); }
avs-app-switcher[variant="topbar"] .avs-app-switcher__trigger-icon {
  background: var(--avs-action); color: var(--avs-action-text);
}
avs-app-switcher[variant="topbar"] .avs-app-switcher__trigger-hint { color: var(--avs-text-tertiary); }
avs-app-switcher[variant="topbar"] .avs-app-switcher__chevron { color: var(--avs-text-tertiary); }
@media (max-width: 640px) {
  avs-app-switcher[variant="topbar"] .avs-app-switcher__trigger-text { display: none; }
}

/* ---------- 6. RESPONSIVE ----------
   Sub 900px sidebar-ul din aviseco-design devine bară orizontală; panoul
   nu mai poate fi ancorat sub declanșator, devine foaie fixă sub bara de sus. */
@media (max-width: 900px) {
  .avs-app-switcher__panel {
    position: fixed; top: var(--avs-space-16); left: var(--avs-space-4); right: var(--avs-space-4);
    width: auto; max-width: none;
  }
}

/* ---------- 7. PRINT ---------- */
@media print { avs-app-switcher { display: none; } }
