/* AGRIXON — "Earth" layout for the field map: the map fills the screen like Google Earth,
   everything else floats on top of it. Only the map page changes; other routes keep their layout.
   Switched on by html[data-earth] (earth-ui.js). */

html[data-earth] main:has(> #map-page:not([hidden])) { padding: 0; max-width: none; }
html[data-earth] #map-page:not([hidden]) { padding: 0; max-width: none; margin: 0; }
html[data-earth] #map-page .page-heading { display: none; }

html[data-earth] #map-page .map-workspace {
  position: relative;
  display: block;
  height: calc(100dvh - var(--agx-top, 72px));
  min-height: 380px;
  max-height: none;
  border: 0;
  border-radius: 0;
  margin: 0;
  box-shadow: none;
  background: #05070a;
  overflow: hidden;
}
html[data-earth] #map-page .map-stage { position: absolute; inset: 0; height: auto; }

/* Floating instruments share one look. */
html[data-earth] .earth-float {
  background: rgba(8, 12, 16, 0.82);
  border: 1px solid rgba(150, 195, 215, 0.24);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  color: #e8eef2;
  border-radius: 14px;
}
html[data-earth]:not([data-mc="dark"]) .earth-float { background: rgba(255, 255, 255, 0.9); color: #1b1d16; border-color: rgba(0, 0, 0, 0.08); }

/* Stats: one compact strip at the top centre of the map. */
html[data-earth] #map-page .overview.earth-stats {
  position: absolute;
  top: 64px;
  left: 14px;
  z-index: 5;
  display: flex;
  gap: 0;
  padding: 4px;
  margin: 0;
  width: auto;
  max-width: calc(100% - 28px);
  min-height: 0; /* the page's overview card is 89px tall; the strip is not */
  align-items: center;
  border-radius: 999px;
}
html[data-earth] .earth-stats .overview-item { flex: none; padding: 5px 14px; border: 0; min-width: 0; min-height: 0; gap: 8px; background: none; box-shadow: none; }
html[data-earth] .earth-stats .overview-item > div { display: flex; flex-direction: column; gap: 0; }
html[data-earth] .earth-stats .overview-item small { white-space: nowrap; line-height: 1.2; opacity: 0.8; }
html[data-earth] .earth-stats .overview-item strong { line-height: 1.2; white-space: nowrap; margin-top: 1px; letter-spacing: -0.2px; }
html[data-earth] .earth-stats .overview-item + .overview-item { border-left: 1px solid rgba(150, 195, 215, 0.2); }
html[data-earth] .earth-stats .metric-icon, html[data-earth] .earth-stats .overview-source { display: none; }
html[data-earth] .earth-stats .overview-item small { font-size: 10px; letter-spacing: 0.08em; }
html[data-earth] .earth-stats .overview-item strong, html[data-earth] .earth-stats .overview-item b { font-size: 15px; }

