/* ── App Shell Layout ── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  position: relative;
  z-index: 20;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
/* Official TTC logo (assets/brand): two-tone on the dark theme, full colour (navy tagline) on the light theme. */
.sidebar-logo img { width: 100%; max-width: 180px; height: auto; display: block; }
.sidebar-logo .logo-light { display: none; }
:root[data-theme="light"] .sidebar-logo .logo-dark,
:root[data-theme="sand"] .sidebar-logo .logo-dark { display: none; }
:root[data-theme="light"] .sidebar-logo .logo-light,
:root[data-theme="sand"] .sidebar-logo .logo-light { display: block; }

/* Downtown: the sidebar is a deep navy shell. Re-scope the tokens it uses (the two-tone logo stays, as on Dark).
   The notifications popover inside it gets the white-surface tokens back. Selected item: inset bar, not colour only. */
:root[data-theme="downtown"] .sidebar {
  --bg2: #102e52;
  --bg3: #163a63;
  --bg4: #1a416e;
  --bg5: #245791;
  --border: rgba(231,239,250,0.12);
  --border2: rgba(231,239,250,0.20);
  --text: #e7effa;
  --text2: #b8c9de;
  --text3: #b8c9de;
  --blue: #8db8f0;
  --blue-bg: rgba(141,184,240,0.14);
  --blue-border: rgba(141,184,240,0.35);
  --green: #7fd1a6;
  --green-bg: rgba(127,209,166,0.14);
  --green-border: rgba(127,209,166,0.35);
  --amber: #f3c969;
  --amber-bg: rgba(243,201,105,0.14);
  --amber-border: rgba(243,201,105,0.35);
  --red: #f59aa3;
  --red-bg: rgba(245,154,163,0.14);
  --red-border: rgba(245,154,163,0.35);
  color-scheme: dark;
}
:root[data-theme="downtown"] .sidebar .notifications-panel {
  --bg3: #ffffff;
  --border: rgba(23,43,70,0.09);
  --border2: #c9d5e3;
  --text: #172b46;
  --text2: #52647a;
  --text3: #52647a;
  --blue: #174a8b;
  --amber: #805000;
  --red: #aa2835;
  color-scheme: light;
}
:root[data-theme="downtown"] .nav-item.active { box-shadow: inset 3px 0 0 var(--blue); }


.sidebar-nav {
  padding: 12px 10px;
  flex: 1;
  overflow-y: auto;
}

.nav-section {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 10px 10px 4px;
  font-family: var(--mono);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text2);
  font-size: 13px;
  transition: all 0.15s;
  margin-bottom: 2px;
  user-select: none;
}

.nav-item:hover { background: var(--bg4); color: var(--text); }
.nav-item.active { background: var(--bg5); color: var(--text); }

.nav-item .nav-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.65;
}

.nav-item.active .nav-icon { opacity: 1; }

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-family: var(--mono);
  background: var(--bg5);
  color: var(--text2);
  padding: 1px 7px;
  border-radius: 10px;
  flex-shrink: 0;
}

.nav-badge.green  { background: var(--green-bg);  color: var(--green);  border: 1px solid var(--green-border); }
.nav-badge.amber  { background: var(--amber-bg);  color: var(--amber);  border: 1px solid var(--amber-border); }
.nav-badge.red    { background: var(--red-bg);    color: var(--red);    border: 1px solid var(--red-border); }
.nav-badge.blue   { background: var(--blue-bg);   color: var(--blue);   border: 1px solid var(--blue-border); }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.notifications-anchor { position: relative; margin-bottom: 10px; }
.notifications-bell { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 9px; color: var(--text2); background: var(--bg3); border: 1px solid var(--border); border-radius: 7px; cursor: pointer; font: inherit; font-size: 12px; text-align: left; }
.notifications-bell:hover { color: var(--text); background: var(--bg4); }
.notifications-bell:focus-visible, .notifications-panel button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.notifications-badge { margin-left: auto; padding: 1px 6px; border-radius: 9px; background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); font-size: 10px; }
.notifications-badge[hidden], .notifications-panel[hidden] { display: none; }
.notifications-panel { position: absolute; z-index: 30; bottom: calc(100% + 8px); left: 0; width: min(360px, calc(100vw - 32px)); max-height: min(420px, 60vh); overflow-y: auto; padding: 12px; background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius-lg); box-shadow: 0 8px 28px var(--shadow); color: var(--text2); font-size: 12px; }
.notifications-title { color: var(--text); font-weight: 600; margin-bottom: 8px; }
.notifications-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px; padding: 9px 6px 9px 10px; border-top: 1px solid var(--border); border-left: 3px solid var(--blue); }
.notifications-row.error { border-left-color: var(--red); }
.notifications-row.warning { border-left-color: var(--amber); }
.notifications-row.info { border-left-color: var(--blue); }
.notifications-contract, .notifications-dismiss { border: 0; background: none; color: var(--text); cursor: pointer; font: inherit; }
.notifications-contract { text-align: left; font-weight: 600; padding: 0; overflow-wrap: anywhere; }
.notifications-dismiss { color: var(--text3); padding: 0 4px; }
.notifications-meta { grid-column: 1 / -1; color: var(--text3); line-height: 1.5; }
.notifications-row.error .notifications-tier { color: var(--red); }
.notifications-row.warning .notifications-tier { color: var(--amber); }
.notifications-row.info .notifications-tier { color: var(--blue); }

