/* ============================================================
   App-shell chrome — the authenticated frame every page mounts inside:
   sidebar, topbar, page-container, notification panel, mobile bottom nav.

   Relocated out of the legacy 6000-line styles.css into the layered,
   token-only system (docs/FRONTEND-ARCHITECTURE.md). The base structural
   definitions for .dash-shell/.dash-sidebar/.dash-topbar/.dash-main/
   .dash-content/.dash-nav-item/.dash-icon-btn live in
   design-system/components.css; this file carries the styles.css
   *extensions* and the body.citizen-theme shell *overrides*.

   SELECTORS/CLASS NAMES ARE LOAD-BEARING: frontend/app.js queries them
   (.dash-nav-item[data-page], .dash-sidebar__section-label,
   .mobile-bottom-nav__item, .sidebar-sub, .skip-to-content, .notif-*,
   .logout-btn, #notif-panel, …). DO NOT rename them.

   @layer layout  — structure only (grid/flex/sizing/position/spacing). No color.
   @layer design  — paint only. Every color/background/border/shadow a token.
   Layer order is declared in app/00-layers.css.
   ============================================================ */

@layer layout {

  /* ── Skip-to-content (a11y) ── */
  .skip-to-content {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 9999;
    padding: var(--mea-space-2) var(--mea-space-4);
    text-decoration: none;
    border-radius: var(--mea-radius-md);
  }
  .skip-to-content:focus {
    position: fixed;
    top: var(--mea-space-2);
    left: var(--mea-space-2);
    width: auto;
    height: auto;
  }

  /* ── Sidebar extensions ── */
  .sidebar-sub {
    letter-spacing: var(--mea-ls-wide);
    text-transform: uppercase;
    margin-top: 2px;
    white-space: nowrap;
  }

  .dash-nav-item .nav-icon {
    width: 18px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
  }

  .nav-badge {
    margin-left: auto;
    border-radius: 10px;
    padding: 1px 7px;
    display: none;
  }
  .nav-badge.visible {
    display: inline-block;
  }

  .unread-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
  }

  .sidebar-footer {
    margin-top: auto;
    padding: var(--mea-space-4) var(--mea-space-5);
  }

  .sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--mea-space-3);
  }
  .sidebar-user-info {
    flex: 1;
    min-width: 0;
  }
  .sidebar-user-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .logout-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--mea-radius-md);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  /* Sidebar gradient glow */
  .dash-sidebar::before {
    content: '';
    position: absolute; top: 0; right: -1px;
    width: 80px; height: 100%;
    pointer-events: none;
  }
  .dash-sidebar { position: relative; }

  /* ── Topbar extensions ── */
  .topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--mea-space-3);
  }

  .topbar-select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: var(--mea-radius-sm);
    padding: 4px 24px 4px 8px;
    cursor: pointer;
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 10px 6px;
    min-height: 32px;
  }

  .notif-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: var(--mea-radius-circle);
  }

  /* iOS safe-area insets (PWA polish) */
  .dash-topbar {
    padding-top: env(safe-area-inset-top, 0px);
  }

  /* ── Mobile bottom nav ── */
  .mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--mea-space-1) 0;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-bottom-nav__items {
    display: flex;
    justify-content: space-around;
    max-width: 500px;
    margin: 0 auto;
  }
  .mobile-bottom-nav__item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--mea-space-1) var(--mea-space-2);
    cursor: pointer;
    text-decoration: none;
    border: none;
    background: none;
  }
  .mobile-bottom-nav__icon {
    font-size: 20px;            /* fallback for legacy entity-glyph roles */
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .mobile-bottom-nav__icon svg {
    width: 23px;
    height: 23px;
    display: block;
  }

  /* ── Notification panel ── */
  .dash-notif-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 360px; max-width: 100vw;
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex; flex-direction: column;
  }
  .dash-notif-panel.is-open { transform: translateX(0); }
  .dash-notif-panel__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--mea-space-4) var(--mea-space-5);
    flex-shrink: 0;
  }
  .dash-notif-panel__title {
    font-weight: var(--mea-w-bold);
    font-size: 16px;
  }
  .dash-notif-panel__close {
    background: none; border: none; cursor: pointer;
    font-size: 22px;
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    border-radius: var(--mea-radius-md);
  }
  .dash-notif-panel__body {
    flex: 1; overflow-y: auto;
  }
  .dash-notif-panel__empty {
    text-align: center;
    padding: var(--mea-space-8) 0;
  }

  .notif-item {
    display: flex; align-items: flex-start; gap: 10px;
    padding: var(--mea-space-3) var(--mea-space-4);
    transition: background var(--mea-dur-fast);
  }
  .notif-item__dot {
    width: 8px; height: 8px; margin-top: 5px;
    border-radius: var(--mea-radius-circle);
    flex-shrink: 0;
  }
  .notif-detail {
    margin-top: 2px;
  }
  .notif-empty { text-align: center; padding: var(--mea-space-8) 0; }
  .notif-body { flex: 1; min-width: 0; }
  .notif-time { font-size: 12px; }

  /* ── Responsive: reveal the mobile bottom nav ── */
  @media (max-width: 768px) {
    .mobile-bottom-nav {
      display: block;
    }
    /* NOTE: hiding .dash-sidebar and re-padding .dash-content for mobile
       CANNOT be done here — those elements' base rules live UNLAYERED in
       design-system/components.css, which beats any @layer rule. The
       sidebar/content collapse therefore lives there (search "collapse the
       desktop sidebar shell"). .mobile-bottom-nav is layer-owned here, so
       its reveal works. */
  }
}

