/* ─────────────────────────────────────────────────────────────────────────────
   App Shell — shared dashboard chrome (Material Design 3)

   Reusable header / brand / button / title / snackbar primitives that give the
   ecosystem landing pages (mt, expense, present) the same identity as Slides.
   Lifted verbatim from slides/css/main.css so they are pixel-identical.

   MD3 tokens (--md-*) come from /css/shared.css and resolve in BOTH light and
   dark schemes. Classes are namespaced `shell-` to coexist with Tailwind.
───────────────────────────────────────────────────────────────────────────── */

/* ── Sticky, blurred top bar ── */
.shell-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--glass-bar-bg);
  -webkit-backdrop-filter: blur(var(--glass-bar-blur));
  backdrop-filter: blur(var(--glass-bar-blur));
  border-bottom: none;
  box-shadow: var(--shadow-sm);
}
.shell-header-left,
.shell-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* ── Brand logo (SPCY ◇ / App) ── */
.shell-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--md-on-surface);
  text-decoration: none;
  white-space: nowrap;
  padding: 8px 12px 8px 8px;
  border-radius: var(--md-shape-full);
  transition: background var(--md-duration-s) var(--md-easing-standard);
}
.shell-logo:hover { background: var(--md-surface-container-high); }
.shell-logo svg { opacity: 0.95; flex-shrink: 0; }
.shell-logo .shell-logo-sep { opacity: 0.4; }

/* ── Cross-app launcher (replaces shell-logo as the brand mark).
       Visual parity with shell-logo; adds a chevron so users see "opens menu". */
.shell-launcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--md-on-surface);
  white-space: nowrap;
  padding: 8px 10px 8px 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--md-shape-full);
  transition: background var(--md-duration-s) var(--md-easing-standard);
}
.shell-launcher:hover { background: var(--md-surface-container-high); }
.shell-launcher:focus-visible {
  outline: 2px solid var(--md-primary, #818cf8);
  outline-offset: 2px;
}
.shell-launcher-label {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.shell-launcher-chev {
  font-size: 18px;
  opacity: 0.5;
}

/* ── Round tonal icon button (back / stat / theme / lang) ── */
.shell-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
  background: transparent;
  color: var(--md-on-surface-variant);
  border: none;
  border-radius: var(--md-shape-full);
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition: color var(--md-duration-s) var(--md-easing-standard),
              transform var(--md-duration-xs) var(--md-easing-standard);
}
.shell-icon-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-duration-s) var(--md-easing-standard);
}
.shell-icon-btn:hover { color: var(--md-on-surface); }
.shell-icon-btn:hover::after { opacity: 0.08; }
.shell-icon-btn:active::after { opacity: 0.12; }
.shell-icon-btn:active { transform: scale(0.96); }
.shell-icon-btn .material-symbols-outlined { font-size: 22px; }

/* ── MD3 filled button (primary action / extended FAB) ── */
.shell-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 24px;
  height: 48px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: none;
  border-radius: var(--md-shape-lg);
  cursor: pointer;
  text-decoration: none;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition: box-shadow var(--md-duration-m) var(--md-easing-standard),
              filter var(--md-duration-s) var(--md-easing-standard);
}
.shell-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-duration-s) var(--md-easing-standard);
}
.shell-btn:hover::after { opacity: 0.08; }
.shell-btn:active::after { opacity: 0.12; }
.shell-btn:active { transform: scale(0.99); }
.shell-btn .material-symbols-outlined { font-size: 20px; }

.shell-btn-filled {
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--shadow-sm);
}
.shell-btn-filled:hover {
  box-shadow: var(--shadow-md);
}
/* Compact variant for header-placed actions */
.shell-btn-sm { height: 40px; padding: 0 18px; font-size: 13px; }

/* ── Page title with brand-gradient accent word ── */
.shell-title {
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--md-on-surface);
  margin: 0;
}
.shell-title-accent {
  background: linear-gradient(135deg, #6366f1, #a855f7);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── MD3 snackbar (toast) ── */
.shell-snackbar {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--md-surface-container-highest);
  border: 1px solid var(--md-outline-variant);
  color: var(--md-on-surface);
  padding: 14px 22px;
  border-radius: var(--md-shape-xs);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: transform var(--md-duration-m) var(--md-easing-enter),
              opacity var(--md-duration-m);
  z-index: 300;
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
}
.shell-snackbar.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.shell-snackbar.error { color: #ffb4ab; border-color: rgba(255, 180, 171, 0.4); }

/* ── Responsive header (mobile compact) ─────────────────────────────────── */
@media (max-width: 640px) {
  .shell-header {
    padding: 10px 12px;
    gap: 8px;
  }
  .shell-logo {
    font-size: 14px;
    gap: 8px;
    padding: 6px 8px 6px 4px;
  }
  .shell-title { font-size: 24px; }
  .shell-btn { height: 44px; padding: 0 20px; font-size: 13px; }
}

/* ── Shell content wrapper ──────────────────────────────────────────────── */
.shell-content {
  max-width: var(--md-content-max);
  margin-inline: auto;
  padding: var(--md-space-6) var(--md-space-4);
  mask-image: linear-gradient(to bottom, transparent 0, black 12px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, black 12px);
}
@media (min-width: 768px) {
  .shell-content { padding: var(--md-space-8) var(--md-space-6); }
}

/* ── Shell section card (unified container for app content) ─────────────── */
.shell-card {
  background: var(--md-surface-container-low);
  border-radius: var(--md-shape-lg);
  padding: var(--md-space-6);
  max-width: var(--md-content-medium);
  margin-inline: auto;
}
@media (max-width: 640px) {
  .shell-card {
    border-radius: var(--md-shape-md);
    padding: var(--md-space-4);
  }
}

/* ── Shell empty state ──────────────────────────────────────────────────── */
.shell-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--md-space-3);
  padding: var(--md-space-12) var(--md-space-4);
  text-align: center;
  color: var(--md-on-surface-variant);
}
.shell-empty .material-symbols-outlined { font-size: 48px; opacity: 0.4; }

