/* =========================================================
   App shell: grouped sidebar + top bar + content area
   ========================================================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: calc(100vh / var(--z, 1));
}
body.nav-collapsed { --sidebar-w: 76px; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--navy-800) 0%, var(--navy-900) 100%);
  color: #DCE6F5;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: calc(100vh / var(--z, 1));
  overflow-y: auto;
  z-index: 20;
}
.sidebar__brand {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.logo-slot {
  width: 88px; height: 88px; border-radius: 50%;
  border: 2px dashed rgba(255,255,255,.35);
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 11px; line-height: 1.3; color: #B9C8E0;
  overflow: hidden; flex-shrink: 0;
}
.logo-slot img { width: 100%; height: 100%; object-fit: contain; }
.logo-slot.has-logo { border: 0; background: #fff; }
.sidebar__menu-btn { display: none; }

.nav { display: flex; flex-direction: column; padding: 10px 0; gap: 2px; }

/* Top-level row: single link or group header */
.nav__top {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 46px; padding: 8px 18px 8px 16px;
  color: #DCE6F5; font-size: 14px; font-weight: 600; text-align: left;
  background: transparent; border: 0; border-left: 4px solid transparent; cursor: pointer;
}
.nav__top:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav__top svg { width: 22px; height: 22px; flex-shrink: 0; }
.nav__label { flex: 1; min-width: 0; }
.nav__chev { display: inline-flex; transition: transform .15s ease; opacity: .8; }
.nav__chev svg { width: 16px; height: 16px; }
.nav__group.is-open > .nav__top .nav__chev { transform: rotate(180deg); }

