/* Kapella-inspired top header + centered tab strip (built from scratch,
   not copied from BootstrapDash's actual template files). Primary blue
   matches the existing app's .streamlit/config.toml (#2563eb). */

/* ---------- Flag emoji fallback ----------
   country_flag() (data.py) returns plain Unicode regional-indicator flag
   sequences. Firefox bundles its own color-emoji font (Twemoji Mozilla)
   so flags always render there; Chrome relies on the OS's emoji font
   (Segoe UI Emoji on Windows), which historically lacks flag glyphs and
   falls back to showing the raw two-letter code. Self-hosting the same
   font Firefox uses fixes this everywhere with no markup changes —
   unicode-range scopes it to ONLY the flag codepoints (26 regional-
   indicator letters, covering any two-letter country combination, plus
   the white-flag placeholder), so it never affects normal text
   rendering. Subsetted from Twemoji Mozilla v0.7.0 (1.47MB -> 81KB) via
   fontTools' pyftsubset — see dev2/README.md if it ever needs redoing
   (e.g. a non-ASEAN flag gets added and turns out to need a codepoint
   outside this subset, which shouldn't happen since it covers all 26
   regional-indicator letters, not just the 11 ASEAN ones). */
@font-face {
  font-family: "TwemojiFlags";
  src: url("fonts/twemoji-flags-subset.woff2") format("woff2");
  unicode-range: U+1F1E6-1F1FF, U+1F3F3, U+FE0F;
  font-display: swap;
}

/* ---------- Status-dot glyph fallback ----------
   The app-wide compliance convention (feedback_no_emoji_convention memory
   — no check/X or red/green, use a blue dot-fill scale instead) is three
   plain Unicode circle characters: U+25CF (Meets, filled), U+25D0
   (Partially meets, half-filled), U+25CB (Does not meet, outline). In the
   default system font these are NOT drawn at consistent optical size —
   U+25CF renders visibly smaller than the other two (confirmed via a
   side-by-side render) — which undercuts the "same visual weight, no
   color-of-judgment" point of using plain shapes in the first place.
   Noto Sans Symbols2 draws all three at matching size; subsetted to just
   these 3 codepoints (1.2MB -> ~2.5KB) via the same fontTools pipeline as
   the flag fallback above. */
@font-face {
  font-family: "StatusDots";
  src: url("fonts/status-dots-subset.woff2") format("woff2");
  unicode-range: U+25CF, U+25D0, U+25CB;
  font-display: swap;
}

/* ---------- Status-dot glyph sizing ----------
   Separate issue from the font-face fix above (that one equalizes the
   three glyphs' optical weight AT a given font-size; this pins the
   font-size itself). Every "bare glyph, no label" usage of ●/◐/○ used to
   set its own ad hoc inline font-size — Gap Analysis's status symbol
   (1.1rem), its legend (unset, ~1rem ambient), the Table tab's ag-grid
   cells (unset, ag-grid's own default) — so the same glyph read as
   visibly different sizes depending on which page showed it. One shared
   class, applied everywhere a bare glyph is shown (not the colored
   Boolean/Single-select value badges in taxonomy.py — those are a text
   label with an emoji prefix inside a chip, a different affordance with
   its own deliberately compact sizing, not a bare glyph). */
.status-dot {
  font-size: 1rem;
  font-weight: 700;
}

:root {
  --primary: #2563eb;
  --header-bg: #1e2a38;
  --header-text: #ffffff;
  --content-bg: #f4f6f9;
  --card-bg: #ffffff;
  --border: #e2e8f0;
}

/* ---------- Dark mode ----------
   Piggybacks on Bootstrap 5.3's native [data-bs-theme="dark"] attribute
   (set by app.py's clientside callback, from a localStorage-backed
   dcc.Store, default "light" — see components.py's theme-toggle-btn) so
   every dbc component (Card/Table/Modal/Alert/Button/...) restyles itself
   automatically; these overrides only cover this app's own custom
   properties, which Bootstrap doesn't know about. */
