/* Fizzavo Mac-window chrome (UI-M1 step 2/3).
   Loaded AFTER views.css (see app.html <head> comment) so these shell rules
   win the cascade without !important. Owns: backdrop, window frame, title
   bar, traffic lights, brand tab strip, sidebar restyle, practice banner
   layout, auth-gate restyle, mobile drawer, Tauri edge-to-edge mode.
   See plans/ui-mockup-stitching/dom-conventions.md for the class rules. */

/* ---------- App shell (full-bleed — the Mac window frame/title bar was
   removed 2026-07-27; the sharp edge-to-edge layout matches the mockups'
   content area directly) ---------- */

html, body {
  background: var(--bg);
}

.mac-backdrop {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
}

.mac-window {
  width: 100%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.mac-drawer-toggle {
  flex: none;
  display: none;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
  padding: var(--space-1) var(--space-2);
  -webkit-app-region: no-drag;
}

/* ---------- Sidebar brand dropdown (mockup 01: "PlaceFinder ⌄" at the top
   of the sidebar, replacing the old title-bar tab strip). brand.js is the
   only writer of the <select> inside this container. ---------- */

.brand-dropdown {
  padding: 0 var(--space-2) var(--space-3);
}

.brand-select {
  width: 100%;
  appearance: none;
  font-family: var(--font-system);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-sunken)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%236b6478' d='M1 1l5 5 5-5'/%3E%3C/svg%3E")
    no-repeat right 0.8em center;
  background-size: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.6em 2em 0.6em 0.9em;
  cursor: pointer;
}

.brand-select:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

/* ---------- Content-header brand tab strip (owner ruling 2026-07-27:
   one-click always-visible brand switching, alongside the sidebar dropdown
   above — same state, brand.js single-writer). Styled like the mockups'
   platform tabs: idle = muted text, active = white pill + purple underline. */

.brand-tabstrip {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 1 auto;
  min-width: 0;
  overflow-x: auto;
}

.brand-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-system);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.5em 1em;
  border-radius: var(--radius-md);
  cursor: pointer;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}

.brand-tab:hover {
  color: var(--text);
  background: var(--bg-sunken);
}

.brand-tab.active {
  background: var(--bg-elevated);
  color: var(--primary-ink);
  border-bottom-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- Content header (mobile hamburger + outbox indicator, sits
   above the practice banner in the content column). ---------- */

.content-header {
  grid-row: 1;
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.content-header-spacer {
  flex: 1;
}

/* Outbox indicator relocated into the content header (bell). outbox-indicator.js
   is untouched — same #outbox-indicator / #outbox-indicator-count /
   #outbox-retry-btn hooks, just restyled + moved via markup+CSS. */
.content-header .outbox-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.78rem;
  color: var(--banner-amber-ink);
  background: color-mix(in srgb, var(--banner-amber) 20%, transparent);
  border-radius: var(--radius-pill);
  padding: 0.35em 0.9em;
  white-space: nowrap;
}

.content-header .outbox-indicator-conflict {
  color: var(--danger-ink);
  background: color-mix(in srgb, var(--danger) 18%, transparent);
}

.outbox-bell {
  font-size: 0.9rem;
}

/* ---------- App shell layout (sidebar + header + banner + main, as a grid
   so the content header and practice banner span the full content width
   above main, matching the mockups, without requiring app.html DOM changes
   beyond what already exists: nav, header, banner, main as siblings inside
   #app-shell). ---------- */

.app-shell {
  display: grid !important;
  grid-template-columns: 240px minmax(0, 1fr);
  grid-template-rows: auto auto 1fr;
  min-height: 0 !important;
  flex: 1;
}

/* The grid rule above ties tokens.css's `[hidden] { display: none !important }`
   on specificity (0,1,0) and wins on link order (chrome.css is linked after),
   so #app-shell's own `hidden` attribute did nothing: logged out, the app
   painted with every card on "Loading…" and no login gate. Scoping the
   attribute to the class breaks the tie. See tests/test_login_gate_shell.py. */
.app-shell[hidden] {
  display: none !important;
}

.app-nav {
  grid-row: 1 / 4;
  grid-column: 1;
  width: auto !important;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
}

.practice-mode-banner {
  grid-row: 2;
  grid-column: 2;
}

.app-main {
  grid-row: 3;
  grid-column: 2;
  max-width: none !important;
  overflow-y: auto;
}

/* ---------- Sidebar restyle (wordmark, icon nav w/ active pill, footer) --- */

.app-nav .brand {
  padding: 0 var(--space-2) var(--space-3);
}

.app-nav .brand-mark {
  font-size: 1.3rem;
}

.nav-link.active {
  background: var(--primary);
  color: #ffffff;
}

/* ---------- User block popover (mockup 08: Daniel ⌃ expands to
   Profile / Log out). #nav-user/#nav-user-name/#nav-logout-btn IDs are
   unchanged from before — auth.js still finds and drives them the same
   way; this is a restyle + a hidden-toggle wrapper around them. ---------- */

.nav-user {
  position: relative;
}

.nav-user-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: none;
  border: none;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-display);
  color: var(--text);
}

.nav-user-toggle:hover {
  background: var(--bg-sunken);
}

.nav-user-avatar {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-user-toggle .nav-user-name {
  flex: 1;
  text-align: left;
}

.nav-user-caret {
  flex: none;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.nav-user-toggle[aria-expanded="true"] .nav-user-caret {
  transform: rotate(180deg);
}

.nav-user-popover {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 10;
}

.nav-user-popover-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  text-decoration: none;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.6em 0.8em;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.nav-user-popover-item:hover {
  background: var(--bg-sunken);
}

.nav-user-popover-logout {
  color: var(--danger-ink);
}

/* ---------- Auth gate restyle: plain centered card, no window chrome
   (matches the mockups — the login screen isn't "inside" the app window). */

.auth-gate {
  background: var(--paper);
  backdrop-filter: none;
}

/* ---------- Mobile (<900px): frame/backdrop collapse to full-bleed, sidebar
   becomes a drawer opened by the hamburger next to the traffic lights. --- */

@media (max-width: 900px) {
  .mac-drawer-toggle {
    display: inline-flex;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1200;
    width: 260px !important;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-md);
    overflow-y: auto;
    /* views.css's own @media(max-width:860px) rule sets flex-direction:row
       + align-items:center for its old horizontal-scroll mobile nav; that
       block loads before chrome.css but this @media(900px) block's rules
       still need to explicitly win here since neither media query alone
       has higher specificity — the drawer must stack vertically. */
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .app-nav .nav-list {
    flex-direction: column !important;
  }

  @media (prefers-reduced-motion: reduce) {
    .app-nav {
      transition: none;
    }
  }

  .app-nav.nav-open {
    transform: translateX(0);
  }

  .app-shell.nav-drawer-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1100;
  }

  .content-header,
  .practice-mode-banner,
  .app-main {
    grid-column: 1;
  }
}

/* ---------- Tauri quick-compose popup (body.quick): no room for the
   content header. The shell is already full-bleed, so nothing else to
   suppress. --- */

body.quick .content-header {
  display: none;
}
