/*
 * App shell: the left sidebar (views/partials/sidebar.ejs) and the thin top bar (views/partials/nav.ejs),
 * the same on every signed-in page, the inbox included. Modelled on Flexiibook's sidebarStyles.css:
 * white sidebar, outline icons, light-blue active pill, uppercase grey section labels, trial card at
 * the bottom. Loaded after hd-ui.css, app.css and page CSS (inbox.css) so it can place the inbox.
 *
 * ≥992px: the sidebar is fixed on the left (240px) and the page sits beside it.
 * <992px: the sidebar is a drawer opened from the top bar's menu button (/js/shell.js).
 */
:root {
  --fx-brand: #167DD1;
  --fx-brand-hover: #1269b3;
  --fx-brand-bg: #eef3ff;
  --fx-brand-ring: rgba(22, 125, 209, 0.18);
  --fx-line: #e8e8e5;
  --fx-line-soft: #f0f0ed;
  --fx-hover: #f7f7f5;
  --fx-text: #101828;
  --fx-text-2: #555;
  --fx-muted: #666;
  --fx-label: #a3a3a0;
  --fx-side-w: 240px;
  --fx-bar-h: 52px;
}

/* ---------- Page frame ---------- */
body.hd-body:has(> .fx-side) { background: #fff; }
@media (min-width: 992px) {
  body.hd-body:has(> .fx-side) { padding-left: var(--fx-side-w); }
}
/* Full-screen pages (the inbox): the bar and the app fill the screen, nothing scrolls the body. */
body.fs-app .fx-bar { flex-shrink: 0; }
body.fs-app:has(> .fx-side) .sp { height: auto; flex: 1; min-height: 0; }

/* ---------- Sidebar ---------- */
.fx-side {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 1001; width: var(--fx-side-w);
  background: #fff; border-right: 1px solid var(--fx-line);
  font-family: var(--hd-font); font-feature-settings: 'cv11'; color: var(--fx-text); -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px);
}
.fx-side *, .fx-side *::before, .fx-side *::after { box-sizing: border-box; }
.fx-side-in {
  height: 100%; display: flex; flex-direction: column; padding: 14px 10px 10px;
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #e0e0dd transparent;
}
/* The menu scrolls on short screens; the footer (notice, trial card, workspace) stays pinned. */
.fx-side-scroll {
  flex: 1 1 auto; min-height: 140px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
  margin: 0 -10px; padding: 0 10px; scrollbar-width: thin; scrollbar-color: #e0e0dd transparent;
}
.fx-side-foot { flex-shrink: 0; padding-top: 10px; }

.fx-brand-row { display: flex; align-items: center; gap: 8px; padding: 4px 0 10px; min-height: 40px; }
.fx-brand { font-size: 18px; font-weight: 500; letter-spacing: -0.01em; padding: 0 8px; color: var(--fx-text); text-decoration: none; white-space: nowrap; }
.fx-brand:hover { color: var(--fx-text); text-decoration: none; }
.fx-dot { color: var(--fx-brand); font-weight: 700; }
.fx-side-close {
  display: none; align-items: center; justify-content: center; width: 36px; height: 36px; margin-left: auto;
  padding: 0; border: 0; border-radius: 8px; background: none; color: var(--fx-muted); cursor: pointer;
}
.fx-side-close:hover { background: var(--fx-hover); color: var(--fx-text); }
.fx-side-close svg { width: 18px; height: 18px; }

