/* Additions for the HTML/JS front-end. site.css (carried over from HistoAtlas v1.12) remains the design system. */
.boot-message { padding: 40px; color: var(--muted); }
.skip-link { position: absolute; left: -9999px; top: 0; z-index: 3000; background: #fff; color: #172535; padding: 10px 14px; border: 2px solid #172535; }
.skip-link:focus { left: 10px; top: 10px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack-form { display: grid; gap: 14px; }
.stack-form > .button { justify-self: start; }
.check-label { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 6px 0; cursor: pointer; }
.check-label input { width: auto; }
.neutral-change { color: #66727f; }
.top-space { margin-top: 16px; }

/* Body-level dialog */
.app-modal-backdrop { position: fixed; inset: 0; z-index: 2000; background: #10203080; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow: auto; }
.app-modal { width: 480px; max-width: 100%; position: relative; background: #fff; box-shadow: 0 12px 40px #0005; }
.app-modal.wide { width: 720px; }
.app-modal h2 { padding-right: 40px; margin-bottom: 14px; }
.app-modal .marker-modal-close { position: absolute; top: 14px; right: 14px; }
.marker-modal { position: relative; }
.marker-modal .marker-modal-close { position: absolute; top: 14px; right: 14px; }

/* Compact editors (marker, global effect, linked effect): sized to fit without vertical scrolling. */
/* Centred vertically (auto margins stay scroll-safe on short screens); extra bottom padding nudges it up. */
.app-modal-backdrop.compact-backdrop { padding: 16px 16px 8vh; }
.compact-backdrop .app-modal { margin: auto 0; }
.app-modal.compact.wide { width: 680px; }
.app-modal.compact, .marker-modal.compact { padding: 14px 18px 16px; }
.marker-modal.compact { width: 560px; }
.compact h2 { margin: 0 0 10px; font-size: 18px; }
.compact .marker-modal-close { top: 10px; right: 10px; }
.compact .stack-form, .compact .marker-editor { display: grid; gap: 9px; }
.compact .stack-form > .button { margin-top: 2px; }
.compact .field, .compact .marker-editor .field { gap: 3px; margin: 0; }
.compact .field label { font-size: 11px; }
.compact small.muted-text { font-size: 11px; line-height: 1.35; }
.compact input:not([type=checkbox]):not([type=range]):not([type=file]), .compact select, .compact textarea { min-height: 32px; padding: 5px 8px; font-size: 13px; }
.compact textarea { resize: vertical; }
.compact .two-fields, .compact .three-fields, .compact .marker-coordinate-fields { gap: 8px; margin: 0; }
.compact-row { display: grid; gap: 8px; align-items: end; }
.compact-row.name-desc { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
/* Stage + Value on one line, From / To / Applies to on the next. */
.compact-row.five { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.compact-row.five > :nth-child(-n+2) { grid-column: span 3; }
.compact-row.five > :nth-child(n+3) { grid-column: span 2; }
.compact-row.asset-years { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); }
.compact-row.title-icon { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.compact-row.position { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
.compact-row.position .button { min-height: 32px; }
.compact-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.compact-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.compact-checks { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.compact-checks .check-label { margin: 0; }
.compact .target-head { margin: 0 0 4px; gap: 8px; font-size: 12px; }
.compact .target-list { margin: 0; max-height: 220px; border-radius: 4px; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); align-content: start; }
.compact .target-list label { padding: 5px 8px; border-bottom: 0; font-size: 12px; }
.compact .target-list small { font-size: 10px; }
.compact .linked-source-editor { margin: 0; padding: 8px 10px; }
.compact .linked-source-editor .mini-title { margin-bottom: 6px; }
.compact .linked-source-editor p.muted-text { margin: 0 0 6px; }
.compact .linked-source-row { margin-bottom: 6px; gap: 6px; }
.compact .marker-country-picker { margin: 0; padding: 8px; gap: 6px 12px; max-height: 110px; overflow: auto; }
.compact .mode-toggle { height: 22px; }
@media (max-width: 730px) {
  .compact-row.five, .compact-row.asset-years { grid-template-columns: 1fr 1fr; }
  .compact-row.five > :nth-child(n) { grid-column: auto; }
  .compact-row.asset-years > :first-child, .compact-row.five > :last-child { grid-column: 1 / -1; }
  .compact-pair, .compact-row.name-desc { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .compact-row.five, .compact-row.title-icon { grid-template-columns: 1fr; }
}

/* Toasts */
.toast-host { position: fixed; right: 16px; bottom: 16px; z-index: 2147483647; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 12px 15px; border-radius: 2px; background: #182636; color: #fff; box-shadow: 0 6px 20px #0004; font-size: 13px; }
.toast.error { background: #8e2b35; }

/* Logistics popover: anchored to the change cell. */
.logistics-forecast-cell:focus-visible { outline: 2px solid #2e6d9c; outline-offset: -2px; }
.logistics-forecast-cell .deviance-popover { cursor: default; }
@media (max-width: 760px) {
  .logistics-forecast-cell .deviance-popover { position: fixed; left: 10px; right: 10px; top: 10vh; width: auto; max-height: 80vh; overflow: auto; z-index: 1500; }
  .logistics-forecast-cell .deviance-popover::before { display: none; }
}
.shell:not(.menu-open) .mobile-nav-backdrop { display: none !important; }
/* Management site sidebar: full viewport height on the left, like the public sidebar.
   All eight sections fit without scrolling on normal screens; very short screens scroll the sidebar itself. */
.manage-sidebar { height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain; }
.manage-sidebar .sidebar-foot a { color: #dfe8f0; text-decoration: underline; }
.manage-sidebar .sidebar-foot a:hover { color: #fff; }
@media (max-height: 760px) and (min-width: 901px) {
  .manage-sidebar { padding-top: 16px; padding-bottom: 12px; }
  .manage-sidebar .identity-brand { margin-bottom: 16px; padding-bottom: 12px; }
  .manage-sidebar .navitem { min-height: 34px; padding-top: 7px; padding-bottom: 7px; }
}
/* Public site: top bar + tab row (same look as the old administration tabs), no sidebar. */
.public-shell { min-height: 100vh; background: var(--bg); }
.topbar-brand { display: inline-flex; align-items: center; flex-shrink: 0; }
.topbar-brand img { display: block; height: 32px; width: auto; }
.public-tabs { align-items: flex-end; }
.public-tabs a { background: #e8edf1; border: 1px solid #b7c2cd; border-bottom: 0; border-radius: 0; color: #435567;
  font-size: 13px; font-weight: 650; margin-right: 3px; padding: 12px 17px; white-space: nowrap; text-decoration: none; }
.public-tabs a:hover { background: #dae5ed; color: #203e56; text-decoration: none; }
.public-tabs a.active, .public-tabs a.active:hover { background: #23394f; border-color: #23394f; color: #fff; }
.public-tabs .tab-spacer { flex: 1 1 auto; min-width: 12px; }
.public-tabs a { display: inline-flex; align-items: center; gap: 8px; }
.tab-icon { font-size: 15px; line-height: 1; width: 16px; text-align: center; opacity: .85; }
/* Sidebar icons are symbols now, not monospace codes. */
.manage-sidebar .nav-icon { font-family: 'Segoe UI Symbol', 'Segoe UI', sans-serif; font-size: 17px; font-weight: 400; line-height: 1; color: #c3d0dc; }
.manage-sidebar .navitem.active .nav-icon { color: #fff; }
.manage-sidebar .sidebar-foot small { margin-bottom: 8px; }
.manage-sidebar .sidebar-foot a.navitem { color: #d9e1e9; text-decoration: none; margin: 4px -11px 0; }
.manage-sidebar .sidebar-foot a.navitem:hover { color: #fff; text-decoration: none; }
.manage-sidebar .nav-icon svg { display: block; margin: 0 auto; }
@media (max-width: 600px) {
  .public-tabs a { font-size: 12px; padding: 11px 10px; }
  .topbar-brand img { height: 28px; }
}
.marker-list-row .check-label { margin: 0; }
.gateway-navigation a.gateway-small:hover { color: #fff; }
/* Map layer panel: one entry per layer, show/hide checkbox on the left, optional upload button on the right. */
.layer-entry { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--edge); }
.layer-entry .layer-option { flex: 1 1 auto; min-width: 0; border-top: 0; padding: 10px 2px; }
.layer-entry .layer-option input { width: auto; margin: 0; flex-shrink: 0; accent-color: #426885; }
.layer-entry.unavailable .layer-option { cursor: default; }
.layer-entry.unavailable .layer-option strong { color: var(--muted); }
.layer-icon.names { color: #3d6f86; font-size: 12px; font-weight: 700; }
.layer-icon.mark { color: #8a5a1f; }
.layer-upload-button { flex-shrink: 0; display: grid; place-items: center; }
.layer-upload-button svg { display: block; }
.map-side .field-inline select { flex: 1 1 auto; min-width: 0; }
/* Public Assets page: Equipment / Resources sub-tabs under the country toolbar. */
.asset-subtabs { margin: 16px 0 14px; }

/* ------------------------------------------------------------------ Mobile compatibility
   Loaded after site.css, so these rules settle the older, overlapping breakpoints. */
/* Safety net against stray sideways scrolling; `clip` (unlike `hidden`) keeps sticky positioning working. */
html, body { overflow-x: clip; }
.page-head h1, .topbar-title strong, .gateway-lead h1, .gateway-card h2 { overflow-wrap: anywhere; }
/* Map placement hint: the Cancel button is the touch replacement for Esc. */
.marker-placement-hint { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.marker-placement-hint[hidden] { display: none; }
.marker-placement-cancel { pointer-events: auto; min-height: 30px !important; padding: 5px 12px; }
/* Lock the page behind the open management menu drawer. */
@media (max-width: 900px) { body:has(.shell.menu-open) { overflow: hidden; } }

/* Touch devices: 16px form text stops iOS zooming on focus; larger tap targets. */
@media (pointer: coarse) {
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), select, textarea,
  .compact input:not([type=checkbox]):not([type=range]):not([type=file]), .compact select, .compact textarea { font-size: 16px; }
  .compact input:not([type=checkbox]):not([type=range]):not([type=file]), .compact select { min-height: 40px; }
  .button, .button.small, .square-button, .year-button { min-height: 40px; }
  .square-button { min-width: 40px; }
  .compact-row.position .button { min-height: 40px; }
  .tiny-logout { min-width: 40px; min-height: 40px; }
  .check-label { min-height: 32px; }
  .check-label input, .layer-entry .layer-option input { width: 18px; height: 18px; }
  input[type=range] { min-height: 28px; }
}

@media (max-width: 730px) {
  /* Public scenario tabs wrap into a grid of buttons instead of a cut-off row. */
  .public-tabs { flex-wrap: wrap; gap: 5px; overflow: visible; padding-bottom: 12px; margin-bottom: 16px; }
  .public-tabs .tab-spacer { display: none; }
  .public-tabs a { flex: 1 1 calc(33.333% - 5px); justify-content: center; margin: 0; border: 1px solid #b7c2cd; padding: 10px 8px; min-width: 0; }
  /* Body-level dialogs: near-full-width sheets that scroll internally. */
  .app-modal-backdrop, .app-modal-backdrop.compact-backdrop { padding: 10px; align-items: flex-start; }
  .compact-backdrop .app-modal { margin: 0; }
  .app-modal, .app-modal.wide, .app-modal.compact.wide { width: 100%; max-height: calc(100dvh - 20px); overflow: auto; }
  .app-modal.panel.padded { padding: 16px 14px; }
  /* The marker editor leaves the small map frame and covers the screen instead. */
  .marker-modal-backdrop { position: fixed; z-index: 2000; padding: 10px; }
  .marker-modal, .marker-modal.compact { width: 100%; max-height: calc(100dvh - 20px); }
  .compact .marker-coordinate-fields, .compact-row.position { grid-template-columns: 1fr 1fr; }
  .compact-row.position .button { grid-column: 1 / -1; }
  .compact .target-list { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  /* Toasts span the bottom edge. */
  .toast-host { left: 10px; right: 10px; bottom: 10px; max-width: none; }
  /* Tables keep their own sideways scroll rather than widening the page. */
  .scroll-table, .account-table, .table-scroll { -webkit-overflow-scrolling: touch; }
  .data-table td, .data-table th { padding: 9px 8px; }
  .row-buttons .button { flex: 1 1 auto; }
  .gateway-navigation .button { flex: 0 0 auto; }
  .asset-subtabs { margin: 12px 0 10px; }
}

@media (max-width: 480px) {
  .public-tabs a { flex-basis: calc(50% - 5px); font-size: 12px; }
  .compact-row.title-icon, .compact .marker-coordinate-fields { grid-template-columns: 1fr; }
  .gateway-cards { grid-template-columns: 1fr; }
  .topbar-brand { padding: 0; }
  .public-topbar .topbar-title { gap: 8px; }
}
