/* ---------- shell: top bar, rail, section tabs ---------- */
:root {
  --topbar-h: 56px;
  --rail-w: 104px;
  --bottombar-h: 62px;
  --tabs-h: 44px;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .topbar {
    background: var(--surface);
  }
}
.topbar .spacer {
  flex: 1;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  min-width: 0;
}
.brand img {
  border-radius: 7px;
  flex: none;
}
.btn.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}
.btn.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}
.topbar .top-add {
  min-height: 38px;
  margin-left: 10px;
  padding: 0 16px 0 12px;
  gap: 6px;
  justify-content: center;
  border-radius: 999px;
  font-weight: 650;
}
/* Secondary actions sit together as one quiet group; Add stands apart after them. */
.top-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
.top-sep {
  width: 1px;
  height: 22px;
  margin: 0 6px;
  background: var(--border);
}
/* Top-bar actions: icon with a visible label (stacked under the icon on phones). */
.top-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font: 550 0.88rem var(--font);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
@media (hover: hover) {
  .top-action:not(.active):hover {
    color: var(--text);
    box-shadow: inset 0 0 0 2px var(--border-strong);
  }
}
.top-action.active {
  color: var(--on-white);
  background: var(--white-fill);
  box-shadow: inset 0 0 0 2px var(--line);
}
.top-more {
  display: none;
}
.topbar.compact .top-actions > .top-action:not(.top-more),
.topbar.compact .top-sep {
  display: none;
}
.topbar.compact .top-action.top-more,
.topbar.compact .top-actions > .top-action.top-search,
.topbar.compact .top-actions > .top-action.top-sync {
  display: inline-flex;
}
/* Only when even the folded bar is too narrow does the name give way to the logo. */
.topbar.tiny .brand-name {
  display: none;
}

.rail {
  position: fixed;
  z-index: 20;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  left: 0;
  bottom: 0;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 6px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: none;
}
.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  /* Wide enough that the longest label ("Measurements", ~84px) fits whole inside the pill. */
  padding: 9px 3px 8px;
  border: 0;
  border-radius: 16px;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: none;
  color: var(--text-2);
  font: 550 0.72rem/1.15 var(--font);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
/* Hover previews the selected look as an outline only, so it never outshines it. */
@media (hover: hover) {
  .rail-btn:not(.active):hover {
    color: var(--text);
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--sec-line) 60%, transparent);
  }
  .section-tab[aria-selected='false']:hover {
    color: var(--text);
    box-shadow: inset 0 0 0 2px var(--border-strong);
  }
}
.rail-btn.active {
  background: var(--sec-bg);
  color: var(--sec-ink);
  box-shadow: inset 0 0 0 2px var(--sec-line);
}
.rail-sep {
  flex: none;
  height: 1px;
  margin: 6px 10px;
  background: var(--border);
}
.rail-narrow,
.section-tabs {
  display: none;
}
.main {
  margin-left: var(--rail-w);
  padding: 24px 28px 48px;
  outline: none;
  min-width: 0;
}
.main > .page {
  max-width: 1120px;
  margin: 0 auto;
}
.boot {
  padding: 40px;
  text-align: center;
  color: var(--muted);
}
.page > * + * {
  margin-top: 16px;
}

.section-tab {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 5px 2px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--text-2);
  font: 550 0.84rem var(--font);
  text-decoration: none;
  white-space: nowrap;
}
.section-tab[aria-selected='true'] {
  color: var(--sec-ink);
  background: var(--sec-bg);
  box-shadow: inset 0 0 0 2px var(--sec-line);
}

@media (max-width: 1000px) {
  .hide-md {
    display: none !important;
  }
}

