/* ==========================================================================
   AlDerhamy HCAG — Application shell: sidebar, topbar, content, footer
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns var(--t-base);
}
.app[data-nav-collapsed="true"] { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ============================ SIDEBAR ============================ */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid rgba(201, 162, 77, 0.16);
  z-index: 60;
}
.sidebar::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 3px;
  background: linear-gradient(180deg, rgba(201,162,77,0.55), rgba(18,131,106,0.25) 45%, transparent);
  pointer-events: none;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-4) var(--sp-4) var(--sp-5);
  min-height: var(--topbar-h);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.brand { display: flex; align-items: center; gap: var(--sp-3); color: var(--sidebar-text-strong); text-decoration: none; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand__mark { flex: none; width: 38px; height: 38px; display: block; }
.brand__mark svg { width: 100%; height: 100%; }
.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__text strong { font-size: var(--fs-md); letter-spacing: 0.02em; }
.brand__text small { font-size: 10.5px; letter-spacing: 0.05em; color: rgba(231, 205, 139, 0.82); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar__nav { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-4) var(--sp-3) var(--sp-5); }
.nav-group { margin-bottom: var(--sp-5); }
.nav-group__label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(231, 205, 139, 0.62);
  padding: 0 var(--sp-3) var(--sp-2);
  font-weight: 700;
}
.nav-item { position: relative; }
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--sidebar-text);
  font-size: 13.4px;
  font-weight: 520;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background var(--t-fast), color var(--t-fast);
  width: 100%;
  text-align: left;
  background: none;
}
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); text-decoration: none; }
.nav-link .nav-icon { flex: none; width: 19px; height: 19px; opacity: 0.9; }
.nav-link .nav-label { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-link .nav-count {
  flex: none; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.1); color: var(--sidebar-text-strong);
}
.nav-link .nav-count--alert { background: rgba(226, 120, 108, 0.28); color: #ffe0db; }
.nav-link .nav-chev { flex: none; transition: transform var(--t-base); }
.nav-item[data-open="true"] .nav-chev { transform: rotate(90deg); }
.nav-link.is-active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-strong);
  border-color: rgba(201, 162, 77, 0.4);
  font-weight: 620;
}
.nav-link.is-active::before {
  content: "";
  position: absolute;
  left: -3px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%;
  background: var(--gold-500);
  border-radius: var(--r-pill);
}
.nav-item--parent > .nav-link.is-active-parent { color: var(--sidebar-text-strong); }
.nav-sub { margin: 2px 0 var(--sp-2) 0; padding-left: 26px; display: flex; flex-direction: column; gap: 1px; }
.nav-sub .nav-link { font-size: 12.6px; padding: 6px var(--sp-3); color: rgba(200, 212, 226, 0.86); }
.nav-sub .nav-link.is-active { background: rgba(201, 162, 77, 0.14); border-color: transparent; }
.nav-sub .nav-link.is-active::before { display: none; }

.sidebar__foot { padding: var(--sp-4); border-top: 1px solid rgba(255, 255, 255, 0.07); }
.env-chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 700;
  padding: 5px 10px; border-radius: var(--r-pill);
  background: rgba(201, 162, 77, 0.14); color: var(--gold-300); border: 1px solid rgba(201, 162, 77, 0.3);
}
.env-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gold-400); box-shadow: 0 0 0 3px rgba(201, 162, 77, 0.2); }
.sidebar__disclaimer { font-size: 10.8px; line-height: 1.55; color: rgba(168, 184, 202, 0.72); margin: var(--sp-3) 0 0; }

/* Collapsed sidebar */
.app[data-nav-collapsed="true"] .brand__text,
.app[data-nav-collapsed="true"] .nav-group__label,
.app[data-nav-collapsed="true"] .nav-label,
.app[data-nav-collapsed="true"] .nav-count,
.app[data-nav-collapsed="true"] .nav-chev,
.app[data-nav-collapsed="true"] .sidebar__foot,
.app[data-nav-collapsed="true"] .sidebar__collapse .chev { display: none; }
.app[data-nav-collapsed="true"] .sidebar__collapse .chev { display: none; }
.app[data-nav-collapsed="true"] .nav-link { justify-content: center; padding: 11px 0; }
.app[data-nav-collapsed="true"] .nav-sub { display: none; }
.app[data-nav-collapsed="true"] .sidebar__brand { justify-content: center; padding-inline: 0; }
.app[data-nav-collapsed="true"] .sidebar__collapse { display: none; }
.app[data-nav-collapsed="true"] .nav-item { position: relative; }
.app[data-nav-collapsed="true"] .nav-link[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  background: var(--navy-800); color: #fff; font-size: 12px; font-weight: 500;
  padding: 6px 10px; border-radius: var(--r-sm); white-space: nowrap; z-index: 90;
  box-shadow: var(--shadow-md); border: 1px solid rgba(201, 162, 77, 0.3);
}

/* ============================ MAIN ============================ */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: var(--topbar-h);
  padding: var(--sp-3) var(--sp-6);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar__menu { display: none; }
.topbar__heading { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 0 1 320px; }
.topbar__title { font-size: var(--fs-lg); font-weight: 660; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumbs { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-muted); flex-wrap: wrap; }
.breadcrumbs a { color: var(--text-soft); text-decoration: none; }
.breadcrumbs a:hover { color: var(--gold-600); text-decoration: underline; }
.breadcrumbs__sep { color: var(--border-strong); }
.breadcrumbs__current { color: var(--text-muted); font-weight: 600; }

.global-search { position: relative; flex: 1 1 340px; max-width: 460px; }
.global-search input {
  width: 100%;
  padding: 9px 42px 9px 36px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.global-search input:focus { outline: none; border-color: var(--gold-500); box-shadow: 0 0 0 3px rgba(201, 162, 77, 0.18); background: var(--surface); }
.global-search__icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); display: flex; }
.global-search__kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 10.5px; padding: 2px 6px; border-radius: var(--r-xs);
  border: 1px solid var(--border); background: var(--surface-3); color: var(--text-muted);
}
.topbar__actions { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; }

.content { flex: 1 1 auto; padding: var(--sp-6); }
.content__inner { max-width: var(--content-max); margin: 0 auto; }
.content:focus { outline: none; }

.app-footer {
  display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4);
  justify-content: space-between; align-items: center;
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  background: var(--surface-2);
}
.app-footer__right { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* ============================ OVERLAYS ============================ */
.overlay-root { position: fixed; inset: 0; z-index: 120; display: flex; }
.overlay-root[hidden] { display: none; }
.nav-scrim {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(6, 20, 36, 0.5);
  backdrop-filter: blur(2px);
}

.loading-state {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-3);
  min-height: 300px; color: var(--text-muted);
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--gold-500);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-loading-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent); z-index: 5;
}