[data-bs-theme="dark"] {
  --header-bg: #0b1420;
  --content-bg: #0f172a;
  --card-bg: #1e293b;
  --border: #334155;
}
[data-bs-theme="dark"] .nav-tab { color: #cbd5e1; }
[data-bs-theme="dark"] .nav-tab:hover:not(.disabled) { background: rgba(37, 99, 235, 0.18); }

/* dcc.Dropdown (the .dash-dropdown control + its popup) is a plain Dash
   component, not a dash-bootstrap-components one — Bootstrap's
   data-bs-theme doesn't reach it at all, so its background stays
   hardcoded white regardless of theme (confirmed: text color WAS already
   flipping via inherited --bs-body-color, just against a white
   background — the worst possible combination for legibility). */
[data-bs-theme="dark"] .dash-dropdown {
  background-color: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}
[data-bs-theme="dark"] .dash-dropdown-content {
  background-color: #1e293b;
  border-color: #334155;
}
[data-bs-theme="dark"] .dash-dropdown-option {
  color: #e2e8f0;
}
[data-bs-theme="dark"] .dash-dropdown-option:hover,
[data-bs-theme="dark"] .dash-dropdown-option[aria-selected="true"] {
  background-color: rgba(37, 99, 235, 0.25);
}
[data-bs-theme="dark"] .dash-dropdown-option.selected {
  color: #93c5fd;
}
[data-bs-theme="dark"] .dash-dropdown-search {
  background-color: #1e293b;
  color: #e2e8f0;
}
/* The wrapper AROUND the search input + magnifying-glass icon is its own
   element with its own hardcoded white background, independent of the
   input inside it (already covered above) — showed as a white strip
   around the icon even once the input itself went dark. */
[data-bs-theme="dark"] .dash-dropdown-search-container {
  background-color: #1e293b;
  fill: #e2e8f0;
  color: #e2e8f0;
}
/* The unselected-placeholder text ("Select a country…") has its own
   hardcoded color independent of the button's — inherited color didn't
   reach it, so it stayed dark navy-on-dark-navy, barely visible. */
[data-bs-theme="dark"] .dash-dropdown-placeholder {
  color: rgba(226, 232, 240, 0.6);
}
/* Multi-select's "N selected" overflow badge — same issue, its own
   hardcoded color/background independent of everything else. */
[data-bs-theme="dark"] .dash-dropdown-value-count {
  color: rgba(226, 232, 240, 0.75);
  background-color: rgba(226, 232, 240, 0.08);
}

body {
  background: var(--content-bg);
  margin: 0;
  font-family: "TwemojiFlags", "StatusDots", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- dcc.Input full-width fix ----------
   In this Dash version, dcc.Input renders as a wrapper div (which
   correctly gets the "form-control" class's full width — this is the
   full-width "bar" that's visible) containing an INNER <input
   class="dash-input-element"> that does NOT inherit that width — it
   defaults to the browser's native ~190px input size regardless of its
   wrapper. Confirmed via computed-style inspection (wrapper 1286px,
   inner input 190px) on the Regulations edit form's Regulator/Year/URL
   fields. dcc.Textarea doesn't have this wrapper split (className applies
   directly to the <textarea> itself) so it's unaffected. This targets
   the inner element's class directly — a single global rule, since every
   dcc.Input in the app uses the same "dash-input-element" class. */
.dash-input-element {
  width: 100%;
  box-sizing: border-box;
}

/* ---------- Sticky top bar (header + tabs) ----------
   Matches dev/'s own top nav, which is sticky (CLAUDE.md). Wrapping both
   in one sticky container, rather than giving each its own `position:
   sticky; top:` offset, means there's no hardcoded height dependency
   between them — the tab strip just stacks under the header inside the
   same stack-to-top-of-viewport box, so it stays correct even if the
   header's height changes (e.g. wraps on a narrow viewport).
   z-index:20 is deliberately modest — high enough to sit above normal
   page content, but well under dbc.Modal (1050) and the Gap Analysis
   toast (1080, see gap_analysis_page.py), both of which portal outside
   this stacking context anyway and don't actually need to clear it. */
.sticky-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
}

/* ---------- Tip banner's close button ----------
   Applied to every dismissible tip dbc.Alert across the app (Map, Table,
   Regulations, Gap Analysis, Review, Regulatory Structure). Bootstrap's
   own .btn-close inside .alert-dismissible is a FIXED size (~56px tall
   including its padding) positioned top:0/right:0, sized for a single
   default-padded line. That reads as "off-center" any time the alert
   isn't exactly that height: Map/Table's tips use className="py-2" to
   sit shorter than default, so the button overflowed past the bottom;
   several of the longer tips elsewhere (Gap Analysis, Review, ...) wrap
   to 2-3 lines at default padding, so the button stays pinned near the
   top instead of centering in the taller box. Centering vertically
   (rather than anchoring to top:0) and shrinking the button's own
   padding fixes both cases — it always sits centered and inside the
   banner regardless of exact height or how many lines the tip wraps to. */
.tip-banner .btn-close {
  top: 50%;
  transform: translateY(-50%);
  padding: 0.5rem;
}

/* ---------- Header ---------- */
.app-header {
  background: var(--header-bg);
  color: var(--header-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.15rem;
  font-weight: 700;
}

.brand-icon { height: 28px; width: auto; }

.header-user {
  font-size: 0.8rem;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.role-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(37, 99, 235, 0.28);
  color: #ffffff;
}

/* "Public visitor" label in the header. It used Bootstrap's text-muted
   (dark grey), which is near-invisible on the always-dark header bar in
   light mode; a white outlined pill reads in both themes and matches the
   role badge shown to signed-in users. */
.public-badge {
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 3px 12px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  white-space: nowrap;
}

.theme-toggle-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.9rem;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
}
.theme-toggle-btn:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- Tab strip (top center) ---------- */
.nav-tabs {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1rem;
  flex-wrap: wrap;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  color: #475569;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-tab:hover:not(.disabled) {
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
}

.nav-tab.active {
  background: var(--primary);
  color: #ffffff;
}

.nav-tab.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nav-tab-icon { font-size: 0.95rem; }

/* ---------- Content ---------- */
.page-content {
  padding: 1.5rem;
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.app-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  margin-bottom: 1.25rem;
}

.filter-row {
  margin-bottom: 1rem;
}

/* Fixed-position replacement for Plotly's own hover tooltip on the Map
   graph — that one renders right under the cursor, on top of the country
   you're trying to click. pointer-events:none so it never itself blocks a
   click, even though it's out of the cursor's way anyway. Hidden by
   default (no .visible class) so it doesn't show an empty box before the
   first hover. */
.map-hover-tooltip {
  display: none;
  position: absolute;
  top: 8px;
  right: 22px;
  max-width: 200px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.76rem;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18);
  pointer-events: none;
  z-index: 30;
}
.map-hover-tooltip.visible {
  display: block;
}

