/* ==========================================================================
   SYMMETRA shell — app frame, sidebar navigation, page header, profile dock,
   theme toggle, mobile drawer, boot overlay, assistant launcher + panel.
   ========================================================================== */

@layer shell {

  /* ------------------------------------------------------------ app frame */
  .app {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
    /* the sidebar column's surface runs the full page height, even past the sticky sidebar */
    background: linear-gradient(to right, var(--sidebar-bg) var(--sidebar-w), transparent var(--sidebar-w));
  }
  /* the sidebar colours are tokens (symmetra-tokens.css): deep navy in both themes */
  .main {
    min-width: 0;
    padding: var(--space-5) var(--page-pad) var(--space-12);
  }
  .main > * { max-width: var(--content-max); margin-left: auto; margin-right: auto; }
  .main > * + * { margin-top: var(--space-4); }

  /* ------------------------------------------------------------- sidebar */
  .sidebar {
    position: sticky; top: 0; z-index: var(--z-sidebar);
    height: 100vh;
    display: flex; flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-2-5) var(--space-3);
    background: linear-gradient(180deg, var(--sidebar-bg-2) 0%, var(--sidebar-bg) 38%);
    border-right: 1px solid var(--sidebar-border);
    color: var(--sidebar-fg);
    overflow-y: auto;
    scrollbar-color: rgba(255, 255, 255, .14) transparent;
  }

  .sidebar-brand, .sym-sidebar-brand {
    display: flex; align-items: center; gap: var(--space-2-5);
    height: 40px; padding: 0 var(--space-2);
  }

  .nav { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-height: 0; }
  .nav-btn, .nav-subbtn, .nav-section-btn {
    position: relative;
    display: flex; align-items: center; gap: var(--space-2-5);
    width: 100%;
    height: 34px;
    padding: 0 var(--space-2-5);
    border: 0; border-radius: var(--radius-sm);
    background: transparent;
    color: var(--sidebar-fg);
    font-size: var(--text-sm);
    font-weight: var(--fw-medium);
    text-align: left;
    transition: background-color var(--dur-2), color var(--dur-2);
  }
  .nav-btn:hover, .nav-subbtn:hover, .nav-section-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-title); }
  .nav-btn.active, .nav-subbtn.active {
    background: var(--sidebar-active);
    color: var(--sidebar-title);
    font-weight: var(--fw-semibold);
    box-shadow: inset 0 0 0 1px rgba(130, 144, 255, .18);
  }
  .nav-btn.active::before, .nav-subbtn.active::before {
    content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px;
    border-radius: 0 3px 3px 0; background: var(--brand-grad); box-shadow: 0 0 12px rgba(124, 77, 255, .7);
  }
  .nav-btn-icon { display: inline-flex; width: 18px; height: 18px; color: var(--sidebar-muted); flex: none; }
  .nav-btn-icon svg { width: 18px; height: 18px; stroke-width: 1.7; }
  .nav-btn:hover .nav-btn-icon, .nav-subbtn:hover .nav-btn-icon { color: var(--sidebar-fg); }
  .nav-btn.active .nav-btn-icon, .nav-subbtn.active .nav-btn-icon { color: #a9b3ff; }
  .nav-btn-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-section { margin-top: var(--space-3); display: flex; flex-direction: column; gap: 1px; }
  .nav-section-label {
    padding: var(--space-2) var(--space-2-5) var(--space-1);
    color: var(--sidebar-muted);
    font-size: var(--text-2xs);
    font-weight: var(--fw-semibold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }
  .nav-subnav { display: flex; flex-direction: column; gap: 1px; }
  .nav-bottom { margin-top: auto; padding-top: var(--space-2); display: flex; flex-direction: column; gap: 1px; }
  .nav-divider { height: 1px; background: var(--sidebar-border); margin: var(--space-2) var(--space-1); }

  .sidebar-footer {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
    padding: var(--space-2) var(--space-2-5) 0;
    border-top: 1px solid var(--sidebar-border);
    min-height: 40px;
  }
  .brand-footer, .brand { display: flex; align-items: center; gap: var(--space-2-5); min-width: 0; }
  .sidebar-mark { width: 24px; height: 24px; flex: none; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .18)); }
  .sidebar-brand-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; line-height: 1.2; }
  .sidebar-wordmark {
    font-size: var(--text-2xs);
    font-weight: var(--fw-semibold);
    letter-spacing: .28em;
    color: var(--sidebar-title);
  }
  .sym-app-version {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: var(--text-2xs); color: var(--sidebar-muted); font-variant-numeric: tabular-nums;
    max-width: 120px; overflow: hidden; white-space: nowrap;
  }
  .sym-app-version__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--subtle); flex: none; }
  .sym-app-version.is-healthy .sym-app-version__dot { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
  .sym-app-version__text { overflow: hidden; text-overflow: ellipsis; }

  /* theme toggle (in the sidebar footer) */
  .sym-theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    color: var(--sidebar-muted); background: transparent; border: 1px solid transparent;
    transition: background-color var(--dur-2), color var(--dur-2), border-color var(--dur-2);
  }
  .sym-theme-toggle:hover { background: var(--sidebar-hover); color: var(--sidebar-title); }
  .sym-theme-toggle svg { width: 16px; height: 16px; }

  /* profile dock (top of the sidebar) */
  .sym-profile-dock {
    display: flex; align-items: center; gap: var(--space-2-5);
    width: 100%;
    padding: var(--space-2);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, .04);
    text-align: left;
    margin-bottom: var(--space-2);
    transition: background-color var(--dur-2), border-color var(--dur-2);
  }
  .sym-profile-dock:hover { background: var(--sidebar-hover); border-color: rgba(255, 255, 255, .14); }
  .sym-profile-dock .sym-avatar { width: 30px; height: 30px; font-size: var(--text-2xs); }
  .sym-profile-dock__copy { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
  .sym-profile-dock__name { font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--sidebar-title); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sym-profile-dock__role { font-size: var(--text-2xs); color: var(--sidebar-muted); }
  .sym-profile-dock__chev { color: var(--sidebar-muted); display: inline-flex; }
  .sym-profile-dock .sym-avatar { background: var(--brand-grad); color: #fff; }
  .sym-profile-dock__chev svg { width: 14px; height: 14px; }

  /* ---------------------------------------------------------- page header */
  .page-head, .page-header, .gl-top-header {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
    min-height: 40px;
    flex-wrap: wrap;
  }
  .page-head h1, .page-header h1 {
    font-size: var(--text-xl); line-height: var(--lh-xl); font-weight: var(--fw-semibold);
    letter-spacing: var(--tracking-tight); color: var(--text); margin: 0;
  }
  .page-head > div:first-child { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
  .page-head .actions, .page-header .actions, .page-actions {
    display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end;
  }
  .page-head .actions input:not([type="checkbox"]), .page-head .actions select { width: 240px; }
  .page-sub, .page-subtitle { color: var(--muted); font-size: var(--text-sm); }

  /* ---------------------------------------------------- mobile navigation */
  .sym-mnav-toggle, .sym-mnav-backdrop { display: none; }
  @media (max-width: 900px) {
    .app { grid-template-columns: minmax(0, 1fr); background: none; }
    .main { padding-top: 64px; }
    .sidebar {
      position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); height: 100dvh;
      transform: translateX(-102%);
      transition: transform var(--dur-4) var(--ease-out);
      box-shadow: var(--elev-3);
      z-index: calc(var(--z-overlay) + 1);
    }
    :root.sym-mnav-open .sidebar { transform: none; }
    :root.sym-mnav-enabled .sym-mnav-toggle {
      display: inline-flex; align-items: center; justify-content: center;
      position: fixed; left: 12px; top: 12px; z-index: var(--z-header);
      width: 40px; height: 40px;
      border-radius: var(--radius-md);
      border: 1px solid var(--border);
      background: color-mix(in srgb, var(--surface) 90%, transparent);
      backdrop-filter: blur(8px);
      color: var(--text);
      box-shadow: var(--elev-2);
    }
    .sym-mnav-toggle svg { width: 20px; height: 20px; }
    :root.sym-mnav-open .sym-mnav-backdrop {
      display: block; position: fixed; inset: 0; z-index: var(--z-overlay); background: var(--scrim);
      animation: sym-fade-in var(--dur-3) var(--ease-out);
    }
    .page-head .actions input:not([type="checkbox"]), .page-head .actions select { width: 100%; }
  }

  /* -------------------------------------------------------- boot overlay */
  #sym-boot-overlay {
    position: fixed; inset: 0; z-index: var(--z-toast);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3);
    background: var(--bg) var(--bg-grad) no-repeat;
    transition: opacity .3s ease;
  }
  #sym-boot-overlay.is-hidden { opacity: 0; pointer-events: none; visibility: hidden; }
  #sym-boot-overlay .sym-boot-spin {
    width: 28px; height: 28px; border-radius: 50%;
    border: 2px solid var(--accent-soft-2); border-top-color: var(--accent);
    animation: sym-spin .75s linear infinite;
  }
  #sym-boot-overlay .sym-boot-text { font-size: var(--text-xs); font-weight: var(--fw-medium); color: var(--muted); letter-spacing: .02em; }

  /* ----------------------------------------------- assistant (Denarius) */
  #sym-copilot-fab {
    position: fixed; right: 20px; bottom: 20px; z-index: var(--z-header);
    width: 44px; height: 44px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid rgba(255, 255, 255, .14);
    background: radial-gradient(120% 120% at 30% 20%, #5b8cff 0%, #2563eb 55%, #1d3fb8 100%);
    color: #fff;
    box-shadow: 0 10px 24px -8px rgba(37, 99, 235, .55), 0 0 0 4px var(--accent-soft);
    transition: transform var(--dur-2) var(--ease-out), box-shadow var(--dur-2);
  }
  #sym-copilot-fab:hover { transform: translateY(-1px); box-shadow: 0 14px 28px -8px rgba(37, 99, 235, .6), 0 0 0 5px var(--accent-soft); }
  #sym-copilot-fab svg { width: 20px; height: 20px; }
  #sym-copilot-panel {
    position: fixed; right: 20px; bottom: 76px; z-index: var(--z-modal);
    width: 392px; max-width: calc(100vw - 24px);
    height: 560px; max-height: calc(100vh - 110px);
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--surface-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--elev-3);
    animation: sym-pop-in var(--dur-3) var(--ease-out);
  }
  #sym-copilot-panel .cp-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 var(--space-2) 0 var(--space-4); height: 48px;
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text);
  }
  #sym-copilot-panel .cp-head span::before {
    content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px;
    background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); vertical-align: 1px;
  }
  #sym-copilot-panel .cp-head button {
    width: 30px; height: 30px; border-radius: var(--radius-sm); color: var(--muted); font-size: 18px;
  }
  #sym-copilot-panel .cp-head button:hover { background: var(--surface-3); color: var(--text); }
  #sym-copilot-panel .cp-body { flex: 1; overflow-y: auto; padding: var(--space-4); background: var(--surface-2); font-size: var(--text-sm); line-height: 1.55; }
  #sym-copilot-panel .cp-msg {
    margin: 0 0 var(--space-2-5); padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md); max-width: 86%; white-space: pre-wrap; word-break: break-word;
  }
  #sym-copilot-panel .cp-user { margin-left: auto; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 4px; }
  #sym-copilot-panel .cp-bot { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }
  #sym-copilot-panel .cp-chip { font-size: var(--text-2xs); color: var(--muted); padding: 2px 4px; }
  #sym-copilot-panel .cp-foot {
    display: flex; gap: var(--space-2); align-items: flex-end;
    padding: var(--space-2-5); border-top: 1px solid var(--border); background: var(--surface);
  }
  #sym-copilot-panel .cp-foot textarea { flex: 1; resize: none; height: 38px; min-height: 38px; padding: 8px 10px; }
  #sym-copilot-panel .cp-foot button { height: 38px; padding: 0 var(--space-3); border-radius: var(--radius-sm); font-weight: var(--fw-medium); }
  #sym-copilot-panel .cp-send { background: var(--accent); color: var(--on-accent); }
  #sym-copilot-panel .cp-send:hover { background: var(--accent-hover); }
  #sym-copilot-panel .cp-attach { width: 38px; padding: 0 !important; background: var(--surface-3); color: var(--text-2); font-size: 18px; }

  /* ------------------------------------------------- help coach / guide */
  .coach-overlay, .sym-coach-overlay { position: fixed; inset: 0; z-index: var(--z-overlay); background: var(--scrim); }
  .coach-card, .coach-panel, .sym-coach {
    position: fixed; z-index: var(--z-modal);
    max-width: 360px; padding: var(--space-4);
    background: var(--surface-overlay); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--elev-3); color: var(--text);
  }
}

