/* Datos · estilos propios */
body { overflow: hidden; }
.shell { display: grid; height: 100dvh; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: 48px minmax(0, 1fr); grid-template-areas: "top top" "main side"; }
.topbar { grid-area: top; }
.top-mid { margin: 0 auto; display: flex; gap: 6px; }
.topbar .top-actions { margin-left: 0; }

.main { grid-area: main; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; padding: 10px 12px 12px; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.search { position: relative; width: 260px; }
.search .ic { position: absolute; left: 9px; top: 8px; width: 14px; height: 14px; color: var(--text-3); pointer-events: none; }
.search kbd { position: absolute; right: 7px; top: 6px; pointer-events: none; }
.search input { width: 100%; height: 30px; padding: 0 26px 0 29px; border: 1px solid var(--border); border-radius: var(--r); background: var(--panel); outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input:focus ~ kbd, .search input:not(:placeholder-shown) ~ kbd { display: none; }
.search input::-webkit-search-cancel-button { display: none; }
.filter-add { display: flex; gap: 4px; align-items: center; }
.filter-add .input { height: 30px; width: auto; max-width: 160px; font-size: 12.5px; }
.filter-add #fVal { width: 120px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 10px; border-radius: 99px; background: var(--accent-soft); color: var(--text); font-size: 12px; }
.chip b { color: var(--accent); font-weight: 600; }
.chip button { width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--text-2); font-size: 14px; line-height: 1; }
.chip button:hover { background: var(--hover); color: var(--text); }

.table-area { position: relative; flex: 1; min-height: 0; overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.grid { border-collapse: separate; border-spacing: 0; font-size: 12.5px; font-variant-numeric: tabular-nums; min-width: 100%; }
.grid th { position: sticky; top: 0; z-index: 2; height: 36px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--border-2); text-align: left; font-weight: 600; white-space: nowrap; cursor: pointer; user-select: none; }
.grid th:hover { background: var(--hover); }
.grid th .ty { display: inline-block; min-width: 18px; margin-right: 6px; color: var(--text-3); font: 500 10.5px var(--mono); }
.grid th b { color: var(--accent); font-size: 10px; }
.grid td { height: 32px; padding: 0 12px; border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.grid th.r, .grid td.r { text-align: right; }
.grid .rn { position: sticky; left: 0; z-index: 1; width: 44px; padding: 0 8px; background: var(--sunken); color: var(--text-3); text-align: right; font-size: 11px; }
.grid th.rn { z-index: 3; }
.grid th.sel, .grid td.sel { background: var(--accent-soft); }
.grid tbody tr:hover td:not(.rn) { background: var(--hover); }
.grid .none { text-align: center; color: var(--text-3); padding: 30px; }
.more { display: block; margin: 12px auto; }
.drop { position: absolute; inset: 14px; display: grid; place-items: center; border: 1.5px dashed var(--border-2); border-radius: 12px; }
.drop-in { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; color: var(--text-2); }
.drop-in strong { font-size: 16px; color: var(--text); }
.drop-in .row { margin-top: 8px; }
.drop-ic { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); margin-bottom: 4px; }
.drop-ic .ic { width: 26px; height: 26px; }
body.dragging .table-area { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Lateral */
.side { grid-area: side; overflow: auto; border-left: 1px solid var(--border); }
.s-sec { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px 16px; border-bottom: 1px solid var(--border); }
.s-sec .sec-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.s-sec .sec-h .input { height: 28px; width: auto; max-width: 180px; font-size: 12px; }
.stats { grid-template-columns: 1fr 1fr 1fr; }
.mt { margin-top: 10px; }
.top { display: grid; gap: 2px; margin-top: 12px; }
.top .field-l { margin-bottom: 4px; }
.top-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 40px; gap: 8px; align-items: baseline; padding: 4px 6px; border: 0; border-radius: 6px; background: none; text-align: left; font-size: 12.5px; }
.top-row:hover { background: var(--hover); }
.top-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.top-row small { color: var(--text-3); text-align: right; font-variant-numeric: tabular-nums; }
.s-sec .tbl-wrap { max-height: 260px; }
.cols { display: grid; gap: 4px; max-height: 220px; overflow: auto; }
.cols .check small { margin-left: auto; color: var(--text-3); font-size: 11px; }
.cols .check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pasteDlg .modal { width: min(720px, 100%); }
#pasteArea { min-height: 260px; }

@media (max-width: 1000px) {
  body { overflow: auto; }
  .shell { height: auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; grid-template-areas: "top" "main" "side"; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .top-mid { order: 3; margin: 0; }
  .table-area { min-height: 60vh; }
  .side { border-left: 0; border-top: 1px solid var(--border); }
  .search { width: 100%; }
  .filter-add { width: 100%; flex-wrap: wrap; }
  .filter-add .input, .filter-add #fVal { flex: 1 1 100px; width: auto; max-width: none; min-width: 0; }
}

/* Edición */
.edit-tools { display: flex; align-items: center; gap: 2px; }
.grid td[data-r] { cursor: cell; }
.grid td.editing { cursor: text; max-width: none; white-space: pre-wrap; overflow: visible; background: var(--panel) !important; outline: 2px solid var(--accent); outline-offset: -2px; }
.grid .rn span { display: inline; }
.grid .rn-del { display: none; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 5px; background: none; color: var(--danger); font-size: 15px; line-height: 1; cursor: pointer; }
.grid tr:hover .rn span { display: none; }
.grid tr:hover .rn-del { display: inline-grid; place-items: center; }
.grid .rn-del:hover { background: var(--danger-soft); }
.th-in { width: 100%; min-width: 90px; height: 26px; padding: 0 6px; border: 1px solid var(--accent); border-radius: 5px; background: var(--panel); font: inherit; font-weight: 600; outline: none; }

/* ───────── Móvil y pantallas táctiles ───────── */
.t-hint { margin: 0; color: var(--text-3); font-size: 12.5px; }
.main:has(#grid[hidden]) .t-hint { display: none !important; }
#grid { touch-action: manipulation; }
@media (max-width: 700px) {
  .top-mid { display: flex; width: 100%; gap: 6px; }
  .top-mid .btn { flex: 1; justify-content: center; padding: 0 8px; }
  .topbar .top-actions { margin-left: auto; }
  .filter-add .btn { flex: 1 1 100%; justify-content: center; }
  .edit-tools { width: 100%; }
  .edit-tools .btn { flex: 1; justify-content: center; }
  .table-area { min-height: 55vh; }
}
:root[data-input="touch"] .grid th { height: 44px; }
:root[data-input="touch"] .grid td { height: 42px; font-size: 14px; }
:root[data-input="touch"] .search input { height: 42px; font-size: 16px; }
:root[data-input="touch"] .search kbd { display: none; }
:root[data-input="touch"] .filter-add .input { height: 42px; max-width: none; font-size: 16px; }
:root[data-input="touch"] .grid td.editing { font-size: 16px; }
:root[data-input="touch"] .search .ic { top: 14px; }
.cell-nav { display: flex; gap: 8px; }
.cell-nav .btn { flex: 1; justify-content: center; }
#cellVal { min-height: 96px; resize: vertical; }

/* Herramientas: gráfico, tabla dinámica, columna calculada, unir, duplicados */
.x-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.x-tools .btn { justify-content: flex-start; min-width: 0; }
.x-tools .btn:last-child:nth-child(odd) { grid-column: span 2; }
.x-tools .fx { font-style: italic; font-family: Georgia, serif; font-size: 14px; margin-right: 2px; }
.x-modal { width: min(900px, 100%); max-height: 92dvh; overflow: auto; }
.x-modal.sm2 { width: min(620px, 100%); }
.x-modal .modal-h { gap: 10px; }
.x-seg { margin-bottom: 10px; flex-wrap: wrap; }
.x-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 10px; margin-bottom: 10px; }
.x-form [hidden] { display: none; }
.ch-out { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--panel); }
.ch-out svg { display: block; width: 100%; height: auto; }
.fx-ins { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 6px 0; }
.fx-ins > span:not(.muted) { display: contents; }
.chip-btn { min-height: 26px; padding: 0 8px; border: 1px solid var(--border); border-radius: 99px; background: var(--bg); color: var(--text); font: inherit; font-size: 12px; cursor: pointer; }
.chip-btn:hover { border-color: var(--accent); }
#fxExpr { width: 100%; font-size: 13.5px; resize: vertical; }
.err-line { margin: 6px 0; color: var(--danger, #d33); font-size: 13px; }
.pv-wrap { max-height: 52dvh; overflow: auto; }
.tbl.pv th, .tbl.pv td { white-space: nowrap; }
.tbl.pv thead th { position: sticky; top: 0; background: var(--panel); }
.tbl.pv tfoot td, .tbl.pv tfoot th, .tbl.pv .tot { font-weight: 600; }
.tbl.pv tbody th { text-align: left; font-weight: 500; }
.jn-pick { align-items: center; gap: 10px; margin-bottom: 10px; }
:root[data-input="touch"] .chip-btn { min-height: 36px; padding: 0 12px; }
:root[data-input="touch"] #fxExpr, :root[data-input="touch"] #jnPaste { font-size: 16px; }
