/* csvexec — spreadsheet mode for .csv notes in exec view */

/* swap the CodeMirror editor for the grid while a .csv note is in exec view */
#csvexecPane { display: none; position: absolute; inset: 0; z-index: 3; background: var(--primary); }
body.csvexec-active #csvexecPane { display: block; }
body.csvexec-active .text-area-wrapper > .CodeMirror,
body.csvexec-active .text-area-wrapper > .note-textarea { visibility: hidden; pointer-events: none; }

.cx-root {
  position: absolute; inset: 0; display: flex; flex-direction: column; outline: none;
  background: var(--primary); color: var(--color);
  font-size: 13px;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  --cx-z: 1;                                   /* grid zoom — set from JS; only cells + headers use it, the toolbar never does */
}

/* toolbar */
.cx-toolbar { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--c-panel); border-bottom: 1px solid var(--c-border); }
.cx-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.cx-row-actions { overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
.cx-row-actions::-webkit-scrollbar { display: none; }
.cx-name { width: 74px; flex: 0 0 74px; text-align: center; }
.cx-name, .cx-fx {
  height: 32px; box-sizing: border-box; padding: 0 10px; border-radius: 10px;
  background: var(--c-panel-2); color: var(--color); border: 1px solid var(--c-border);
  font: inherit; outline: none; user-select: text; -webkit-user-select: text;
}
.cx-fx { flex: 1 1 auto; min-width: 0; resize: none; overflow: hidden; line-height: 30px; padding-top: 0; padding-bottom: 0; white-space: nowrap; }
.cx-name:focus, .cx-fx:focus { border-color: var(--c-accent); }
.cx-btn {
  flex: 0 0 auto; height: 32px; padding: 0 12px; border-radius: 10px; cursor: pointer;
  background: var(--c-panel-2); color: var(--color); border: 1px solid var(--c-border);
  font: inherit; font-size: 12.5px; white-space: nowrap;
}
.cx-btn:active { background: var(--c-panel-3); }
.cx-btn.on { background: var(--c-accent); color: var(--primary); border-color: var(--c-accent); }
.cx-sep { flex: 0 0 1px; align-self: stretch; margin: 4px 2px; background: var(--c-border); }
.cx-b { font-weight: 800; }
.cx-i { font-style: italic; font-family: serif; }
.cx-fxbtn { font-style: italic; font-weight: 600; width: 38px; padding: 0; }
.cx-status { margin-left: auto; padding-left: 8px; font-size: 12px; opacity: .65; white-space: nowrap; }
.cx-status.cx-busy { opacity: 1; color: var(--c-warn); }

/* grid */
.cx-scroller { position: relative; flex: 1 1 auto; min-height: 0; overflow: auto; scrollbar-width: thin; overscroll-behavior: contain; }
.cx-sizer { position: absolute; top: 0; left: 0; pointer-events: none; }
.cx-stage { position: sticky; top: 0; left: 0; overflow: hidden; touch-action: none; cursor: cell; }
.cx-cells, .cx-heads { position: absolute; inset: 0; pointer-events: none; }

.cx-c {
  position: absolute; box-sizing: border-box; padding: 0 calc(8px * var(--cx-z)); line-height: calc(29px * var(--cx-z)); font-size: calc(13px * var(--cx-z));
  border-right: 1px solid var(--c-border); border-bottom: 1px solid var(--c-border);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.cx-wr { white-space: pre-wrap; word-break: break-all; line-height: calc(18px * var(--cx-z)); padding-top: calc(5px * var(--cx-z)); text-overflow: clip; }
.cx-fz { background: var(--primary); }
.cx-fzr { border-right: 2px solid var(--c-accent) !important; }
.cx-fzb { border-bottom: 2px solid var(--c-accent) !important; }
.cx-cells-f { z-index: 1; }
.cx-fm { color: var(--c-green); }
.cx-err { color: var(--c-danger); }
.cx-pend { opacity: .45; }

.cx-corner, .cx-ch, .cx-rh {
  position: absolute; box-sizing: border-box; background: var(--c-panel); color: var(--color);
  border-right: 1px solid var(--c-border); border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: center; font-size: clamp(9px, calc(12px * var(--cx-z)), 16px); opacity: 1; overflow: hidden;
}
.cx-corner { left: 0; top: 0; z-index: 3; }
.cx-ch { top: 0; z-index: 2; }
.cx-rh { left: 0; z-index: 2; }
.cx-ch, .cx-rh { color: color-mix(in srgb, var(--color) 70%, transparent); }
.cx-ch.cx-hl, .cx-rh.cx-hl { background: var(--c-panel-3); color: var(--color); }
.cx-ch.cx-hw, .cx-rh.cx-hw { background: var(--c-accent); color: var(--primary); }

.cx-sel, .cx-active, .cx-fillprev, .cx-refbox { position: absolute; display: none; pointer-events: none; box-sizing: border-box; }
.cx-sel { background: color-mix(in srgb, var(--c-accent) 14%, transparent); border: 1px solid var(--c-accent); }
.cx-active { display: block; border: 2px solid var(--c-accent); }
.cx-fillprev { border: 2px dashed var(--c-accent); background: color-mix(in srgb, var(--c-accent) 8%, transparent); }
.cx-refbox { border: 2px dashed var(--c-warn); }
.cx-fh {
  position: absolute; width: 12px; height: 12px; background: var(--c-accent); border: 2px solid var(--primary);
  box-sizing: border-box; border-radius: 3px; cursor: crosshair; touch-action: none; z-index: 4;
}
.cx-fh::after { content: ""; position: absolute; inset: -4px; }
.cx-touch .cx-fh::after { inset: -9px; }
.cx-sh {
  display: none; position: absolute; width: 18px; height: 18px; border-radius: 50%; z-index: 3; touch-action: none;
  background: var(--c-accent); border: 2px solid var(--primary); box-sizing: border-box; box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.cx-sh::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; }
.cx-moveprev { position: absolute; display: none; pointer-events: none; box-sizing: border-box; border: 2px dashed var(--c-green); background: color-mix(in srgb, var(--c-green) 14%, transparent); z-index: 2; }
.cx-editor {
  position: absolute; display: none; z-index: 4; resize: none; overflow: hidden; box-sizing: border-box;
  background: var(--primary); color: var(--color); border: 2px solid var(--c-accent);
  font: inherit; font-size: calc(13px * var(--cx-z)); line-height: calc(18px * var(--cx-z)); padding: 0 calc(8px * var(--cx-z)); outline: none; user-select: text; -webkit-user-select: text; border-radius: 0;
}
.cx-editor::placeholder, .cx-fx::placeholder { color: color-mix(in srgb, var(--color) 40%, transparent); opacity: 1; }
.cx-heads { z-index: 5; }
.cx-sel, .cx-active, .cx-fillprev, .cx-refbox { z-index: 2; }

/* autocomplete */
.cx-suggest {
  display: none; position: absolute; z-index: 20; max-width: min(420px, calc(100% - 8px)); max-height: 240px; overflow-y: auto;
  background: var(--c-panel); border: 1px solid var(--c-border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.cx-sg { padding: 7px 10px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; border-bottom: 1px solid var(--c-border-soft); }
.cx-sg:last-child { border-bottom: 0; }
.cx-sg.on, .cx-sg:hover { background: var(--c-panel-3); }
.cx-sg b { font-weight: 600; font-size: 12.5px; }
.cx-sg span { font-size: 11.5px; opacity: .65; }

/* find & replace bar */
.cx-find { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.cx-find input { height: 32px; box-sizing: border-box; padding: 0 10px; border-radius: 10px; background: var(--c-panel-2); color: var(--color); border: 1px solid var(--c-border); font: inherit; outline: none; user-select: text; -webkit-user-select: text; min-width: 110px; flex: 1 1 110px; }
.cx-find input:focus { border-color: var(--c-accent); }
.cx-fcount { font-size: 12px; opacity: .7; white-space: nowrap; padding: 0 6px; }

/* ───────── zoom control (toolbar) ───────── */
.cx-zlbl { min-width: 58px; text-align: center; font-variant-numeric: tabular-nums; }
.cx-zoomtip {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 46; padding: 8px 18px; border-radius: 999px;
  background: color-mix(in srgb, var(--c-panel-2) 90%, transparent); color: var(--color); border: 1px solid var(--c-border);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); font-size: 15px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .22s;
}
.cx-zoomtip.show { opacity: 1; }

/* ───────── resize grip + selection circles on a selected row / column ───────── */
.cx-rg {
  --ic-h: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 12l5-5v4h10V7l5 5-5 5v-4H7v4z'/%3E%3C/svg%3E");
  --ic-v: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2l5 5h-4v10h4l-5 5-5-5h4V7H7z'/%3E%3C/svg%3E");
  display: none; position: absolute; z-index: 7; width: 26px; height: 26px; transform: translate(-50%, -50%); border-radius: 50%; box-sizing: border-box;
  align-items: center; justify-content: center; background: var(--c-panel-4); color: var(--color); border: 1px solid var(--c-border);
  box-shadow: 0 2px 8px rgba(0,0,0,.55); touch-action: none;
}
.cx-rg::before { content: ""; width: 16px; height: 16px; background: currentColor; -webkit-mask: var(--ic-h) center / contain no-repeat; mask: var(--ic-h) center / contain no-repeat; }
.cx-rg.cx-rgr::before { -webkit-mask-image: var(--ic-v); mask-image: var(--ic-v); }
.cx-rg::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; }
.cx-rgc { cursor: col-resize; } .cx-rgr { cursor: row-resize; }
.cx-hh {
  display: none; position: absolute; z-index: 7; width: 16px; height: 16px; transform: translate(-50%, -50%); border-radius: 50%; box-sizing: border-box;
  background: var(--c-accent); border: 2px solid var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.55); touch-action: none; cursor: grab;
}
.cx-hh::after { content: ""; position: absolute; inset: -14px; border-radius: 50%; }

/* ───────── floating action bar (tap inside the selection) ───────── */
.cx-pill {
  display: none; position: absolute; z-index: 45; max-width: calc(100% - 8px); overflow-x: auto; scrollbar-width: none; gap: 2px; padding: 4px; box-sizing: border-box;
  border-radius: 999px; background: color-mix(in srgb, var(--c-panel-2) 92%, transparent); color: var(--color);
  border: 1px solid color-mix(in srgb, var(--c-white) 8%, transparent); box-shadow: 0 10px 30px rgba(0,0,0,.5);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.cx-pill::-webkit-scrollbar { display: none; }
.cx-pill.open { display: flex; }
.cx-pb { flex: 0 0 auto; padding: 9px 13px; border: 0; border-radius: 999px; background: none; color: inherit; font: inherit; font-size: 13.5px; white-space: nowrap; cursor: pointer; }
.cx-pb:active, .cx-pb:hover { background: var(--c-panel-3); }
.cx-pm { font-weight: 800; font-size: 16px; padding: 7px 12px; }

/* ───────── desktop right-click popover ───────── */
.cx-menu {
  display: none; position: absolute; z-index: 40; min-width: 230px; max-width: calc(100% - 8px); max-height: 70%; overflow-y: auto; padding: 4px; border-radius: 12px;
  background: color-mix(in srgb, var(--c-panel) 88%, transparent); border: 1px solid color-mix(in srgb, var(--c-white) 8%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); box-shadow: 0 25px 50px -12px rgba(0,0,0,.6);
}
.cx-menu.open { display: block; }

/* menu rows / headings — used by the popover AND inside the site modal */
.cx-mi { display: flex; justify-content: space-between; align-items: center; gap: 16px; width: 100%; box-sizing: border-box; padding: 11px 12px; text-align: left; background: none; border: 0; border-radius: 8px; color: var(--color); font: inherit; font-size: 13.5px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.cx-mi:hover, .cx-mi:active { background: var(--c-panel-3); }
.cx-mi em { font-style: normal; font-size: 11px; opacity: .5; }
.cx-mi.danger { color: var(--c-danger); }
.cx-msep { height: 1px; margin: 4px 6px; background: var(--c-border); }
.cx-mh { padding: 8px 12px 4px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .6; }

/* ───────── content that lives inside the site modal (top-aligned, same look as every other dialog) ───────── */
.modal-body .cx-mlist, .modal-body .cx-pk { margin: -4px; }
.cx-pal { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; padding: 4px 4px 10px; max-width: 460px; }
.cx-sw { aspect-ratio: 1; min-height: 28px; border-radius: 8px; border: 1px solid var(--c-border); cursor: pointer; }
.cx-pk { display: flex; flex-direction: column; min-height: 0; }
.cx-pk-search { margin-top: 0 !important; }
.cx-pk-list { max-height: 58dvh; overflow-y: auto; margin-top: 8px; padding-bottom: 6px; overscroll-behavior: contain; }
.cx-pcat { position: sticky; top: 0; padding: 8px 10px 4px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .7; background: color-mix(in srgb, var(--c-panel-2) 96%, transparent); }
.cx-pfn { padding: 9px 10px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; border-radius: 8px; }
.cx-pfn:hover, .cx-pfn:active { background: var(--c-panel-3); }
.cx-pfn b { font-weight: 600; font-size: 13px; }
.cx-pfn span { font-size: 12px; opacity: .65; }
.cx-pempty { padding: 24px; text-align: center; opacity: .6; }
.cx-zpre { display: flex; flex-wrap: wrap; gap: 8px; }
.cx-zpre .modal-btn { flex: 1 1 64px; }
.cx-zrow { display: flex; align-items: center; gap: 10px; }
.cx-zrow input { margin-top: 0 !important; max-width: 140px; }
.cx-zrow span { font-size: 13px; opacity: .65; }

/* Read mode (bottom bar → Read): nothing can be changed, so the editing controls disappear */
.cx-readonly .cx-fh,
.cx-readonly .cx-fxbtn,
.cx-readonly [data-a="undo"], .cx-readonly [data-a="redo"],
.cx-readonly [data-a="cut"], .cx-readonly [data-a="paste"], .cx-readonly [data-a="clear"],
.cx-readonly [data-a="bold"], .cx-readonly [data-a="italic"], .cx-readonly [data-a="wrap"],
.cx-readonly [data-a="al-l"], .cx-readonly [data-a="al-c"], .cx-readonly [data-a="al-r"],
.cx-readonly [data-a="tc"], .cx-readonly [data-a="bg"], .cx-readonly [data-a="filldown"],
.cx-readonly .cx-rg, .cx-readonly .cx-hh { display: none !important; }
.cx-readonly .cx-fx { cursor: default; opacity: .85; }
.cx-readonly .cx-row-actions .cx-sep:nth-of-type(1), .cx-readonly .cx-row-actions .cx-sep:nth-of-type(3) { display: none; }

/* leave room for the Read / Design bar floating at the bottom */
body.execbar-on #csvexecPane { bottom: calc(var(--diff-topbar-height, 70px) + var(--diff-topbar-gap, 2vh) + 10px); }

/* ── filter ── */
.cx-flh { background: color-mix(in srgb, var(--c-accent) 14%, var(--c-panel, transparent)); font-weight: 600; }
.cx-fb { position: absolute; right: calc(3px * var(--cx-z)); top: 50%; transform: translateY(-50%); width: calc(17px * var(--cx-z)); height: calc(17px * var(--cx-z)); line-height: calc(17px * var(--cx-z));
  text-align: center; font-size: calc(10px * var(--cx-z)); border-radius: 3px; background: var(--c-panel-3); color: var(--color); cursor: pointer; font-weight: 400; }
.cx-fb.on { background: var(--c-accent); color: var(--primary); }
.cx-rh.cx-rfl { color: var(--c-accent); }
.cx-flt { display: flex; flex-direction: column; gap: 8px; min-width: min(360px, 80vw); }
.cx-flt .cx-fl { font-size: 12px; opacity: .7; margin-top: 4px; }
.cx-flt .cx-fsort { display: flex; gap: 8px; }
.cx-flt .cx-fsort button, .cx-flt .cx-fall button { flex: 1; padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 6px; background: var(--c-panel-3); color: var(--color); cursor: pointer; }
.cx-flt .cx-fall { display: flex; gap: 8px; align-items: center; }
.cx-flt .cx-fall button { flex: 0 0 auto; padding: 4px 10px; }
.cx-flt .cx-fcnt { margin-left: auto; font-size: 12px; opacity: .7; }
.cx-flt select, .cx-flt input[type=text], .cx-flt .cx-fa, .cx-flt .cx-fb2, .cx-flt .cx-fs { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 6px; background: var(--c-panel-3); color: var(--color); font: inherit; }
.cx-flt .cx-fin { display: flex; flex-direction: column; gap: 6px; }
.cx-flt .cx-flist { max-height: 38vh; overflow: auto; border: 1px solid var(--c-border); border-radius: 6px; }
.cx-flt .cx-fv { display: flex; align-items: center; gap: 10px; padding: 7px 10px; cursor: pointer; }
.cx-flt .cx-fv span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-flt .cx-fv em { font-style: normal; font-size: 12px; opacity: .6; }
