/* ==========================================================
   MetaCell — estilos propios (sobre shared/meta.css).
   La hoja (papel) sigue blanca en modo oscuro, como en Pages.
   ========================================================== */

/* ---------- Zona principal ---------- */
.mc-main { flex-direction: column; background: var(--bg); }
.mc-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.mc-gridhost { position: relative; flex: 1; min-height: 0; }
.mc-main.mc-drop::after { content: "Suelta el archivo para abrirlo"; position: absolute; inset: 10px; z-index: 50; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: var(--r-lg); background: color-mix(in srgb, var(--accent) 10%, var(--glass)); color: var(--accent); font-size: 16px; font-weight: 600; pointer-events: none; }

/* ---------- Rejilla ---------- */
.mc-grid { position: absolute; inset: 0; overflow: hidden; background: #fff; user-select: none; -webkit-user-select: none; }
.mc-canvas { position: absolute; left: 0; top: 0; display: block; }
.mc-scroll { position: absolute; inset: 0; overflow: auto; z-index: 2; cursor: cell; touch-action: pan-x pan-y; outline: none; scrollbar-color: rgba(0, 0, 0, .28) transparent; }
.mc-scroll::-webkit-scrollbar-thumb { background-color: rgba(0, 0, 0, .25); }
.mc-scroll::-webkit-scrollbar-track { background: rgba(0, 0, 0, .025); }
.mc-spacer { width: 1px; height: 1px; pointer-events: none; }
body.mc-brush .mc-scroll { cursor: copy; }

/* Gráficos e imágenes */
.mc-layer { position: absolute; left: 0; top: 0; z-index: 3; overflow: hidden; pointer-events: none; }
.mc-layer-in { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.mc-obj { position: absolute; left: 0; top: 0; pointer-events: auto; background: #fff; border-radius: 10px; box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 6px 22px -10px rgba(0, 0, 0, .28), 0 0 0 .5px rgba(0, 0, 0, .1); cursor: move; outline: none; transition: box-shadow var(--fast) var(--ease); }
.mc-obj canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; border-radius: 10px; }
.mc-obj.image { background: transparent; box-shadow: none; }
.mc-obj img { width: 100%; height: 100%; display: block; object-fit: fill; border-radius: 2px; pointer-events: none; }
.mc-obj.on { box-shadow: 0 0 0 2px var(--accent), 0 10px 30px -12px rgba(0, 0, 0, .35); }
.mc-h { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1.5px var(--accent), 0 1px 3px rgba(0, 0, 0, .25); opacity: 0; pointer-events: none; transition: opacity var(--fast) var(--ease); }
.mc-obj.on .mc-h { opacity: 1; pointer-events: auto; }
.mc-h.nw { left: 0; top: 0; cursor: nwse-resize; } .mc-h.n { left: 50%; top: 0; cursor: ns-resize; } .mc-h.ne { left: 100%; top: 0; cursor: nesw-resize; }
.mc-h.e { left: 100%; top: 50%; cursor: ew-resize; } .mc-h.se { left: 100%; top: 100%; cursor: nwse-resize; } .mc-h.s { left: 50%; top: 100%; cursor: ns-resize; }
.mc-h.sw { left: 0; top: 100%; cursor: nesw-resize; } .mc-h.w { left: 0; top: 50%; cursor: ew-resize; }

/* Controlador de relleno */
.mc-handle { position: absolute; left: 0; top: 0; z-index: 4; width: 9px; height: 9px; margin: -5px 0 0 -5px; border-radius: 2px; background: var(--accent); box-shadow: 0 0 0 1.5px #fff; cursor: crosshair; touch-action: none; transition: transform 0s; }
.mc-grid.touch .mc-handle { width: 24px; height: 24px; margin: -12px 0 0 -12px; border-radius: 50%; background: transparent; box-shadow: none; }
.mc-grid.touch .mc-handle::after { content: ""; position: absolute; left: 6px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2.5px var(--accent), 0 2px 6px rgba(0, 0, 0, .25); }

/* Editor en la celda (y receptor del teclado) */
.mc-edwrap { position: absolute; left: 0; top: 0; z-index: 5; width: 20px; height: 20px; background: var(--fill, #fff); box-shadow: 0 0 0 2px var(--accent), 0 6px 20px -8px rgba(0, 0, 0, .35); border-radius: 1px; overflow: hidden; }
.mc-edwrap.sink { opacity: 0; pointer-events: none; box-shadow: none; }
.mc-ed, .mc-ed-hl { position: absolute; inset: 0; margin: 0; border: 0; padding: 2px 4px; font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif; line-height: 1.25; white-space: pre-wrap; word-break: break-word; overflow: hidden; letter-spacing: 0; tab-size: 4; }
.mc-ed { width: 100%; height: 100%; resize: none; background: transparent; color: var(--ink, #1d1d1f); outline: none; caret-color: #1d1d1f; }
.mc-edwrap .mc-ed { color: #1d1d1f; }
.mc-ed-hl { color: #1d1d1f; pointer-events: none; display: none; }
.mc-edwrap.formula .mc-ed-hl { display: block; }
.mc-edwrap.formula .mc-ed { color: transparent; -webkit-text-fill-color: transparent; }

/* Avisos sobre la rejilla */
.mc-tip { position: absolute; left: 0; top: 0; z-index: 8; max-width: 300px; padding: 7px 10px; border-radius: 9px; background: var(--glass-strong); backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%); box-shadow: var(--shadow-pop); color: var(--ink); font-size: 12.5px; line-height: 1.4; white-space: pre-wrap; pointer-events: none; opacity: 0; transition: opacity var(--fast) var(--ease); }
.mc-tip.on { opacity: 1; }
.mc-tip.note { background: #fffbe0; color: #3a3a3c; box-shadow: 0 0 0 .5px rgba(150, 120, 0, .35), 0 8px 24px -10px rgba(0, 0, 0, .35); }
.mc-guide { position: absolute; left: 0; top: 0; z-index: 7; pointer-events: none; display: none; }
.mc-guide.on { display: block; }
.mc-guide.col { width: 0; height: 100%; border-left: 1.5px dashed var(--accent); }
.mc-guide.row { height: 0; width: 100%; border-top: 1.5px dashed var(--accent); }

/* ---------- Barra de herramientas ---------- */
.mc-toolbar .mc-font { width: 150px; }
.mc-toolbar .mc-size { width: 56px; padding: 0 6px; text-align: center; }
.mc-toolbar .mc-numfmt { width: 128px; }

/* ---------- Barra de fórmulas ---------- */
.mc-fbar { display: flex; align-items: flex-start; gap: 4px; padding: 5px 10px; background: var(--surface); border-bottom: .5px solid var(--line); position: relative; z-index: 19; }
.mc-namebox { flex: 0 0 auto; width: 104px; height: 28px; padding: 0 8px; border: 0; border-radius: var(--r-sm); background: var(--surface-2); box-shadow: inset 0 0 0 .5px var(--line); font-family: var(--mono); font-size: 12.5px; color: var(--ink); outline: none; }
.mc-namebox:focus { box-shadow: 0 0 0 3px var(--accent-soft), inset 0 0 0 1px var(--accent); background: var(--surface); }
.mc-fbar .mo-tool { height: 28px; min-width: 28px; }
.mc-barwrap { position: relative; flex: 1; min-width: 0; height: 28px; }
.mc-fbar.tall .mc-barwrap { height: 104px; }
.mc-bar, .mc-bar-hl { position: absolute; inset: 0; margin: 0; padding: 5px 9px; border: 0; border-radius: var(--r-sm); font-family: var(--mono); font-size: 13px; line-height: 18px; white-space: pre-wrap; word-break: break-all; overflow: auto; }
.mc-bar { resize: none; background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 .5px var(--line); outline: none; }
.mc-bar:focus { background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft), inset 0 0 0 1px var(--accent); }
.mc-bar.formula { background: transparent; color: transparent; -webkit-text-fill-color: transparent; caret-color: var(--ink); }
.mc-bar-hl { pointer-events: none; color: var(--ink); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft), inset 0 0 0 1px var(--accent); scrollbar-width: none; }
.mc-bar-hl::-webkit-scrollbar { display: none; }
.mc-fbar:not(.tall) .mc-bar, .mc-fbar:not(.tall) .mc-bar-hl { white-space: pre; overflow: hidden; }

/* ---------- Pestañas de hojas ---------- */
.mc-tabsbar { flex: 0 0 auto; display: flex; align-items: center; gap: 2px; height: 36px; padding: 0 8px; background: var(--surface-2); border-top: .5px solid var(--line); }
.mc-tabsbar > .mo-tool { flex: 0 0 auto; }
.mc-tabs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 3px; overflow-x: auto; scrollbar-width: none; padding: 3px 2px; }
.mc-tabs::-webkit-scrollbar { display: none; }
.mc-tab { --tab: transparent; position: relative; flex: 0 0 auto; max-width: 200px; height: 26px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-2); font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--mid) var(--spring); touch-action: none; }
.mc-tab span { pointer-events: none; }
.mc-tab::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: 2px; height: 3px; border-radius: 3px; background: var(--tab); }
.mc-tab:hover { background: var(--hover); color: var(--ink); }
.mc-tab.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
.mc-tab.drag { z-index: 2; box-shadow: var(--shadow); transition: none; opacity: .9; }
.mc-tab-input { height: 26px; width: 140px; padding: 0 10px; border: 0; border-radius: 7px; background: var(--surface); box-shadow: 0 0 0 2px var(--accent); font-size: 12.5px; color: var(--ink); outline: none; }

/* ---------- Barra de estado ---------- */
.mc-stats { display: flex; gap: 14px; align-items: center; }
.mc-stats b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.mc-mode { padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mo-statusbar .mo-zoom button { min-width: 22px; }

/* ---------- Autocompletar y ayuda de argumentos ---------- */
.mc-ac { position: fixed; z-index: 1200; width: 320px; max-height: 280px; overflow-y: auto; padding: 4px; border-radius: var(--r); background: var(--glass-strong); backdrop-filter: blur(28px) saturate(180%); -webkit-backdrop-filter: blur(28px) saturate(180%); box-shadow: var(--shadow-pop); animation: mo-pop var(--mid) var(--spring); }
.mc-ac-item { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; padding: 5px 9px; border: 0; border-radius: 6px; background: transparent; text-align: left; color: var(--ink); }
.mc-ac-item b { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.mc-ac-item small { font-size: 11px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.mc-ac-item.on, .mc-ac-item:hover { background: var(--accent); color: var(--accent-ink); }
.mc-ac-item.on small, .mc-ac-item:hover small { color: inherit; opacity: .85; }
.mc-hint { position: fixed; z-index: 1199; max-width: 380px; padding: 7px 11px; border-radius: 9px; background: var(--glass-strong); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); box-shadow: var(--shadow-pop); font-size: 12px; pointer-events: none; }
.mc-hint .sig { font-family: var(--mono); font-size: 12px; color: var(--ink); }
.mc-hint .sig b { color: var(--accent); }
.mc-hint .d { margin-top: 2px; color: var(--ink-2); }

/* ---------- Diálogos ---------- */
.mc-pane { min-height: 120px; }
.mc-numgrid { display: grid; grid-template-columns: 170px 1fr; gap: 10px; }
.mc-numgrid select[size] { height: 210px; padding: 4px; background-image: none; }
.mc-preview { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; padding: 10px 14px; border-radius: var(--r); background: var(--surface-3); }
.mc-preview > span { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.mc-preview b { font-size: 15px; font-weight: 500; min-height: 20px; padding: 2px 8px; border-radius: 5px; font-variant-numeric: tabular-nums; }
.mc-preview.font b { font-weight: 400; }
.mc-colorpick { justify-content: flex-start; gap: 8px; font-family: var(--mono); font-size: 12px; }
.mc-colorpick .sw { width: 16px; height: 16px; border-radius: 4px; box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .25); background-image: linear-gradient(135deg, transparent 45%, rgba(255, 59, 48, .7) 45%, rgba(255, 59, 48, .7) 55%, transparent 55%); }
.mc-colorrow { display: flex; gap: 12px; }
.mc-rotv { min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.mc-bgrid { display: grid; grid-template-columns: repeat(6, 32px); gap: 4px; }
.mc-bgrid .mo-tool { width: 32px; height: 32px; }
.mc-bgrid.big { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); margin-bottom: 12px; }
.mc-bgrid.big .on { box-shadow: 0 0 0 2px var(--accent); }
.mo-swatches.big { grid-template-columns: repeat(10, 1fr); }
.mo-swatches.big .mo-swatch { width: auto; height: 26px; }
.mo-swatch.on { box-shadow: 0 0 0 2px var(--accent); }
.mc-borders .mo-popover-foot select { height: 26px; }
.mc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; max-height: 210px; overflow: auto; padding: 4px 0; }
.mc-t2c, .mc-csvprev { max-height: 230px; overflow: auto; margin-top: 10px; border-radius: var(--r-sm); box-shadow: inset 0 0 0 .5px var(--line); }
.mc-t2c td, .mc-csvprev td { white-space: nowrap; font-size: 12px; }
.mc-find-res { max-height: 200px; overflow: auto; margin-top: 6px; }
.mc-find-res .mo-list button { width: 100%; font-size: 12.5px; }
.mc-sortkey { align-items: end; }

/* Autofiltro */
.mc-filter-pop { padding: 10px; }
.mc-filter { width: 290px; display: grid; gap: 8px; }
.mc-filter-sort { display: flex; gap: 6px; }
.mc-filter-sort .mo-btn { flex: 1; }
.mc-filter-list { max-height: 220px; overflow: auto; padding: 2px 4px; border-radius: var(--r-sm); background: var(--surface); box-shadow: inset 0 0 0 .5px var(--line); }
.mc-filter-list .mo-check { padding: 3px 0; }
.mc-filter-list .mo-check span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-filter-list .mo-check small { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.mc-filter details summary { font-size: 12px; font-weight: 600; color: var(--ink-2); cursor: default; padding: 2px 0; }
.mc-filter details .mo-row { margin-top: 6px; flex-wrap: nowrap; }
.mc-filter details .mo-input { width: 100%; }
.mc-filter .mo-popover-foot { margin-top: 0; }

/* Asistente de funciones */
.mc-fx { display: grid; grid-template-columns: 250px 1fr; gap: 16px; min-height: 380px; }
.mc-fx-left { display: grid; grid-template-rows: auto auto 1fr; gap: 8px; min-height: 0; }
.mc-fx-list { overflow: auto; max-height: 330px; padding: 2px; border-radius: var(--r-sm); background: var(--surface-2); box-shadow: inset 0 0 0 .5px var(--line); }
.mc-fx-list button { font-family: var(--mono); font-size: 12.5px; padding: 4px 9px; }
.mc-fx-right h3 { margin: 2px 0 6px; font-size: 16px; font-family: var(--mono); }
.mc-fx-right .sig { display: block; padding: 6px 9px; border-radius: 6px; background: var(--surface-3); font-size: 12px; overflow-x: auto; white-space: nowrap; }
.mc-fx-right .ds { margin: 8px 0 10px; }
.mc-fx-right .args { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; max-height: 190px; overflow: auto; }
.mc-fx-right .args .mo-field { margin-bottom: 8px; }
.mc-fx-right [name=formula] { font-family: var(--mono); }

/* Asistente de gráficos */
.mc-ctypes { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-bottom: 14px; }
.mc-ctype { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 2px 6px; border: 0; border-radius: var(--r); background: var(--surface-3); font-size: 11.5px; color: var(--ink-2); transition: background var(--fast), box-shadow var(--fast), transform var(--mid) var(--spring); }
.mc-ctype svg { width: 26px; height: 26px; color: var(--ink); }
.mc-ctype:hover { transform: translateY(-2px); }
.mc-ctype.on { background: var(--accent-soft); color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.mc-ctype.on svg { color: var(--accent); }
.mc-cgrid { display: grid; grid-template-columns: 1fr 1.15fr; gap: 16px; }
.mc-cprev { position: relative; height: 330px; border-radius: var(--r-lg); background: #fff; box-shadow: var(--shadow); }
.mc-cprev canvas { position: absolute; inset: 8px; }
.mc-exopts { margin-top: 14px; }
.mc-exopts .mo-label { margin-bottom: 6px; display: block; }

/* ---------- Móvil ---------- */
@media (max-width: 760px) {
  .mc-fbar { padding: 4px 6px; gap: 2px; }
  .mc-namebox { width: 66px; padding: 0 6px; font-size: 12px; }
  .mc-fbar .mo-tool { min-width: 32px; height: 32px; }
  .mc-namebox, .mc-barwrap { height: 32px; }
  .mc-bar, .mc-bar-hl { font-size: 14px; line-height: 20px; padding: 6px 8px; }
  .mc-fbar.tall .mc-barwrap { height: 110px; }
  .mc-tabsbar { height: 40px; }
  .mc-tab { height: 30px; padding: 0 12px; }
  .mc-hide-sm { display: none; }
  .mc-stats { gap: 8px; }
  .mo-statusbar .mo-zoom input[type="range"] { display: none; }
  .mc-numgrid, .mc-fx, .mc-cgrid { grid-template-columns: 1fr; }
  .mc-numgrid select[size] { height: 120px; }
  .mc-fx-list { max-height: 180px; }
  .mc-fx-right .args { grid-template-columns: 1fr; }
  .mc-ctypes { grid-template-columns: repeat(4, 1fr); }
  .mc-cprev { height: 240px; }
  .mc-cols { grid-template-columns: 1fr; }
  .mc-filter { width: min(290px, calc(100vw - 40px)); }
  .mc-ac { width: min(320px, calc(100vw - 16px)); }
  .mc-toolbar .mc-font { width: 120px; }
}
.mo-dialog .mo-tabs { overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
.mo-dialog .mo-tabs::-webkit-scrollbar { display: none; }
.mo-dialog .mo-tabs button { flex: 0 0 auto; }