/* Phones: sections in a bottom bar, the section's views as tabs just above it. */
@media (max-width: 760px) {
  :root {
    --topbar-h: 52px;
  }
  .hide-sm {
    display: none !important;
  }
  .topbar {
    gap: 4px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }
  .brand-name {
    font-size: 1rem;
  }
  .topbar .top-add {
    width: 40px;
    min-height: 40px;
    margin-left: 8px;
    padding: 0;
  }
  .top-add-label {
    display: none;
  }
  .top-sep {
    display: none;
  }
  .rail {
    top: auto;
    right: 0;
    width: auto;
    height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
    flex-direction: row;
    padding: 4px max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
    border-right: 0;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    backdrop-filter: saturate(1.6) blur(14px);
  }
  .rail-wide,
  .rail-sep {
    display: none;
  }
  .rail-narrow {
    display: flex;
    flex: 1 1 0;
    justify-content: center;
    font-size: 0.74rem;
  }
  .rail-narrow.active,
  .rail-narrow:hover {
    background: none;
    box-shadow: none !important;
    color: var(--text);
  }
  /* On the bottom bar the icon carries the pill, sized the same in every state. */
  .rail-narrow .icon {
    border-radius: 999px;
    padding: 3px 14px;
    width: 52px;
    height: 28px;
    box-sizing: border-box;
  }
  .rail-narrow.active .icon {
    background: var(--sec-bg);
    color: var(--sec-ink);
    box-shadow: inset 0 0 0 2px var(--sec-line);
  }
  @media (hover: hover) {
    .rail-narrow:not(.active):hover .icon {
      box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--sec-line) 60%, transparent);
    }
  }
  .section-tabs {
    position: fixed;
    z-index: 19;
    left: 0;
    right: 0;
    bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
    height: var(--tabs-h);
    padding: 0 max(4px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    backdrop-filter: saturate(1.6) blur(14px);
    border-top: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
  }
  body.has-section-tabs .section-tabs {
    display: flex;
  }
  .main {
    margin-left: 0;
    padding: 16px max(16px, env(safe-area-inset-right)) calc(var(--bottombar-h) + 28px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  body.has-section-tabs .main {
    padding-bottom: calc(var(--bottombar-h) + var(--tabs-h) + 28px + env(safe-area-inset-bottom));
  }
}
/* Tabs that don't fit tighten, then drop their icons, rather than scroll (fitSectionTabs). */
.section-tabs.compact .section-tab {
  margin-inline: 1px;
  padding: 0 8px;
  gap: 4px;
  font-size: 0.8rem;
}
.section-tabs.tiny .section-tab .icon {
  display: none;
}
/* Narrower still, the labels share what's left. */
.section-tabs.tiny .section-tab {
  flex-shrink: 1;
  min-width: 0;
  padding: 0 6px;
}
.section-tabs.tiny .section-tab span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- menus ---------- */
.menu {
  position: fixed;
  z-index: 60;
  inset: auto;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: pop 0.12s ease;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: 500 0.92rem var(--font);
  text-align: left;
  cursor: pointer;
}
.menu-item .icon {
  color: var(--text);
}
.menu-item:hover,
.menu-item:focus-visible {
  background: var(--surface-2);
  outline: none;
}
.menu-label {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}
.menu-sub {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}
.menu-aside {
  flex: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}
.menu-item.selected .menu-label > span:first-child {
  font-weight: 700;
}
.menu-check {
  flex: none;
  color: var(--accent);
}
.menu-heading {
  padding: 8px 12px 2px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}

/* ---------- command palette ---------- */
/* Pinned near the top so the box doesn't jump as the list grows and shrinks. */
dialog.modal.palette {
  margin: min(12vh, 96px) auto auto;
  width: min(620px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - min(12vh, 96px) - 24px));
}
@supports (height: 100dvh) {
  dialog.modal.palette {
    max-height: min(640px, calc(100dvh - min(12vh, 96px) - 24px));
  }
}
.palette .modal-head {
  padding-block: 8px;
}
.palette .modal-title {
  font-size: 0.95rem;
  color: var(--muted);
}
.palette .modal-body {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.palette-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 12px 6px;
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.palette-field:focus-within {
  border-color: var(--accent);
}
.palette-field .icon {
  flex: none;
  color: var(--muted);
}
.palette-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: 500 1rem var(--font);
  outline: none;
}
.palette-hint {
  flex: none;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font: 600 0.72rem var(--font);
}
@media (hover: none) {
  .palette-hint {
    display: none;
  }
}
.palette-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0 6px 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}
.palette-heading {
  padding: 10px 12px 4px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.palette-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.palette-item > .icon {
  flex: none;
  margin-top: 1px;
}
.palette-item[aria-selected='true'] {
  background: var(--surface-2);
  box-shadow: inset 3px 0 0 var(--accent);
}
.palette-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.palette-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 8px;
  font-weight: 600;
  font-size: 0.92rem;
}
.palette-when,
.palette-sub {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}
.palette-sub {
  overflow-wrap: anywhere;
}
.palette-label {
  font-weight: 600;
}
.palette-sub mark {
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}
.palette-empty {
  padding: 14px 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- page header ---------- */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-radius: var(--radius);
  background: var(--sec-bg);
  color: var(--sec-ink);
  border: 2px solid var(--sec-line);
}
.page-head .subtitle {
  color: inherit;
  font-size: 1.02rem;
  font-weight: 550;
}
/* A pink button would vanish into a pink header, so it turns blue there. */
body.sec-labs .page-head .btn-primary {
  background: var(--flag-blue);
  color: var(--on-blue);
}
.page-head h1 {
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--text-2);
  margin: 4px 0 0;
}
.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.section-title {
  margin-top: 28px !important;
  font-size: 1.05rem;
  color: var(--text);
}
/* A small blue, white and pink pill before each section title. */
.section-title::before {
  content: '';
  display: inline-block;
  width: 26px;
  height: 10px;
  margin-right: 10px;
  border-radius: 999px;
  vertical-align: 0.05em;
  box-shadow: inset 0 0 0 2px var(--line);
  background: linear-gradient(90deg, var(--flag-blue) 0 33.3%, var(--white-fill) 0 66.6%, var(--flag-pink) 0);
}
.group-title {
  font-size: 0.95rem;
  color: var(--text-2);
  margin-top: 24px !important;
}

