/* ============================================================================
   ATLAS MAP — Restyle overlay (drop-in, non distruttivo)
   Caricare DOPO assets/atlasmap.css. Nessun cambio funzionale: solo palette,
   tipografia, Dark Field e polish. Ridefinisce le variabili --atlas-* gia'
   usate dall'app, quindi la nuova palette si propaga ovunque.
   v1 — Fase 1 (foundation) + core components
   ========================================================================== */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap");

/* ---------------------------------------------------------------------------
   1) PALETTE LOCKATA (override variabili esistenti)
   --------------------------------------------------------------------------- */
:root {
  --atlas-navy: #1e3a5f;
  --atlas-navy-deep: #17304e;
  --atlas-navy-dark: #17304e;
  --atlas-cyan: #1ba6e8;
  --atlas-orange: #f39200;
  --atlas-amber: #f39200;      /* un solo accento: amber -> arancio */
  --atlas-green: #7cb342;
  --atlas-bg: #fafaf7;
  --atlas-surface: #ffffff;
  --atlas-surface-2: #f2f2ee;
  --atlas-line: #e5e5e0;
  --atlas-muted: #5a6270;
  --atlas-ink: #1a1d24;
  --atlas-white: #ffffff;
  --atlas-radius-sm: 4px;
  --atlas-radius-md: 6px;
  --atlas-radius-lg: 8px;
  --atlas-shadow: 0 1px 2px rgba(15, 33, 55, 0.08);
  --atlas-shadow-hover: 0 4px 14px rgba(15, 33, 55, 0.12);
  --atlas-focus: 0 0 0 3px rgba(27, 166, 232, 0.32);

  /* token semantici aggiuntivi del restyle */
  --atlas-yellow: #f5c518;
  --atlas-error: #d64545;
  --atlas-font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --atlas-font-mono: "JetBrains Mono", ui-monospace, monospace;
}

/* ---------------------------------------------------------------------------
   2) TIPOGRAFIA — Inter (UI) + JetBrains Mono (numerici/coordinate)
   --------------------------------------------------------------------------- */
body,
button,
input,
select,
textarea,
.atlasmap-header-descriptor,
summary,
.hint {
  font-family: var(--atlas-font-ui) !important;
}
/* coordinate / zoom / valori numerici tecnici in mono */
#coordInput,
#addressInput,
.map-zoom-badge,
.atlas-coord,
.atlas-coordinate,
.atlas-latlon,
.atlas-mono,
[class*="coord"] input,
.atlas-profile-summary,
.atlas-stake-value,
.atlas-point-coords {
  font-family: var(--atlas-font-mono) !important;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------------
   3) HEADER — flat navy (no gradiente decorativo), ombra minima, accento 2px
   --------------------------------------------------------------------------- */
header {
  background: var(--atlas-navy) !important;
  border-bottom: 2px solid var(--atlas-orange) !important;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15) !important;
}
.header-right a,
.header-right button,
.atlasmap-header-actions a,
.atlasmap-header-actions button {
  border-radius: var(--atlas-radius-sm) !important;
}

/* ---------------------------------------------------------------------------
   4) COMPONENTI — bordi 1px, radius contenuti, ombre minime, focus ring
   --------------------------------------------------------------------------- */
aside,
.field-group,
.card,
.panel {
  border-radius: var(--atlas-radius-md);
}
input[type="text"],
input[type="number"],
input[type="search"],
select,
textarea {
  border-radius: var(--atlas-radius-sm) !important;
  border: 1px solid var(--atlas-line) !important;
}
input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: none !important;
  box-shadow: var(--atlas-focus) !important;
  border-color: var(--atlas-cyan) !important;
}
.btn-primary,
.report-btn,
.atlas-profile-actions button.primary {
  border-radius: var(--atlas-radius-sm) !important;
}
/* CTA primaria = arancio ; export/relazione/successo = verde (semantica lock) */
.btn-primary {
  background: var(--atlas-orange) !important;
  border-color: var(--atlas-orange) !important;
  color: #fff !important;
}
.btn-primary:hover { background: #d98200 !important; border-color: #d98200 !important; }

/* tabelle: numeri in mono tabulari */
table td,
table th { font-family: var(--atlas-font-ui); }
table td.num,
table td[data-num],
.atlas-table-num { font-family: var(--atlas-font-mono); font-variant-numeric: tabular-nums; text-align: right; }

/* ---------------------------------------------------------------------------
   5) THEME TOGGLE (segmented control nell'header)
   --------------------------------------------------------------------------- */
.atlas-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  margin-right: 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--atlas-radius-sm);
}
.atlas-theme-toggle button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 26px;
  padding: 0;
  border: none !important;
  background: transparent !important;
  color: rgba(255, 255, 255, 0.7) !important;
  border-radius: 3px !important;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.atlas-theme-toggle button svg { width: 15px; height: 15px; display: block; }