a.nav__top.is-active { background: var(--blue-600); color: #fff; border-left-color: #fff; }
.nav__group.has-active > .nav__top { color: #fff; border-left-color: var(--amber-500); }

/* Sub-menu */
.nav__sub { display: none; flex-direction: column; padding: 2px 0 8px; background: rgba(0,0,0,.14); }
.nav__group.is-open > .nav__sub { display: flex; }
.nav__flyout-title { display: none; }
.nav__subitem {
  display: flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 6px 16px 6px 56px;
  color: #C9D6EA; font-size: 13.5px; font-weight: 500; position: relative;
}
.nav__subitem::before {
  content: ""; position: absolute; left: 36px; top: 50%; width: 6px; height: 6px; margin-top: -3px;
  border-radius: 50%; background: rgba(255,255,255,.3);
}
.nav__subitem span:first-child { flex: 1; }
.nav__subitem:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav__subitem.is-active { background: var(--blue-600); color: #fff; font-weight: 600; }
.nav__subitem.is-active::before { background: #fff; }

.nav__badge {
  min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--red-600); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav__group.is-open .nav__badge--group { display: none; }

/* Footer */
.sidebar__foot {
  margin-top: auto; padding: 12px 14px; font-size: 11px; color: #9FB2D1;
  border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 10px;
}
.role-switch { display: flex; flex-direction: column; gap: 4px; font-size: 11px; }
.role-switch select {
  height: 32px; border-radius: 6px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.08); color: #fff; padding: 0 6px; font-size: 12px;
}
.role-switch option { color: var(--grey-900); }
.collapse-btn {
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 8px;
  background: transparent; border: 1px solid rgba(255,255,255,.18); border-radius: 6px;
  color: #DCE6F5; font-size: 12px; cursor: pointer;
}
.collapse-btn:hover { background: rgba(255,255,255,.06); }
.collapse-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- Collapsed rail (desktop) ---------- */
@media (min-width: 961px) {
  body.nav-collapsed .sidebar { overflow: visible; }
  body.nav-collapsed .logo-slot { width: 48px; height: 48px; font-size: 0; }
  body.nav-collapsed .nav__label,
  body.nav-collapsed .nav__chev,
  body.nav-collapsed .role-switch,
  body.nav-collapsed .sidebar__ver { display: none; }
  body.nav-collapsed .nav__top { justify-content: center; padding: 8px 0; position: relative; }
  body.nav-collapsed .nav__group.is-open .nav__badge--group,
  body.nav-collapsed .nav__badge--group { position: absolute; top: 4px; right: 8px; min-width: 18px; height: 16px; font-size: 10px; display: inline-flex; }
  body.nav-collapsed .collapse-btn { justify-content: center; }
  body.nav-collapsed .nav__group,
  body.nav-collapsed a.nav__top { position: relative; }

  /* Flyout on hover / keyboard focus */
  body.nav-collapsed .nav__sub,
  body.nav-collapsed .nav__group.is-open > .nav__sub {
    display: none; position: absolute; left: 100%; top: 0; min-width: 230px;
    background: var(--navy-800); border-radius: 0 8px 8px 0; box-shadow: 0 8px 24px rgba(0,0,0,.25);
    padding: 6px 0;
  }
  body.nav-collapsed .nav__group:hover > .nav__sub,
  body.nav-collapsed .nav__group:focus-within > .nav__sub { display: flex; }
  body.nav-collapsed .nav__flyout-title { display: block; padding: 8px 16px 6px; font-size: 12px; font-weight: 700; color: #9FB2D1; text-transform: uppercase; letter-spacing: .5px; }
  body.nav-collapsed .nav__subitem { padding-left: 16px; }
  body.nav-collapsed .nav__subitem::before { display: none; }

  /* Tooltip for single links (Dashboard) */
  body.nav-collapsed a.nav__top:hover::after,
  body.nav-collapsed a.nav__top:focus-visible::after {
    content: attr(data-tip); position: absolute; left: 100%; top: 50%; transform: translateY(-50%);
    background: var(--navy-800); color: #fff; padding: 8px 14px; border-radius: 0 6px 6px 0; white-space: nowrap;
    font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  }
}

/* ---------- Top bar ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface);
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}
.topbar__title { flex: 1 1 360px; min-width: 0; }
.topbar > .gsearch { flex: 0 1 auto; align-self: center; }
.topbar__title h1 {
  font-size: 26px; font-weight: 800; letter-spacing: .3px; color: var(--navy-800);
  text-transform: uppercase;
}
.topbar__title p { margin: 2px 0 0; color: var(--grey-700); font-size: 14px; }
.topbar__meta { flex: 1 1 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; }
.topbar__crumb { margin-right: auto; border-right: 0 !important; }   /* breadcrumb left; date, language, alarms, user on the right */
.topbar__crumb, .topbar__clock {
  display: flex; align-items: center; gap: 8px; color: var(--grey-700); font-size: 13px;
  padding-right: 18px; border-right: 1px solid var(--border);
}
.topbar__crumb a { display: inline-flex; }
.topbar__crumb svg, .topbar__clock svg { width: 18px; height: 18px; color: var(--navy-800); }
.icon-btn {
  position: relative; width: 44px; height: 44px; border: 0; background: transparent;
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--navy-800);
}
.icon-btn:hover { background: var(--grey-100); }
.icon-btn svg { width: 22px; height: 22px; }
.badge {
  position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--red-600); color: #fff;
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.lang-toggle { display: inline-flex; border: 1px solid var(--grey-300); border-radius: 6px; overflow: hidden; }
.lang-toggle button {
  border: 0; background: var(--surface); padding: 0 12px; height: 34px; cursor: pointer; font-size: 13px;
}
.lang-toggle button.is-active { background: var(--navy-800); color: #fff; font-weight: 600; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip__avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--navy-800); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.user-chip__text { display: flex; flex-direction: column; line-height: 1.25; }
.user-chip__text strong { font-size: 13px; color: var(--navy-800); }
.user-chip__text span { font-size: 12px; color: var(--text-muted); }

.tagline {
  background: var(--green-700); color: #fff;
  display: flex; justify-content: flex-end; gap: 14px;
  padding: 5px 24px; font-size: 15px; font-weight: 600;
  border-top: 3px solid var(--amber-500);
}
.tagline span + span::before { content: "|"; margin-right: 14px; opacity: .7; }

.content { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- Tablet / phone ---------- */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; overflow: visible; }
  .sidebar__brand { justify-content: space-between; padding: 10px 16px; }
  .logo-slot { width: 44px; height: 44px; font-size: 0; }
  .sidebar__menu-btn {
    display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px;
    background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.2); border-radius: 6px;
    font-size: 14px; cursor: pointer;
  }
  .sidebar__menu-btn svg { width: 20px; height: 20px; }
  .nav, .sidebar__foot { display: none; }
  .sidebar.is-open .nav, .sidebar.is-open .sidebar__foot { display: flex; }
  .collapse-btn { display: none; }
  .topbar__title h1 { font-size: 20px; }
  .topbar__crumb, .topbar__clock { border-right: 0; padding-right: 0; }
  .content { padding: 16px; }
}
.user-menu__lang { display: none; }
/* ---------- Phone: one compact row – breadcrumb · bell · avatar (language and name move into the user menu) ---------- */
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 6px; }
  .topbar__title { flex: 1 1 0; }
  .topbar__title h1 { font-size: 17px; }
  .topbar > .gsearch { margin: -6px -8px -6px 0; }
  .topbar__title p { display: none; }
  .topbar__meta { flex-wrap: nowrap; gap: 6px; }
  .topbar__crumb { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; font-size: 12.5px; }
  .topbar__crumb > *:not(a):not(:last-child) { display: none; }   /* phone: home icon + current page only */
  .topbar__crumb > :last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .topbar__meta > :not(.topbar__crumb) { flex-shrink: 0; }
  .topbar__clock, .topbar__lang, .user-chip__text, .user-chip__caret { display: none; }
  .user-menu__lang { display: inline-flex; margin: 6px 10px 8px; align-self: flex-start; }
  .tagline { font-size: 12.5px; gap: 8px; padding: 4px 16px; justify-content: center; }
  .tagline span + span::before { margin-right: 8px; }
}

