/* ============================================================
 * Excel Web Recreation — Fluent chrome styles
 * ============================================================ */
:root {
  --xl-green: #217346;
  --xl-green-dark: #1b5e3a;
  --xl-green-hover: #1e6e42;
  --xl-green-light: #e9f2ec;
  --xl-rib-bg: #f3f2f1;
  --xl-rib-hover: #e1dfdd;
  --xl-rib-active: #cedeD9;
  --xl-line: #d2d0ce;
  --xl-text: #323130;
  --xl-text-2: #605e5c;
  --xl-grid-line: #d9d9d9;
  --xl-head-bg: #f3f2f1;
  --xl-sel-fill: rgba(33, 115, 70, 0.10);
  --xl-font-ui: 'Selawik', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --xl-font-grid: 'Carlito', Calibri, 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--xl-font-ui);
  font-size: 12px;
  color: var(--xl-text);
  background: #e6e5e3;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; font-size: inherit; color: inherit; background: none; border: none; cursor: default; }
input, textarea, select { font-family: inherit; font-size: inherit; color: var(--xl-text); }
svg { display: block; }

.xl-app { display: flex; flex-direction: column; height: 100vh; }

/* ---------------- title bar ---------------- */
.xl-titlebar {
  height: 32px; background: var(--xl-green); color: #fff;
  display: flex; align-items: center; flex: none;
  padding-left: 4px; gap: 2px;
}
.xl-qat { display: flex; align-items: center; gap: 1px; }
.xl-qat .xl-qbtn {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  border-radius: 3px; color: #fff;
}
.xl-qat .xl-qbtn:hover { background: rgba(255,255,255,0.16); }
.xl-qat .xl-qbtn:active { background: rgba(255,255,255,0.28); }
.xl-qat .xl-qbtn.disabled { opacity: 0.4; }
.xl-qat .xl-qsep { width: 1px; height: 16px; background: rgba(255,255,255,0.35); margin: 0 3px; }
.xl-title-center { flex: 1; display: flex; align-items: center; justify-content: center; gap: 14px; min-width: 0; }
.xl-search {
  display: flex; align-items: center; gap: 8px; width: 220px; height: 22px;
  background: rgba(255,255,255,0.92); border-radius: 3px; padding: 0 10px;
  color: #605e5c; font-size: 11px;
}
.xl-search:hover { background: #fff; box-shadow: 0 0 0 1px rgba(255,255,255,0.6); }
.xl-search-ic { width: 12px; height: 12px; border: 1.6px solid #605e5c; border-radius: 50%; position: relative; flex: none; }
.xl-search-ic::after { content: ''; position: absolute; width: 1.6px; height: 5px; background: #605e5c; transform: rotate(-45deg); right: -3px; bottom: -3px; }
.xl-docname { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xl-wincontrols { display: flex; height: 100%; }
.xl-wc { width: 44px; display: flex; align-items: center; justify-content: center; font-size: 11px; }
.xl-wc:hover { background: rgba(255,255,255,0.16); }
.xl-wc-close:hover { background: #e81123; }

/* ---------------- ribbon ---------------- */
.xl-ribbon { flex: none; background: var(--xl-green); position: relative; }
.xl-ribtabs {
  display: flex; align-items: flex-end; height: 26px; padding-left: 2px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
}
.xl-ribtabs::-webkit-scrollbar { height: 3px; }
.xl-ribtabs::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.45); border-radius: 2px; }
.xl-ribtabs::-webkit-scrollbar-track { background: transparent; }
.xl-ribtab {
  color: #fff; font-size: 12px; padding: 0 12px 3px; margin: 0 1px;
  border-radius: 3px 3px 0 0; height: 26px; display: flex; align-items: center;
  position: relative;
}
.xl-ribtab:hover { background: rgba(255,255,255,0.16); }
.xl-ribtab.active {
  background: #faf9f8; color: var(--xl-text); font-weight: 600;
}
.xl-ribtab.filetab { background: var(--xl-green-dark); margin-right: 8px; }
.xl-ribtab.filetab:hover { background: #164a2e; }
.xl-ribtab.filetab.active { background: #185c37; color: #fff; }
.xl-ribtabs .xl-tab-collapser {
  margin-left: auto; color: #fff; width: 28px; height: 22px; margin-right: 4px; margin-bottom: 2px;
  display: flex; align-items: center; justify-content: center; border-radius: 3px; font-size: 9px;
}
.xl-ribtabs .xl-tab-collapser:hover { background: rgba(255,255,255,0.16); }
.xl-ribbody {
  background: var(--xl-rib-bg); border-bottom: 1px solid var(--xl-line);
  display: flex; align-items: stretch; padding: 0 4px 0 0; height: 96px; overflow: hidden;
}
.xl-ribbon.collapsed .xl-ribbody { display: none; }
.xl-ribgroup { display: flex; flex-direction: column; padding: 2px 6px 0 8px; position: relative; flex: none; }
.xl-ribgroup:not(:last-child)::after {
  content: ''; position: absolute; right: 0; top: 6px; bottom: 20px; width: 1px; background: #e1dfdd;
}
.xl-ribgroup-body { flex: 1; display: flex; align-items: center; gap: 4px; }
.xl-ribgroup-label {
  text-align: center; color: var(--xl-text-2); font-size: 11px; padding: 1px 0 3px;
}
.xl-ribcol { display: flex; flex-direction: column; gap: 2px; justify-content: center; }
.xl-ribrow { display: flex; gap: 4px; align-items: stretch; }

/* -------- narrow-width ribbon adaptation --------
 * Stage 1 (.xl-compact): group labels drop, big buttons collapse to
 * icon-only rows, combos shrink. Stage 2 (JS): trailing groups collapse
 * into the .xl-riboverflow button which opens .xl-rib-popout. */
.xl-ribbody.xl-compact .xl-ribgroup { padding: 2px 3px 0 4px; }
.xl-ribbody.xl-compact .xl-ribgroup:not(:last-child)::after { top: 4px; bottom: 4px; }
.xl-ribbody.xl-compact .xl-ribgroup-label { display: none; }
.xl-ribbody.xl-compact .xl-ribgroup-body { gap: 2px; }
.xl-ribbody.xl-compact .xl-bt-big {
  flex-direction: row; min-width: 0; max-width: none; padding: 0 4px;
  gap: 0; align-self: center;
}
.xl-ribbody.xl-compact .xl-bt-big .xl-bt-label,
.xl-ribbody.xl-compact .xl-bt-big .xl-sublabel { display: none; }
.xl-ribbody.xl-compact .xl-bt-sm .xl-bt-label { display: none; }
.xl-ribbody.xl-compact .xl-bt-sm { padding: 0 3px; gap: 0; }
.xl-ribbody.xl-compact .xl-bt-big .xl-bt-icon { width: 19px; height: 19px; }
.xl-ribbody.xl-compact .xl-bt-split.xl-bt-big { flex-direction: row; }
.xl-ribbody.xl-compact .xl-combo input { width: 46px; }
.xl-ribbody.xl-compact .xl-combo { max-width: 90px; }
.xl-riboverflow {
  flex: none; align-self: center; margin-left: 2px; width: 28px; height: 68px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; border-radius: 3px; color: var(--xl-text-2); border: 1px solid transparent;
}
.xl-riboverflow:hover { background: var(--xl-rib-hover); }
.xl-riboverflow:active { background: var(--xl-rib-active); }
.xl-riboverflow svg { width: 15px; height: 15px; }
.xl-riboverflow .xl-ov-label { font-size: 9px; }
/* popout panel hosting collapsed groups (opened via XL.showMenu node) */
.xl-rib-popout { max-width: calc(100vw - 16px); padding: 6px 4px 4px; }
.xl-rib-popout .xl-popcol { display: flex; flex-direction: column; }
.xl-rib-popout .xl-ribgroup { position: static; padding: 4px 6px 2px; flex: none; }
.xl-rib-popout .xl-ribgroup::after { display: none; }
.xl-rib-popout .xl-ribgroup + .xl-ribgroup { border-top: 1px solid #e1dfdd; margin-top: 5px; }
.xl-rib-popout .xl-ribgroup-body { flex: none; flex-wrap: wrap; row-gap: 3px; }
.xl-rib-popout .xl-ribgroup-label { padding-top: 2px; text-align: left; }
.xl-bt {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 3px; border: 1px solid transparent; color: var(--xl-text);
  position: relative; white-space: nowrap;
}
.xl-bt:hover:not(.disabled) { background: #e9e8e6; }
.xl-bt:active:not(.disabled) { background: #dcdcda; }
.xl-bt.disabled { opacity: 0.38; }
.xl-bt.toggled { background: #d3e0d8; border-color: #b3ccc0; }
.xl-bt-big {
  flex-direction: column; gap: 3px; min-width: 46px; padding: 3px 6px 2px; align-self: stretch;
  font-size: 12px; max-width: 84px;
}
.xl-bt-big .xl-bt-icon { width: 26px; height: 26px; }
/* compact stacked big button (two-per-column groups, Charts rows) */
.xl-bt-big.slim { min-width: 38px; max-width: none; height: 36px; padding: 1px 6px; gap: 2px; }
.xl-bt-big.slim .xl-bt-icon { width: 18px; height: 18px; }
.xl-bt-big.slim .xl-bt-label { font-size: 11px; white-space: nowrap; }
.xl-bt-big.slim .xl-sublabel { display: none; }
.xl-ribbody .xl-check { margin: 1px 0; }
.xl-bt-sm { gap: 5px; padding: 0 6px; height: 24px; }
.xl-bt-sm .xl-bt-icon { width: 16px; height: 16px; }
.xl-bt-ico { width: 32px; height: 30px; }
.xl-bt-ico .xl-bt-icon { width: 18px; height: 18px; }
.xl-bt-split { display: inline-flex; align-self: stretch; }
.xl-bt-split .xl-bt-main { border-radius: 3px 0 0 3px; }
.xl-bt-split .xl-bt-caret { width: 14px; border-radius: 0 3px 3px 0; display: flex; align-items: center; justify-content: center; }
.xl-bt-split .xl-bt-caret:hover { background: #e0dfdd; }
.xl-bt-caret svg { width: 8px; height: 8px; }
.xl-bt-ico-spl { flex-direction: column; gap: 2px; padding: 3px 4px 1px; }
.xl-bt-ico-spl .xl-split-row { display: flex; border-radius: 3px; overflow: hidden; }
.xl-bt-ico-spl .xl-bt-caret { height: 12px; width: 100%; border-radius: 0 0 3px 3px; }
.xl-bt .xl-sublabel { font-size: 11px; color: var(--xl-text); }
.xl-bt-checkrow { display: flex; align-items: center; gap: 4px; }

/* combo in ribbon */
.xl-ribcombo {
  display: flex; flex-direction: column; gap: 1px; align-items: center;
}
.xl-ribcombo .xl-combo-label { font-size: 11px; color: var(--xl-text-2); }
.xl-combo {
  display: flex; align-items: center; height: 24px; background: #fff;
  border: 1px solid var(--xl-line); border-radius: 2px; overflow: hidden;
}
.xl-combo:hover { border-color: #bdbdbb; }
.xl-combo select, .xl-combo input {
  border: none; outline: none; height: 22px; padding: 0 4px; background: transparent;
  font-size: 12px;
}
.xl-combo input { width: 74px; }
.xl-combo select { cursor: default; }
.xl-combo .xl-combo-btn { width: 18px; display: flex; align-items: center; justify-content: center; border-left: 1px solid var(--xl-line); align-self: stretch; background: #fff; }
.xl-ribspin { display: flex; align-items: center; border: 1px solid var(--xl-line); background: #fff; border-radius: 2px; height: 24px; }
.xl-ribspin input { width: 56px; border: none; outline: none; text-align: center; }
.xl-ribspin button { width: 17px; font-size: 9px; color: #605e5c; }

/* screen tips */
.xl-tip {
  position: fixed; z-index: 9000; background: #fff; border: 1px solid #d1d1d1; box-shadow: 0 3px 10px rgba(0,0,0,0.22);
  border-radius: 3px; padding: 7px 10px; max-width: 280px; font-size: 12px; pointer-events: none;
}
.xl-tip b { display: block; margin-bottom: 3px; }
.xl-tip .xl-tip-hint { color: #757575; font-size: 11px; margin-top: 5px; border-top: 1px solid #ecebe9; padding-top: 4px; }
.xl-tip .xl-tip-kbd { display: inline-block; border: 1px solid #d1d1d1; border-radius: 2px; padding: 0 4px; font-size: 10px; color: #444; margin-left: 6px; }

/* keytips */
.xl-keytip {
  position: fixed; z-index: 9500; background: #fffbd6; border: 1px solid #a3a3a3; color: #333;
  font-size: 11px; font-weight: 600; padding: 1px 4px; border-radius: 2px; pointer-events: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ---------------- formula bar ---------------- */
.xl-formularow {
  flex: none; display: flex; align-items: stretch; height: 24px; background: #fff;
  border-bottom: 1px solid var(--xl-line);
}
.xl-namebox { width: 108px; border-right: 1px solid var(--xl-line); display: flex; align-items: center; position: relative; }
.xl-namebox input {
  width: 100%; height: 100%; border: none; outline: none; padding: 0 6px; font-size: 12px;
  font-family: var(--xl-font-ui); text-align: center;
}
.xl-namebox input:focus { text-align: left; }
.xl-fb-btns { display: flex; align-items: center; border-right: 1px solid var(--xl-line); }
.xl-fb-btn { width: 22px; height: 100%; display: flex; align-items: center; justify-content: center; color: #605e5c; font-size: 12px; }
.xl-fb-btn:hover:not(.disabled) { background: #e9e8e6; }
.xl-fb-btn.disabled { opacity: 0.35; }
.xl-fb-btn.xl-fx { font-family: 'Cambria', Georgia, serif; font-style: italic; font-weight: 700; font-size: 13px; }
.xl-formulabox { flex: 1; position: relative; display: flex; }
.xl-formulabox textarea {
  flex: 1; resize: none; border: none; outline: none; padding: 3px 8px 0 8px; font-size: 13px;
  font-family: var(--xl-font-ui); line-height: 17px; overflow: hidden; white-space: pre;
  background: transparent;
}
.xl-formulabox.expanded textarea { white-space: pre-wrap; overflow-y: auto; }

/* ---------------- grid ---------------- */
.xl-gridarea { flex: 1; position: relative; overflow: hidden; background: #fff; }
#grid-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.xl-gridobjects { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.xl-gridobjects > * { pointer-events: auto; }
.xl-celleditor {
  position: absolute; display: none; z-index: 20; outline: 2px solid var(--xl-green);
  background: #fff; padding: 0 4px; font-family: var(--xl-font-grid); font-size: 14.666px;
  line-height: 18px; overflow: hidden; white-space: pre; min-height: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18); user-select: text; -webkit-user-select: text;
}
.xl-celleditor.wrap { white-space: pre-wrap; overflow-wrap: break-word; }
.xl-gridtooltip {
  position: absolute; z-index: 40; background: #fff; border: 1px solid #d1d1d1; padding: 1px 6px;
  font-size: 11px; color: #5a5a5a; border-radius: 2px; box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}
.xl-vscroll { position: absolute; right: 0; top: 0; bottom: 14px; width: 14px; background: #f0f0ef; border-left: 1px solid #e0dfdd; }
.xl-hscroll { position: absolute; left: 0; right: 14px; bottom: 0; height: 14px; background: #f0f0ef; border-top: 1px solid #e0dfdd; }
.xl-corner-scroll { position: absolute; right: 0; bottom: 0; width: 14px; height: 14px; background: #f0f0ef; border-top: 1px solid #e0dfdd; border-left: 1px solid #e0dfdd; }
.xl-vthumb { position: absolute; left: 0; width: 100%; background: #cdccca; border-radius: 2px; border: 2px solid #f0f0ef; }
.xl-hthumb { position: absolute; top: 0; height: 100%; background: #cdccca; border-radius: 2px; border: 2px solid #f0f0ef; }
.xl-vthumb:hover, .xl-hthumb:hover { background: #b9b8b6; }

/* floating objects (charts, images) */
.xl-obj {
  position: absolute; background: #fff; border: 1px solid #b3b0ad;
  box-shadow: 0 1px 4px rgba(0,0,0,0.14);
}
.xl-obj .xl-obj-title { position: absolute; inset: 0; pointer-events: none; }
.xl-obj.selected { outline: 1.5px solid var(--xl-green); }
.xl-obj-h { position: absolute; width: 8px; height: 8px; background: var(--xl-green); border: 1px solid #fff; display: none; z-index: 5; }
.xl-obj.selected .xl-obj-h { display: block; }

/* ---------------- sheet tabs ---------------- */
.xl-sheetbar {
  flex: none; height: 27px; display: flex; align-items: stretch; background: #f5f4f2;
  border-top: 1px solid #d2d0ce;
}
.xl-tabnav { width: 18px; display: flex; align-items: center; justify-content: center; color: #605e5c; font-size: 8px; }
.xl-tabnav:hover { background: #e8e7e5; }
.xl-tabscroll { flex: 1; overflow: hidden; display: flex; align-items: stretch; }
#sheet-tabs { display: flex; align-items: flex-end; }
.xl-sheet-tab {
  display: flex; align-items: center; height: 25px; padding: 0 9px; font-size: 12px;
  color: #444; border-right: 1px solid #dcdad8; position: relative; cursor: default;
  white-space: nowrap; margin-bottom: 0; background: #f5f4f2;
}
.xl-sheet-tab:hover { background: #eceae8; }
.xl-sheet-tab.active { background: #fff; color: var(--xl-green); font-weight: 600; }
.xl-sheet-tab.active::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--xl-green); }
.xl-sheet-tab .xl-tab-colorbar { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.xl-sheet-tab.hidden-sheet { font-style: italic; }
.xl-sheetadd { width: 26px; color: var(--xl-green); font-size: 15px; display: flex; align-items: center; justify-content: center; }
.xl-sheetadd:hover { background: #e4ebe6; }
.xl-tabbar-spacer { flex: 1; }

/* ---------------- status bar ---------------- */
.xl-statusbar {
  flex: none; height: 25px; background: var(--xl-green); color: #fff; display: flex;
  align-items: center; padding: 0 8px; gap: 10px; font-size: 12px;
}
.xl-statusleft { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; overflow: hidden; }
.xl-statuscircular { background: rgba(0,0,0,0.22); padding: 1px 8px; border-radius: 2px; }
.xl-statusagg { display: flex; gap: 12px; white-space: nowrap; }
.xl-statusright { display: flex; align-items: center; gap: 4px; }
.xl-viewbtn { width: 26px; height: 22px; border-radius: 2px; display: flex; align-items: center; justify-content: center; }
.xl-viewbtn:hover { background: rgba(255,255,255,0.16); }
.xl-viewbtn.toggled { background: rgba(255,255,255,0.26); }
.xl-viewbtn svg { width: 15px; height: 15px; }
.xl-zoomer { display: flex; align-items: center; gap: 6px; margin-left: 12px; }
.xl-zoombtn { width: 20px; height: 20px; border-radius: 2px; font-size: 13px; display: flex; align-items: center; justify-content: center; }
.xl-zoombtn:hover { background: rgba(255,255,255,0.16); }
.xl-zoomslider { width: 96px; height: 18px; position: relative; display: flex; align-items: center; cursor: pointer; }
.xl-zoomslider::before { content: ''; position: absolute; left: 0; right: 0; height: 3px; background: rgba(255,255,255,0.35); border-radius: 2px; }
#zoom-fill { position: absolute; left: 0; height: 3px; background: #fff; border-radius: 2px; }
#zoom-knob { position: absolute; width: 7px; height: 7px; border-radius: 50%; background: #fff; box-shadow: 0 0 2px rgba(0,0,0,0.4); }
.xl-zoompct { min-width: 40px; text-align: center; border-radius: 2px; height: 20px; }
.xl-zoompct:hover { background: rgba(255,255,255,0.16); }

/* ---------------- menus ---------------- */
.xl-menu {
  position: fixed; z-index: 8000; background: #fff; border: 1px solid #d1d1d1;
  box-shadow: 0 4px 12px rgba(0,0,0,0.22); padding: 3px; min-width: 170px;
  font-size: 12px;
}
.xl-menu.xl-menu-anim { animation: xlmenu 0.12s ease-out; }
@keyframes xlmenu { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.xl-mi {
  display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 3px;
  position: relative; white-space: nowrap;
}
.xl-mi:hover:not(.disabled) { background: #e9e8e6; }
.xl-mi.disabled { color: #b1b0ae; }
.xl-mi .xl-mi-ic { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; flex: none; }
.xl-mi .xl-mi-check { width: 18px; text-align: center; font-size: 11px; color: var(--xl-green); flex: none; }
.xl-mi .xl-mi-label { flex: 1; }
.xl-mi .xl-mi-sub { color: #605e5c; font-size: 10px; }
.xl-mi .xl-mi-hint { color: #757575; font-size: 11px; margin-left: 18px; }
.xl-mi.xl-mi-title { font-weight: 600; color: var(--xl-green); border-bottom: 1px solid #e5e4e2; border-radius: 0; margin-bottom: 2px; padding-left: 8px; }
.xl-msep { height: 1px; background: #e5e4e2; margin: 3px 6px; }

/* gallery */
.xl-gallery { padding: 4px; }
.xl-gallery-title { font-size: 11px; color: var(--xl-text-2); padding: 2px 4px 6px; }
.xl-gallery-grid { display: grid; gap: 3px; }
.xl-gcell { border: 1px solid transparent; border-radius: 2px; display: flex; align-items: center; justify-content: center; padding: 2px; }
.xl-gcell:hover { border-color: var(--xl-green); background: #f1f7f3; }
.xl-gcell.selected { border-color: var(--xl-green); }
.xl-color-sw { width: 17px; height: 17px; border: 1px solid rgba(0,0,0,0.18); }
.xl-gcell .xl-swatch { width: 63px; height: 18px; display: flex; align-items: center; padding: 0 6px; font-size: 11px; }
.xl-gbar { display: flex; height: 20px; }
.xl-gbar i { flex: 1; }
.xl-menu-footer { border-top: 1px solid #e5e4e2; padding: 4px 8px; display: flex; gap: 6px; align-items: center; margin-top: 3px; }

/* ---------------- dialogs ---------------- */
.xl-dialog-mask { position: fixed; inset: 0; background: rgba(0,0,0,0.18); z-index: 8500; }
.xl-dialog {
  position: fixed; z-index: 8600; background: #fff; border-radius: 4px;
  box-shadow: 0 6px 26px rgba(0,0,0,0.32); min-width: 340px;
  display: flex; flex-direction: column; max-height: 92vh;
}
.xl-dialog-title {
  padding: 9px 12px 8px; font-size: 15px; color: var(--xl-green); display: flex; align-items: center;
}
.xl-dialog-title .xl-dlg-close { margin-left: auto; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 3px; color: #666; font-size: 11px; }
.xl-dialog-title .xl-dlg-close:hover { background: #e9e8e6; }
.xl-dialog-body { padding: 0 14px 14px; overflow: auto; }
.xl-dialog-foot {
  padding: 10px 14px; background: #f3f2f1; border-radius: 0 0 4px 4px; display: flex; gap: 8px;
  justify-content: flex-end; align-items: center;
}
.xl-dialog-foot .left { margin-right: auto; display: flex; gap: 8px; }
.xl-btn {
  min-width: 78px; height: 26px; padding: 0 14px; border: 1px solid #adadad; border-radius: 3px;
  background: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.xl-btn:hover:not(:disabled) { background: #e8f0ec; border-color: #4c986d; }
.xl-btn:disabled { color: #a6a6a6; background: #f3f3f3; border-color: #dcdcdc; }
.xl-btn.primary { background: var(--xl-green); border-color: var(--xl-green); color: #fff; }
.xl-btn.primary:hover:not(:disabled) { background: #1b5e3a; border-color: #1b5e3a; }
.xl-btn.toggled { border-color: #4c986d; background: #e2efe7; }

.xl-dlg-tabs { display: flex; border-bottom: 1px solid #d2d0ce; padding: 0 10px; margin-bottom: 12px; }
.xl-dlg-tab { padding: 5px 10px; border-radius: 3px 3px 0 0; color: #444; position: relative; }
.xl-dlg-tab:hover { background: #f0efee; }
.xl-dlg-tab.active { color: var(--xl-green); font-weight: 600; }
.xl-dlg-tab.active::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--xl-green); }

.xl-field { display: flex; align-items: center; gap: 8px; margin: 9px 0; flex-wrap: wrap; }
.xl-field > label { min-width: 90px; text-align: right; color: #333; }
.xl-field input[type=text], .xl-field input[type=number], .xl-field select {
  border: 1px solid #8a8886; border-radius: 2px; height: 24px; padding: 0 6px; outline: none; flex: 1; min-width: 90px;
  background: #fff;
}
.xl-field input:focus, .xl-field select:focus { border-color: var(--xl-green); }
.xl-field .unit { color: #666; }
.xl-radio-row { display: flex; gap: 14px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.xl-check { display: flex; align-items: center; gap: 6px; margin: 5px 0; }
.xl-check .xl-box {
  width: 14px; height: 14px; border: 1px solid #605e5c; border-radius: 2px; background: #fff;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 10px; flex: none;
}
.xl-check.on .xl-box { background: var(--xl-green); border-color: var(--xl-green); }
.xl-radio { width: 14px; height: 14px; border: 1px solid #605e5c; border-radius: 50%; position: relative; flex: none; }
.xl-radio.on::after { content: ''; position: absolute; inset: 2.5px; border-radius: 50%; background: var(--xl-green); }
.xl-seg { display: flex; border: 1px solid #8a8886; border-radius: 2px; overflow: hidden; }
.xl-seg button { padding: 3px 12px; background: #fff; border-right: 1px solid #d2d0ce; }
.xl-seg button:last-child { border-right: none; }
.xl-seg button.on { background: #d3e0d8; font-weight: 600; }
.xl-note { color: var(--xl-text-2); font-size: 11px; margin: 6px 0; }

/* format cells border picker */
.xl-border-pick { display: grid; grid-template-columns: repeat(3, 26px); gap: 0; border-collapse: collapse; }
.xl-border-cell { width: 26px; height: 26px; border: 1px solid #d2d0ce; display: flex; align-items: center; justify-content: center; }
.xl-border-cell.on { background: #d3e0d8; box-shadow: inset 0 0 0 1.5px var(--xl-green); }
.xl-border-preview { width: 110px; height: 74px; border: 1px solid #8a8886; position: relative; margin: auto; background: #fff; }
.xl-border-preview i { position: absolute; background: #000; }
.xl-border-preview i.pretop { left: 12px; right: 12px; top: 12px; height: 2px; }
.xl-border-preview i.prebot { left: 12px; right: 12px; bottom: 12px; height: 2px; }
.xl-border-preview i.preleft { top: 12px; bottom: 12px; left: 12px; width: 2px; }
.xl-border-preview i.preright { top: 12px; bottom: 12px; right: 12px; width: 2px; }
.xl-border-preview i.preh { left: 12px; right: 12px; top: 50%; height: 1px; }
.xl-border-preview i.prev { top: 12px; bottom: 12px; left: 50%; width: 1px; }
.xl-border-preview i.preoutline { left: 12px; right: 12px; top: 12px; bottom: 12px; border: 2px solid #000; background: none; }

/* ---------------- autocomplete / function help ---------------- */
.xl-sugg {
  position: fixed; z-index: 8200; background: #fff; border: 1px solid #c7c6c4;
  box-shadow: 0 4px 10px rgba(0,0,0,0.24); width: 320px; max-height: 260px; overflow: auto;
}
.xl-sugg-item { padding: 4px 10px; display: flex; align-items: baseline; gap: 8px; }
.xl-sugg-item .xl-sg-name { font-weight: 600; }
.xl-sugg-item .xl-sg-sig { color: #757575; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xl-sugg-item.sel, .xl-sugg-item:hover { background: #e9f2ec; }
.xl-fntip {
  position: fixed; z-index: 8210; background: #ffffe1; border: 1px solid #a5a5a5; padding: 3px 8px;
  font-size: 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.18); max-width: 440px;
}
.xl-fntip b { font-weight: 700; }

/* ---------------- backstage ---------------- */
.xl-backstage { position: fixed; inset: 0; z-index: 7000; background: #faf9f8; display: flex; }
.xl-bs-nav { width: 200px; background: var(--xl-green); color: #fff; padding: 10px 0; display: flex; flex-direction: column; }
.xl-bs-back { padding: 10px 20px; display: flex; align-items: center; gap: 10px; font-size: 15px; margin-bottom: 12px; border-radius: 0; }
.xl-bs-back:hover { background: rgba(0,0,0,0.18); }
.xl-bs-item { padding: 8px 20px; font-size: 13px; border-radius: 0; text-align: left; }
.xl-bs-item:hover { background: rgba(255,255,255,0.14); }
.xl-bs-item.active { background: rgba(0,0,0,0.24); font-weight: 600; }
.xl-bs-sep { height: 1px; background: rgba(255,255,255,0.25); margin: 8px 20px; }
.xl-bs-main { flex: 1; display: flex; overflow: auto; }
.xl-bs-content { flex: 1; padding: 20px 30px; }
.xl-bs-title { font-size: 26px; font-weight: 300; color: #333; margin-bottom: 18px; }
.xl-bs-tplgrid { display: grid; grid-template-columns: repeat(auto-fill, 140px); gap: 18px; }
.xl-bs-tpl { width: 140px; text-align: center; }
.xl-bs-tpl .xl-tpl-thumb {
  width: 140px; height: 90px; border: 1px solid #c8c6c4; background: #fff; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12); display: flex; align-items: center; justify-content: center;
}
.xl-bs-tpl:hover .xl-tpl-thumb { border-color: var(--xl-green); box-shadow: 0 2px 8px rgba(33,115,70,0.3); }
.xl-bs-tpl .xl-tpl-name { margin-top: 6px; font-size: 12px; color: #333; }
.xl-bs-search { padding: 6px 10px; border: 1px solid #8a8886; width: 260px; border-radius: 2px; outline: none; margin-bottom: 16px; }

/* print preview */
.xl-print-wrap { display: flex; flex: 1; gap: 18px; overflow: hidden; }
.xl-print-opts { width: 240px; flex: none; overflow-y: auto; }
.xl-print-preview { flex: 1; overflow: auto; background: #e8e7e5; padding: 20px; text-align: center; }
.xl-print-page { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.25); margin: 0 auto 20px auto; }
.xl-print-page canvas { display: block; }
.xl-po-group { margin-bottom: 16px; text-align: left; }
.xl-po-label { display: flex; justify-content: space-between; font-size: 12px; color: #444; margin-bottom: 4px; }
.xl-po-ctrl { border: 1px solid #8a8886; border-radius: 2px; height: 26px; display: flex; align-items: center; padding: 0 2px; background: #fff; }
.xl-po-ctrl:hover { border-color: var(--xl-green); }
.xl-po-ctrl span { padding: 0 8px; flex: 1; }
.xl-po-ctrl .xl-po-caret { width: 20px; align-self: stretch; display: flex; align-items: center; justify-content: center; border-left: 1px solid #e1dfdd; }

/* ---------------- toasts ---------------- */
#toast-layer { position: fixed; bottom: 34px; right: 16px; z-index: 9600; display: flex; flex-direction: column; gap: 8px; }
.xl-toast {
  background: #333; color: #fff; padding: 10px 16px; border-radius: 4px; font-size: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4); max-width: 340px; animation: xltoast 0.18s ease-out;
}
@keyframes xltoast { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* find-replace results */
.xl-findall { border: 1px solid #d2d0ce; height: 150px; overflow: auto; margin-top: 8px; background: #fff; }
.xl-fa-row { display: grid; grid-template-columns: 70px 90px 1fr; font-size: 11px; padding: 3px 8px; border-bottom: 1px solid #f0efee; }
.xl-fa-row.head { font-weight: 600; background: #f3f2f1; position: sticky; top: 0; }
.xl-fa-row.sel { background: #cde3d6; }

/* sort dialog rows */
.xl-sort-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; padding: 6px; border: 1px solid #e1dfdd; border-radius: 3px; }
.xl-sort-row .xl-sort-x { color: #666; width: 18px; }
.xl-sort-row select { flex: 1; }

/* conditional formats manager */
.xl-cf-row { display: flex; gap: 8px; align-items: center; padding: 5px 8px; border-bottom: 1px solid #eee; }
.xl-cf-row.sel { background: #cde3d6; }

/* filter panel */
.xl-filter-panel {
  position: fixed; z-index: 8300; background: #fff; border: 1px solid #c7c6c4; border-radius: 3px;
  box-shadow: 0 5px 16px rgba(0,0,0,0.3); width: 280px; display: flex; flex-direction: column;
}
.xl-filter-panel .xl-fp-search { padding: 8px; border-bottom: 1px solid #e1dfdd; }
.xl-filter-panel .xl-fp-search input { width: 100%; border: 1px solid #8a8886; border-radius: 2px; height: 24px; padding: 0 6px; outline: none; }
.xl-filter-panel .xl-fp-list { max-height: 240px; overflow: auto; padding: 4px; }
.xl-fp-item { display: flex; align-items: center; gap: 7px; padding: 3px 6px; border-radius: 2px; }
.xl-fp-item:hover { background: #f0efee; }
.xl-fp-item .xl-box { width: 13px; height: 13px; border: 1px solid #605e5c; border-radius: 2px; display: flex; align-items: center; justify-content: center; font-size: 9px; color: #fff; flex: none; }
.xl-fp-item.on .xl-box { background: var(--xl-green); border-color: var(--xl-green); }
.xl-fp-group { font-weight: 600; padding: 3px 6px; color: #444; }
.xl-filter-panel .xl-fp-foot { border-top: 1px solid #e1dfdd; padding: 8px; display: flex; gap: 8px; justify-content: flex-end; }

/* misc */
.xl-swatch-row { display: flex; align-items: center; gap: 6px; }
.xl-colorwell { width: 15px; height: 15px; border: 1px solid #999; }
.xl-hr { height: 1px; background: #e1dfdd; margin: 10px 0; }
.xl-dialog img.xl-dlg-help { max-width: 420px; }

/* custom color picker dialog inputs */
.xl-cp-palette { display: grid; grid-template-columns: repeat(10, 20px); gap: 2px; }
.xl-cp-palette .xl-color-sw { width: 20px; height: 20px; }
.xl-cp-palette .xl-color-sw:hover { outline: 2px solid var(--xl-green); outline-offset: -1px; }
.xl-cp-palette .xl-color-sw.nocolor { background: #fff; position: relative; }
.xl-cp-palette .xl-color-sw.nocolor::after { content: ''; position: absolute; left: 2px; right: 2px; top: 8px; height: 2px; background: #d13438; transform: rotate(-45deg); }

/* scrollbars in dialogs/lists */
.xl-dialog ::-webkit-scrollbar, .xl-menu ::-webkit-scrollbar, .xl-sugg ::-webkit-scrollbar { width: 10px; height: 10px; }
.xl-dialog ::-webkit-scrollbar-thumb, .xl-menu ::-webkit-scrollbar-thumb, .xl-sugg ::-webkit-scrollbar-thumb { background: #c8c6c4; border-radius: 5px; border: 2px solid #fff; }

/* ---------------- narrow-viewport adaptation ----------------
 * Flyouts/dropdowns never exceed the viewport at any width. */
.xl-dialog { max-width: calc(100vw - 16px); }
.xl-sugg { max-width: calc(100vw - 12px); }
.xl-fntip { max-width: calc(100vw - 12px); }
.xl-filter-panel { max-width: calc(100vw - 12px); }
.xl-tip { max-width: min(280px, calc(100vw - 16px)); }
.xl-menu { max-width: calc(100vw - 8px); }

@media (max-width: 1023px) {
  .xl-ribtab { padding: 0 8px 3px; }
}

@media (max-width: 767px) {
  .xl-search { display: none; }
  .xl-title-center { gap: 8px; }
  .xl-ribtab { padding: 0 6px 3px; font-size: 11px; }
  .xl-ribtab.filetab { margin-right: 4px; }
  .xl-namebox { width: 76px; }
  .xl-zoomslider { width: 64px; }
  .xl-statusbar { gap: 6px; }
  .xl-statusleft { gap: 8px; }
  .xl-statusagg { gap: 8px; }
  .xl-zoomer { margin-left: 6px; }
  .xl-bs-nav { width: 132px; }
  .xl-bs-content { padding: 14px 16px; }
  .xl-bs-title { font-size: 20px; }
  .xl-print-wrap { flex-direction: column; overflow: visible; }
  .xl-print-opts { width: auto; }
  .xl-bs-tplgrid { grid-template-columns: repeat(auto-fill, 120px); }
  .xl-bs-tpl, .xl-bs-tpl .xl-tpl-thumb { width: 120px; }
}

@media (max-width: 519px) {
  .xl-qat .xl-qbtn { width: 22px; }
  .xl-namebox { width: 60px; }
  .xl-wc { width: 36px; }
  .xl-zoomslider { width: 48px; }
  .xl-sheet-tab { padding: 0 6px; font-size: 11px; }
  .xl-docname { font-size: 11px; }
  .xl-bs-nav { width: 108px; }
  .xl-bs-item { padding: 8px 12px; font-size: 12px; }
  .xl-bs-back { padding: 10px 12px; font-size: 13px; }
}

@media print {
  body * { visibility: hidden; }
  #print-container, #print-container * { visibility: visible; }
  #print-container { position: absolute; left: 0; top: 0; }
  .xl-app, .xl-backstage, .xl-dialog-mask { display: none !important; }
}
