/* ============================================================
   UmbraDNS Design System — App Shell
   FASE 3: shell hierarchy, navigation and institutional screens.
   FASE 10: official brand assets at metrics/static/brand/ → /assets/brand/
   ============================================================ */

/* Shell */
.shell {
  --rail-width: 248px;
  --rail-width-collapsed: 72px;
  --shell-header-height: 76px;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  background: var(--canvas);
  transition: grid-template-columns var(--motion-normal) var(--ease-out);
}

.shell.rail-collapsed {
  --rail-width: var(--rail-width-collapsed);
}

.main,
.content {
  background: var(--canvas);
}

.content {
  padding: var(--space-6) var(--space-8) var(--space-12);
}

.brand {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: var(--space-2) var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
  border-bottom-color: var(--border-subtle);
}

.brand-mark {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  width: auto;
  height: auto;
  min-width: 0;
  max-width: 100%;
  padding: var(--space-1) 0;
}

.brand-logo {
  display: block;
  width: auto;
  height: 28px;
  max-width: 168px;
  object-fit: contain;
  object-position: left center;
}

.brand-logo--symbol {
  width: 32px;
  height: 32px;
  max-width: 32px;
  display: none;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--shell-header-height);
  box-sizing: border-box;
  margin-bottom: var(--space-4);
  padding-bottom: 0;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-row .brand {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

.rail-toggle {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    background var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out);
}

.rail-toggle:hover {
  color: var(--text-primary);
  background: rgba(73, 38, 130, 0.12);
  border-color: rgba(73, 38, 130, 0.22);
}

.rail-toggle:focus-visible {
  outline: 2px solid var(--umbra-400);
  outline-offset: 2px;
}

.rail-toggle .icon {
  width: 18px;
  height: 18px;
}

/* Collapsed rail — icons + symbol logo */
.rail.is-collapsed .brand-logo--full,
.shell.rail-collapsed .brand-logo--full {
  display: none;
}

.rail.is-collapsed .brand-logo--symbol,
.shell.rail-collapsed .brand-logo--symbol {
  display: block;
}

.rail.is-collapsed,
.shell.rail-collapsed .rail {
  padding: 0 var(--space-2) var(--space-3);
}

.rail.is-collapsed .brand-row,
.shell.rail-collapsed .brand-row {
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  height: var(--shell-header-height);
  padding-bottom: 0;
}

.rail.is-collapsed .brand,
.shell.rail-collapsed .brand {
  justify-content: center;
  padding: var(--space-1) 0;
}

.rail.is-collapsed .nav-kicker,
.shell.rail-collapsed .nav-kicker,
.rail.is-collapsed .nav-copy,
.shell.rail-collapsed .nav-copy {
  display: none;
}

.rail.is-collapsed .rail-btn,
.shell.rail-collapsed .rail-btn,
.rail.is-collapsed .nav-item,
.shell.rail-collapsed .nav-item {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: var(--space-2);
  min-height: 44px;
}

.rail.is-collapsed .nav-mark,
.shell.rail-collapsed .nav-mark {
  margin: 0;
}

@media (max-width: 860px) {
  .rail-toggle,
  .brand-logo--symbol {
    display: none;
  }

  .shell.rail-collapsed {
    --rail-width: 1fr;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.brand-text strong {
  color: var(--text-primary);
  font-family: var(--font-family-base);
  font-size: 0.95rem;
  font-weight: var(--font-weight-bold);
  letter-spacing: -0.02em;
}

.brand-text em {
  color: var(--text-muted);
  font-family: var(--font-family-base);
  letter-spacing: 0.08em;
}

/* Sidebar */
.rail {
  padding: 0 var(--space-3) var(--space-4);
  background: var(--surface);
  border-right-color: var(--border-subtle);
  backdrop-filter: none;
}

[data-theme="light"] .rail {
  background: var(--surface);
}

.nav-kicker,
.rail-foot {
  color: var(--text-muted);
  font-family: var(--font-family-base);
}

.rail-nav {
  gap: var(--space-1);
}

.rail-indicator {
  display: none;
}

/* Navigation */
a.rail-btn,
.rail-btn,
.nav-item {
  min-height: 48px;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-family-base);
  transition:
    background var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out),
    transform var(--motion-fast) var(--ease-out);
}

.nav-mark {
  color: inherit;
  opacity: 0.9;
}

.nav-mark .icon {
  width: 20px;
  height: 20px;
}

.nav-label {
  color: inherit;
  font-family: var(--font-family-base);
  font-size: 0.84rem;
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0;
}

.nav-preview {
  color: var(--text-muted);
  font-family: var(--font-family-base);
}

[data-theme="light"] .rail-btn,
[data-theme="light"] .nav-item {
  color: var(--text-secondary);
}

[data-theme="light"] .nav-preview {
  color: var(--text-muted);
}

[data-theme="light"] .rail-btn:hover,
[data-theme="light"] .nav-item:hover {
  color: var(--text-primary);
}

.rail-btn:hover,
.nav-item:hover {
  background: rgba(73, 38, 130, 0.12);
  color: var(--text-primary);
}

.rail-btn.active,
.nav-item.active,
.rail-btn.active:hover,
.nav-item.active:hover {
  background: var(--umbra-800);
  color: var(--text-on-accent);
}

.rail-btn.active .nav-label,
.nav-item.active .nav-label,
.rail-btn.active .nav-preview,
.nav-item.active .nav-preview {
  color: var(--text-on-accent);
}