@layer design {

  /* ── Skip-to-content (a11y) ── */
  .skip-to-content {
    background: var(--mea-blue);
    color: var(--mea-white);
    font-weight: var(--mea-w-semibold);
  }

  /* ── Sidebar extensions ── */
  .sidebar-sub {
    font-size: var(--mea-desk-xs);
    color: color-mix(in srgb, var(--mea-baby-blue) 60%, transparent);
    font-weight: var(--mea-w-medium);
  }

  .nav-badge {
    background: var(--mea-baby-blue);
    color: var(--mea-navy);
    font-size: var(--mea-desk-sm);
    font-weight: var(--mea-w-bold);
  }

  .unread-dot {
    background: var(--mea-blue);
  }

  .sidebar-footer {
    border-top: 1px solid color-mix(in srgb, var(--mea-baby-blue) 12%, transparent);
  }

  .sidebar-user-name {
    font-size: var(--mea-desk-base);
    font-weight: var(--mea-w-semibold);
    color: var(--mea-white);
  }
  .sidebar-user-role {
    font-size: var(--mea-desk-sm);
    color: color-mix(in srgb, var(--mea-white) 60%, transparent);
  }

  .logout-btn {
    border: 1px solid color-mix(in srgb, var(--mea-white) 15%, transparent);
    background: transparent;
    color: color-mix(in srgb, var(--mea-white) 50%, transparent);
    transition: all var(--mea-dur-normal);
  }
  .logout-btn:hover {
    background: color-mix(in srgb, var(--mea-white) 10%, transparent);
    color: var(--mea-white);
  }

  /* Sidebar gradient glow */
  .dash-sidebar::before {
    background: linear-gradient(to right, transparent, color-mix(in srgb, var(--mea-baby-blue) 6%, transparent));
  }

  /* ── Topbar extensions ── */
  .topbar-select {
    background-color: var(--mea-surface-card);
    border: 1px solid var(--mea-gray-200);
    font-family: var(--mea-font-body);
    font-size: var(--mea-desk-sm);
    font-weight: var(--mea-w-semibold);
    color: var(--mea-gray-700);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3e%3cpath d='M0 0l5 6 5-6z' fill='%237AAFD4'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 10px 6px;
  }
  .topbar-select:focus-visible {
    outline: 2px solid var(--mea-baby-blue);
    outline-offset: 1px;
  }

  .notif-dot {
    background: var(--mea-red);
    border: 1.5px solid var(--mea-white);
  }

  /* ── Mobile bottom nav ── */
  .mobile-bottom-nav {
    background: var(--mea-surface-card);
    border-top: 1px solid var(--mea-gray-200);
    box-shadow: 0 -2px 10px color-mix(in srgb, var(--mea-black) 5%, transparent);
  }
  .mobile-bottom-nav__item {
    font-size: 11px;
    font-weight: var(--mea-w-semibold);
    color: var(--mea-gray-400);
    font-family: var(--mea-font-body);
  }
  .mobile-bottom-nav__item.is-active {
    color: var(--mea-blue);
  }

  /* ── Notification panel ── */
  .dash-notif-panel {
    background: var(--mea-surface-card);
    border-left: 1px solid var(--mea-gray-100);
    box-shadow: -4px 0 20px color-mix(in srgb, var(--mea-navy) 12%, transparent);
  }
  .dash-notif-panel__header {
    border-bottom: 1px solid var(--mea-gray-100);
  }
  .dash-notif-panel__close {
    color: var(--mea-gray-400);
  }
  .dash-notif-panel__close:hover { background: var(--mea-gray-50); color: var(--mea-gray-700); }
  .dash-notif-panel__empty {
    color: var(--mea-gray-400);
  }

  .notif-item {
    border-bottom: 1px solid var(--mea-gray-100);
  }
  .notif-item:hover { background: var(--mea-baby-pale); }
  .notif-item__dot {
    background: var(--mea-gray-300);
  }
  .notif-item--unread .notif-item__dot { background: var(--mea-blue); }
  .notif-item--unread .notif-title { font-weight: var(--mea-w-semibold); }
  .notif-detail {
    font-size: var(--mea-desk-sm);
    color: var(--mea-gray-500);
  }
  .notif-empty { color: var(--mea-gray-400); }
  .notif-title { font-weight: var(--mea-w-semibold); font-size: 13px; color: var(--mea-gray-900); }
  .notif-time { color: var(--mea-gray-400); }

  /* ════════════════════════════════════════════════════════════
     body.citizen-theme — participant dark-shell overrides.
     Paint only; rebinds the shell chrome to the dark identity.
     ════════════════════════════════════════════════════════════ */

  body.citizen-theme .topbar-select {
    background-color: var(--mea-navy);
    border-color: color-mix(in srgb, var(--mea-white) 15%, transparent);
    color: color-mix(in srgb, var(--mea-white) 80%, transparent);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3e%3cpath d='M0 0l5 6 5-6z' fill='%2382CBF5'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 10px 6px;
  }
  body.citizen-theme .topbar-select option {
    background: var(--mea-navy);
    color: var(--mea-white);
  }

  body.citizen-theme .dash-shell { background: var(--mea-dark); }
  body.citizen-theme .dash-main { background: var(--mea-dark); }
  body.citizen-theme .dash-topbar {
    background: var(--mea-dark);
    border-bottom: 1px solid color-mix(in srgb, var(--mea-white) 8%, transparent);
  }
  body.citizen-theme .dash-topbar__title { color: var(--mea-white); }

  body.citizen-theme .dash-sidebar {
    background: var(--mea-dark);
    border-right-color: color-mix(in srgb, var(--mea-white) 8%, transparent);
  }
  body.citizen-theme .dash-sidebar__item { color: color-mix(in srgb, var(--mea-white) 60%, transparent); }
  body.citizen-theme .dash-sidebar__item:hover { background: color-mix(in srgb, var(--mea-white) 6%, transparent); }
  body.citizen-theme .dash-sidebar__item.is-active {
    background: color-mix(in srgb, var(--mea-baby-mid) 12%, transparent);
    color: var(--mea-white);
  }

  body.citizen-theme .dash-icon-btn {
    background: color-mix(in srgb, var(--mea-white) 6%, transparent);
    border-color: color-mix(in srgb, var(--mea-white) 12%, transparent);
    color: color-mix(in srgb, var(--mea-white) 70%, transparent);
  }
  body.citizen-theme .dash-icon-btn:hover {
    background: color-mix(in srgb, var(--mea-white) 10%, transparent);
    color: var(--mea-white);
  }

  /* Notification panel (citizen dark) */
  body.citizen-theme .dash-notif-panel {
    background: var(--mea-navy-mid);
    border-left-color: color-mix(in srgb, var(--mea-white) 8%, transparent);
  }
  body.citizen-theme .dash-notif-panel__header { border-bottom-color: color-mix(in srgb, var(--mea-white) 8%, transparent); }
  body.citizen-theme .dash-notif-panel__close { color: color-mix(in srgb, var(--mea-white) 50%, transparent); }
  body.citizen-theme .dash-notif-panel__close:hover { background: color-mix(in srgb, var(--mea-white) 6%, transparent); color: var(--mea-white); }
  body.citizen-theme .dash-notif-panel__title { color: var(--mea-white); }
  body.citizen-theme .notif-item { border-bottom-color: color-mix(in srgb, var(--mea-white) 6%, transparent); }
  body.citizen-theme .notif-item:hover { background: color-mix(in srgb, var(--mea-white) 4%, transparent); }
  body.citizen-theme .notif-detail { color: color-mix(in srgb, var(--mea-white) 60%, transparent); }
  body.citizen-theme .notif-title { color: var(--mea-white); }

  body.citizen-theme .dash-notif-item {
    border-bottom-color: color-mix(in srgb, var(--mea-white) 6%, transparent);
  }
  body.citizen-theme .dash-notif-item.is-unread {
    background: color-mix(in srgb, var(--mea-baby-mid) 8%, transparent);
  }
  body.citizen-theme .dash-notif-item__title { color: var(--mea-white); }

  /* Mobile bottom nav (citizen dark) */
  body.citizen-theme .mobile-bottom-nav {
    background: var(--mea-navy);
    border-top-color: color-mix(in srgb, var(--mea-white) 8%, transparent);
  }
  body.citizen-theme .mobile-bottom-nav__item { color: color-mix(in srgb, var(--mea-white) 50%, transparent); }
  body.citizen-theme .mobile-bottom-nav__item.is-active { color: var(--mea-baby-blue); }
}
