/* ============================================================
   maps-widget Sandbox — style.css
   Tema scuro professionale
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg-base: #1a1a2e;
  --bg-panel: #16213e;
  --bg-element: #0f3460;
  --bg-input: #0d1b2a;
  --border: #2a3f6f;
  --text-primary: #e0e0e0;
  --text-muted: #8899bb;
  --accent: #0ea5e9;
  --accent-hover: #38bdf8;
  --accent-dim: rgba(14, 165, 233, 0.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius: 6px;
  --transition: 150ms ease;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 13px;
  background: var(--bg-base);
  color: var(--text-primary);
}

/* ============================================================
   Layout principale
   ============================================================ */

.sandbox-layout {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   Pannello sinistro (editor + controlli)
   ============================================================ */

.panel-left {
  width: 380px;
  min-width: 100px;
  max-width: 1000px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* ============================================================
   Pannello centrale (iframe widget)
   ============================================================ */

.panel-center {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: var(--bg-base);
}

/* ============================================================
   Pannello destro (event log + method tester)
   ============================================================ */

.panel-right {
  width: 320px;
  min-width: 100px;
  max-width: 1000px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

/* ============================================================
   Toolbar (version picker + preset buttons)
   ============================================================ */

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

/* ============================================================
   Selects e input
   ============================================================ */

select,
input,
textarea {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-family: var(--font-sans);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
}

select {
  cursor: pointer;
  flex: 1;
}

select option {
  background: var(--bg-input);
}

/* ============================================================
   Bottoni
   ============================================================ */

button {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 12px;
  font-size: 12px;
  font-family: var(--font-sans);
  background: var(--bg-element);
  color: var(--text-primary);
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}

button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button:active {
  opacity: 0.85;
}

button.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

button.btn-ghost:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   Preset buttons
   ============================================================ */

.preset-buttons {
  display: flex;
  gap: 6px;
}

.preset-btn {
  flex: 1;
}

/* ============================================================
   Editor container Monaco
   ============================================================ */

#editor-container {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* ============================================================
   Actions (apply, snippet, docs)
   ============================================================ */

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.actions #btn-apply {
  flex: 1;
}

.actions a#link-docs {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-element);
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}

.actions a#link-docs:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.actions a#link-docs.disabled {
  color: var(--text-muted);
  pointer-events: none;
  opacity: 0.5;
}

/* ============================================================
   Widget status bar
   ============================================================ */

.widget-status {
  flex-shrink: 0;
  padding: 4px 12px;
  font-size: 11px;
  background: var(--bg-element);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.widget-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--transition);
}

.widget-status.status-loading .status-dot {
  background: var(--warning);
}

.widget-status.status-ready .status-dot {
  background: var(--success);
}

.widget-status.status-error .status-dot {
  background: var(--error);
}

.widget-status .status-text {
  color: var(--text-muted);
}

.widget-status.status-ready .status-text {
  color: var(--success);
}

.widget-status.status-error .status-text {
  color: var(--error);
}

/* ============================================================
   iframe widget
   ============================================================ */

#widget-frame {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ============================================================
   Pannello destro — intestazioni
   ============================================================ */

.panel-right h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.panel-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ============================================================
   Filtro eventi (chips)
   ============================================================ */

.event-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.filter-chip {
  padding: 1px 7px;
  font-size: 9px;
  font-family: var(--font-mono);
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.filter-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.filter-chip.filter-chip-all {
  font-weight: 700;
  font-family: var(--font-sans);
}

.filter-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   Collapsible sections
   ============================================================ */

.panel-right-bottom {
  flex: 0 1 auto;
  max-height: 62%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scrollbar-gutter: stable;
  border-top: 2px solid var(--border);
}

.collapsible-section {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.collapsible-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: var(--bg-element);
  border: none;
  border-radius: 0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.collapsible-header:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: transparent;
}

.collapse-icon {
  font-size: 9px;
  color: var(--text-muted);
}

.collapsible-body {
  overflow-y: auto;
  max-height: 400px;
}

#method-tester-wrap {
  max-height: none;
  padding-bottom: 12px;
}

/* ============================================================
   Event log
   ============================================================ */

.event-log-header {
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.event-log-header .collapsible-header {
  flex: 1;
  border-bottom: none;
}

.event-log-header #btn-clear-log {
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--border);
  padding: 0 10px;
  flex-shrink: 0;
}

.event-log-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.event-count {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

#event-log {
  flex: 1 1 auto;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 4px 0;
  min-height: 0;
}

#event-log::-webkit-scrollbar {
  width: 4px;
}

#event-log::-webkit-scrollbar-track {
  background: transparent;
}

#event-log::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.event-item {
  padding: 4px 10px;
  border-bottom: 1px solid rgba(42, 63, 111, 0.4);
  cursor: pointer;
  transition: background var(--transition);
}

.event-item:hover {
  background: var(--accent-dim);
}

