:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c2330;
  --border: #2a3340;
  --txt: #e6edf3;
  --txt-dim: #8b949e;
  --accent: #3fb950;
  --accent-2: #58a6ff;
  --danger: #f85149;
  --warn: #d29922;
  --key: #79c0ff;
  --str: #a5d6ff;
  --num: #f0883e;
  --bool: #d2a8ff;
  --null: #8b949e;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Easing curves (fuertes, intencionales) */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* Iconos */
.ico { display: inline-block; vertical-align: -0.18em; flex-shrink: 0; }
.brand-ico { display: inline-flex; color: var(--accent); vertical-align: -0.18em; }
body {
  background: var(--bg);
  color: var(--txt);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  letter-spacing: 0.1px;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- LOGIN ---------- */
.login-screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #15301f 0%, var(--bg) 60%);
}
.login-card {
  width: min(360px, 90vw);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-logo { font-size: 30px; font-weight: 700; text-align: center; display: flex; align-items: center; justify-content: center; gap: 10px; }
.login-logo .ico { width: 34px; height: 34px; }
.login-logo .brand-ico { vertical-align: middle; }
.login-sub { margin: -6px 0 8px; text-align: center; color: var(--txt-dim); }
.login-card input {
  background: var(--bg); border: 1px solid var(--border); color: var(--txt);
  padding: 12px 14px; border-radius: var(--radius); font-size: 15px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  background: var(--accent); color: #04260f; border: none; font-weight: 700;
  padding: 12px; border-radius: var(--radius); font-size: 15px;
}
.login-card button:hover { filter: brightness(1.08); }
.login-err { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }

/* ---------- APP LAYOUT ---------- */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }
.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.sidebar-tools {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 8px; border-bottom: 1px solid var(--border);
}
.chk { color: var(--txt-dim); font-size: 12px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.db-list { overflow-y: auto; flex: 1; padding: 8px; }

/* Cabecera de cluster */
.cluster-head {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 8px 10px 4px; margin-top: 4px;
  color: var(--txt-dim); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px;
}
.cluster-name { display: flex; align-items: center; gap: 6px; overflow: hidden; }
.cluster-name .ico { color: var(--accent); }
.cluster-head .icon-btn.xsmall { opacity: .55; }
.cluster-head:hover .icon-btn.xsmall { opacity: 1; }
.cluster-err { color: var(--danger); font-size: 11px; padding: 2px 12px 8px; }
.empty.sm { padding: 8px 12px; font-size: 12px; }
.crumb-cluster {
  color: var(--accent); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  background: rgba(63,185,80,.12); border: 1px solid #1a3a23; padding: 1px 7px; border-radius: 6px;
}

.db-item { margin-bottom: 4px; }
.db-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; gap: 8px;
}
.db-row:hover { background: var(--bg-3); }
.db-row.system { opacity: .5; }
.db-name { font-weight: 600; display: flex; align-items: center; gap: 8px; overflow: hidden; min-width: 0; }
.db-ico { display: inline-flex; color: var(--accent-2); flex-shrink: 0; }
.db-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-size { color: var(--txt-dim); font-size: 11px; flex-shrink: 0; }
.col-list { margin: 2px 0 6px 14px; border-left: 1px solid var(--border); padding-left: 6px; }
.col-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; border-radius: 6px; cursor: pointer; gap: 8px;
}
.col-row:hover { background: var(--bg-3); }
.col-row.active { background: #173a24; color: #7ee787; }
.col-left { display: flex; align-items: center; gap: 7px; overflow: hidden; min-width: 0; }
.col-ico { display: inline-flex; color: var(--txt-dim); flex-shrink: 0; }
.col-row.active .col-ico { color: #7ee787; }
.col-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Acciones por fila (crear/borrar/importar/exportar) */
.db-name, .col-left { flex: 1; }
.row-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; opacity: 0; transition: opacity 120ms ease; }
.db-row:hover .row-actions, .col-row:hover .row-actions { opacity: 1; }
.row-actions .icon-btn.xsmall { width: 25px; height: 25px; }
@media (hover: none) { .row-actions { opacity: .55; } }

/* Formularios de los modales */
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-lbl { font-size: 12px; color: var(--txt-dim); }
.form-inp {
  background: var(--bg); border: 1px solid var(--border); color: var(--txt);
  padding: 9px 12px; border-radius: 8px; outline: none; font-family: inherit; font-size: 13px;
}
.form-inp:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(88,166,255,.12); }
input[type="file"].form-inp { padding: 7px; cursor: pointer; }
.col-count {
  background: var(--bg-3); color: var(--txt-dim); font-size: 11px;
  padding: 1px 7px; border-radius: 10px; flex-shrink: 0;
}
.col-row.active .col-count { background: #0d2916; color: #7ee787; }
.col-right { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.col-size { color: var(--txt-dim); font-size: 11px; min-width: 42px; text-align: right; }

/* ---------- MAIN ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.crumbs { font-family: var(--mono); color: var(--txt-dim); font-size: 13px; }
.crumbs b { color: var(--txt); }

.query-bar {
  display: flex; flex-direction: column; gap: 10px; padding: 12px 18px;
  border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.q-input {
  background: var(--bg); border: 1px solid var(--border); color: var(--txt);
  padding: 8px 12px; border-radius: 8px; font-family: var(--mono); font-size: 12px; outline: none;
}
.q-input.hidden { display: none; }
.q-input.sort { flex: 0 0 150px; min-width: 110px; }
.json-filter { width: 100%; font-size: 13px; padding: 10px 12px; }
.json-filter:focus { border-color: var(--accent); }
.q-input:focus { border-color: var(--accent-2); }
.lim-sel {
  background: var(--bg); border: 1px solid var(--border); color: var(--txt);
  padding: 8px; border-radius: 8px;
}

/* Constructor de filtros */
.builder-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filter-builder { display: flex; flex-direction: column; gap: 6px; }
.cond-row { display: flex; align-items: center; gap: 6px; }
.cond-field, .cond-op, .cond-val {
  background: var(--bg); border: 1px solid var(--border); color: var(--txt);
  padding: 7px 10px; border-radius: 8px; font-size: 13px; outline: none; max-width: 240px;
}
.cond-field:focus, .cond-op:focus, .cond-val:focus { border-color: var(--accent-2); }
.cond-op { color: var(--accent-2); font-weight: 600; }
.cond-val-wrap { display: inline-flex; }
.hint { color: var(--txt-dim); font-size: 12px; font-style: italic; }

.qb-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.page-info { color: var(--txt-dim); font-size: 12px; min-width: 120px; text-align: center; }

.docs { overflow-y: auto; flex: 1; padding: 16px 18px; }

/* ---------- DOC CARD ---------- */
.doc-card {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 12px; overflow: hidden;
}
.doc-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg-3);
}
.doc-id { font-family: var(--mono); font-size: 12px; color: var(--txt-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-id b { color: var(--accent-2); }
.doc-actions { display: flex; gap: 6px; flex-shrink: 0; }
.doc-body { padding: 12px 14px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; overflow-x: auto; }

/* JSON coloreado */
.j-key { color: var(--key); }
.j-str { color: var(--str); }
.j-num { color: var(--num); }
.j-bool { color: var(--bool); }
.j-null { color: var(--null); }
.j-punct { color: var(--txt-dim); }
.j-line { white-space: pre; }
.j-oid { color: var(--bool); }
.j-date { color: var(--accent); }
.j-line { border-radius: 5px; transition: background 110ms ease; }
.j-line:hover { background: var(--bg-3); }
.j-line.j-top { display: flex; align-items: flex-start; gap: 18px; padding-left: 16px; }
.j-line-content { flex: 1; min-width: 0; }
.j-type { color: var(--txt-dim); font-size: 11px; font-family: var(--mono); flex-shrink: 0; padding-top: 1px; user-select: none; }
.j-collapse { cursor: pointer; user-select: none; color: var(--txt-dim); display: inline-flex; align-items: center; gap: 2px; }
.j-collapse:hover { color: var(--txt); }
.j-collapse .ico { vertical-align: middle; }
.j-children.collapsed { display: none; }
.j-ellipsis { color: var(--txt-dim); }

/* Pastilla campo grande */
.big-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 20px;
  padding: 2px 6px 2px 12px; font-size: 12px; vertical-align: middle;
}
.big-pill .bp-meta { color: var(--warn); font-weight: 600; }
.big-pill .bp-type { color: var(--txt-dim); font-size: 11px; }
.big-pill .bp-file { color: var(--accent-2); font-size: 11px; }
.big-pill .bp-btn {
  background: var(--bg); border: 1px solid var(--border); color: var(--txt);
  border-radius: 14px; padding: 3px 9px; font-size: 12px;
  display: inline-flex; align-items: center; gap: 4px;
}
.big-pill .bp-btn:hover { border-color: var(--accent-2); color: var(--accent-2); }

/* Vista esquema */
.schema-note { color: var(--txt-dim); font-size: 12px; margin-bottom: 14px; }
/* Una tarjeta por fila, dos paneles. */
.schema-grid { display: flex; flex-direction: column; gap: 12px; max-width: 1100px; }
.schema-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 20px; display: flex; gap: 28px; align-items: stretch;
}
.sc-left { flex: 0 0 240px; display: flex; flex-direction: column; gap: 10px; border-right: 1px solid var(--border); padding-right: 24px; }
.sc-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.sc-right-title { font-size: 12px; color: var(--txt-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }

.schema-name { font-weight: 700; color: var(--key); font-family: var(--mono); font-size: 16px; word-break: break-all; }
.presence-note { font-size: 11px; color: var(--txt-dim); }

.schema-bars { display: flex; flex-direction: column; gap: 7px; }
.schema-bar-row { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.sb-label { flex: 0 0 200px; color: var(--str); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.sb-track { flex: 1; height: 10px; background: var(--bg-3); border-radius: 5px; overflow: hidden; }
.sb-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), #388bfd); border-radius: 5px; }
.sb-count { flex: 0 0 90px; color: var(--txt-dim); font-size: 12px; text-align: right; font-family: var(--mono); }
.schema-more { color: var(--txt-dim); font-size: 12px; margin-top: 2px; font-style: italic; }

.schema-range { display: flex; align-items: center; gap: 16px; }
.range-block { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 18px; display: flex; flex-direction: column; gap: 3px; }
.rb-label { font-size: 11px; color: var(--txt-dim); text-transform: uppercase; letter-spacing: 0.4px; }
.rb-value { font-size: 15px; font-weight: 600; color: var(--num); font-family: var(--mono); }
.sr-arrow { color: var(--txt-dim); font-size: 18px; }
.schema-hc { color: var(--txt-dim); font-size: 13px; line-height: 1.5; max-width: 520px; }
.sc-preview { margin-top: 4px; }
.sc-preview-img { max-width: 260px; max-height: 150px; border-radius: 8px; background: #0a0d12; padding: 4px; display: block; }
.sc-preview-vid { max-width: 300px; max-height: 170px; border-radius: 8px; background: #000; display: block; }

@media (max-width: 720px) {
  .schema-card { flex-direction: column; gap: 14px; }
  .sc-left { flex: none; border-right: none; border-bottom: 1px solid var(--border); padding-right: 0; padding-bottom: 14px; }
  .sb-label { flex: 0 0 130px; }
}

/* ---------- BUTTONS ---------- */
.ghost-btn {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--txt);
  padding: 7px 14px; border-radius: 8px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 140ms var(--ease-out);
}
.ghost-btn:hover { border-color: var(--accent-2); }
.ghost-btn:active { transform: scale(0.97); }
.ghost-btn.small { padding: 6px 11px; font-size: 12px; }
.ghost-btn.xsmall { padding: 4px 9px; font-size: 11px; gap: 4px; }
.ghost-btn.active { border-color: var(--accent-2); color: var(--accent-2); }
.ghost-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--txt);
  width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 140ms var(--ease-out);
}
.icon-btn:hover { background: var(--bg-3); color: var(--accent-2); border-color: var(--accent-2); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.xsmall { width: 26px; height: 26px; }
.icon-btn.danger-hover:hover { background: rgba(248,81,73,.12); color: var(--danger); border-color: var(--danger); }
.btn-primary {
  background: var(--accent); color: #04260f; border: none; font-weight: 700;
  padding: 9px 18px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: filter 160ms ease, transform 140ms var(--ease-out);
}
.btn-primary.small { padding: 7px 14px; font-size: 13px; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.97); }
.btn-danger {
  background: var(--danger); color: #2b0606; border: none; font-weight: 700;
  padding: 9px 18px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: filter 160ms ease, transform 140ms var(--ease-out);
}
.btn-danger:hover { filter: brightness(1.08); }
.btn-danger:active { transform: scale(0.97); }
.icon-btn .ico, .ghost-btn .ico, .bp-btn .ico { transition: transform 200ms var(--ease-out); }
#refreshDbs:active .ico { transform: rotate(-180deg); }

.empty { text-align: center; color: var(--txt-dim); padding: 60px 20px; }

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: grid; place-items: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px;
  width: min(900px, 95vw); max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 70px rgba(0,0,0,.6);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700;
}
.modal-body { padding: 16px 18px; overflow: auto; flex: 1; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--border);
}
.modal-body .json-area {
  width: 100%; min-height: 360px; background: var(--bg); color: var(--txt);
  border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5; resize: vertical; outline: none;
}
.modal-body .json-area:focus { border-color: var(--accent-2); }
.modal-body iframe { width: 100%; height: 72vh; border: none; border-radius: 10px; background: #fff; }
.modal-body .media-img {
  display: block; width: 100%; max-height: 74vh; object-fit: contain;
  border-radius: 10px; background: #0a0d12; padding: 8px;
}
.modal-body video { display: block; width: 100%; max-height: 74vh; border-radius: 10px; background: #000; }

/* Reproductor de audio custom */
.aplayer {
  display: flex; align-items: center; gap: 14px;
  background: #0a0d12; border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 20px; margin: 12px 0;
}
.aplayer audio { display: none; }
.ap-play {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #04260f; border: none;
  display: flex; align-items: center; justify-content: center;
  transition: transform 140ms var(--ease-out), filter 160ms ease;
}
.ap-play:hover { filter: brightness(1.1); }
.ap-play:active { transform: scale(0.93); }
.ap-time { font-family: var(--mono); font-size: 12px; color: var(--txt-dim); min-width: 36px; text-align: center; }
.ap-wave { flex: 1; height: 44px; cursor: pointer; display: block; }
.ap-vol { color: var(--txt-dim); display: flex; flex-shrink: 0; }
.modal-body pre {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono); font-size: 12.5px; color: var(--str); max-height: 70vh; overflow: auto;
}
.modal-err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 16px; }
.modal-msg { color: var(--txt); line-height: 1.6; }

