:root {
  --app-bg: #080b09;
  --app-surface: #15151b;
  --app-surface-strong: #1d1d29;
  --app-ink: #f5f4f8;
  --app-muted: #b8b5c0;
  --app-quiet: #817f8c;
  --app-line: #302f3a;
  --app-line-bright: #45445c;
  --app-coral: #8fa8ff;
  --app-teal: #88d8e9;
  --app-gold: #bdb2ff;
  --app-shadow: 0 28px 72px rgba(0, 0, 0, .38);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body.app-shell-page {
  min-width: 320px;
  margin: 0;
  background: var(--app-bg);
  color: var(--app-ink);
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0;
}

body.app-shell-page::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  opacity: .32;
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0, rgba(255,255,255,.018) 1px, transparent 1px, transparent 4px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.012) 0, rgba(255,255,255,.012) 1px, transparent 1px, transparent 7px),
    radial-gradient(circle at 22% 18%, rgba(143,168,255,.07), transparent 30%),
    radial-gradient(circle at 82% 74%, rgba(136,216,233,.045), transparent 34%);
  background-size: auto, auto, 720px 720px, 840px 840px;
}

body.app-shell-page h1,
body.app-shell-page h2,
body.app-shell-page h3 {
  font-family: "Syne", Georgia, serif;
  letter-spacing: 0;
}

.app-header {
  width: 232px;
  height: 100dvh;
  padding: 24px 16px 18px;
  display: flex;
  align-items: stretch;
  flex-direction: column;
  gap: 0;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  border: 0;
  border-right: 1px solid var(--app-line);
  background: #141116;
  box-shadow: none;
}

.app-header .brand {
  display: flex;
  flex: 0 0 48px;
  height: 58px;
  min-height: 58px;
  padding: 4px 6px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 5px;
}

.app-header .brand-copy small {
  margin: 0;
  color: var(--app-quiet);
  font-size: 8px;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
}

.desktop-nav {
  width: 100%;
  height: auto;
  flex: 0 0 auto;
  margin-top: 34px;
  padding: 0;
  display: grid;
  gap: 5px;
}

.desktop-nav a,
.desktop-nav button {
  width: 100%;
  min-width: 0;
  height: 44px;
  flex: 0 0 44px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 11px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--app-muted);
  font-size: 11px;
  font-weight: 600;
  text-align: left;
  transition: background-color 160ms ease, color 160ms ease;
}

.desktop-nav a:hover,
.desktop-nav button:hover {
  color: var(--app-ink);
  background: #201f2b;
}

.desktop-nav a:focus-visible,
.desktop-nav button:focus-visible {
  outline: 2px solid var(--app-coral);
  outline-offset: 2px;
}

.desktop-nav .active {
  color: var(--app-ink);
  background: transparent !important;
  box-shadow: none !important;
}

.desktop-nav .active svg {
  color: var(--app-coral);
}

.desktop-nav svg {
  width: 17px;
  height: 17px;
}

.app-header .header-actions {
  width: 100%;
  margin-top: auto;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 8px;
}

.app-header .icon-button,
.app-header .profile-button {
  border: 1px solid var(--app-line);
  background: #171419;
  color: var(--app-ink);
  box-shadow: none;
}

.app-header .icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 11px;
}

.app-header .login-button,
.app-header .profile-button {
  min-width: 0;
  height: 44px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 700;
}

.app-header .login-button {
  width: 100%;
  border: 1px solid #555d91;
  background: #303452;
  color: #e5e5ff;
}

.app-header .profile-button {
  width: 100%;
  grid-column: 1 / -1;
  justify-content: flex-start;
}

.app-header .profile-button > span {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: #303452;
  color: #e5e5ff;
  font-weight: 700;
}

.app-header .profile-button strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.app-header .profile-button svg {
  width: 14px;
  margin-left: auto;
}