.version-badge {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text3);
  line-height: 1.7;
}

.version-badge .version-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

.version-badge .version-link[href]:hover {
  color: var(--text2);
}

/* ── Main Area ── */
.main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Top Bar ── */
.topbar {
  height: auto;
  min-height: var(--topbar-height);   /* one row normally; on a narrow window the buttons wrap below the breadcrumb */
  flex-wrap: wrap;
  row-gap: 6px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
  position: relative;
  z-index: 50;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;   /* lets a long breadcrumb shrink and end in … */
  flex: 1 1 260px; /* …but keeps ~260px for it before the buttons move to a second row */
}
/* Review: the document-intake line sits under the breadcrumb, not beside it */
#page-review .topbar-left { flex-direction: column; align-items: flex-start; gap: 2px; }
#page-review .topbar-left .topbar-breadcrumb { max-width: 100%; }
#rv-intake-summary { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-title {
  font-size: 14px;
  font-weight: 500;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text3);
}

.topbar-breadcrumb .crumb {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.topbar-breadcrumb .sep { opacity: 0.4; }
.topbar-breadcrumb .current { color: var(--text); }
/* Long contract names: the trail stays on one line and the name ends in … (full text on hover) */
.topbar-breadcrumb { min-width: 0; }
.topbar-breadcrumb .current,
.topbar-breadcrumb .crumb-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-breadcrumb .crumb,
.topbar-breadcrumb .sep,
.topbar-breadcrumb .crumb-back { flex-shrink: 0; white-space: nowrap; }
.topbar-breadcrumb .crumb:hover { color: var(--text); text-decoration: underline; }
/* "← Back": the previous CMAI page (js/router.js) */
.topbar-breadcrumb .crumb-back {
  margin-right: 6px;
  padding: 3px 10px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  background: var(--bg3);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.topbar-breadcrumb .crumb-back:hover { background: var(--bg4); }
.topbar-breadcrumb .crumb-back:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;   /* phones: the buttons wrap instead of running off the edge */
}

/* ── Content ── */
.content {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}

/* ── Page width: Settings → Appearance → Layout (js/theme.js Layout). Centered = an 800 px column, Full = the whole content area. ── */
.page-narrow { max-width: 800px; margin: 0 auto; }
[data-layout="full"] .page-narrow { max-width: none; }
/* Centered (default): the other pages centre in a wide column; the padding grows instead of wrapping markup,
   so the scrollbar stays at the window edge. Below ~1490 px of content area this is the usual 24 px. */
@media (min-width: 1025px) {
  :root:not([data-layout="full"]) .page-scroll { padding-inline: max(24px, calc((100% - 1440px) / 2)); }
}

/* ── Pages ── */
.page { display: none; height: 100%; }
.page.active { display: flex; flex-direction: column; overflow: hidden; }

/* ── Scrollable content area within a page ── */
.page-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── Nav drawer (tablet / mobile) ──
   Breakpoint mirrored in js/app.js (_initNavDrawer). */
.nav-toggle,
.nav-backdrop { display: none; }

@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 200;
    width: min(var(--sidebar-width), 82vw);
    min-width: 0;
    transform: translateX(-100%);
    visibility: hidden;                 /* keeps closed-drawer links out of the Tab order */
    transition: transform .2s ease, visibility 0s linear .2s;
  }
  .app.nav-open .sidebar {
    transform: none;
    visibility: visible;
    box-shadow: 8px 0 32px var(--shadow);
    transition: transform .2s ease, visibility 0s;
  }

  .nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 10px;
    left: 12px;
    z-index: 210;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-control);
    background: var(--bg3);
    color: var(--text);
    cursor: pointer;
  }
  .sidebar:focus { outline: none; }
  .sidebar-logo { padding-top: 54px; }   /* clear the fixed ☰ button, which doubles as the close control */
  .nav-toggle:hover { border-color: var(--text2); }
  .nav-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

  .nav-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 190;
    background: var(--overlay);
  }

  .topbar { padding-left: 56px; }
}

@media (max-width: 1024px) and (prefers-reduced-motion: reduce) {
  .sidebar, .app.nav-open .sidebar { transition: none; }
}
