/* Certus App Shell — sidebar, header (appbar), main content, page header, toast.
   Mirrors the shell of the other Certus products (FichaCerta, Identity): navy sidebar with the
   official Certus logo + product name, translucent header with breadcrumb and user block. */

.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }

/* ---------- Sidebar ---------- */

.sidebar {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column;
  color: rgba(255, 255, 255, 0.62);
  background: linear-gradient(180deg, var(--certus-primary) 0%, var(--certus-sidebar-end) 100%);
  overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.sidebar-brand {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2);
  padding: var(--space-6) var(--space-5) var(--space-4);
  border-radius: 0;
}
.sidebar-brand:hover { text-decoration: none; }
.certus-logo { display: block; width: 72px; height: auto; flex: none; }
.sidebar-product { font-size: 21px; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; color: #fff; }
.sidebar-product .accent { color: var(--certus-accent-on-dark); }

.sidebar-rule {
  height: 1px; margin: 0 var(--space-5) var(--space-2);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.12) 25%, rgba(255, 255, 255, 0.12) 75%, transparent);
}

.nav { display: flex; flex-direction: column; gap: var(--space-1); flex: 1; padding: 0 var(--space-3); }
.nav-label {
  margin: var(--space-4) var(--space-2) var(--space-1);
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}
.nav-label:first-child { margin-top: var(--space-1); }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 44px; padding: 0 var(--space-3); border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.7); font-size: 14.5px; font-weight: 500;
  transition: background-color var(--motion-fast), color var(--motion-fast), box-shadow var(--motion-fast);
}
.nav-item .mdi { font-size: 20px; line-height: 1; }
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: rgba(255, 255, 255, 0.94); text-decoration: none; }
.nav-item.active {
  color: #fff; font-weight: 700;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.9) 0%, rgba(37, 99, 235, 0.65) 100%);
  box-shadow: 0 2px 10px -2px rgba(37, 99, 235, 0.55);
}
.nav-item:focus-visible, .sidebar-brand:focus-visible { box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.65); }

.sidebar-footer { display: grid; gap: 2px; padding: var(--space-4) var(--space-5) var(--space-5); font-size: 12px; }
.sidebar-org { color: rgba(255, 255, 255, 0.5); }
.sidebar-host { font-family: var(--font-mono); font-size: 11px; color: rgba(255, 255, 255, 0.36); }

/* ---------- Workspace & header ---------- */

.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 100dvh; }

.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  height: var(--appbar-h); padding: 0 var(--content-pad);
  background: rgba(245, 246, 250, 0.88);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  border-bottom: 1px solid var(--border);
}

.crumbs { min-width: 0; }
.crumbs ol { display: flex; align-items: center; min-width: 0; margin: 0; padding: 0; list-style: none; font-size: 0.875rem; }
.crumbs li { display: flex; align-items: center; min-width: 0; white-space: nowrap; }
.crumbs li + li::before { content: "\203A"; margin: 0 var(--space-2); font-size: 1.05rem; color: var(--text-subtle); }
.crumbs a { color: var(--text-muted); font-weight: 500; }
.crumbs a:hover { color: var(--certus-accent-hover); text-decoration: none; }
.crumbs [aria-current] { overflow: hidden; text-overflow: ellipsis; font-weight: 700; color: var(--text); }