/* ── Shell section title ────────────────────────────────────────────────── */
.shell-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--md-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 var(--md-space-3) 0;
}

/* ── Cross-app launcher ─────────────────────────────────────────────────── */
/* `.hidden` is a Tailwind utility and only some hosts load Tailwind — declare it
   here so the component is self-contained wherever app-shell.css is loaded. */
.app-launcher.hidden,
.app-launcher-overlay.hidden { display: none; }

.app-launcher-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  /* Above app content incl. the Notebook tablet drawer (100) and tooltips,
     below the shared modal scrim (1000). */
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--md-easing-standard);
}
.app-launcher-overlay.open { opacity: 1; pointer-events: auto; }

.app-launcher {
  position: fixed;
  z-index: 401;
  width: min(360px, calc(100vw - 24px));
  max-height: min(70vh, 560px);
  background: var(--md-surface-container-low);
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-lg, 20px);
  box-shadow: var(--md-elevation-3);
  display: flex;
  flex-direction: column;
  padding: var(--md-space-2) var(--md-space-1) var(--md-space-1);
  transform: translateY(-8px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s var(--md-easing-standard);
}
.app-launcher.open { transform: translateY(0) scale(1); opacity: 1; pointer-events: auto; }

.app-launcher-handle { display: none; }

.app-launcher-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--md-space-2) var(--md-space-3) var(--md-space-1);
}
.app-launcher-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--md-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.app-launcher-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  color: var(--md-on-surface-variant);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s var(--md-easing-standard);
}
.app-launcher-close:hover { background: var(--md-surface-container-high); }
.app-launcher-close .material-symbols-outlined { font-size: 20px; }

.app-launcher-list {
  overflow-y: auto;
  /* Stop scroll chaining: reaching the end of the list must not start
     scrolling the page behind the panel / bottom sheet. */
  overscroll-behavior: contain;
  padding: var(--md-space-1) var(--md-space-1);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.app-launcher-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 14px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 0.12s var(--md-easing-standard);
  outline: none;
}
.app-launcher-item:hover,
.app-launcher-item.kb-active { background: var(--md-surface-container-high); }
.app-launcher-item.is-current { background: var(--md-surface-container); }

.app-launcher-icon {
  font-size: 24px;
  color: var(--md-on-surface-variant);
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}
.app-launcher-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.app-launcher-label { font-size: 15px; font-weight: 500; line-height: 1.2; }
.app-launcher-desc { font-size: 12.5px; color: var(--md-on-surface-variant); line-height: 1.3; }
.app-launcher-current {
  font-size: 11px;
  font-weight: 600;
  color: var(--md-on-surface-variant);
  background: var(--md-surface-container-highest);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Continue (resume last app) row */
.app-launcher-continue { padding: 0 var(--md-space-2) var(--md-space-1); }
.app-launcher-continue-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--md-surface-container);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  margin-bottom: 6px;
}
.app-launcher-continue-row:hover { background: var(--md-surface-container-high); }
.app-launcher-continue-row .material-symbols-outlined:first-child { font-size: 22px; color: var(--md-on-surface-variant); }
.app-launcher-continue-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.app-launcher-continue-label { font-size: 14px; font-weight: 600; }
.app-launcher-last { font-size: 11.5px; color: var(--md-on-surface-variant); }
.app-launcher-chevron { font-size: 20px; color: var(--md-on-surface-variant); }

/* Mobile: bottom sheet */
@media (max-width: 767px) {
  .app-launcher-overlay {
    z-index: 402;
    /* The sheet is not dismissible-by-drag, so swallow touch gestures on the
       scrim rather than letting them scroll the page underneath it. */
    touch-action: none;
  }
  .app-launcher {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    /* Overlay is bumped above the drawer/content on mobile; the sheet must
       sit above it or the scrim swallows taps on the links (links never
       navigate). */
    z-index: 403;
    width: 100%;
    max-width: none;
    max-height: 80vh;
    border-radius: 24px 24px 0 0;
    overscroll-behavior: contain;
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s var(--md-easing-standard);
    padding: 0 var(--md-space-1) var(--md-space-2);
  }
  .app-launcher.open { transform: translateY(0); opacity: 1; }
  .app-launcher-handle {
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: var(--md-outline-variant);
    margin: 8px auto 4px;
  }
  .app-launcher-header { padding-top: var(--md-space-1); }
}