/* String truncado en el visor */
.j-trunc { cursor: pointer; }
.j-trunc:hover { text-decoration: underline dotted; text-underline-offset: 2px; }
.j-trunc.expanded { white-space: pre-wrap; word-break: break-word; }

/* ---------- MAPA ---------- */
.map-pin {
  display: inline-flex; align-items: center; gap: 4px; vertical-align: middle;
  margin-left: 8px; padding: 2px 9px; border-radius: 14px; font-size: 11.5px;
  background: var(--bg-3); border: 1px solid var(--border); color: var(--accent);
  transition: border-color 160ms ease, color 160ms ease, transform 140ms var(--ease-out);
}
.map-pin:hover { border-color: var(--accent); }
.map-pin:active { transform: scale(0.94); }
.mapbox {
  position: relative; width: 100%; height: 440px; overflow: hidden;
  border-radius: 10px; background: #0a0d12; border: 1px solid var(--border);
  cursor: grab; user-select: none; touch-action: none;
}
.mapbox.grabbing { cursor: grabbing; }
.map-layer { position: absolute; inset: 0; }
.map-tile { position: absolute; width: 256px; height: 256px; user-select: none; pointer-events: none; }
.map-marker {
  position: absolute; transform: translate(-50%, -100%); color: var(--danger);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); line-height: 0; pointer-events: none;
}
.map-marker svg { fill: var(--danger); stroke: #fff; stroke-width: 1.5; }
.map-attr { font-size: 11px; color: var(--txt-dim); text-align: right; margin-top: 6px; }
.map-ctrl { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.map-zbtn {
  width: 34px; height: 34px; border-radius: 8px; color: var(--txt);
  background: rgba(13,17,23,.85); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 120ms var(--ease-out);
}
.map-zbtn:hover { background: var(--bg-3); border-color: var(--accent-2); color: var(--accent-2); }
.map-zbtn:active { transform: scale(0.92); }

/* ---------- EDITOR ESTILO COMPASS ---------- */
.editor { display: flex; flex-direction: column; gap: 12px; }
.editor-head { display: flex; align-items: center; gap: 14px; }
.editor-mod { color: var(--warn); font-size: 12px; font-weight: 600; }
.editor-list { display: flex; flex-direction: column; gap: 2px; }
.ed-row {
  display: grid; grid-template-columns: 22px minmax(120px, 200px) 108px 1fr auto;
  align-items: center; gap: 8px; padding: 4px 6px; border-radius: 7px;
  transition: background 120ms ease;
}
.ed-row:hover { background: var(--bg); }
.ed-row.changed { background: rgba(210,153,34,.09); }
.ed-row.deleted { background: rgba(248,81,73,.13); box-shadow: inset 3px 0 0 var(--danger); }
.ed-row.deleted .ed-key, .ed-row.deleted .ed-val, .ed-row.deleted .ed-type { text-decoration: line-through; color: var(--danger); opacity: .85; }
.ed-ins { opacity: 0; transition: opacity 120ms ease; }
.ed-row:hover .ed-ins { opacity: .7; }
.ed-ins:hover { opacity: 1 !important; }
.ed-key, .ed-val, .ed-type {
  background: var(--bg); border: 1px solid var(--border); color: var(--txt);
  padding: 6px 9px; border-radius: 7px; font-family: var(--mono); font-size: 12.5px; outline: none; min-width: 0;
}
.ed-area { resize: vertical; line-height: 1.45; min-height: 32px; white-space: pre; overflow: auto; }
.ed-key { color: var(--key); font-weight: 600; }
.ed-key:focus, .ed-val:focus, .ed-type:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(88,166,255,.12); }
.ed-key:disabled { opacity: .6; cursor: not-allowed; }
.ed-type { color: var(--txt-dim); cursor: pointer; }
.ed-valwrap { display: flex; min-width: 0; }
.ed-valwrap .ed-val { width: 100%; }
.ed-nullval { color: var(--null); font-style: italic; font-family: var(--mono); font-size: 12.5px; padding: 6px 2px; }
.ed-locked { opacity: .7; background: var(--bg-3); border-style: dashed; }
.ed-big { color: var(--warn); font-size: 11.5px; font-family: var(--mono); padding: 6px 2px; }
.ed-type-lock { color: var(--txt-dim); font-size: 11px; font-family: var(--mono); padding: 6px 4px; text-align: center; }
.ed-actions { display: flex; gap: 4px; }

@media (max-width: 640px) {
  .ed-row { grid-template-columns: 18px 1fr 90px; grid-auto-flow: row; }
  .ed-row .ed-valwrap { grid-column: 1 / -1; }
  .ed-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

/* ---------- TOAST ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--border); color: var(--txt);
  padding: 12px 20px; border-radius: 10px; z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.toast.ok { border-color: var(--accent); }
.toast.err { border-color: var(--danger); }

/* spinner */
.spinner { text-align: center; color: var(--txt-dim); padding: 40px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.spinner::before {
  content: ""; width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ANIMACIONES / POLISH ---------- */

/* Entradas de modal y overlay */
.modal-overlay:not(.hidden) { animation: overlayIn 160ms var(--ease-out); }
.modal-overlay:not(.hidden) .modal { animation: modalIn 240ms var(--ease-out); }
@keyframes overlayIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.96) translateY(8px); } }

/* Toast desliza desde abajo (misma dirección entrada/salida) */
.toast { animation: toastIn 280ms var(--ease-out); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(14px); } }