.event-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.event-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: lowercase;
  flex-shrink: 0;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Badge colorati per tipo evento */
.badge-map_loaded {
  background: #14532d;
  color: #86efac;
}

.badge-mounted {
  background: #052e16;
  color: #4ade80;
}

.badge-identify_result {
  background: #1e3a5f;
  color: #93c5fd;
}

.badge-new_notification {
  background: #451a03;
  color: #fcd34d;
}

.badge-center_changed {
  background: #1e1b4b;
  color: #a5b4fc;
}

.badge-drawn_geometry {
  background: #312e81;
  color: #c4b5fd;
}

.badge-drawn_geometry_clear {
  background: #2d1d5e;
  color: #ddd6fe;
}

.badge-search_result {
  background: #083344;
  color: #67e8f9;
}

.badge-change_lang {
  background: #1c1917;
  color: #d6d3d1;
}

.badge-finish_tour {
  background: #14532d;
  color: #86efac;
}

.badge-panel_active_themes_changed {
  background: #0c4a6e;
  color: #7dd3fc;
}

.badge-module-event {
  background: #4a1942;
  color: #f0abfc;
}

.badge-error {
  background: #7f1d1d;
  color: #fca5a5;
}

.badge-default {
  background: var(--bg-element);
  color: var(--text-muted);
}

.event-ts {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-left: auto;
  flex-shrink: 0;
}

.event-detail {
  display: none;
  margin-top: 4px;
  padding: 4px 6px;
  background: var(--bg-input);
  border-radius: var(--radius);
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 150px;
  overflow-y: auto;
}

.event-item.expanded .event-detail {
  display: block;
}

/* ============================================================
   Pannello destro — layout a due sezioni
   ============================================================ */

.panel-right-top {
  flex: 1 1 0;
  min-height: 0;
  max-height: 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-right-top.collapsed {
  flex: 0 0 auto;
  max-height: none;
}

.event-log-body {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-right-bottom.expanded {
  flex: 1 1 auto;
  max-height: none;
}

/* ============================================================
   Method tester
   ============================================================ */

#method-tester {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

#method-tester select {
  width: 100%;
}

/* Firma metodo */
.method-sig {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--bg-input);
  padding: 4px 7px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.method-sig:empty {
  display: none;
}

/* Descrizione */
.method-desc {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.method-desc:empty {
  display: none;
}

/* Tabella parametri */
.method-params-wrap {
  font-size: 10px;
}

.method-params-wrap:empty {
  display: none;
}

.method-params-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  font-family: var(--font-mono);
}

.method-params-table td {
  padding: 2px 4px;
  vertical-align: top;
  border-bottom: 1px solid rgba(42, 63, 111, 0.4);
}

.param-name {
  color: var(--accent);
  white-space: nowrap;
  min-width: 80px;
}

.param-req {
  color: var(--error);
  font-size: 9px;
  vertical-align: super;
  margin-left: 1px;
}

.param-opt {
  color: var(--text-muted);
  font-size: 9px;
  vertical-align: super;
  margin-left: 1px;
}

.param-type {
  color: var(--warning);
  white-space: nowrap;
  padding-right: 6px;
}

.param-default {
  color: var(--text-muted);
  font-size: 9px;
}

.param-desc {
  color: var(--text-muted);
  word-break: break-word;
}

/* Snippet */
.method-snippet-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.method-snippet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.method-snippet-copy {
  font-size: 10px;
  padding: 1px 8px;
}

.method-snippet-code {
  margin: 0;
  padding: 6px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 10px;
  color: #a5f3fc;
  white-space: pre;
  overflow-x: auto;
  max-height: 130px;
  overflow-y: auto;
  resize: none;
}

/* Args label */
.method-args-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#method-args {
  width: 100%;
  resize: vertical;
  min-height: 48px;
  font-family: var(--font-mono);
  font-size: 11px;
}

#btn-call-method {
  align-self: flex-end;
}

#method-result {
  padding: 8px 10px;
  flex-shrink: 0;
  min-height: 32px;
  max-height: 80px;
  overflow-y: auto;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-input);
  margin: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-all;
}

#method-result.result-ok {
  border-color: var(--success);
  color: var(--success);
}

#method-result.result-error {
  border-color: var(--error);
  color: var(--error);
}

/* ============================================================
   Toast notification
   ============================================================ */

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 9999;
  white-space: nowrap;
}

#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Scrollbar globale
   ============================================================ */

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ============================================================
   Resize handles
   ============================================================ */

.resize-handle {
  width: 5px;
  flex-shrink: 0;
  background: var(--border);
  cursor: col-resize;
  transition: background var(--transition);
  position: relative;
  z-index: 10;
}

.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent);
}

/* ============================================================
   Responsive: su schermi piccoli mostra solo il pannello centrale
   ============================================================ */

@media (max-width: 768px) {

  .panel-left,
  .panel-right {
    display: none;
  }

  .panel-center {
    flex: 1;
    width: 100%;
  }
}