* {
  box-sizing: border-box;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  margin: 0;
  padding: 0;
  background: #f5f5f5;
  color: #1d1d1f;
}

/* ---- Navigation ---- */
.app-nav {
  background: white;
  border-bottom: 1px solid #e5e5e7;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 52px;
  gap: 32px;
}
.app-nav-brand {
  font-weight: 700;
  color: #1d1d1f;
  font-size: 16px;
  letter-spacing: -0.4px;
}
.app-nav-links {
  display: flex;
  gap: 2px;
}
.app-nav-link {
  color: #86868b;
  text-decoration: none;
  padding: 14px 14px;
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.app-nav-link:hover {
  color: #1d1d1f;
}
.app-nav-link.active {
  color: #0066cc;
  border-bottom-color: #0066cc;
}

/* ---- Page Header ---- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* ---- Logout Button ---- */
.btn-logout {
  background: transparent;
  border: 1px solid #d2d2d7;
  padding: 8px 18px;
  font-size: 13px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.2s;
}
.btn-logout:hover {
  background: #f5f5f7;
  color: #1d1d1f;
  border-color: #b0b0b5;
}

/* ---- Hidden ---- */
.hidden {
  display: none !important;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1d1d1f;
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Status ---- */
.status {
  text-align: center;
  padding: 48px 20px;
  color: #86868b;
  font-size: 15px;
}
.status.error {
  color: #ff3b30;
}
.status.loading::before {
  content: '';
  display: block;
  width: 28px;
  height: 28px;
  border: 2.5px solid #e5e5e7;
  border-top-color: #0066cc;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Non-destructive refetch (PERF-04) ----
   Applied by shared/table-loading.js while new data is in flight: the previous
   rows stay visible but dimmed and inert, so the page never blanks. */
.is-refreshing {
  opacity: 0.5;
  pointer-events: none;
  user-select: none;
  transition: opacity 0.15s ease;
}
/* Small busy affordance next to the row count / meta line while refreshing. */
.results-count.is-refreshing::after {
  content: '';
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-left: 7px;
  vertical-align: -1px;
  border: 2px solid #e5e5e7;
  border-top-color: #0066cc;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ---- Filter Presets (inline in action bar) ---- */
.filter-presets {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.filter-presets-divider {
  width: 1px;
  height: 24px;
  background: #d2d2d7;
  margin-right: 6px;
}
.filter-presets select {
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  background: white;
  color: #86868b;
  min-width: 140px;
  cursor: pointer;
  transition: all 0.2s;
}
.filter-presets select:focus {
  outline: none;
  border-color: #0066cc;
  color: #1d1d1f;
}
.filter-presets select:not([value=""]),
.filter-presets select.has-value {
  color: #1d1d1f;
}
.btn-preset {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  background: white;
  color: #6e6e73;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-preset:hover {
  background: #f5f5f7;
  border-color: #b0b0b5;
  color: #1d1d1f;
}
.btn-preset-delete {
  padding: 7px 10px;
  color: #b0b0b5;
  font-size: 15px;
  line-height: 1;
}
.btn-preset-delete:hover:not(:disabled) {
  color: #ff3b30;
  border-color: #ff3b30;
  background: #fff5f5;
}
.btn-preset:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ---- Multi-Select Filter Component ---- */
.ms-filter-mount { position: relative; }

.ms-filter-trigger {
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  background: #f5f5f7;
  color: #1d1d1f;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ms-filter-trigger:hover { border-color: #b0b0b5; }
.ms-filter-trigger:focus {
  outline: none;
  border-color: #0066cc;
  background: white;
  box-shadow: 0 0 0 3px rgba(0,102,204,0.12);
}
.ms-filter-trigger .ms-trigger-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.ms-filter-trigger .ms-trigger-chevron {
  font-size: 10px;
  color: #86868b;
  margin-left: 8px;
  transition: transform 0.2s;
}
.ms-filter-trigger.open .ms-trigger-chevron {
  transform: rotate(180deg);
}

.ms-filter-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 100%;
  width: max-content;
  background: white;
  border: 1px solid #d2d2d7;
  border-top: none;
  border-radius: 0 0 10px 10px;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  display: none;
}
.ms-filter-dropdown.open { display: block; }

.ms-filter-search {
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
  border: none;
  border-bottom: 1px solid #f0f0f2;
  outline: none;
  background: #fafafa;
  box-sizing: border-box;
}
.ms-filter-search::placeholder { color: #b0b0b5; }
.ms-filter-search:focus { background: white; }

.ms-filter-list {
  max-height: 240px;
  overflow-y: auto;
  padding: 4px 0;
}
.ms-filter-empty {
  padding: 16px 12px;
  text-align: center;
  color: #b0b0b5;
  font-size: 13px;
}

.ms-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  color: #1d1d1f;
  transition: background 0.1s;
}
.ms-filter-item:hover { background: #f5f5f7; }

.ms-filter-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #0066cc;
  cursor: pointer;
  flex-shrink: 0;
}

.ms-filter-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ms-filter-item-label mark {
  background: transparent;
  color: #0066cc;
  font-weight: 600;
}

.ms-filter-mode {
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  letter-spacing: 0.3px;
  opacity: 0;
  pointer-events: none;
}
.ms-filter-item.checked .ms-filter-mode {
  opacity: 1;
  pointer-events: auto;
}
.ms-filter-mode[data-mode="include"] {
  background: #e8f5e9;
  color: #2e7d32;
}
.ms-filter-mode[data-mode="include"]:hover {
  background: #c8e6c9;
}
.ms-filter-mode[data-mode="exclude"] {
  background: #fce4ec;
  color: #c62828;
}
.ms-filter-mode[data-mode="exclude"]:hover {
  background: #f8bbd0;
}

/* ---- Multi-Search Filter Component (split layout) ---- */
.ms-search-mount { position: relative; }

.ms-search-wrap { position: relative; }

.ms-search-input-standalone {
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  background: #f5f5f7;
  color: #1d1d1f;
  transition: all 0.2s;
  box-sizing: border-box;
}
.ms-search-input-standalone::placeholder { color: #b0b0b5; }
.ms-search-input-standalone:focus {
  outline: none;
  border-color: #0066cc;
  background: white;
  box-shadow: 0 0 0 3px rgba(0,102,204,0.12);
}

.ms-search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #d2d2d7;
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 60;
  box-shadow: 0 6px 16px rgba(0,0,0,0.1);
  display: none;
}
.ms-search-suggestions.open { display: block; }

.ms-search-suggestion {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  color: #1d1d1f;
  transition: background 0.1s;
}
.ms-search-suggestion:hover,
.ms-search-suggestion.active {
  background: #f0f4ff;
  color: #0066cc;
}
.ms-search-suggestion mark {
  background: transparent;
  color: #0066cc;
  font-weight: 600;
}

.ms-search-empty {
  padding: 12px;
  text-align: center;
  color: #b0b0b5;
  font-size: 13px;
}

/* ---- Pills Row (rendered outside filter grid) ---- */
.ms-pills-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
}
.ms-pills-label {
  font-size: 12px;
  font-weight: 600;
  color: #86868b;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-right: 2px;
}
.ms-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e8f5e9;
  color: #1d1d1f;
  padding: 4px 8px;
  border-radius: 14px;
  font-size: 13px;
  white-space: nowrap;
}
.ms-pill.exclude {
  background: #fce4ec;
}
.ms-pill-text {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.ms-pill-mode {
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  letter-spacing: 0.3px;
  transition: all 0.15s;
}
.ms-pill-mode[data-mode="include"] {
  background: rgba(46,125,50,0.15);
  color: #2e7d32;
}
.ms-pill-mode[data-mode="include"]:hover {
  background: rgba(46,125,50,0.25);
}
.ms-pill-mode[data-mode="exclude"] {
  background: rgba(198,40,40,0.15);
  color: #c62828;
}
.ms-pill-mode[data-mode="exclude"]:hover {
  background: rgba(198,40,40,0.25);
}
.ms-pill-remove {
  border: none;
  background: none;
  color: #86868b;
  font-size: 15px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}
.ms-pill-remove:hover { color: #ff3b30; }

/* ---- Text Input Clear Button ---- */
.input-clearable {
  position: relative;
  display: flex;
}
.input-clearable input {
  padding-right: 28px !important;
}
.input-clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: #b0b0b5;
  font-size: 15px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  display: none;
}
.input-clear-btn:hover { color: #ff3b30; }
.input-clearable input:not(:placeholder-shown) + .input-clear-btn {
  display: block;
}

/* ---- Expand Table Toggle ---- */
.btn-expand {
  width: 34px;
  height: 34px;
  border: 1px solid #d2d2d7;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  color: #86868b;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-expand:hover {
  background: #f5f5f7;
  border-color: #b0b0b5;
  color: #1d1d1f;
}

.view-expanded {
  position: fixed;
  top: 60px;
  left: 24px;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  background: #f5f5f5;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  padding: 16px 20px;
  overflow: hidden;
}
.view-expanded .results-toolbar {
  flex-shrink: 0;
  margin-bottom: 12px;
}
.view-expanded .table-wrapper {
  max-height: none;
  flex: 1;
  min-height: 0;
}
.view-expanded .pagination-controls {
  flex-shrink: 0;
  margin-top: 12px;
}
.view-expanded .empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ---- Filters drawer: filter access while a view is expanded ---- */
/* The funnel button only exists inside an expanded view (normal layout has
   the filter bar itself), and overlays #filterPanel as a fixed drawer. */
.btn-drawer-filters { display: none; position: relative; }
.view-expanded .btn-drawer-filters { display: flex; }
.drawer-filter-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #0066cc;
  color: white;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.4;
  border-radius: 9px;
  padding: 1px 5px;
  min-width: 17px;
  text-align: center;
}
.drawer-filter-badge.hidden { display: none; }

.filters-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 205;
  background: rgba(0, 0, 0, 0.35);
}
body.filters-drawer-open .filters-drawer-backdrop {
  display: block;
  animation: filters-backdrop-in 0.2s ease;
}
/* The id selector outweighs .filter-panel's display:none, so the drawer
   shows even when the page's filter bar is collapsed — and collapsing state
   is untouched when the drawer closes. */
body.filters-drawer-open #filterPanel {
  display: block;
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translate(-50%, 0);
  width: min(1240px, calc(100vw - 48px));
  margin: 0;
  z-index: 210;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  animation: filters-drawer-in 0.22s ease;
}
/* Short screens: cap height and scroll (dropdowns may clip at the panel edge
   there; better than the panel running off-screen). Everywhere else overflow
   stays visible so the multi-select dropdowns can extend past the panel. */
@media (max-height: 760px) {
  body.filters-drawer-open #filterPanel {
    max-height: calc(100vh - 104px);
    overflow-y: auto;
  }
}
@keyframes filters-drawer-in {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes filters-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* =====================================================================
   Responsive nav (mobile)
   ===================================================================== */
.is-mobile .app-nav {
  padding: 0 14px;
  padding-top: env(safe-area-inset-top);
}
.is-mobile .app-nav-inner { gap: 14px; height: 50px; }
.is-mobile .app-nav-link { padding: 14px 4px; }
/* Hide non-ready nav links on PHONES only (<=600px). At tablet widths
   (601-768px) `is-mobile` is set but the page falls through to the desktop
   layout, so it must keep its full nav — and on phones, non-ready pages are
   replaced by the interstitial anyway, so this only ever trims the nav on a
   mobile-ready page (Stock). */
@media (max-width: 600px) {
  .app-nav-links a:not([data-mobile-ready]) { display: none; }
}

/* =====================================================================
   Bottom-sheet primitive (sheet.js)
   ===================================================================== */
body.sheet-open { overflow: hidden; }
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0,0,0,0);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: background 0.25s ease;
  pointer-events: none;
}
.sheet-overlay.open { background: rgba(0,0,0,0.4); pointer-events: auto; }
.sheet-panel {
  background: #fff;
  width: 100%;
  max-width: 640px;
  max-height: 92dvh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 -8px 32px rgba(0,0,0,0.2);
}
.sheet-overlay.open .sheet-panel { transform: translateY(0); }
.sheet-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid #f0f0f2;
  flex-shrink: 0;
}
.sheet-header::before {
  content: '';
  position: absolute;
  top: 7px;
  left: 50%;
  transform: translateX(-50%);
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: #d8d8dc;
}
.sheet-title {
  font-size: 17px;
  font-weight: 700;
  color: #1d1d1f;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-close {
  border: none;
  background: #f0f0f2;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: #6e6e73;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 12px;
}
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 18px 18px;
  flex: 1;
}
.sheet-footer {
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid #f0f0f2;
  flex-shrink: 0;
  display: flex;
  gap: 10px;
}