/* Topbar */
.topbar {
  height: var(--shell-header-height);
  min-height: var(--shell-header-height);
  box-sizing: border-box;
  padding: 0 var(--space-8);
  background: rgba(15, 13, 22, 0.92);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: none;
  backdrop-filter: blur(12px);
}

[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.92);
}

.crumb h1 {
  color: var(--text-primary);
  font-family: var(--font-family-base);
  font-size: 1.125rem;
  font-weight: var(--font-weight-bold);
  letter-spacing: -0.02em;
}

.crumb-title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.crumb-title-row h1 {
  margin: 0;
}

.crumb .path,
.crumb .path a {
  color: var(--text-muted);
  font-family: var(--font-family-base);
}

.crumb .path strong {
  color: var(--text-secondary);
  font-weight: var(--font-weight-semibold);
}

/* Portal Search */
.search {
  min-height: 42px;
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  border-color: var(--border-subtle);
}

.search kbd {
  border-color: var(--border-subtle);
  background: var(--canvas);
  color: var(--text-muted);
}

.search-results {
  border-color: var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.search-hit:hover,
.search-hit.is-active {
  background: rgba(73, 38, 130, 0.14);
}

/* User Actions */
.top-actions {
  gap: var(--space-2);
  align-self: center;
}

.user {
  border-color: var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.avatar {
  border-radius: var(--radius-sm);
  background: var(--umbra-800);
  color: var(--text-on-accent);
}

.user-meta strong {
  color: var(--text-primary);
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-semibold);
}

.user-meta span {
  color: var(--text-muted);
  font-family: var(--font-family-base);
}

/* Boot */
.boot-screen {
  background: var(--canvas);
}

.boot-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-3);
  padding: var(--space-3);
  display: grid;
  place-items: center;
  border: 1px solid rgba(152, 134, 190, 0.35);
  border-radius: var(--radius-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-md);
}

.boot-mark .boot-symbol,
.boot-mark img {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
  animation: umbra-boot-breathe 2.8s ease-in-out infinite;
}

@keyframes umbra-boot-breathe {
  0%,
  100% {
    opacity: 0.88;
  }

  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .boot-mark img {
    animation: none;
  }
}

.boot-card h1 {
  color: var(--text-primary);
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-bold);
}

.boot-card p {
  color: var(--text-secondary);
  font-family: var(--font-family-base);
}

/* Login */
#login-form.card {
  border-color: var(--border-subtle);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

#login-form h1 {
  color: var(--text-primary);
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-bold);
}

#login-form p.sub,
#login-form label {
  color: var(--text-secondary);
  font-family: var(--font-family-base);
}

#login-form input {
  min-height: 42px;
  border-color: var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  color: var(--text-primary);
}

#login-form button {
  min-height: 42px;
  border: 1px solid var(--umbra-600);
  border-radius: var(--radius-md);
  background: var(--umbra-800);
  color: var(--text-primary);
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-semibold);
}

#login-form button:hover {
  background: var(--umbra-600);
}

#login-form .err {
  color: var(--status-danger);
}

/* Logout */
body > .card {
  border-color: var(--border-subtle);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

body > .card h1 {
  color: var(--text-primary);
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-bold);
}

body > .card p {
  color: var(--text-secondary);
  font-family: var(--font-family-base);
}

/* Responsive */
@media (max-width: 1280px) {
  .shell {
    grid-template-columns: 232px minmax(0, 1fr);
  }

  .topbar,
  .content {
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .topbar-center.portal-time-scope {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .search-wrap .search.is-open {
    width: min(100%, 360px);
  }
}

/* Portal global time filter (topbar) */
.topbar-center.portal-time-scope {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  align-self: center;
}

.topbar-center.portal-time-scope > .portal-range-row,
.topbar-center.portal-time-scope > .metrics-custom-range,
.topbar-center.portal-time-scope > .search-wrap {
  align-self: center;
  flex: 0 0 auto;
}

.topbar-center.portal-time-scope > .portal-range-row {
  transform: translateY(-3px);
}

.topbar .icon-btn {
  box-sizing: border-box;
}

.portal-time-scope .portal-range-row {
  margin: 0;
  height: 38px;
  box-sizing: border-box;
  padding: 2px 3px;
  display: inline-flex;
  align-items: center;
  align-self: center;
  vertical-align: middle;
}

.portal-time-scope .portal-range-row .chip[data-range] {
  height: 32px;
  min-height: 32px;
  max-height: 32px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-top: 0;
  padding-bottom: 0;
  line-height: 1;
  transform: none;
}

.portal-time-scope .portal-range-row .chip[data-range]:hover {
  transform: none;
}

.portal-time-scope .metrics-custom-range,
.portal-time-scope .metrics-range-control {
  height: 38px;
  display: inline-flex;
  align-items: center;
  align-self: center;
}

.portal-time-scope .metrics-custom-trigger--icon {
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  max-height: 38px;
  padding: 0;
  justify-content: center;
  align-self: center;
  box-sizing: border-box;
  transform: none;
}

.portal-time-scope .metrics-custom-trigger--icon:hover {
  transform: none;
}

.portal-time-scope .metrics-custom-trigger--icon .icon {
  margin: 0;
}

/* Accessibility */
.brand:focus-visible,
.rail-btn:focus-visible,
.search-hit:focus-visible {
  outline: 2px solid var(--umbra-400);
  outline-offset: 2px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .rail-btn,
  .nav-item {
    transition-duration: 0.01ms;
  }
}