.user-menu { position: relative; flex: none; }
.user-menu form { margin: 0; }
.user-trigger {
  display: inline-flex; align-items: center; gap: var(--space-2); max-width: 240px; height: 42px; padding: 0 var(--space-2) 0 5px;
  border: 1px solid transparent; border-radius: var(--radius-full); background: transparent; color: var(--text);
  font: 600 0.9rem/1 var(--font); cursor: pointer;
  transition: background-color var(--motion-fast), border-color var(--motion-fast);
}
.user-trigger:hover, .user-trigger[aria-expanded="true"] { background: var(--surface); border-color: var(--border); }
.user-trigger:focus-visible { box-shadow: var(--ring); border-radius: var(--radius-full); }
.user-first { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chevron { font-size: 1.1rem; color: var(--text-muted); transition: transform var(--motion-fast); }
.user-trigger[aria-expanded="true"] .user-chevron { transform: rotate(180deg); }
.user-popover {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; width: 288px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-raised);
  animation: rise 0.16s var(--ease) both;
}
.user-pop-identity { padding: 16px 18px; }
.user-pop-name { font-size: 15px; font-weight: 700; line-height: 1.3; color: var(--text); overflow-wrap: anywhere; }
.user-pop-email { margin-top: 4px; font-size: 13px; color: var(--text-muted); overflow-wrap: anywhere; }
.user-pop-meta { margin-top: 10px; }
.user-pop-meta p { font-size: 13px; line-height: 1.45; color: var(--text-muted); }
.user-pop-divider { height: 1px; background: var(--border); }
.user-pop-logout {
  display: block; width: 100%; padding: 13px 18px; border: 0; background: none; text-align: left;
  font: 600 14px/1.2 var(--font); color: var(--text); cursor: pointer;
}
.user-pop-logout:hover { background: var(--surface-2); }
.user-pop-logout:focus-visible { box-shadow: inset var(--ring); border-radius: 0; }
.avatar {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: var(--radius-full); font-weight: 700; font-size: 0.78rem; letter-spacing: 0.02em;
  color: #fff; background: var(--certus-primary);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.avatar-light { color: var(--certus-blue-700); background: #E6EEFF; box-shadow: inset 0 0 0 1px #CFDCFA; }

/* ---------- Main content ---------- */

.content {
  flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto;
  padding: 28px var(--content-pad) 56px; outline: none;
}

/* ---------- Page header ---------- */

.page-header {
  display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-4) var(--space-6);
  flex-wrap: wrap; margin-bottom: var(--space-6);
}
.page-heading { flex: 1 1 420px; min-width: 0; }
.page-header h1 { font-size: var(--fs-page-title); font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; color: var(--text); }
.page-sub { margin-top: 6px; max-width: 80ch; color: var(--text-muted); }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.back-link {
  display: inline-flex; align-items: center; gap: 0.3rem; margin-bottom: 6px;
  font-size: 0.85rem; font-weight: 600; color: var(--text-muted);
}
.back-link:hover { color: var(--certus-accent-hover); text-decoration: none; }
.actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

.meta-line {
  display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 10px 0 0; padding: 0; list-style: none;
  font-size: 0.875rem; color: var(--text-muted);
}
.meta-line li { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.meta-line > li > .mdi { font-size: 1rem; color: var(--text-subtle); }
.meta-id code { font-size: 0.78rem; color: var(--text-subtle); }

/* ---------- Toast ---------- */

.toast-region {
  position: fixed; right: var(--space-6); bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px)); z-index: 60;
  display: grid; gap: var(--space-2); width: min(440px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 10px 12px 14px;
  border-radius: var(--radius-md); border-left: 4px solid var(--success-solid);
  color: #fff; background: var(--certus-primary); box-shadow: var(--shadow-modal);
  animation: rise 0.25s var(--ease) both;
  transition: opacity var(--motion-base), transform var(--motion-base);
}
.toast > .mdi { font-size: 1.25rem; line-height: 1.2; color: #4ADE80; }
.toast p { flex: 1; min-width: 0; padding-top: 1px; font-size: 0.9rem; line-height: 1.45; overflow-wrap: anywhere; }
.toast.is-leaving { opacity: 0; transform: translateY(8px); }
.toast-close {
  display: inline-grid; place-items: center; width: 28px; height: 28px; flex: none;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-on-dark-muted); cursor: pointer;
}
.toast-close:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

/* ---------- Responsive shell ---------- */

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center;
    gap: var(--space-3); padding: var(--space-2) var(--space-3); overflow: visible;
  }
  .sidebar-brand { flex-direction: row; align-items: center; padding: 0 var(--space-1); }
  .certus-logo { width: 56px; }
  .sidebar-product { font-size: 17px; }
  .sidebar-rule, .sidebar-footer, .nav-label { display: none; }
  .nav { flex-direction: row; align-items: center; gap: var(--space-1); padding: 0; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item { flex: none; min-height: 38px; padding: 0 10px; font-size: 0.88rem; }
  .appbar { position: static; height: 54px; }
  .content { padding-top: 20px; }
}

@media (max-width: 640px) {
  .nav-item span:not(.mdi) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .sidebar-product { display: none; }
  .user-first { display: none; }
  .crumbs li:first-child { display: none; }
  .crumbs li:nth-child(2)::before { display: none; }
  .page-header h1 { font-size: 1.35rem; }
  .page-header { align-items: flex-start; }
  .actions { width: 100%; }
  .toast-region { right: 16px; bottom: 16px; }
}