/* ---------- Global search (top bar) ---------- */
.gsearch { position: relative; }
.gsearch__open { display: none; }
.gsearch__box { position: relative; display: flex; align-items: center; }
.gsearch__ico { position: absolute; left: 10px; width: 18px; height: 18px; color: var(--grey-600); pointer-events: none; }
.gsearch__box input {
  width: clamp(240px, 28vw, 420px); height: 36px; padding: 0 34px 0 34px; border: 1px solid var(--grey-300); border-radius: 18px;
  background: var(--grey-50); font: inherit; font-size: 13px; color: var(--grey-900);
}
.gsearch__box input:focus { outline: 2px solid var(--navy-700); outline-offset: 0; background: var(--surface); border-color: var(--navy-700); }
.gsearch__box input::-webkit-search-cancel-button { display: none; }
.gsearch__key { position: absolute; right: 10px; font: 600 11px/1 var(--font); color: var(--grey-600); border: 1px solid var(--grey-300); border-radius: 4px; padding: 3px 6px; background: var(--surface); }
.gsearch__box input:focus ~ .gsearch__key { display: none; }
.gsearch__close { display: none; }
.gsearch__pop {
  position: absolute; top: calc(100% + 6px); right: 0; width: max(100%, 440px); max-height: min(70vh, 520px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0, 0, 0, .16); z-index: 70; padding: 6px 0;
}
.gsearch__pop[hidden] { display: none; }
.gsearch__grp { padding: 8px 14px 4px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--grey-600); }
.gsearch__item { display: flex; flex-direction: column; gap: 1px; padding: 7px 14px; text-decoration: none; color: var(--grey-900); }
.gsearch__item.is-sel, .gsearch__item:hover { background: var(--grey-50); box-shadow: inset 3px 0 0 var(--navy-700); }
.gsearch__t { font-size: 13.5px; font-weight: 600; }
.gsearch__s { font-size: 12px; color: var(--grey-600); }
.gsearch__item mark { background: var(--amber-100, #FFF1C2); color: inherit; border-radius: 2px; padding: 0 1px; }
.gsearch__empty, .gsearch__note { padding: 10px 14px; font-size: 13px; color: var(--grey-600); }
.gsearch__note { font-size: 12px; padding-top: 4px; }
.gsearch__more { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 10px 14px 6px; margin-top: 4px; border-top: 1px solid var(--border); font-size: 12.5px; }
.gsearch__more span { color: var(--grey-600); }
.gsearch__more a { color: var(--navy-700); }

@media (max-width: 640px) {
  .gsearch__open { display: inline-flex; }
  .gsearch__box { display: none; }
  .gsearch.is-open { position: static; }
  .gsearch.is-open .gsearch__box { display: flex; position: absolute; left: 12px; right: 12px; top: 8px; z-index: 72; background: var(--surface); }
  .gsearch.is-open .gsearch__box input { width: 100%; height: 42px; border-radius: 21px; }
  .gsearch.is-open .gsearch__close { display: inline-flex; position: absolute; right: 6px; width: 32px; height: 32px; border: 0; background: none; align-items: center; justify-content: center; color: var(--grey-700); }
  .gsearch.is-open .gsearch__close svg { width: 18px; height: 18px; }
  .gsearch__pop { position: absolute; left: 12px; right: 12px; top: 56px; width: auto; }
  .topbar { position: relative; }
}