/* Tarjetas de documento: entrada con stagger + hover */
.doc-card { transition: border-color 160ms ease, transform 160ms var(--ease-out); animation: cardIn 300ms var(--ease-out) backwards; }
.doc-card:hover { border-color: #38414f; }
.doc-card:nth-child(1) { animation-delay: 0ms; }
.doc-card:nth-child(2) { animation-delay: 40ms; }
.doc-card:nth-child(3) { animation-delay: 80ms; }
.doc-card:nth-child(4) { animation-delay: 120ms; }
.doc-card:nth-child(5) { animation-delay: 160ms; }
.doc-card:nth-child(6) { animation-delay: 200ms; }
.doc-card:nth-child(n+7) { animation-delay: 220ms; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } }

/* Filas sidebar fluidas */
.db-row, .col-row { transition: background 140ms ease, color 140ms ease; }
.db-ico, .col-ico { transition: color 140ms ease; }
.db-row:active, .col-row:active { transform: scale(0.99); }

/* Inputs y selects nativos: foco fluido */
.q-input, .lim-sel, .cond-val, input, select, textarea {
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.q-input:focus, .cond-val:focus, .login-card input:focus, .modal-body textarea:focus {
  box-shadow: 0 0 0 3px rgba(88,166,255,.12);
}

/* Pastilla campo grande: hover suave */
.big-pill { transition: border-color 160ms ease; }
.bp-btn { transition: border-color 160ms ease, color 160ms ease, transform 140ms var(--ease-out); }
.bp-btn:active { transform: scale(0.94); }

/* Tarjetas esquema: entrada stagger */
.schema-card { animation: cardIn 280ms var(--ease-out) backwards; transition: border-color 160ms ease; }
.schema-card:hover { border-color: #38414f; }
.sb-fill { transition: width 420ms var(--ease-out); }

/* ---------- SELECT CUSTOM (desplegable animado) ---------- */
.msel { position: relative; display: inline-flex; }
.msel-trigger {
  background: var(--bg); border: 1px solid var(--border); color: var(--txt);
  padding: 7px 10px; border-radius: 8px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; justify-content: space-between;
  min-width: 90px; max-width: 240px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.msel-trigger:hover { border-color: #38414f; }
.msel.open .msel-trigger { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(88,166,255,.12); }
.msel-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msel-label.placeholder { color: var(--txt-dim); }
.msel-chevron { display: inline-flex; color: var(--txt-dim); transition: transform 200ms var(--ease-out); flex-shrink: 0; }
.msel.open .msel-chevron { transform: rotate(180deg); }
.msel-panel {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 100%;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 5px; z-index: 60; max-height: 260px; overflow-y: auto;
  box-shadow: 0 14px 40px rgba(0,0,0,.5);
  transform-origin: top; opacity: 0; transform: scale(0.96) translateY(-6px); pointer-events: none;
  transition: opacity 160ms var(--ease-out), transform 160ms var(--ease-out);
}
.msel.open .msel-panel { opacity: 1; transform: none; pointer-events: auto; }
.msel-opt {
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  transition: background 110ms ease;
}
.msel-opt:hover { background: var(--bg-3); }
.msel-opt.sel { color: var(--accent); }
.msel-opt .opt-count { color: var(--txt-dim); font-size: 11px; flex-shrink: 0; }
.msel-empty { padding: 10px; color: var(--txt-dim); font-size: 12px; text-align: center; }

/* ---------- SKELETON ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-3) 25%, #232b38 50%, var(--bg-3) 75%);
  background-size: 200% 100%; border-radius: 6px; animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.sk-row { height: 34px; margin: 6px 8px; }
.sk-doc { height: 120px; margin-bottom: 12px; border-radius: var(--radius); }

/* ---------- TOGGLE DATOS/ESQUEMA ---------- */
.seg { display: inline-flex; background: var(--bg-3); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.seg-btn {
  background: transparent; border: none; color: var(--txt-dim);
  padding: 6px 13px; border-radius: 7px; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 180ms var(--ease-out), color 160ms ease, transform 140ms var(--ease-out);
}
.seg-btn:hover { color: var(--txt); }
.seg-btn:active { transform: scale(0.96); }
.seg-btn.active { background: var(--bg); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- SECCIÓN ESQUEMA ---------- */
.schema-view { overflow-y: auto; flex: 1; padding: 18px; }
.schema-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px;
  margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.sh-title { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; }
.sh-title .ico { color: var(--accent); }
.sh-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat-pill {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 16px; display: flex; flex-direction: column; align-items: center; min-width: 86px;
}
.stat-val { font-size: 18px; font-weight: 700; color: var(--accent-2); }
.stat-lbl { font-size: 10.5px; color: var(--txt-dim); margin-top: 1px; }

.schema-name-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.schema-name { cursor: pointer; }
.schema-name:hover { text-decoration: underline; text-underline-offset: 2px; }

.type-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.tb {
  font-size: 10.5px; font-weight: 600; padding: 2px 9px; border-radius: 20px;
  font-family: var(--mono); background: var(--bg-3); color: var(--txt-dim); border: 1px solid var(--border);
}
.tb-objectId { color: #d2a8ff; border-color: #3a2d52; }
.tb-string { color: #a5d6ff; border-color: #1d3b52; }
.tb-int, .tb-double, .tb-decimal { color: #f0883e; border-color: #4a2f1a; }
.tb-date { color: #3fb950; border-color: #1a3a23; }
.tb-boolean { color: #79c0ff; border-color: #1d3b52; }
.tb-array { color: #ffa657; border-color: #4a2f1a; }
.tb-object { color: #8b949e; }
.tb-binary { color: #f85149; border-color: #4a1f1d; }

.presence-wrap { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.presence-track { flex: 1; height: 6px; background: var(--bg-3); border-radius: 3px; overflow: hidden; }
.presence-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #2ea043); border-radius: 3px; transition: width 520ms var(--ease-out); }
.presence-pct { font-size: 11px; color: var(--accent); min-width: 34px; text-align: right; }

.schema-bar-row { cursor: pointer; padding: 3px 5px; margin: 0 -5px; border-radius: 6px; transition: background 120ms ease; }
.schema-bar-row:hover { background: var(--bg-3); }

.sr-bar { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--accent-2), var(--num)); margin-bottom: 6px; }
.sr-labels { display: flex; justify-content: space-between; gap: 10px; font-family: var(--mono); font-size: 11px; color: var(--num); }
.sr-labels span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .spinner::before { animation-duration: 700ms !important; animation-iteration-count: infinite !important; }
  .skeleton { animation-duration: 1.3s !important; animation-iteration-count: infinite !important; }
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 38vh; }
  .q-input.sort { flex: 1 1 100%; }
}
