/* ============================================================================
   Markets — shared layer on the app kit (theme pass Batch D, 2026-11-12)
   ----------------------------------------------------------------------------
   Loaded on every /markets page via base_markets.html, after the kit
   (_shell/kit_css.html: style.css, res_kit.css, res_ui.css) and before each
   page's head_extra, so a page rule can still size its own element.

   The look is the residential shell's: 32px controls with an 8px radius and
   13px text, 10px cards, the ui-table header (12px, 600, muted, on the input
   fill), the popover look for every dialog, neutral chips. Color is never a
   judgment here: a market metric above or below its peers, a cycle phase or a
   coverage level is said in words and numbers, never in green, amber or red.
   Errors (a failed save) use the app's --error-color.

   The --mk-* names alias the app tokens (style.css :root) so a page reads
   clearly at each use site. There are no good / bad tokens on purpose.
   ========================================================================== */

:root {
  /* Surfaces + lines */
  --mk-bg-card:      var(--bg-card, #FFFFFF);
  --mk-fill:         var(--bg-input, #F5F7FA);   /* header rows, quiet fills */
  --mk-line:         var(--border-color, #E5E7EB);
  --mk-line-soft:    var(--border-color, #E5E7EB);

  /* Ink */
  --mk-ink:          var(--text-primary, #1F2937);
  --mk-muted:        var(--text-secondary, #4B5563);
  --mk-faint:        var(--text-muted, #6B7280);

  /* Primary (navy) family */
  --mk-navy:         var(--primary-color, #1E3A5F);
  --mk-navy-dark:    var(--primary-dark, #162D4A);
  --mk-navy-light:   var(--primary-light, #2A4D7A);
  --mk-navy-tint:    #EEF2F8;                  /* selected / pinned wash */
  --mk-navy-tint-2:  #E4EBF4;

  /* State (not judgment): a failed save or a capped picker */
  --mk-error:        var(--error-color, #DC2626);

  /* Shadows + radii + type, straight from the app tokens */
  --mk-shadow-sm:    var(--shadow-sm);
  --mk-shadow-md:    var(--shadow-md);
  --mk-shadow-lg:    0 8px 24px rgba(15, 23, 42, 0.12);   /* the popover shadow */
  --mk-radius-sm:    var(--radius-control, 8px);
  --mk-radius-md:    var(--radius-control, 8px);
  --mk-radius-lg:    var(--radius-card, 10px);
  --mk-font:         var(--font-body);
  --mk-mono:         var(--font-mono);
}

/* ── Page frame: the kit page padding (.ui-page) ─────────────────────────── */
.markets-wrap {
  padding: 16px 24px 32px;
  box-sizing: border-box;
  min-width: 0;
  color: var(--mk-ink);
  font-family: var(--mk-font);
  -webkit-font-smoothing: antialiased;
}
body.mobile .markets-wrap { padding: 12px; }

/* Page title (the kit page title, 20px / 600) and its subtitle */
.markets-wrap h1 {
  font-family: var(--font-heading, var(--mk-font));
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--mk-ink);
  margin: 0 0 4px;
}
.markets-wrap .sub,
.markets-wrap .header-meta {
  color: var(--mk-muted);
  font-size: 13px;
}

/* Numbers: tabular figures everywhere a value shows */
.val, .kpi-value, .fact-value, .count, .num,
.market-meta, .th-src {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ── Secondary nav (Grid / Criteria / Compare / Charts / Cycle) ──────────── */
/* The page tab strip of _shell/nav_tabs.html: a bordered 32px segment strip,
   the current page filled with the primary color. */
.scanner-nav.nav {
  display: inline-flex;
  height: 32px;
  box-sizing: border-box;
  margin: 0 0 16px;
  padding: 0;
  gap: 0;
  border: 1px solid var(--mk-line);
  border-radius: var(--radius-control, 8px);
  max-width: 100%;
  overflow-x: auto;
  background: var(--mk-fill);
  box-shadow: none;
  font-size: 13px;
}
.scanner-nav.nav a {
  display: flex;
  align-items: center;
  padding: 0 14px;
  margin: 0;
  font-family: var(--mk-font);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  color: var(--mk-muted);
  text-decoration: none;
  white-space: nowrap;
  border-radius: 0;
  border-bottom: none;
  transition: var(--transition-fast);
}
.scanner-nav.nav a + a { border-left: 1px solid var(--mk-line); }
.scanner-nav.nav a:hover { color: var(--mk-ink); background: var(--bg-hover, #F3F4F6); }
.scanner-nav.nav a.active { background: var(--mk-navy); color: #fff; box-shadow: none; }

/* ── Cards: one 10px card, hairline border, no lift ──────────────────────── */
.panel, .chart-card, .rail-card, .lens-card, .hero {
  background: var(--mk-bg-card);
  border: 1px solid var(--mk-line);
  border-radius: var(--mk-radius-lg);
  box-shadow: none;
}

/* ── Controls: the kit button and input (res_ui.css .ui-btn / .ui-input) ─── */
.markets-wrap :is(.tb-btn, .add-btn, .btn, .chart-btn, .overlay-btn, .picker-actions a) {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; box-sizing: border-box; padding: 0 12px; margin: 0;
  border: 1px solid var(--mk-line); border-radius: var(--radius-control, 8px);
  background: var(--mk-bg-card); color: var(--mk-ink); text-decoration: none;
  font-family: var(--mk-font); font-size: 13px; font-weight: 600; line-height: 1;
  white-space: nowrap; cursor: pointer; box-shadow: none; transform: none;
  transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
}
.markets-wrap :is(.tb-btn, .add-btn, .btn, .chart-btn, .overlay-btn, .picker-actions a):hover:not(:disabled) {
  border-color: var(--mk-navy); color: var(--mk-navy); background: var(--mk-bg-card);
}
.markets-wrap :is(.tb-btn, .add-btn, .btn, .chart-btn, .overlay-btn):disabled { opacity: .5; cursor: default; }
.markets-wrap :is(.tb-btn, .add-btn, .btn, .chart-btn, .overlay-btn):focus-visible {
  outline: 2px solid var(--mk-navy); outline-offset: 1px;
}
/* The one filled button per surface */
.markets-wrap :is(.tb-btn.tb-primary, .add-btn:not(.secondary), .btn.primary, .btn.btn-primary) {
  background: var(--mk-navy); border-color: var(--mk-navy); color: #fff;
}
.markets-wrap :is(.tb-btn.tb-primary, .add-btn:not(.secondary), .btn.primary, .btn.btn-primary):hover:not(:disabled) {
  background: var(--mk-navy-dark); border-color: var(--mk-navy-dark); color: #fff;
}
/* Toggles that are on (shade all, an overlay showing) read as selected */
.markets-wrap :is(.tb-btn.on, .chart-btn.has-overlay, .overlay-btn.has-overlay) {
  border-color: var(--mk-navy); color: var(--mk-navy); background: var(--mk-navy-tint);
}
/* Destructive: the error ink on the plain button, never a red fill */
.markets-wrap .btn.danger { color: var(--mk-error); }
.markets-wrap .btn.danger:hover:not(:disabled) { border-color: var(--mk-error); color: var(--mk-error); }

.markets-wrap :is(input:where(:not([type]), [type="text"], [type="search"], [type="number"]), select) {
  height: 32px; min-height: 32px; box-sizing: border-box; padding: 0 10px;
  border: 1px solid var(--mk-line); border-radius: var(--radius-control, 8px);
  background-color: var(--mk-bg-card); color: var(--mk-ink);
  font-family: var(--mk-font); font-size: 13px; line-height: 1;
}
.markets-wrap :is(input:where(:not([type]), [type="text"], [type="search"], [type="number"]), select):focus {
  outline: none; border-color: var(--border-focus, var(--mk-navy));
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.08);
}
.markets-wrap input::placeholder { color: var(--mk-faint); }

/* ── Chips: the neutral state chip (res_ui.css .ui-chip) ─────────────────── */
.markets-wrap :is(.chip, .rank-pill, .pill, .deal-chip, .cov-badge, .badge) {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border: none; border-radius: 12px;
  background: var(--mk-fill); color: var(--mk-muted);
  font-family: var(--mk-font); font-size: 11.5px; font-weight: 600; line-height: 1.2;
  letter-spacing: 0; text-transform: none; white-space: nowrap;
}

/* ── Tables: the ui-table look, dense (res_ui.css table.ui-table--dense) ──── */
.markets-wrap table th {
  font-family: var(--mk-font);
  font-size: 12px; font-weight: 600; color: var(--mk-faint);
  text-transform: none; letter-spacing: 0;
  background: var(--mk-fill);
}
.markets-wrap table td { font-size: 12.5px; color: var(--mk-muted); }

/* ── Dialogs: the popover look (res_ui.css .ui-modal) ────────────────────── */
/* Markup on these pages: .modal-backdrop.open > .modal (grid, compare) and
   .dd-backdrop.open > .dd-modal (market overview). */
.markets-wrap :is(.modal-backdrop, .dd-backdrop) {
  background: rgba(15, 23, 42, 0.32);
  backdrop-filter: none;
  padding: 6vh 16px 16px;
  box-sizing: border-box;
}
.markets-wrap :is(.modal-backdrop > .modal, .dd-modal) {
  /* style.css's legacy .modal is a full screen fixed scrim: undo it here */
  position: static; height: auto; backdrop-filter: none;
  align-items: stretch; justify-content: flex-start;
  display: flex; flex-direction: column; min-height: 0;
  max-height: 85vh; overflow-y: auto; box-sizing: border-box;
  padding: 16px 18px;
  background: var(--mk-bg-card);
  border: 1px solid var(--mk-line);
  border-radius: var(--mk-radius-lg);
  box-shadow: var(--mk-shadow-lg);
  font-family: var(--mk-font); font-size: 13px; color: var(--mk-muted);
}
.markets-wrap :is(.modal-header, .dd-head) {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  flex: 0 0 auto; margin-bottom: 12px; padding-bottom: 0; border-bottom: none;
}
.markets-wrap :is(.modal-title, .dd-title) {
  margin: 0; font-family: var(--font-heading, var(--mk-font));
  font-size: 15px; font-weight: 600; letter-spacing: 0; color: var(--mk-ink);
}
.markets-wrap :is(.modal-meta, .dd-meta) {
  margin-top: 2px; font-size: 12px; color: var(--mk-faint);
  text-transform: none; letter-spacing: 0;
}
.markets-wrap :is(.modal-close, .dd-close) {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex: none; padding: 0;
  border: none; border-radius: var(--radius-control, 8px); background: none;
  font-size: 20px; line-height: 1; color: var(--mk-faint); cursor: pointer;
}
.markets-wrap :is(.modal-close, .dd-close):hover { background: var(--mk-fill); color: var(--mk-ink); }
/* A small table inside a dialog (history, airports, teams, sectors) */
.markets-wrap table.mk-pop-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.markets-wrap table.mk-pop-table th { position: sticky; top: 0; z-index: 1; height: 32px;
  padding: 0 8px; text-align: left; border-bottom: 1px solid var(--mk-line); cursor: default; }
.markets-wrap table.mk-pop-table td { height: 28px; padding: 0 8px; border-bottom: 1px solid var(--mk-line);
  border-right: none; vertical-align: middle; text-align: left; }
.markets-wrap table.mk-pop-table .ui-num { text-align: right; }
.markets-wrap table.mk-pop-table .mk-sub { color: var(--mk-faint); }
.markets-wrap .mk-pop-note { margin-top: 10px; font-size: 12px; color: var(--mk-faint); }
.markets-wrap .mk-pop-empty { padding: 20px; color: var(--mk-faint); }
.markets-wrap .mk-pop-group { margin: 12px 0 4px; font-size: 12px; font-weight: 600; color: var(--mk-faint); }
.markets-wrap .mk-pop-lead { margin-bottom: 8px; font-size: 13px; color: var(--mk-ink); }
.markets-wrap .mk-sub { color: var(--mk-faint); }
.markets-wrap .mk-stats { margin: 0 0 12px; font-size: 12px; color: var(--mk-muted); }
.markets-wrap .mk-single { padding: 32px 16px; text-align: center; }