/* Primary actions: top right. */
html[data-earth] .earth-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 6;
  display: flex;
  gap: 8px;
  align-items: center;
}
html[data-earth] .earth-actions .btn { border-radius: 999px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }
html[data-earth] .earth-drawtools { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; }
html[data-earth] .earth-drawtools button {
  border: 0; background: none; color: inherit; font: inherit; font-size: 13px;
  padding: 7px 11px; border-radius: 999px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center;
}
html[data-earth] .earth-drawtools button:hover { background: rgba(95, 224, 176, 0.14); }
html[data-earth] .earth-drawtools button[aria-pressed="true"] { background: #5fe0b0; color: #04120c; }
html[data-earth] .earth-drawtools svg { width: 16px; height: 16px; }

/* Top-left: my fields + search stay where they are (map-topline). */
html[data-earth] .map-topline { top: 14px; left: 14px; right: auto; z-index: 6; }

/* Analysis panel becomes a drawer on the right. */
html[data-earth] #map-page .analysis-panel {
  position: absolute;
  top: 68px;
  right: 14px;
  bottom: 84px;
  width: 340px;
  z-index: 7;
  border-radius: 16px;
  border: 1px solid rgba(150, 195, 215, 0.24);
  background: rgba(8, 12, 16, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s ease;
}
html[data-earth]:not([data-mc="dark"]) #map-page .analysis-panel { background: rgba(255, 255, 255, 0.94); }
html[data-earth][data-drawer="closed"] #map-page .analysis-panel { transform: translateX(calc(100% + 24px)); opacity: 0; pointer-events: none; }
html[data-earth] .earth-drawer-toggle {
  position: absolute;
  right: 14px;
  top: 50%;
  z-index: 8;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  padding: 12px 7px;
  border-radius: 12px;
  cursor: pointer;
  font: 11px ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
html[data-earth][data-drawer="open"] .earth-drawer-toggle { right: 362px; }
html[data-earth][data-drawer="open"] .map-tools { right: 368px; }
html[data-earth] .map-tools { right: 14px; transition: right 0.35s ease; z-index: 6; }

/* Bottom: one centred control row. */
html[data-earth] .map-bottom {
  left: 50%;
  right: auto;
  bottom: 24px; /* leaves a line for the imagery credit underneath */
  transform: translateX(-50%);
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 28px);
}
html[data-earth][data-drawer="open"] .map-bottom { left: calc(50% - 177px); }
html[data-earth] .map-caption { left: auto; right: 14px; bottom: 2px; max-width: 46%; font-size: 10px; z-index: 5; }

/* Quick-draw hint. */
html[data-earth] .earth-hint {
  position: absolute;
  left: 50%;
  top: 112px; /* below the stats strip */
  transform: translateX(-50%);
  z-index: 9;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: center;
}
html[data-earth] .earth-hint kbd { font: 10px ui-monospace, Menlo, monospace; padding: 1px 5px; border: 1px solid rgba(150, 195, 215, 0.3); border-radius: 4px; }
html[data-earth] .earth-hint[hidden] { display: none; }
html[data-earth][data-quickdraw] #map .maplibregl-canvas { cursor: crosshair; }

/* The 3D twin keeps covering the whole map block. */
html[data-earth] .map-workspace > .tw { border-radius: 0; }

@media (max-width: 900px) {
  /* Phones: stats become one scrollable line under the actions; controls wrap at the bottom. */
  html[data-earth] #map-page .overview.earth-stats { top: 108px; bottom: auto; left: 8px; right: 8px; max-width: none; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  html[data-earth] .earth-stats .overview-item { padding: 4px 10px; }
  html[data-earth] .earth-stats .overview-item small { font-size: 9px; }
  html[data-earth] .earth-stats .overview-item strong { font-size: 14px; }
  html[data-earth] .map-bottom { left: 8px; right: 8px; bottom: 10px; transform: none; width: auto; max-width: none; }
  html[data-earth] .map-bottom > * { flex: none; }
  html[data-earth] .map-caption { display: none; } /* sources stay in the map's attribution control */
  html[data-earth] .map-tools { bottom: 150px; top: auto; }
  html[data-earth] #map-page .analysis-panel { left: 8px; right: 8px; width: auto; top: auto; bottom: 8px; height: 55%; }
  html[data-earth][data-drawer="closed"] #map-page .analysis-panel { transform: translateY(calc(100% + 24px)); }
  html[data-earth] .earth-drawer-toggle { writing-mode: horizontal-tb; top: auto; bottom: 150px; left: 8px; right: auto; transform: none; }
  html[data-earth][data-drawer="open"] .earth-drawer-toggle { left: 8px; right: auto; bottom: calc(55% + 16px); }
  html[data-earth][data-drawer="open"] .map-tools { right: 14px; }
  html[data-earth][data-drawer="open"] .map-bottom { left: 50%; }
  html[data-earth] .map-bottom { flex-wrap: wrap; justify-content: center; gap: 6px; }
  html[data-earth] .earth-actions { top: 60px; left: 8px; right: 8px; overflow-x: auto; justify-content: flex-start; flex-wrap: nowrap; scrollbar-width: none; }
  html[data-earth] .earth-actions::-webkit-scrollbar { display: none; }
  html[data-earth] .earth-actions .heading-actions { display: flex; gap: 6px; flex: none; }
  html[data-earth] .earth-actions .btn { padding: 6px 12px; font-size: 13px; white-space: nowrap; }
  html[data-earth] .earth-drawtools { flex: none; }
  html[data-earth] .earth-drawtools span { display: none; }
  html[data-earth] .earth-actions .heading-actions .btn:not(.primary) { font-size: 0; gap: 0; padding: 8px 10px; } /* icon only: frees room for the shape tools */
  html[data-earth] .map-topline { top: 8px; left: 8px; right: 8px; }
  html[data-earth] .earth-hint { top: 108px; max-width: calc(100% - 16px); font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  html[data-earth] #map-page .analysis-panel, html[data-earth] .map-tools { transition: none; }
}
