/* Jadwal — interface styles (title bar, ribbon, formula bar, grid, sheet tabs, status bar, menus, dialogs, File tab).
 * Logical properties (inline-start/end) make the whole interface mirror automatically for right-to-left (Arabic).
 * Same structure as Qalam's ui.css, with Excel's green. The grid itself is drawn on a canvas (grid/render.ts) using
 * the --cell-* / --grid-* / --hdr-* colours below. */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Arabic", "Segoe UI", "Geeza Pro", Tahoma, Arial, sans-serif;
  --accent: #217346; --accent-hover: #1a5c38; --accent-text: #1d6b40; --accent-weak: #d5e8dc; --accent-dark: #185c37;
  --ic-accent: #217346;
  --titlebar-bg: #217346; --titlebar-fg: #fff;
  --chrome-bg: #f3f3f3; --ribbon-bg: #ffffff; --sep: #e1dfdd;
  --fg: #242424; --fg-muted: #616161;
  --hover: #ebebeb; --pressed: #e0e0e0; --checked: #d9ecdf; --checked-border: #a9d1b7;
  --menu-bg: #fff; --menu-border: #d6d6d6; --menu-shadow: 0 8px 24px rgba(0,0,0,.16);
  --input-bg: #fff; --input-border: #c8c8c8; --btn-bg: #fff; --btn-border: #c8c8c8; --bs-bg: #fff;
  /* grid (read by the canvas renderer) */
  --cell-bg: #ffffff; --cell-fg: #000000; --grid-line: #dadcdf;
  --hdr-bg: #f5f5f5; --hdr-fg: #444444; --hdr-line: #d0d0d0; --hdr-sel: #dcebe2; --hdr-sel-fg: #185c37; --hdr-full: #c4ddcd;
  --grid-accent: #217346; --sel-fill: rgba(33,115,70,0.11); --frozen-line: #a8a8a8; --filter-bg: #ffffff;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --accent: #3c9a62; --accent-hover: #4aab71; --accent-text: #8fd4a9; --accent-weak: #284033; --accent-dark: #1d3a2a;
  --ic-accent: #8fd4a9;
  --titlebar-bg: #1d3a2a;
  --chrome-bg: #1f1f1f; --ribbon-bg: #2b2b2b; --sep: #3d3d3d;
  --fg: #f0f0f0; --fg-muted: #b3b3b3;
  --hover: #3a3a3a; --pressed: #454545; --checked: #2f4a3a; --checked-border: #457a5a;
  --menu-bg: #2b2b2b; --menu-border: #474747; --menu-shadow: 0 8px 24px rgba(0,0,0,.5);
  --input-bg: #1e1e1e; --input-border: #565656; --btn-bg: #333; --btn-border: #565656; --bs-bg: #242424;
  --cell-bg: #1e1e1e; --cell-fg: #e8e8e8; --grid-line: #383838;
  --hdr-bg: #2a2a2a; --hdr-fg: #c8c8c8; --hdr-line: #444444; --hdr-sel: #2f4537; --hdr-sel-fg: #8fd4a9; --hdr-full: #3b5a46;
  --grid-accent: #4fb37b; --sel-fill: rgba(79,179,123,0.16); --frozen-line: #6a6a6a; --filter-bg: #2b2b2b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font: 13px/1.35 var(--font-ui); color: var(--fg); background: var(--chrome-bg); -webkit-font-smoothing: antialiased; }