.settings-dialog {
  width: min(430px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid var(--app-line-bright);
  border-radius: 18px;
  color: var(--app-ink);
  background: #1d1d29;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .55);
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(8px);
}

.settings-dialog h2 {
  margin: 8px 0 6px;
  font: 700 28px "Syne", Georgia, serif;
}

.settings-dialog .eyebrow {
  color: var(--app-coral);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.settings-user {
  margin: 0 0 22px;
  color: var(--app-muted);
  line-height: 1.55;
}

.settings-dialog .dialog-close {
  width: 40px;
  height: 40px;
  padding: 0;
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  border: 1px solid var(--app-line);
  border-radius: 10px;
  background: #171419;
  color: var(--app-ink);
}

.settings-links {
  display: grid;
  gap: 7px;
  margin: 20px 0;
}

.settings-links a {
  display: grid;
  grid-template-columns: 20px 1fr 16px;
  align-items: center;
  gap: 11px;
  padding: 13px 12px;
  border-radius: 10px;
  color: var(--app-ink);
  background: rgba(255,255,255,.045);
}

.settings-links a:hover {
  background: rgba(255,255,255,.09);
}

.settings-links a > svg:last-child {
  color: var(--app-quiet);
}

.settings-logout {
  width: 100%;
  min-height: 42px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(143,168,255,.4);
  border-radius: 10px;
  background: transparent;
  color: #cbd4ff;
}

.mobile-nav {
  display: none;
}

@media (max-width: 1180px) {
  .app-header {
    width: 210px;
  }
}

@media (max-width: 780px) {
  body.app-shell-page {
    padding-bottom: 78px;
  }

  .app-header {
    width: 100%;
    height: 62px;
    padding: 0 12px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0;
    position: sticky;
    inset: 0 0 auto;
    border-right: 0;
    border-bottom: 1px solid var(--app-line);
  }

  .app-header .brand {
    display: flex;
    flex: 0 0 auto;
    min-width: 0;
    height: auto;
    min-height: 0;
    padding: 0;
  }

  .app-header .brand-wordmark,
  .app-header .brand-copy {
    min-width: 0;
    overflow: hidden;
  }

  .app-header .brand-wordmark {
    text-overflow: ellipsis;
  }

  .desktop-nav {
    display: none;
  }

  .app-header .header-actions {
    width: auto;
    margin: 0;
    display: flex;
  }

  .app-header .login-button {
    display: none;
  }

  .app-header .profile-button {
    width: 44px;
    padding: 4px;
    display: grid;
    place-items: center;
  }

  .app-header .profile-button strong,
  .app-header .profile-button > svg {
    display: none;
  }

  .app-header .profile-button > span {
    width: 32px;
    height: 32px;
  }

  .mobile-nav {
    position: fixed;
    z-index: 80;
    right: 10px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 10px;
    height: 64px;
    padding: 5px 8px max(5px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    overflow: hidden;
    border: 1px solid var(--app-line-bright);
    border-radius: 16px;
    background: #19161b;
    box-shadow: 0 14px 38px rgba(0,0,0,.42);
  }

  .mobile-nav a,
  .mobile-nav button {
    min-width: 0;
    min-height: 0;
    flex: 0 0 auto;
    padding: 4px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    border-radius: 11px;
    background: transparent;
    color: var(--app-quiet);
    font-size: 8px;
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;
  }

  .mobile-nav a:hover,
  .mobile-nav button:hover {
    color: #dfe4ff;
    background: #292a40;
  }

  .mobile-nav .active {
    color: #dfe4ff;
    background: transparent !important;
    box-shadow: none !important;
  }

  .mobile-nav .active svg {
    color: var(--app-coral);
  }

  .mobile-nav svg {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 430px) {
  .mobile-nav a[href="/personas.html"] span,
  .mobile-nav button#mobileSettings span {
    font-size: 0;
  }

  .mobile-nav a[href="/personas.html"] span::after,
  .mobile-nav button#mobileSettings span::after {
    display: block;
    font-size: 7px;
    line-height: 1.1;
  }

  .mobile-nav a[href="/personas.html"] span::after {
    content: "Персоны";
  }

  .mobile-nav button#mobileSettings span::after {
    content: "Настр.";
  }
}

@media (max-width: 360px) {
  .app-header .brand-copy {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.app-shell-page::before {
    animation: none;
  }
}

/* Shared popup language: the same dark, soft-cornered surface everywhere. */
body.memora-ui dialog,
body.memora-ui [role="dialog"],
body.memora-ui .modal,
body.memora-ui .popover,
body.memora-ui [role="menu"],
body.memora-ui .context-menu,
body.memora-ui .mobile-sheet {
  border: 0 !important;
  outline: 0 !important;
  border-radius: 22px !important;
  background: #1b1c21 !important;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .52) !important;
}

body.memora-ui dialog::backdrop,
body.memora-ui [role="dialog"]::backdrop {
  background: rgba(5, 6, 8, .72);
  backdrop-filter: blur(4px);
}

body.memora-ui dialog button,
body.memora-ui [role="dialog"] button,
body.memora-ui .modal button,
body.memora-ui .popover button,
body.memora-ui [role="menu"] button,
body.memora-ui .context-menu button,
body.memora-ui .mobile-sheet button {
  border-radius: 999px !important;
  border-color: transparent !important;
  outline: 0;
}

/* Action hierarchy shared by every popup. */
body.memora-ui dialog button[type="submit"],
body.memora-ui dialog .primary,
body.memora-ui dialog .ui-primary,
body.memora-ui [role="dialog"] button[type="submit"],
body.memora-ui [role="dialog"] .primary,
body.memora-ui [role="dialog"] .ui-primary,
body.memora-ui .modal .primary,
body.memora-ui .popover .primary {
  background: #f5f5f2 !important;
  color: #1b1c21 !important;
}

body.memora-ui dialog button:not([type="submit"]),
body.memora-ui dialog .secondary,
body.memora-ui dialog .ui-secondary,
body.memora-ui [role="dialog"] .secondary,
body.memora-ui [role="dialog"] .ui-secondary,
body.memora-ui .modal .secondary,
body.memora-ui .popover .secondary {
  background: #363840 !important;
  color: #f0f0ee !important;
}

body.memora-ui dialog button:focus-visible,
body.memora-ui [role="dialog"] button:focus-visible,
body.memora-ui .modal button:focus-visible,
body.memora-ui .popover button:focus-visible,
body.memora-ui [role="menu"] button:focus-visible,
body.memora-ui .context-menu button:focus-visible,
body.memora-ui .mobile-sheet button:focus-visible {
  outline: 2px solid var(--ui-accent, #c3ded2);
  outline-offset: 2px;
}