.provision-iframe {
  width: 100%;
  border: none;
}

/* ---------- Wide regulation modal ----------
   dbc.Modal's size="xl" tops out at Bootstrap's built-in 1140px cap;
   overriding .modal-dialog directly gets to ~65% wider than the previous
   "lg" (800px) default, capped at 96vw so it stays responsive on small
   viewports instead of overflowing. */
.wide-modal .modal-dialog {
  max-width: min(96vw, 1320px);
}

/* ---------- Map cursor ----------
   Plotly's geo/scattergeo traces don't set a pointer cursor by default —
   without this, hovering a clickable country/marker on the Map tab or Gap
   Analysis's compliance map gives no visual "this is clickable" cue.
   These rules alone turned out not to be enough: geo plots handle mouse
   interaction through one invisible, unclassed <rect> that sits on top of
   the whole plot (Plotly's own internal hit-testing layer — confirmed via
   document.elementFromPoint() over a country shape, which returned this
   rect, not the shape underneath it) — the visible <path>/marker
   elements below never actually receive the pointer, so styling only
   them did nothing. The rect has no class of its own to target, but it's
   always the sole child of <g class="layer bg">. */
.js-plotly-plot .choroplethlayer path,
.js-plotly-plot .scattergeo .point,
.js-plotly-plot .scatterlayer .points path,
.js-plotly-plot .layer.bg rect {
  cursor: pointer;
}

/* Smooths the brightness bump the hover-highlight clientside callback
   (map_page.py) applies directly to the hovered country's <path> — without
   this the filter change snaps on/off instantly. */
.js-plotly-plot .choroplethlayer path {
  transition: filter 0.12s ease;
}

/* ---------- Scrollable regulations list (country detail) ---------- */
.reg-table-scroll {
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.reg-table-scroll .reg-table-thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card-bg);
}

/* ---------- scrollIntoView offset for the sticky top bar ----------
   #gap-selfassess-detail (gap_analysis_page.py) and #tax-detail
   (regulatory_structure_page.py) are both targets of a clientside
   `scrollIntoView({block: "start"})` on row-click. Without this,
   "start" means flush against the very top of the viewport — which is
   now covered by .sticky-topbar, so the panel would land hidden behind
   it. scroll-margin-top is scrollIntoView's native way to reserve that
   space; no JS offset math needed. Value = measured .sticky-topbar
   height (~112px at the default desktop viewport) + a little slack for
   the header wrapping taller on a narrower window. */
#gap-selfassess-detail,
#tax-detail {
  scroll-margin-top: 132px;
}

/* ---------- Disabled hierarchical filter dropdowns ----------
   Targets the [disabled] attribute directly (kept in sync automatically
   by every render, unlike a wrapper class set once at initial layout and
   never updated) so the dimming actually reflects the live state instead
   of freezing at whatever it was on first page load.

   Deliberately NOT opacity on an ancestor wrapper (the original
   approach): opacity < 1 creates a new CSS stacking context, which traps
   the dropdown's own position:fixed popup menu inside it — the popup's
   z-index then only competes within that trapped context instead of
   against the rest of the page, so it rendered underneath the map/table
   card below it. Styling the control's own background/text color instead
   avoids creating any stacking context at all. */