.atlas-theme-toggle button:hover { color: #fff !important; }
.atlas-theme-toggle button[aria-pressed="true"] {
  background: #fff !important;
  color: var(--atlas-navy) !important;
}

/* ===========================================================================
   6) DARK FIELD  (outdoor) — attivo con html[data-atlas-theme="dark"]
   =========================================================================== */

/* --- Token dark (accenti piu' saturi, superfici scure) --- */
html[data-atlas-theme="dark"] {
  --atlas-cyan: #3fbdf9;
  --atlas-orange: #ff9e12;
  --atlas-amber: #ff9e12;
  --atlas-green: #93cc57;
  --atlas-bg: #0e1114;
  --atlas-surface: #161a1f;
  --atlas-surface-2: #1c2127;
  --atlas-line: #2a2f36;
  --atlas-muted: #a7b0bd;
  --atlas-ink: #f2f2f0;
  --atlas-focus: 0 0 0 3px rgba(63,189,249,.4);
}
html[data-atlas-theme="dark"] body { background:#0e1114 !important; color:#f2f2f0 !important; }
html[data-atlas-theme="dark"] .layout { background:#0e1114 !important; }

/* Pannello sinistro: contenitore + card (field-group sono <details> o <div>) */
html[data-atlas-theme="dark"] .layout > aside { background:#0e1114 !important; border-right-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .layout > aside > .field-group { background:#161a1f !important; border-color:#2a2f36 !important; color:#f2f2f0 !important; }
html[data-atlas-theme="dark"] .layout > aside .field-group { background:#161a1f !important; border-color:#2a2f36 !important; color:#f2f2f0 !important; }
html[data-atlas-theme="dark"] .layout > aside details.atlas-desktop-fold { background:#161a1f !important; }
html[data-atlas-theme="dark"] .layout > aside details.atlas-desktop-fold[open] > summary { border-bottom-color:#2a2f36 !important; }

/* Testo: label/summary/heading che usano navy -> chiaro; hint -> muted */
html[data-atlas-theme="dark"] .layout > aside .label,
html[data-atlas-theme="dark"] .layout > aside summary,
html[data-atlas-theme="dark"] .layout > aside .atlas-desktop-fold__summary { color:#f2f2f0 !important; }
html[data-atlas-theme="dark"] .layout > aside .hint,
html[data-atlas-theme="dark"] .layout > aside .cat-hint,
html[data-atlas-theme="dark"] .layout > aside small { color:#a7b0bd !important; }
html[data-atlas-theme="dark"] .layout > aside .hint strong { color:#f2f2f0 !important; }

/* Wrapper risultati interni (catasto / indirizzi) */
html[data-atlas-theme="dark"] .layout > aside .catastal-results,
html[data-atlas-theme="dark"] .layout > aside .address-results,
html[data-atlas-theme="dark"] .layout > aside .catastal-results__head,
html[data-atlas-theme="dark"] .layout > aside .catastal-results__body { background:#1c2127 !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .layout > aside .catastal-note { color:#a7b0bd !important; }

/* Input / select / textarea del pannello */
html[data-atlas-theme="dark"] .layout > aside input,
html[data-atlas-theme="dark"] .layout > aside select,
html[data-atlas-theme="dark"] .layout > aside textarea,
html[data-atlas-theme="dark"] input[type="text"],
html[data-atlas-theme="dark"] input[type="number"],
html[data-atlas-theme="dark"] input[type="search"],
html[data-atlas-theme="dark"] select,
html[data-atlas-theme="dark"] textarea { background:#0f1318 !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] input::placeholder { color:#6f7885 !important; }

/* Bottoni outline (la primaria .btn-primary resta arancio) */
html[data-atlas-theme="dark"] .btn-outline,
html[data-atlas-theme="dark"] .layout > aside button.btn-outline { background:#1c2127 !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }

/* Superfici generiche: pannelli mappa / modali / card */
html[data-atlas-theme="dark"] .card { background:#161a1f !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .panel { background:#161a1f !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] [class*="-panel"] { background:#161a1f !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] [class*="-sheet"] { background:#161a1f !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] [class*="-card"] { background:#161a1f !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }

/* Footer */
html[data-atlas-theme="dark"] footer { background:#1e3a5f !important; color:#b9c6d6 !important; border-top:1px solid #2a2f36 !important; }

/* Leaflet: controlli/popup scuri, tile leggermente attenuati */
html[data-atlas-theme="dark"] .leaflet-control,
html[data-atlas-theme="dark"] .leaflet-bar a,
html[data-atlas-theme="dark"] .leaflet-popup-content-wrapper,
html[data-atlas-theme="dark"] .leaflet-popup-tip { background:#161a1f !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .leaflet-tile-pane .leaflet-tile { filter: brightness(.82) contrast(1.05) saturate(.85); }

/* Transizioni tema (dopo primo paint) */
html[data-atlas-anim] body,
html[data-atlas-anim] .layout > aside,
html[data-atlas-anim] .field-group,
html[data-atlas-anim] input,
html[data-atlas-anim] footer { transition: background-color .2s ease, color .2s ease, border-color .2s ease; }
@media (prefers-reduced-motion: reduce) { html[data-atlas-anim] * { transition:none !important; } }

/* ============================================================================
   7) DARK FIELD — HARDENING pannelli/finestre/legende secondarie (Fase 3)
   ========================================================================== */

/* --- Legenda / categorie livelli --- */
html[data-atlas-theme="dark"] .layer-cat { background:#161a1f !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .layer-cat > summary,
html[data-atlas-theme="dark"] #atlasVisibleLayersPanel summary,
html[data-atlas-theme="dark"] details.atlas-desktop-fold > summary {
  background:var(--atlas-surface) !important;
  color:var(--atlas-ink) !important;
  border-color:var(--atlas-line) !important;
}
html[data-atlas-theme="dark"] .layer-cat[open] > summary,
html[data-atlas-theme="dark"] #atlasVisibleLayersPanel details[open] > summary {
  background:var(--atlas-surface-2) !important;
}
html[data-atlas-theme="dark"] #atlasVisibleLayersPanel summary .cat-hint,
html[data-atlas-theme="dark"] #atlasVisibleLayersPanel summary small {
  color:var(--atlas-muted) !important;
}
html[data-atlas-theme="dark"] #atlasVisibleLayersPanel .toggle-row:hover {
  background:var(--atlas-surface-2) !important;
}
html[data-atlas-theme="dark"] .layer-cat summary .cat-hint { color:#8b95a3 !important; }
html[data-atlas-theme="dark"] .atlas-layer-purpose-heading { color:#cdd6e2 !important; }
html[data-atlas-theme="dark"] #atlasVisibleLayersPanel { background:#161a1f !important; }
html[data-atlas-theme="dark"] .atlas-close-layers-btn { background:#1c2127 !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }

/* --- Finestra PICCHETTAMENTO --- */
html[data-atlas-theme="dark"] .atlas-stake-panel { background:rgba(22,26,31,.98) !important; border-color:#2a2f36 !important; color:#e6ebf1 !important; }
html[data-atlas-theme="dark"] .atlas-stake-head { background:#1c2127 !important; border-bottom-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .atlas-stake-head strong,
html[data-atlas-theme="dark"] .atlas-stake-nav-target,
html[data-atlas-theme="dark"] .atlas-stake-nav-distance { color:#f2f2f0 !important; }
html[data-atlas-theme="dark"] .atlas-stake-note,
html[data-atlas-theme="dark"] .atlas-stake-nav-meta { color:#9aa4b2 !important; }
html[data-atlas-theme="dark"] .atlas-stake-quick-btn,
html[data-atlas-theme="dark"] .atlas-stake-coords-btn,
html[data-atlas-theme="dark"] .atlas-stake-actions button,
html[data-atlas-theme="dark"] .atlas-stake-nav-controls button,
html[data-atlas-theme="dark"] .atlas-stake-panel-close,
html[data-atlas-theme="dark"] .atlas-stake-toggle { background:#232a32 !important; color:#e6ebf1 !important; border-color:#333b45 !important; }
html[data-atlas-theme="dark"] .atlas-stake-quick-btn.primary,
html[data-atlas-theme="dark"] .atlas-stake-quick-btn.active,
html[data-atlas-theme="dark"] .atlas-stake-edit-mode,
html[data-atlas-theme="dark"] .atlas-stake-actions button.active { background:#ff9e12 !important; color:#161a1f !important; border-color:#ff9e12 !important; }
html[data-atlas-theme="dark"] .atlas-stake-nav-row { background:#1e3a5f !important; color:#fff !important; }
html[data-atlas-theme="dark"] .atlas-stake-entry input { background:#0f1318 !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .atlas-stake-table th,
html[data-atlas-theme="dark"] .atlas-stake-table td { border-bottom-color:#2a2f36 !important; color:#dbe2ea !important; }
html[data-atlas-theme="dark"] .atlas-stake-table th { color:#9aa4b2 !important; }
html[data-atlas-theme="dark"] .atlas-stake-table-wrap { background:#12161b !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .atlas-stake-mobile-nav { background:#1c2127 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .atlas-stake-compass { background:#12161b !important; border-color:#333b45 !important; box-shadow:inset 0 0 0 5px #1c2127 !important; }
html[data-atlas-theme="dark"] .atlas-stake-coord-card { background:#161a1f !important; color:#e6ebf1 !important; }
html[data-atlas-theme="dark"] .atlas-stake-coord-card h3 { color:#f2f2f0 !important; }
html[data-atlas-theme="dark"] .atlas-stake-coord-grid input { background:#0f1318 !important; color:#f2f2f0 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .atlas-stake-coord-actions button { background:#232a32 !important; color:#e6ebf1 !important; border-color:#333b45 !important; }
html[data-atlas-theme="dark"] .atlas-stake-coord-actions .save { background:#ff9e12 !important; color:#161a1f !important; border-color:#ff9e12 !important; }
html[data-atlas-theme="dark"] .atlas-stake-delete-btn { background:#2a1416 !important; color:#ff8a8a !important; border-color:#5a2327 !important; }
html[data-atlas-theme="dark"] .atlas-stake-summary { background:#16302a !important; color:#93cc57 !important; box-shadow:inset 0 0 0 1px rgba(147,204,87,.18) !important; }

/* --- Finestra MISURA --- */
html[data-atlas-theme="dark"] .atlas-measure-panel,
html[data-atlas-theme="dark"] .atlas-measure-window-body,
html[data-atlas-theme="dark"] .atlas-measure-window-head { background:#161a1f !important; color:#e6ebf1 !important; border-color:#2a2f36 !important; }
html[data-atlas-theme="dark"] .atlas-measure-panel strong { color:#f2f2f0 !important; }
html[data-atlas-theme="dark"] .atlas-measure-result { color:#93cc57 !important; }
html[data-atlas-theme="dark"] .atlas-measure-hint { color:#9aa4b2 !important; }
html[data-atlas-theme="dark"] .atlas-measure-btn { background:#232a32 !important; color:#e6ebf1 !important; border-color:#333b45 !important; }
html[data-atlas-theme="dark"] .atlas-measure-btn.active { background:#ff9e12 !important; color:#161a1f !important; border-color:#ff9e12 !important; }

/* --- Barra strumenti di lavoro (work tools) --- */
html[data-atlas-theme="dark"] .sidebar-sticky-tools,
html[data-atlas-theme="dark"] .atlas-work-tools {
  background:var(--atlas-surface) !important;
  color:var(--atlas-ink) !important;
  border-color:var(--atlas-line) !important;
}
html[data-atlas-theme="dark"] .atlas-work-tools button {
  background:var(--atlas-surface-2) !important;
  color:var(--atlas-ink) !important;
  border-color:var(--atlas-line) !important;
}
html[data-atlas-theme="dark"] .atlas-work-tools button:hover:not(:disabled) {
  background:#2a3440 !important;
  border-color:var(--atlas-cyan) !important;
}
html[data-atlas-theme="dark"] .atlas-work-tools button.atlas-access-locked {
  opacity:1 !important;
  color:var(--atlas-muted) !important;
}
html[data-atlas-theme="dark"] .sidebar-sticky-tools .atlas-premium-diamond {
  background:var(--atlas-surface-2) !important;
  color:var(--atlas-orange) !important;
  border-color:var(--atlas-orange) !important;
}
html[data-atlas-theme="dark"] .atlas-work-tools .atlas-tool-label { color:#cdd6e2 !important; }
html[data-atlas-theme="dark"] .atlas-project-file { background:#161a1f !important; color:#e6ebf1 !important; border-color:#2a2f36 !important; }

/* ============================================================================
   8) Icone Lucide nei pulsanti toolbar (dimensionamento coerente)
   ========================================================================== */
.atlas-tool-glyph svg.lucide,
.atlas-work-tools button > svg.lucide,
.atlas-measure-btn svg.lucide,
.atlas-map-action-btn svg.lucide { width:18px; height:18px; display:block; }
.atlas-work-tools button > svg.lucide { margin-right:6px; }
.atlas-picchetto-glyph { font-size:0 !important; }

/* --- Dark: controlli Satellite 3D (unico pannello rimasto chiaro) --- */
html[data-atlas-theme="dark"] .atlas-3d-controls { background:rgba(22,26,31,.98) !important; color:#e6ebf1 !important; border-color:rgba(255,255,255,.08) !important; }
html[data-atlas-theme="dark"] .atlas-3d-controls strong,
html[data-atlas-theme="dark"] .atlas-3d-controls small,
html[data-atlas-theme="dark"] .atlas-3d-controls label,
html[data-atlas-theme="dark"] .atlas-3d-controls span { color:#e6ebf1 !important; }
html[data-atlas-theme="dark"] .atlas-3d-controls select,
html[data-atlas-theme="dark"] .atlas-3d-controls button { background:#232a32 !important; color:#e6ebf1 !important; border-color:#333b45 !important; }