html[lang="ar"] body { font-size: 13.5px; }
button { font-family: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#app { display: flex; flex-direction: column; height: 100vh; position: relative; }
.ic { width: 18px; height: 18px; flex: none; display: block; direction: ltr; }
.ic .f { fill: currentColor; stroke: none; }
.ic .a { stroke: var(--ic-accent); }
.ic .af { fill: var(--ic-accent); stroke: none; }
.ic .w { fill: var(--ribbon-bg); }
.ic .rd { stroke: #d13438; }
.ic .gr { stroke: #107c10; }
.ic .pf { fill: #e3008c; stroke: none; }
.ic text { fill: currentColor; stroke: none; }
.ic .at { fill: var(--ic-accent); }
.ic .rt { fill: #c43e1c; }
[dir="rtl"] .ic.flip { transform: scaleX(-1); }

/* ---------------- title bar (browser only; the Mac app has its own) ---------------- */
#titlebar { height: 38px; flex: none; display: flex; align-items: center; padding: 0 8px; background: var(--titlebar-bg); color: var(--titlebar-fg); user-select: none; -webkit-user-select: none; }
.tb-side { flex: 1 1 0; display: flex; align-items: center; gap: 6px; min-width: 0; }
.tb-end { justify-content: flex-end; }
.tb-center { flex: 0 1 auto; min-width: 0; padding: 0 12px; }
.tb-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.tb-title.dirty::after { content: " •"; opacity: .8; }
.app-logo { width: 20px; height: 20px; background: url(../img/icon.svg) center / contain no-repeat; margin-inline-end: 4px; }
.qat { display: flex; align-items: center; gap: 2px; }
.qbtn { width: 30px; height: 28px; display: flex; align-items: center; justify-content: center; border: none; background: none; color: inherit; border-radius: 5px; padding: 0; }
.qbtn:hover:not(:disabled) { background: rgba(255,255,255,.16); }
.qbtn:disabled { opacity: .45; }
.qbtn .ic { width: 17px; height: 17px; }
.cmd-search { width: min(320px, 34vw); height: 26px; display: flex; align-items: center; gap: 6px; padding: 0 8px; border-radius: 6px; background: rgba(255,255,255,.92); color: #333; }
:root[data-theme="dark"] .cmd-search { background: rgba(255,255,255,.12); color: #eee; }
.cmd-search .search-icon .ic { width: 14px; height: 14px; opacity: .7; }
.search-input { flex: 1; min-width: 0; border: none; background: transparent; font: inherit; font-size: 12.5px; color: inherit; outline: none; }
.search-input::placeholder { color: inherit; opacity: .6; }
body.native #titlebar { display: none; }
body.native .cmd-search { width: 220px; height: 24px; margin-bottom: 4px; align-self: center; background: var(--input-bg); color: var(--fg); border: 1px solid var(--input-border); }
.qat.in-tabbar { margin-inline-end: 6px; padding-inline-end: 6px; border-inline-end: 1px solid var(--sep); align-self: center; }
.qat.in-tabbar .qbtn { color: var(--fg); width: 28px; height: 26px; }
.qat.in-tabbar .qbtn:hover:not(:disabled) { background: var(--hover); }

/* ---------------- tabs ---------------- */
#tabbar { height: 34px; flex: none; display: flex; align-items: flex-end; gap: 2px; padding: 0 8px; background: var(--chrome-bg); user-select: none; -webkit-user-select: none; }
.tab { height: 30px; padding: 0 11px; border: none; background: none; color: var(--fg); font-size: 13px; border-radius: 5px 5px 0 0; position: relative; white-space: nowrap; cursor: default; }
html[lang="ar"] .tab { font-size: 13.5px; }
.tab:hover { background: var(--hover); }
.tab.active { color: var(--accent-text); font-weight: 600; }
.tab.active::after { content: ""; position: absolute; inset-inline: 10px; bottom: 3px; height: 3px; border-radius: 2px; background: var(--accent); }
.tab-file { color: var(--accent-text); font-weight: 600; }
.tab-spacer { flex: 1; }
.tab-collapse { width: 28px; height: 26px; margin-bottom: 3px; border: none; background: none; color: var(--fg-muted); border-radius: 5px; display: flex; align-items: center; justify-content: center; padding: 0; }
.tab-collapse:hover { background: var(--hover); }
.tab-collapse .ic { width: 14px; height: 14px; }
body.ribbon-collapsed .tab-collapse .ic { transform: rotate(180deg); }

/* ---------------- ribbon ---------------- */
#ribbon { height: 98px; flex: none; display: flex; margin: 0 6px 6px; background: var(--ribbon-bg); border-radius: 8px; box-shadow: 0 0 0 1px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.12); overflow: hidden; user-select: none; -webkit-user-select: none; }
body.ribbon-collapsed #ribbon { display: none; }
body.ribbon-collapsed.ribbon-peek #ribbon { display: flex; position: absolute; top: 72px; inset-inline: 0; z-index: 60; box-shadow: var(--menu-shadow); }
body.native.ribbon-collapsed.ribbon-peek #ribbon { top: 34px; }
.rpanel { display: none; flex: 1; align-items: stretch; padding: 4px 2px 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.rpanel::-webkit-scrollbar { display: none; }
.rpanel.active { display: flex; }
.rgroup { display: flex; flex-direction: column; flex: none; padding: 0 6px; position: relative; }
.rgroup + .rgroup { border-inline-start: 1px solid var(--sep); }
.rgroup-body { flex: 1; display: flex; align-items: flex-start; gap: 2px; padding-top: 1px; }
.rgroup-label { height: 18px; line-height: 16px; font-size: 11px; color: var(--fg-muted); text-align: center; white-space: nowrap; padding: 0 16px; }
.rlauncher { position: absolute; bottom: 2px; inset-inline-end: 3px; width: 16px; height: 16px; padding: 0; border: none; background: none; color: var(--fg-muted); border-radius: 3px; display: flex; align-items: center; justify-content: center; }
.rlauncher:hover { background: var(--hover); color: var(--fg); }
.rlauncher .ic { width: 11px; height: 11px; }
.rbtn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 26px; min-width: 26px; padding: 0 4px; border: 1px solid transparent; border-radius: 4px; background: none; color: var(--fg); font-size: 12px; white-space: nowrap; position: relative; cursor: default; }
html[lang="ar"] .rbtn { font-size: 12.5px; }
.rbtn:hover:not(:disabled) { background: var(--hover); }
.rbtn:active:not(:disabled), .rbtn.open { background: var(--pressed); }
.rbtn.on { background: var(--checked); border-color: var(--checked-border); }
.rbtn:disabled, .rbtn.disabled { opacity: .38; }
.rbtn-icon { display: flex; align-items: center; justify-content: center; flex: none; }
.rbtn.big { flex-direction: column; justify-content: flex-start; height: 74px; min-width: 52px; max-width: 90px; padding: 4px 4px 2px; gap: 3px; }
.rbtn.big .ic { width: 32px; height: 32px; stroke-width: 1.15; }
.rbtn.big .rbtn-label { white-space: normal; text-align: center; line-height: 1.15; max-width: 86px; }
.rbtn .caret { display: flex; }
.rbtn .caret .ic { width: 10px; height: 10px; stroke-width: 2; }
.rbtn.big.dd .caret { margin-top: -2px; }
.rbtn.labeled { justify-content: flex-start; padding-inline: 4px 7px; }
.rcol { display: flex; flex-direction: column; gap: 0; padding-top: 0; }
.rcol > .rbtn, .rcol > .rsplit > .rbtn { height: 25px; }
.rcol > .rbtn, .rcol > .rsplit { width: 100%; justify-content: flex-start; }
.rrows { display: flex; flex-direction: column; gap: 5px; padding-top: 3px; }
.rrow { display: flex; align-items: center; gap: 1px; }
.rsep { width: 1px; height: 20px; background: var(--sep); margin: 0 4px; flex: none; }
.rsplit { display: inline-flex; align-items: stretch; border-radius: 4px; }
.rsplit > .rbtn { border-radius: 0; }
.rsplit > .rbtn:first-child { border-start-start-radius: 4px; border-end-start-radius: 4px; }
.rsplit > .rbtn:last-child { border-start-end-radius: 4px; border-end-end-radius: 4px; }
.rsplit:hover > .rbtn:not(:disabled) { border-color: var(--sep); }
.rsplit .rarrow { min-width: 14px; width: 14px; padding: 0; }
.rsplit .rarrow .ic { width: 10px; height: 10px; stroke-width: 2; }
.rsplit.big { flex-direction: column; }
.rsplit.big > .rbtn.big { height: 54px; border-radius: 4px 4px 0 0; }
.rsplit.big > .rarrow { width: auto; height: 20px; border-radius: 0 0 4px 4px; }
.rsplit.labeled > .rbtn.labeled { flex: 1; }
.color-btn .rbtn-icon { flex-direction: column; gap: 0; }
.cbar { display: block; width: 16px; height: 4px; margin-top: -2px; border-radius: 1px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.rcombo { display: inline-flex; align-items: center; height: 24px; border: 1px solid var(--input-border); border-radius: 4px; background: var(--input-bg); margin-inline-end: 2px; }
.rcombo:hover { border-color: var(--fg-muted); }
.rcombo:focus-within { border-color: var(--accent); }
.rcombo-input { height: 100%; border: none; background: transparent; padding: 0 6px; font: inherit; font-size: 12px; color: var(--fg); outline: none; min-width: 0; }
.rcombo-arrow { width: 18px; height: 100%; border: none; background: none; color: var(--fg-muted); padding: 0; display: flex; align-items: center; justify-content: center; }
.rcombo-arrow .ic { width: 10px; height: 10px; stroke-width: 2; }
.rcombo.readonly .rcombo-input { cursor: default; caret-color: transparent; }
.rcheck { display: flex; align-items: center; gap: 6px; height: 23px; padding: 0 4px; font-size: 12.5px; white-space: nowrap; }
.rgroup.compact .rbtn.big { height: auto; min-width: 28px; max-width: none; padding: 3px; }
.rgroup.compact .rbtn.big .rbtn-label { display: none; }
.rgroup.compact .rbtn.big .ic { width: 22px; height: 22px; }
.rgroup.compact .rsplit.big > .rbtn.big { height: auto; }
.rgroup.compact .rgroup-label { padding: 0 4px; }
.rgroup.compact .rbtn.labeled .rbtn-label { display: none; }
.rgroup.compact .rcol > .rbtn, .rgroup.compact .rcol > .rsplit { width: auto; }
.rgroup.compact { padding: 0 3px; }

/* ---------------- formula bar ---------------- */
#formulabar { flex: none; display: flex; align-items: stretch; gap: 0; height: 30px; margin: 0 6px 4px; background: var(--ribbon-bg); border: 1px solid var(--sep); border-radius: 6px; overflow: hidden; }
#formulabar.expanded { height: 74px; }
body.no-formulabar #formulabar { display: none; }
.namebox { flex: none; width: 110px; display: flex; align-items: center; border-inline-end: 1px solid var(--sep); }
.nb-input { width: 100%; height: 100%; border: none; background: transparent; color: var(--fg); font: 12.5px var(--font-ui); padding: 0 8px; outline: none; direction: ltr; text-align: start; }
.nb-input:focus { background: var(--input-bg); box-shadow: inset 0 0 0 2px var(--accent); }
.fb-grip { width: 6px; flex: none; }
.fb-buttons { flex: none; display: flex; align-items: center; gap: 2px; padding: 0 4px; border-inline-end: 1px solid var(--sep); }
#formulabar.expanded .fb-buttons, #formulabar.expanded .namebox, #formulabar.expanded .fb-expand { align-items: flex-start; padding-top: 3px; }
.fb-btn { width: 24px; height: 22px; padding: 0; border: none; background: none; border-radius: 4px; color: var(--fg-muted); display: flex; align-items: center; justify-content: center; }
.fb-btn .ic { width: 14px; height: 14px; }
.fb-btn:hover:not(:disabled) { background: var(--hover); color: var(--fg); }
.fb-btn:disabled { opacity: .35; }
.fb-btn.fx .ic { width: 18px; height: 18px; }
.fb-field { flex: 1; min-width: 0; display: flex; }
.fb-input { flex: 1; min-width: 0; border: none; resize: none; background: transparent; color: var(--fg); font: 13px/20px Menlo, "SF Mono", Consolas, var(--font-ui); padding: 4px 8px; outline: none; white-space: pre; overflow: hidden; unicode-bidi: plaintext; text-align: start; }
#formulabar.expanded .fb-input { white-space: pre-wrap; overflow: auto; }
.fb-expand { flex: none; width: 22px; border: none; border-inline-start: 1px solid var(--sep); background: none; color: var(--fg-muted); display: flex; align-items: center; justify-content: center; padding: 0; }
.fb-expand .ic { width: 12px; height: 12px; stroke-width: 2; }
#formulabar.expanded .fb-expand .ic { transform: rotate(180deg); }
.fb-expand:hover { background: var(--hover); }

/* ---------------- grid ---------------- */
#gridwrap { flex: 1; position: relative; overflow: hidden; background: var(--cell-bg); border-top: 1px solid var(--sep); }
#grid-canvas { position: absolute; top: 0; left: 0; display: block; }
#grid-scroll { position: absolute; inset: 0; overflow: scroll; z-index: 1; background: transparent; outline: none; cursor: cell; overscroll-behavior: none; }
#grid-spacer { width: 1px; height: 1px; pointer-events: none; }
#grid-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
#cell-editor { position: absolute; z-index: 3; margin: 0; padding: 1px 4px 0; border: none; outline: none; resize: none; overflow: hidden; white-space: pre-wrap; word-wrap: break-word;
  background: var(--cell-bg); color: var(--cell-fg); opacity: 0; pointer-events: none; caret-color: var(--cell-fg); font: 14.67px Calibri, "Helvetica Neue", Arial, sans-serif; unicode-bidi: plaintext; }
#cell-editor.editing { opacity: 1; pointer-events: auto; box-shadow: 0 0 0 2px var(--grid-accent), 0 2px 8px rgba(0,0,0,.18); }
body.painting #grid-scroll { cursor: copy !important; }
.resize-guide { position: absolute; pointer-events: none; }
.resize-guide.v { border-inline-start: 1px dashed var(--grid-accent); }
.resize-guide.h { border-top: 1px dashed var(--grid-accent); }
.size-tip { position: fixed; z-index: 3000; padding: 3px 8px; background: var(--menu-bg); color: var(--fg); border: 1px solid var(--menu-border); border-radius: 4px; box-shadow: var(--menu-shadow); font-size: 11.5px; pointer-events: none; white-space: nowrap; }
/* function autocomplete and argument hint */
.ac-list { position: fixed; z-index: 2600; min-width: 220px; max-width: 360px; padding: 4px; background: var(--menu-bg); color: var(--fg); border: 1px solid var(--menu-border); border-radius: 6px; box-shadow: var(--menu-shadow); pointer-events: auto; font-size: 12.5px; }
.ac-item { display: flex; align-items: center; gap: 8px; height: 24px; padding: 0 6px; border-radius: 4px; cursor: default; direction: ltr; }
.ac-item.on { background: var(--checked); }
.ac-ic .ic { width: 14px; height: 14px; color: var(--accent-text); }
.ac-name { font-weight: 600; }
.ac-desc { margin-top: 4px; padding: 6px 6px 2px; border-top: 1px solid var(--sep); color: var(--fg-muted); font-size: 12px; line-height: 1.45; unicode-bidi: plaintext; }
.arg-hint { position: fixed; z-index: 2600; padding: 3px 8px; background: #fffde7; color: #333; border: 1px solid #d8d2a0; border-radius: 4px; font: 12px var(--font-ui); box-shadow: 0 2px 6px rgba(0,0,0,.15); pointer-events: none; direction: ltr; white-space: nowrap; }
:root[data-theme="dark"] .arg-hint { background: #3a3826; color: #eee; border-color: #6a6440; }

/* ---------------- sheet tabs ---------------- */
#sheetbar { height: 30px; flex: none; display: flex; align-items: stretch; background: var(--chrome-bg); border-top: 1px solid var(--sep); user-select: none; -webkit-user-select: none; }
.st-navs { display: flex; align-items: center; padding: 0 4px; gap: 1px; }
.st-nav { width: 22px; height: 22px; padding: 0; border: none; background: none; color: var(--fg-muted); border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.st-nav:hover { background: var(--hover); color: var(--fg); }
.st-nav .ic { width: 13px; height: 13px; }
.st-tabs { position: relative; display: flex; align-items: stretch; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; max-width: 70%; }
.st-tabs::-webkit-scrollbar { display: none; }
.st-tab { position: relative; flex: none; display: flex; align-items: center; padding: 0 16px; min-width: 64px; justify-content: center; font-size: 12.5px; color: var(--fg); cursor: default; border-inline-end: 1px solid var(--sep); }
.st-tab:hover { background: var(--hover); }
.st-tab.active { background: var(--ribbon-bg); color: var(--accent-text); font-weight: 600; box-shadow: inset 0 -3px 0 var(--accent); }
.st-tab.colored::after { content: ''; position: absolute; inset-inline: 0; bottom: 0; height: 4px; background: var(--tab-color); }
.st-tab.colored.active { box-shadow: inset 0 -3px 0 var(--tab-color); }
.st-tab.dragging { opacity: .55; }
.st-name { white-space: nowrap; }
.st-rename { width: 120px; height: 22px; border: 1px solid var(--accent); border-radius: 3px; background: var(--input-bg); color: var(--fg); font: inherit; padding: 0 4px; outline: none; }
.st-marker { position: absolute; top: 3px; bottom: 3px; width: 2px; background: var(--accent); pointer-events: none; }
.st-add { width: 30px; flex: none; border: none; background: none; color: var(--fg-muted); display: flex; align-items: center; justify-content: center; padding: 0; }
.st-add:hover { background: var(--hover); color: var(--accent-text); }
.st-add .ic { width: 15px; height: 15px; }
.st-space { flex: 1; }

/* ---------------- status bar ---------------- */
#statusbar { height: 26px; flex: none; display: flex; align-items: center; gap: 2px; padding: 0 8px; background: var(--chrome-bg); border-top: 1px solid var(--sep); font-size: 12px; color: var(--fg-muted); user-select: none; -webkit-user-select: none; }
.sb-item { height: 22px; line-height: 22px; padding: 0 8px; border: none; background: none; border-radius: 4px; font: inherit; color: inherit; white-space: nowrap; }
button.sb-item:hover, .sb-icon:hover { background: var(--hover); color: var(--fg); }
.sb-item b { color: var(--fg); font-weight: 600; }
.sb-mode { min-width: 60px; }
.sb-circ { color: #c42b1c; font-weight: 600; }
.sb-circ[hidden] { display: none; }
.sb-spacer { flex: 1; }
.sb-stats { display: flex; gap: 2px; }
.sb-views { display: flex; gap: 1px; margin-inline: 8px; }
.sb-icon { width: 26px; height: 22px; padding: 0; border: none; background: none; border-radius: 4px; color: var(--fg-muted); display: flex; align-items: center; justify-content: center; }
.sb-icon .ic { width: 15px; height: 15px; }
.sb-icon.on { background: var(--checked); color: var(--accent-text); }
.sb-zoom { display: flex; align-items: center; gap: 2px; direction: ltr; }
.zoom-slider { width: 110px; accent-color: var(--accent); }
.zoom-pct { min-width: 48px; }

/* ---------------- menus & popups ---------------- */
#layer { position: fixed; inset: 0; pointer-events: none; z-index: 2500; }
.menu { position: fixed; pointer-events: auto; min-width: 190px; max-width: 460px; max-height: 76vh; overflow: auto; padding: 4px; background: var(--menu-bg); color: var(--fg); border: 1px solid var(--menu-border); border-radius: 8px; box-shadow: var(--menu-shadow); }
.mi { display: flex; align-items: center; gap: 10px; min-height: 30px; padding: 0 10px; border-radius: 5px; white-space: nowrap; cursor: default; outline: none; }
.mi:hover, .mi:focus { background: var(--hover); }
.mi.disabled { opacity: .45; pointer-events: none; }
.mi.checked-icon { background: var(--checked); }
.mi-icon { width: 18px; height: 18px; flex: none; display: flex; align-items: center; justify-content: center; }
.mi-icon .ic { width: 16px; height: 16px; }
.mi.checked .mi-icon { color: var(--accent-text); }
.mi-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.mi-sample { color: var(--fg-muted); font-size: 12.5px; direction: ltr; unicode-bidi: isolate; }
.font-menu .mi-sample { font-size: 15px; }
.mi-sc { color: var(--fg-muted); font-size: 11.5px; direction: ltr; unicode-bidi: isolate; margin-inline-start: 18px; }
.mi-sub .ic { width: 12px; height: 12px; }
.msep { height: 1px; background: var(--sep); margin: 4px 6px; }
.mhead { padding: 7px 10px 3px; font-size: 11.5px; font-weight: 600; color: var(--fg-muted); }
.combo-menu { max-height: 440px; }
.font-menu { width: 320px; }
.nf-menu { width: 300px; }
.color-panel { width: 236px; padding-bottom: 2px; }
.swatches { display: grid; gap: 2px; padding: 2px 10px; justify-content: start; }
.swatches.cols10 { grid-template-columns: repeat(10, 18px); }
.swatches.first { margin-bottom: 5px; }
.swatches.tints { row-gap: 0; padding-top: 0; padding-bottom: 0; }
.sw { width: 18px; height: 18px; padding: 0; border: 1px solid rgba(0,0,0,.14); border-radius: 2px; }
.sw:hover { outline: 2px solid var(--accent); outline-offset: 1px; position: relative; z-index: 1; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 2px; border: 1px solid rgba(0,0,0,.2); }
.hidden-color { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
.sym-grid { display: grid; grid-template-columns: repeat(10, 30px); gap: 3px; padding: 6px 10px; }
.sym { height: 30px; padding: 0; border: 1px solid var(--sep); background: var(--ribbon-bg); color: var(--fg); border-radius: 4px; font-size: 16px; }
.sym:hover { border-color: var(--accent); background: var(--checked); }
.cs-gallery { width: 560px; padding: 0 6px 8px; }
.cs-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; padding: 2px 4px 6px; }
.cs-tile { height: 30px; padding: 0 4px; border: 1px solid var(--sep); border-radius: 3px; background: var(--cell-bg); color: var(--cell-fg); font: 12px var(--font-ui); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cs-tile:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
/* conditional formatting: galleries, rule dialogs, rules manager */
.cf-gallery { padding: 0 6px 6px; }
.cf-grid { display: grid; grid-template-columns: repeat(3, 46px); gap: 6px; padding: 2px 4px 6px; }
.cf-grid.scales { grid-template-columns: repeat(4, 36px); }
.cf-tile { width: 46px; height: 46px; padding: 6px 5px; border: 1px solid var(--sep); border-radius: 3px; background: #fff; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; }
.cf-tile.scale { width: 36px; height: 46px; padding: 0; }
.cf-tile:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
.cf-tbar { display: block; height: 8px; border: 1px solid; border-radius: 1px; }
.cf-gallery.icons { width: 250px; }
.cf-icongrid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 0 2px 4px; }
.cf-iconrow { display: flex; align-items: center; justify-content: center; height: 28px; padding: 0 6px; border: none; border-radius: 4px; background: none; color: var(--fg); }
.cf-iconrow:hover { background: var(--hover); }
.cf-icons { flex: none; }
.cf-sample { height: 22px; min-width: 110px; padding: 0 8px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--sep); border-radius: 3px; background: #fff; color: #000; font-size: 12px; white-space: nowrap; overflow: hidden; }
.cf-bar { display: block; width: 70%; height: 12px; border: 1px solid; margin-inline-end: auto; }
.cf-between { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }
.cf-between .inp { flex: 1; min-width: 80px; }
.cf-between select.inp { flex: none; }
.cf-between [hidden] { display: none; }
.cf-with { align-items: center; gap: 8px; flex-wrap: nowrap; font-size: 12.5px; }
.cf-with select { flex: 1; }
.cf-quick > div:first-child { font-size: 12.5px; }
.cf-kinds { max-height: none; }
.cf-detail { min-height: 150px; padding: 10px; border: 1px solid var(--sep); border-radius: 6px; }
.cf-preview-row { display: flex; align-items: center; gap: 10px; min-height: 30px; }
.cf-preview-row .cf-sample { flex: 1; height: 28px; }
.cf-vcols { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; }
.cf-vcol { display: flex; flex-direction: column; gap: 6px; font-size: 12px; min-width: 0; }
.cf-thresholds { display: flex; flex-direction: column; gap: 6px; }
.cf-threshold { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.cf-threshold .inp { width: 100px; }
.cf-table { border: 1px solid var(--sep); border-radius: 6px; height: 230px; overflow: auto; }
.cf-tr { display: grid; grid-template-columns: minmax(0, 2fr) 120px minmax(0, 1.3fr) 90px; gap: 8px; align-items: center; padding: 4px 8px; font-size: 12.5px; cursor: default; }
.cf-tr.head { position: sticky; top: 0; z-index: 1; background: var(--menu-bg); color: var(--fg-muted); font-weight: 600; border-bottom: 1px solid var(--sep); }
.cf-tr:not(.head):hover { background: var(--hover); }
.cf-tr.on, .cf-tr.on:hover { background: var(--checked); }
.cf-tr .inp { height: 26px; }
.cf-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; text-align: start; }
.cf-stop { display: flex; justify-content: center; }
.cf-empty { padding: 24px; text-align: center; font-size: 12.5px; }
.tooltip { position: fixed; max-width: 300px; padding: 8px 10px; background: var(--menu-bg); color: var(--fg); border: 1px solid var(--menu-border); border-radius: 6px; box-shadow: var(--menu-shadow); font-size: 12px; pointer-events: none; z-index: 3000; }
.tt-title { font-weight: 600; }
.tt-sc { font-weight: normal; color: var(--fg-muted); direction: ltr; unicode-bidi: isolate; }
.tt-desc { margin-top: 4px; color: var(--fg-muted); line-height: 1.45; }
.toast { position: fixed; bottom: 70px; left: 50%; transform: translate(-50%, 16px); max-width: 80vw; padding: 10px 18px; border-radius: 8px; background: #323130; color: #fff; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: 0; transition: opacity .25s, transform .25s; z-index: 4000; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
/* AutoFilter menu */
.flt-menu { width: 260px; }
.flt-body { display: flex; flex-direction: column; gap: 6px; padding: 6px 8px 0; }
.flt-body .inp { width: 100%; height: 26px; }
.flt-list { height: 200px; overflow: auto; border: 1px solid var(--sep); border-radius: 4px; padding: 3px 0; }
.flt-item { display: flex; align-items: center; gap: 6px; padding: 2px 8px; font-size: 12.5px; white-space: nowrap; }
.flt-item span { overflow: hidden; text-overflow: ellipsis; unicode-bidi: plaintext; }
.flt-foot { display: flex; justify-content: flex-end; gap: 6px; padding: 8px; }

/* ---------------- dialogs ---------------- */
.dlg-back { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.28); }
.dlg-back.modeless { background: transparent; pointer-events: none; align-items: flex-start; padding-top: 130px; }
.dlg-back.modeless .dlg { pointer-events: auto; box-shadow: 0 10px 36px rgba(0,0,0,.3); }
.dlg { max-width: 94vw; max-height: 88vh; display: flex; flex-direction: column; background: var(--menu-bg); color: var(--fg); border: 1px solid var(--menu-border); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.28); }
.dlg-title { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 6px 16px; padding-inline: 16px 10px; font-size: 14px; font-weight: 600; cursor: move; user-select: none; -webkit-user-select: none; }
.dlg-x { width: 28px; height: 28px; border: none; background: none; border-radius: 5px; color: var(--fg-muted); display: flex; align-items: center; justify-content: center; padding: 0; flex: none; }
.dlg-x:hover { background: var(--hover); }
.dlg-x .ic { width: 14px; height: 14px; }
.dlg-body { padding: 6px 16px 12px; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 8px 16px 14px; }
.dlg-foot .btn[hidden] { display: none; }
.btn { height: 30px; padding: 0 16px; border: 1px solid var(--btn-border); border-radius: 6px; background: var(--btn-bg); color: var(--fg); font-size: 13px; white-space: nowrap; cursor: default; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.small { height: 26px; padding: 0 12px; font-size: 12px; }
.btn.color-pick { display: inline-flex; align-items: center; gap: 8px; }
.form { display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; min-width: 0; }
.field[hidden] { display: none; }
.field-label { color: var(--fg-muted); font-size: 12px; }
.inp { height: 30px; min-width: 0; padding: 0 8px; border: 1px solid var(--input-border); border-radius: 6px; background: var(--input-bg); color: var(--fg); font: inherit; font-size: 13px; }
.inp:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
.inp.wide { width: 100%; }
.inp.ltr { direction: ltr; text-align: left; }
.inp.list { height: auto; padding: 4px; width: 100%; }
.inp.num { width: 90px; }
select.inp { padding: 0 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.fs-title { margin-top: 6px; padding-bottom: 3px; border-bottom: 1px solid var(--sep); font-size: 12px; font-weight: 600; }
.opts { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 2px; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.radio-list { gap: 6px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.dlg-tabs { display: flex; gap: 2px; margin-bottom: 12px; border-bottom: 1px solid var(--sep); }
.dlg-tab { padding: 6px 12px; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; color: var(--fg-muted); font: inherit; }
.dlg-tab.active { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }
.find-status { min-height: 18px; font-size: 12px; color: var(--fg-muted); }
.stats { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats td { padding: 6px 4px; border-bottom: 1px solid var(--sep); }
.stats td.kbd { text-align: end; direction: ltr; unicode-bidi: isolate; color: var(--fg-muted); white-space: nowrap; }
.keys-wrap { max-height: 60vh; overflow: auto; }
.sort-levels { display: flex; flex-direction: column; gap: 6px; }
.sort-level { display: grid; grid-template-columns: 70px 1fr 1fr 28px; gap: 8px; align-items: center; }
.dup-list { max-height: 220px; overflow: auto; border: 1px solid var(--sep); border-radius: 6px; padding: 6px 10px; display: flex; flex-direction: column; gap: 4px; }
.font-preview { height: 64px; display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap; border: 1px solid var(--sep); border-radius: 6px; background: #fff; color: #000; }
.about { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.about h2 { margin: 4px 0 0; font-size: 22px; }
.about p { max-width: 440px; line-height: 1.6; }
.about-logo { width: 72px; height: 72px; background: url(../img/icon.svg) center / contain no-repeat; }
.about.big { align-items: flex-start; text-align: start; }
.about.big .about-logo { width: 96px; height: 96px; }
.confirm-msg { font-size: 14px; font-weight: 600; line-height: 1.5; }
.confirm-sub { margin-top: 6px; color: var(--fg-muted); line-height: 1.5; }
.muted { color: var(--fg-muted); }
/* Format Cells */
.fc { min-height: 380px; }
.fc-pane[hidden] { display: none !important; }
.fc-number, .fc-font, .fc-border { display: grid; grid-template-columns: 170px 1fr; gap: 14px; }
.fc-font { grid-template-columns: 1fr 1fr; }
.fc-border { grid-template-columns: 170px 1fr; }
.fc-right, .fc-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.fc-list { border: 1px solid var(--sep); border-radius: 6px; overflow: auto; padding: 3px; max-height: 220px; }
.fc-list.cat { height: 330px; max-height: none; }
.fc-list.fonts { height: 250px; max-height: none; }
.fc-item { padding: 4px 8px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; font-size: 12.5px; }
.fc-item:hover { background: var(--hover); }
.fc-item.on { background: var(--checked); color: var(--accent-text); font-weight: 600; }
.fc-list.neg .fc-item, .if-list .fc-item { direction: ltr; text-align: start; }
.fc-sample { height: 30px; line-height: 28px; padding: 0 8px; border: 1px solid var(--sep); border-radius: 6px; background: var(--cell-bg); color: var(--cell-fg); direction: ltr; text-align: right; overflow: hidden; white-space: nowrap; }
.fc-desc { line-height: 1.5; }
.fc-opts { display: flex; flex-direction: column; gap: 8px; }
.lines .fc-item { height: 24px; display: flex; align-items: center; }
.lines .ln { display: block; width: 100%; border-top: 1px solid var(--fg); }
.line-hair .ln { border-top: 1px dotted var(--fg); } .line-dotted .ln { border-top: 1px dotted var(--fg); } .line-dashed .ln { border-top: 1px dashed var(--fg); }
.line-medium .ln { border-top-width: 2px; } .line-mediumDashed .ln { border-top: 2px dashed var(--fg); } .line-thick .ln { border-top-width: 3px; } .line-double .ln { border-top: 3px double var(--fg); }
.border-box { position: relative; width: 220px; height: 150px; margin-top: 6px; background: var(--cell-bg); border: 1px solid var(--sep); border-radius: 4px; }
.be { position: absolute; cursor: pointer; border-color: var(--fg); }
.be.top { top: 14px; left: 14px; right: 14px; height: 10px; border-top: 1px dashed rgba(128,128,128,.4); }
.be.bottom { bottom: 14px; left: 14px; right: 14px; height: 10px; border-bottom: 1px dashed rgba(128,128,128,.4); }
.be.left { left: 14px; top: 14px; bottom: 14px; width: 10px; border-left: 1px dashed rgba(128,128,128,.4); }
.be.right { right: 14px; top: 14px; bottom: 14px; width: 10px; border-right: 1px dashed rgba(128,128,128,.4); }
.be.insideH { top: 50%; left: 14px; right: 14px; height: 10px; border-top: 1px dashed rgba(128,128,128,.4); }
.be.insideV { left: 50%; top: 14px; bottom: 14px; width: 10px; border-left: 1px dashed rgba(128,128,128,.4); }
.be.on { border-style: solid !important; border-color: var(--cell-fg); }
.be.top.on { border-top-width: 2px; } .be.bottom.on { border-bottom-width: 2px; } .be.left.on { border-left-width: 2px; } .be.right.on { border-right-width: 2px; }
.be.insideH.on { border-top-width: 2px; } .be.insideV.on { border-left-width: 2px; }
.be.on.line-double { border-style: double !important; border-width: 3px; }
.be.on.line-dashed, .be.on.line-mediumDashed { border-style: dashed !important; }
.be.on.line-dotted, .be.on.line-hair { border-style: dotted !important; }
.be-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--fg-muted); pointer-events: none; font-size: 12px; }
.fill-sample { height: 40px; border: 1px solid var(--sep); border-radius: 6px; background: var(--cell-bg); }
.fc .color-panel { width: auto; }
.if-list { height: 210px; }
.if-syntax { font: 600 12.5px Menlo, "SF Mono", Consolas, monospace; direction: ltr; text-align: left; margin-top: 4px; }
.if-desc { color: var(--fg-muted); line-height: 1.5; min-height: 36px; unicode-bidi: plaintext; }

/* ---------------- backstage (File tab) ---------------- */
#backstage { position: fixed; inset: 0; z-index: 1500; display: flex; background: var(--bs-bg); color: var(--fg); }
#backstage[hidden] { display: none; }
.bs-nav { width: 220px; flex: none; display: flex; flex-direction: column; padding: 10px 0; background: var(--accent-dark); color: #fff; user-select: none; -webkit-user-select: none; }
.bs-back { width: 42px; height: 42px; margin: 4px 12px 14px; padding: 0; border: none; background: none; color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.bs-back:hover { background: rgba(255,255,255,.15); }
.bs-back .ic { width: 30px; height: 30px; stroke-width: 1.15; }
.bs-item { display: flex; align-items: center; gap: 12px; height: 42px; padding: 0 20px; border: none; background: none; color: #fff; font-size: 14px; text-align: start; }
.bs-item:hover { background: rgba(255,255,255,.12); }
.bs-item.active { background: rgba(255,255,255,.22); font-weight: 600; }
.bs-item .ic { width: 18px; height: 18px; }
.bs-spacer { flex: 1; }
.bs-main { flex: 1; overflow: auto; padding: 32px 48px; }
.bs-h1 { margin: 0 0 24px; font-size: 30px; font-weight: 300; }
.bs-h2 { margin: 28px 0 12px; font-size: 16px; font-weight: 600; }
.bs-h2-row { display: flex; align-items: center; gap: 16px; max-width: 760px; }
.bs-h2-row .bs-h2 { margin-inline-end: auto; }
.tpl-grid { display: flex; flex-wrap: wrap; gap: 22px; }
.tpl { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0; border: none; background: none; color: var(--fg); font-size: 13px; }
.tpl-thumb { width: 200px; height: 150px; position: relative; overflow: hidden; background: #fff; border: 1px solid var(--sep); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tpl:hover .tpl-thumb { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.tpl-sheet { position: absolute; top: 8px; inset-inline-start: 8px; transform: scale(.42); transform-origin: top left; pointer-events: none; color: #000; }
[dir="rtl"] .tpl-sheet { transform-origin: top right; }
.tpl-sheet table td { border: 1px solid #e3e3e3; }
.tpl-sheet.blank { inset: 0; transform: none; background:
  repeating-linear-gradient(to bottom, transparent 0 19px, #e3e3e3 19px 20px), repeating-linear-gradient(to right, transparent 0 49px, #e3e3e3 49px 50px); }
.bs-row { display: flex; align-items: center; flex-wrap: wrap; gap: 20px; margin-bottom: 18px; }
.bs-big { width: 112px; height: 100px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--sep); border-radius: 8px; background: var(--ribbon-bg); color: var(--fg); font-size: 14px; }
.bs-big .ic { width: 36px; height: 36px; stroke-width: 1.1; }
.bs-big:hover { border-color: var(--accent); background: var(--checked); }
.bs-big.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.recent { display: flex; flex-direction: column; max-width: 780px; }
.recent-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: none; background: none; border-radius: 6px; color: var(--fg); text-align: start; font-size: 13px; }
.recent-item:hover { background: var(--hover); }
.ri-icon .ic { width: 28px; height: 28px; stroke-width: 1.1; }
.ri-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ri-title { font-weight: 600; }
.ri-sub { font-size: 12px; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: start; }
[dir="rtl"] .ri-sub { text-align: right; }
.ri-date { font-size: 12px; color: var(--fg-muted); white-space: nowrap; }
.fmt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; max-width: 940px; }
.fmt-card { display: flex; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--sep); border-radius: 8px; background: var(--ribbon-bg); color: var(--fg); text-align: start; }
.fmt-card:hover { border-color: var(--accent); background: var(--checked); }
.fmt-icon .ic { width: 40px; height: 40px; stroke-width: 1; }
.fmt-text { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.info-card { max-width: 660px; }
.info-doc { display: flex; align-items: center; gap: 12px; }
.info-doc .ic { width: 44px; height: 44px; stroke-width: 1; }
.info-name { font-size: 18px; font-weight: 600; }
.props { width: 100%; border-collapse: collapse; }
.props th { width: 170px; padding: 8px 0; text-align: start; font-weight: normal; color: var(--fg-muted); vertical-align: middle; }
.props td { padding: 6px 0; }
.versions { display: flex; flex-direction: column; gap: 4px; max-width: 760px; }
.version { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid var(--sep); border-radius: 8px; background: var(--ribbon-bg); }
.version.latest { border-color: var(--checked-border); }
.v-icon .ic { width: 22px; height: 22px; color: var(--accent-text); }
.v-text { flex: 1; min-width: 0; }
.v-when { font-weight: 600; }
.v-del { width: 28px; height: 28px; border: none; background: none; border-radius: 5px; color: var(--fg-muted); display: flex; align-items: center; justify-content: center; padding: 0; }
.v-del:hover { background: var(--hover); color: #c42b1c; }
.v-del .ic { width: 16px; height: 16px; }
.opt-row { display: flex; align-items: center; gap: 16px; max-width: 620px; padding: 8px 0; }
.opt-row label { width: 260px; }
.opt-row .inp { min-width: 230px; }
.opt-col { display: flex; flex-direction: column; gap: 10px; max-width: 320px; margin: 10px 0 20px; }

/* ---------------- printing ---------------- */
#print-root { display: none; }
@media print {
  html, body { height: auto; overflow: visible; background: #fff !important; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root table { color: #000; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