/* Search pill */
.fx-search {
  display: flex; align-items: center; gap: 7px; padding: 0 10px; height: 34px; margin: 0 0 12px;
  border-radius: 7px; background: var(--fx-hover); border: 1px solid transparent; transition: border-color 0.1s, background 0.1s;
}
.fx-search:hover { border-color: #e0e0dd; }
.fx-search:focus-within { background: #fff; border-color: var(--fx-brand); box-shadow: 0 0 0 3px var(--fx-brand-ring); }
.fx-search svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--fx-text); opacity: 0.4; }
.fx-search input {
  flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: none; background: transparent;
  font-family: inherit; font-size: 13px; color: var(--fx-text); -webkit-appearance: none; appearance: none;
}
.fx-search input::placeholder { color: #9a9a96; }
.fx-search input::-webkit-search-cancel-button { display: none; }
.fx-kbd {
  flex-shrink: 0; font-size: 10px; line-height: 1.4; color: #9a9a96; background: #fff;
  border: 1px solid #e5e5e2; border-radius: 4px; padding: 1px 5px;
}
.fx-search:focus-within .fx-kbd { display: none; }

/* Sections and items */
.fx-sec { margin-bottom: 4px; }
.fx-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fx-label); padding: 10px 8px 4px; }
.fx-item {
  display: flex; align-items: center; gap: 9px; min-height: 32px; padding: 5px 8px; margin-bottom: 1px;
  border-radius: 6px; border: 1px solid transparent; font-size: 14px; font-weight: 500; line-height: 1.3;
  color: var(--fx-muted); text-decoration: none; cursor: pointer; transition: background 0.1s, color 0.1s;
}
.fx-item:hover { background: var(--fx-hover); color: var(--fx-text); text-decoration: none; }
.fx-item:focus-visible { outline: 2px solid var(--fx-brand); outline-offset: -2px; }
.fx-item.active { background: var(--fx-brand-bg); color: var(--fx-brand); font-weight: 600; }
.fx-item > svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.5; }
.fx-item.active > svg { opacity: 0.9; }
.fx-item-l { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.fx-n { font-size: 12px; font-weight: 500; color: #8a8983; font-variant-numeric: tabular-nums; }
.fx-item.active .fx-n { color: var(--fx-brand); }
.fx-badge:empty, .fx-n:empty { display: none; }
.fx-badge {
  min-width: 18px; height: 18px; padding: 0 6px; border-radius: 9px; background: var(--fx-brand); color: #fff;
  font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums;
}

/* Inbox views: child items under Inbox, aligned with its label */
.fx-sub { margin: 0 0 2px; }
.fx-child { min-height: 28px; padding: 3px 8px 3px 33px; font-size: 13px; }
.fx-child.active { font-weight: 600; }
.fx-more > summary { list-style: none; }
.fx-more > summary::-webkit-details-marker { display: none; }
.fx-chev { width: 12px; height: 12px; opacity: 0.5; transition: transform 0.15s; }
.fx-more[open] > summary .fx-chev { transform: rotate(90deg); }


/* Trial / payment card (bottom of the sidebar) */
.fx-trial {
  position: relative; margin: 0 2px 8px; padding: 12px; border-radius: 12px;
  background: linear-gradient(180deg, #fbfaf7 0%, #f6f4ef 100%); border: 1px solid #ebe7dd; color: #6b5a3a;
}
.fx-trial[hidden] { display: none !important; }
.fx-trial.urgent { background: linear-gradient(180deg, #fef7f6 0%, #fdeeec 100%); border-color: #f6d5d0; color: #a4372a; }
.fx-trial-h { display: flex; align-items: center; gap: 6px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.8; margin-bottom: 6px; }
.fx-trial-h svg { width: 13px; height: 13px; flex-shrink: 0; }
.fx-trial-t { margin: 0; padding-right: 22px; font-size: 15px; font-weight: 600; line-height: 1.25; color: var(--fx-text); }
.fx-trial.urgent .fx-trial-t { color: #a4372a; }
.fx-trial-s { margin: 3px 0 0; font-size: 12px; line-height: 1.4; opacity: 0.85; }
.fx-trial-only { margin-top: 0; padding-right: 22px; }
.fx-trial-meter { height: 4px; margin: 10px 0 0; border-radius: 999px; background: rgba(0, 0, 0, 0.07); overflow: hidden; }
.fx-trial-meter > span { display: block; height: 100%; border-radius: 999px; background: var(--fx-brand); }
.fx-trial.urgent .fx-trial-meter > span { background: #d1483a; }
.fx-trial-cta {
  display: flex; align-items: center; justify-content: center; min-height: 34px; margin-top: 10px; padding: 0 10px;
  border-radius: 8px; background: var(--fx-brand); color: #fff; font-size: 13px; font-weight: 600; text-decoration: none;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1); transition: filter 0.12s, box-shadow 0.12s, transform 0.12s;
}
.fx-trial.urgent .fx-trial-cta { background: #d1483a; }
.fx-trial-cta:hover, .fx-trial-cta:focus-visible { color: #fff; text-decoration: none; filter: brightness(0.9); box-shadow: 0 3px 8px rgba(16, 24, 40, 0.16); transform: translateY(-1px); }
.fx-trial-cta:active { filter: brightness(0.84); transform: none; }
.fx-trial-x {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-radius: 7px; background: transparent; color: inherit; opacity: 0.45; cursor: pointer;
}
.fx-trial-x:hover, .fx-trial-x:focus-visible { opacity: 1; background: rgba(0, 0, 0, 0.07); }
.fx-trial-x svg { width: 12px; height: 12px; }

/* Workspace switcher (bottom). An hd-menu that opens upwards. */
.fx-ws { display: block; border-top: 1px solid var(--fx-line-soft); padding-top: 8px; }
.fx-ws-btn { display: flex; align-items: center; gap: 9px; padding: 6px 8px; min-height: 44px; border-radius: 6px; }
.fx-ws-btn:hover { background: var(--fx-hover); }
.fx-ws-av {
  width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  background: #e8edf3; color: var(--fx-brand); font-size: 11px; font-weight: 600;
}
.fx-ws-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.fx-ws-txt b { font-size: 13px; font-weight: 600; color: var(--fx-text); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.fx-ws-txt span { font-size: 12px; color: #8a8983; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.fx-ws-chev { width: 14px; height: 14px; color: #8a8983; flex-shrink: 0; }
.fx-ws .hd-menu-list { top: auto; bottom: calc(100% + 6px); left: 0; right: 0; min-width: 0; }

/* Drawer scrim (narrow screens) */
.fx-scrim { display: none; }

/* ---------- Top bar ---------- */
.fx-bar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: calc(var(--fx-bar-h) + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 24px 0;
  background: #fff; border-bottom: 1px solid var(--fx-line);
  font-family: var(--hd-font); font-feature-settings: 'cv11'; font-size: 13px; color: var(--fx-text); -webkit-font-smoothing: antialiased;
}
.fx-bar *, .fx-bar *::before, .fx-bar *::after { box-sizing: border-box; }
.fx-bar-l { display: flex; align-items: center; gap: 10px; min-width: 0; }
.fx-bar-r { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.fx-burger {
  display: none; align-items: center; justify-content: center; width: 36px; height: 36px; margin-left: -6px; padding: 0;
  border: 0; border-radius: 8px; background: none; color: var(--fx-muted); cursor: pointer;
}
.fx-burger:hover { background: var(--fx-hover); color: var(--fx-text); }
.fx-burger svg { width: 20px; height: 20px; }

.fx-crumb { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; }
.fx-crumb .parent { color: #8a8983; text-decoration: none; white-space: nowrap; }
.fx-crumb a.parent:hover { color: #5f5e5a; text-decoration: none; }
.fx-crumb .sep { width: 16px; height: 16px; color: #d4d4cf; flex-shrink: 0; }
.fx-crumb .current { color: var(--fx-text); font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.fx-newbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--fx-line); background: #fff; color: var(--fx-text); font-size: 13px; font-weight: 500;
  text-decoration: none; white-space: nowrap; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05); cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.fx-newbtn:hover { background: var(--fx-hover); border-color: #dcdcd8; color: var(--fx-text); text-decoration: none; }
.fx-newbtn svg { width: 15px; height: 15px; color: var(--fx-brand); flex-shrink: 0; }

.fx-acct > summary.fx-avatar {
  width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: #e8edf3; color: var(--fx-brand); font-size: 12px; font-weight: 600; cursor: pointer; user-select: none;
}
.fx-acct > summary.fx-avatar:hover, .fx-acct[open] > summary.fx-avatar { background: #dce5ef; }
.fx-acct .hd-menu-list { min-width: 220px; z-index: 60; }
.hd-menu-list > form { margin: 0; }
.hd-menu-list > form > button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; margin: 0; border: 0; border-radius: 5px;
  background: transparent; box-shadow: none; color: var(--hd-fg-2); font: inherit; font-weight: 400; text-align: left;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hd-menu-list > form > button:hover { background: var(--hd-sel); color: var(--hd-fg); }
.fx-acct .hd-menu-head .hd-tag { margin-top: 6px; }

/* ---------- Narrow screens: the sidebar is a drawer ---------- */
@media (max-width: 991.98px) {
  .fx-side {
    width: min(300px, 88vw); transform: translateX(-100%); visibility: hidden;
    transition: transform 0.24s ease, visibility 0.24s; box-shadow: none; border-right: 0;
  }
  .fx-side.open { transform: none; visibility: visible; box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1); }
  .fx-side-close { display: inline-flex; }
  .fx-scrim {
    display: block; position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, 0.3);
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
  }
  .fx-scrim.open { opacity: 1; pointer-events: auto; }
  body.fx-menu-open { overflow: hidden; }
  .fx-kbd { display: none; }
  .fx-item { min-height: 40px; font-size: 15px; padding: 7px 10px; }
  .fx-child { min-height: 38px; padding-left: 35px; font-size: 14px; }
  .fx-label { font-size: 11px; }
  .fx-search { height: 40px; }
  .fx-search input { font-size: 16px; } /* 16px stops iOS zooming on focus */

  .fx-bar { padding: env(safe-area-inset-top, 0px) 14px 0; --fx-bar-h: 52px; }
  .fx-burger { display: inline-flex; }
}
@media (max-width: 767.98px) {
  .fx-bar { --fx-bar-h: 48px; gap: 8px; }
  .fx-crumb .parent, .fx-crumb .sep { display: none; }
  .fx-newbtn { width: 36px; height: 36px; padding: 0; justify-content: center; }
  .fx-newbtn-l { display: none; }
  .fx-newbtn svg { width: 18px; height: 18px; }
  .fx-acct > summary.fx-avatar { width: 36px; height: 36px; }
  /* Inbox on a phone: an open conversation (or customer) takes the whole screen; its own header has the back button. */
  body.fs-app:has(.sp.has-sel) .fx-bar { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .fx-side, .fx-scrim { transition: none; }
}
@media (pointer: coarse) {
  .fx-item { min-height: 40px; }
  .fx-child { min-height: 38px; }
}

/* Content pages sit at the sidebar's edge (left-aligned, like Flexiibook), not centred in the space. */
body:has(> .fx-side) main.hd { margin: 0; padding-left: 32px; padding-right: 32px; }
@media (max-width: 760px) {
  body:has(> .fx-side) main.hd { padding-left: 16px; padding-right: 16px; }
}

/* Test mode notice (outside production nothing reaches customers) */
.fx-notes { margin: 0 2px 8px; }
.fx-mailmode { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.4; color: var(--hd-amber); background: var(--hd-amber-bg); border: 1px solid #fde68a; }
.fx-mailmode svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 1px; }

/* Touch / narrow: 36px tap targets in the shell's small controls and menus */
@media (max-width: 991.98px), (pointer: coarse) {
  .fx-brand { display: inline-flex; align-items: center; min-height: 36px; }
  .fx-trial-x { width: 36px; height: 36px; top: 0; right: 0; }
  .fx-trial-cta { min-height: 38px; }
  .fx-acct .hd-menu-list > a, .fx-acct .hd-menu-list form button,
  .fx-ws .hd-menu-list > a, .fx-ws .hd-menu-list form button { min-height: 38px; display: flex; align-items: center; }
}