/* ---- workspace switcher (platform owner, 2026-10 peak plan A12) ----------------------------------------- */
@layer shell {
  .sym-ws-switch { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 var(--space-2); width: 100%; margin: 0 0 var(--space-2);
    padding: var(--space-1-5) var(--space-2-5); border-radius: var(--radius-md); border: 1px dashed rgba(130, 144, 255, .35);
    background: rgba(110, 124, 255, .08); color: var(--sidebar-fg); text-align: left; cursor: pointer; }
  .sym-ws-switch:hover { background: var(--sidebar-hover); color: var(--sidebar-title); }
  .sym-ws-switch__label { grid-column: 1; font-size: var(--text-2xs); color: var(--sidebar-muted); text-transform: uppercase; letter-spacing: var(--tracking-caps); }
  .sym-ws-switch__name { grid-column: 1; font-size: var(--text-sm); font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sym-ws-switch > span[aria-hidden] { grid-column: 2; grid-row: 1 / span 2; }
  .sym-ws-list { display: grid; gap: var(--space-1); max-height: 50vh; overflow: auto; margin-top: var(--space-2); }
  .sym-ws-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: var(--space-2) var(--space-3); border: 1px solid var(--border);
    border-radius: var(--radius-md); background: var(--surface); text-align: left; cursor: pointer; }
  .sym-ws-item:hover { border-color: var(--accent); background: var(--accent-soft); }
  .sym-ws-item.is-current { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
  .sym-ws-filter { width: 100%; }
}