.dash-dropdown[disabled] {
  background: rgba(100, 116, 139, 0.12);
  color: #94a3b8;
  cursor: not-allowed;
}

/* ---------- dash-ag-grid: centered, wrapped (not truncated) headers ---------- */
.ag-theme-alpine .ag-header-cell-label {
  justify-content: center;
  text-align: center;
  white-space: normal;
  line-height: 1.25;
}

/* AG Grid's Alpine theme sets its own complete --ag-font-family, which
   wins over the inherited body font-family — so the TwemojiFlags/
   StatusDots fallbacks above need to be added here explicitly too, or
   flag/status-dot characters inside grid headers/cells (Gap Analysis's
   Meets/Partial/Not-met columns, Table's Country column, etc.) wouldn't
   pick them up. */
.ag-theme-alpine {
  --ag-font-family: "TwemojiFlags", "StatusDots", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Gap Analysis Overview's per-country flag+ISO-code column headers
   (gap_analysis_page.py's flag_cols/headerClass) — the small default
   ag-grid header font made the flag glyph hard to make out at a glance;
   headerClass scopes this to just those columns instead of every
   header in the app growing. */
.ag-theme-alpine .flag-col-header {
  font-size: 1.05rem;
  font-weight: 600;
}
/* Generic centered-cell utility — originally just for Overview's flag
   columns, reused for Self-Assessment's symbol-only Status column too. */
.ag-theme-alpine .ag-center-cell {
  text-align: center;
}

/* ---------- dash-ag-grid dark mode ----------
   AG Grid's Alpine theme is CSS-custom-property-driven (a stable public
   API since AG Grid v28+), so overriding these variables under
   [data-bs-theme="dark"] is enough to retheme it — same self-syncing
   attribute-selector approach as .dash-dropdown above, no className swap
   or callback needed. Targets .ag-theme-alpine generally (not scoped to
   one page's grid id) so it covers every grid in the app — Table, Gap
   Analysis, Regulatory Structure, Regulations — in one place instead of
   fixing them one at a time as each gets reported. */
[data-bs-theme="dark"] .ag-theme-alpine {
  --ag-background-color: #1e293b;
  --ag-foreground-color: #e2e8f0;
  --ag-header-background-color: #0f172a;
  --ag-header-foreground-color: #e2e8f0;
  --ag-border-color: #334155;
  --ag-secondary-border-color: #334155;
  --ag-row-border-color: #334155;
  --ag-odd-row-background-color: #24344a;
  --ag-row-hover-color: rgba(37, 99, 235, 0.18);
  --ag-selected-row-background-color: rgba(37, 99, 235, 0.28);
  --ag-input-background-color: #1e293b;
  --ag-input-border-color: #334155;
  --ag-input-focus-border-color: #2563eb;
  --ag-checkbox-background-color: #1e293b;
  --ag-checkbox-unchecked-color: #94a3b8;
  --ag-checkbox-checked-color: #2563eb;
  --ag-range-selection-background-color: rgba(37, 99, 235, 0.2);
  --ag-modal-overlay-background-color: rgba(15, 23, 42, 0.75);
  --ag-control-panel-background-color: #1e293b;
  --ag-subheader-background-color: #0f172a;
  --ag-disabled-foreground-color: #64748b;
}

/* Header "Sign out" link (shown next to the role badge). */
.signout-link {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.78rem;
  text-decoration: underline;
  white-space: nowrap;
}
.signout-link:hover {
  color: #ffffff;
}

/* Regulation form: per-field "changed from the amended regulation" cue
   (regulation_form.py's _changed_badge) -- a sibling label next to the
   field, never the field's own value/children, so it can update live
   without stealing focus while someone is mid-edit. Blue, not a
   checkmark/red-green pair, matching this app's single-accent-color,
   no-check/no-cross status convention used everywhere else. */
.reg-field-changed-badge {
  margin-left: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #2563eb;
}

/* Regulation form: (i) info icon next to an attribute label whose taxonomy
   row sets a Description (regulation_form.py's _attr_label) -- hover
   target for a dbc.Tooltip, same small-circle look as the identical icon
   taxonomy.py's render_provision_table_html draws inline inside its own
   iframe tables (country detail/comparison), kept visually consistent
   even though these are two unrelated rendering paths (live Dash
   component here vs. static iframe HTML there). */
.reg-field-info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  margin-left: 5px;
  border: 1px solid #2563eb;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: #2563eb;
  opacity: 0.75;
  cursor: help;
}