/* ---- Quick Switch (Cmd+K / Ctrl+K) ---- */
.qs-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 1200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}
.qs-overlay.hidden {
  display: none;
}
.qs-panel {
  width: 580px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.qs-input {
  border: none;
  outline: none;
  padding: 15px 18px;
  font-size: 16px;
  font-family: inherit;
  color: #1d1d1f;
  border-bottom: 1px solid #e5e5e7;
}
.qs-input::placeholder {
  color: #a1a1a6;
}
.qs-list {
  max-height: 46vh;
  overflow-y: auto;
  padding: 6px;
}
.qs-item {
  display: flex;
  align-items: baseline;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: #1d1d1f;
  text-align: left;
}
.qs-item.active {
  background: #0066cc;
  color: #fff;
}
.qs-crumb {
  color: #86868b;
  white-space: pre;
}
.qs-item.active .qs-crumb {
  color: rgba(255, 255, 255, 0.75);
}
.qs-title {
  font-weight: 500;
}
.qs-kind {
  margin-left: auto;
  padding-left: 16px;
  font-size: 11px;
  color: #a1a1a6;
}
.qs-item.active .qs-kind {
  color: rgba(255, 255, 255, 0.65);
}
.qs-hl {
  font-weight: 700;
  color: #0066cc;
}
.qs-item.active .qs-hl {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.qs-empty {
  padding: 26px;
  text-align: center;
  color: #86868b;
  font-size: 14px;
}
.qs-hint {
  display: flex;
  gap: 16px;
  padding: 8px 14px;
  border-top: 1px solid #e5e5e7;
  background: #fafafa;
  color: #86868b;
  font-size: 11px;
}
.qs-hint kbd {
  background: #f0f0f2;
  border: 1px solid #d2d2d7;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
  margin-right: 3px;
}
