/* Excel replica — base chrome: desktop staging, window frame, title bar,
 * QAT, formula row, sheet bar, status bar. The app presents as a faithful
 * maximizable Office window on a quiet desktop. */
:root {
  --xl-green: #217346;
  --xl-green-dark: #185c37;
  --xl-green-deep: #0f4b2e;
  --xl-title-text: #ffffff;
  --ribbon-bg: #f5f3f3;
  --ribbon-tab-active: #ffffff;
  --ui-font: "Segoe UI", "Selawik", -apple-system, "Helvetica Neue", Arial, sans-serif;
  --cell-font: Calibri, "Segoe UI", sans-serif;
  --hairline: #d6d2cf;
  --grid-line: #d0d7de;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--ui-font);
  font-size: 12px;
  background:
    radial-gradient(120% 90% at 30% 12%, #3d5a4a 0%, #24352c 46%, #131a16 100%);
  user-select: none;
  cursor: default;
}

#desktop {
  height: 100%;
  padding: 14px;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

/* ------------------------------- window --------------------------------- */
#excelWindow {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 320px;
  min-height: 240px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    0 22px 70px rgba(0,0,0,.55),
    0 3px 10px rgba(0,0,0,.45);
  outline: 1px solid rgba(255,255,255,.08);
}
#excelWindow.notmaximized {
  max-width: calc(100vw - 120px);
  max-height: calc(100vh - 110px);
  margin: auto;
}

#titlebar {
  height: 32px;
  flex: none;
  display: flex;
  align-items: center;
  background: linear-gradient(180deg, var(--xl-green) 0%, var(--xl-green-dark) 100%);
  color: var(--xl-title-text);
  position: relative;
}

#qat { display: flex; align-items: center; gap: 1px; padding-left: 5px; }
#qat .qbtn {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 3px; cursor: pointer;
  position: relative;
}
#qat .qbtn:hover { background: rgba(255,255,255,.16); }
#qat .qbtn:active { background: rgba(0,0,0,.18); }
#qat .qbtn.disabled { opacity: .38; pointer-events: none; }
#qat .qbtn .badge {
  position: absolute; right: 3px; bottom: 3px;
  width: 6px; height: 6px; background: #ffd24d; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,.25);
}

#titleCenter {
  position: absolute; left: 50%; transform: translateX(-50%);
  display: flex; gap: 7px; align-items: center;
  font-size: 13px; letter-spacing: .2px;
  text-shadow: 0 1px 1px rgba(0,0,0,.35);
  white-space: nowrap;
}
.xlappicon { width: 17px; height: 17px; display: inline-block; }
.xlappicon::before {
  content: "";
  display: block; width: 100%; height: 100%;
  background:
    linear-gradient(#fff, #fff) top left / 43% 43% no-repeat,
    linear-gradient(#c9e5d5, #c9e5d5) top right / 43% 43% no-repeat,
    linear-gradient(#fff,#fff) bottom left / 43% 43% no-repeat,
    linear-gradient(var(--xl-green),var(--xl-green)) bottom right / 43% 43% no-repeat,
    linear-gradient(#217346,#217346) center/100% 100%;
  border-radius: 2px;
  opacity: .95;
}

#winbtns { margin-left: auto; display: flex; height: 100%; }
.winbtn {
  width: 44px; height: 100%;
  border: none; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.winbtn:hover { background: rgba(255,255,255,.18); }
.winbtn.close:hover { background: #e81123; }

/* ------------------------- ribbon / formula area -------------------------- */
#ribbonArea { flex: none; background: var(--ribbon-bg); border-bottom: 1px solid var(--hairline); }

#formulaRow {
  height: 26px;
  display: flex;
  align-items: center;
  background: #fff;
  border-top: 1px solid var(--hairline);
  padding-right: 2px;
}
#nameboxwrap {
  width: 132px; height: 21px;
  margin: 0 4px 0 7px;
  display: flex; align-items: stretch;
  border: 1px solid #c7c3bd; border-radius: 2px;
  background: #fff;
  flex: none;
  position: relative;
}
#nameBox {
  flex: 1; min-width: 0;
  border: none; outline: none; background: transparent;
  font-family: var(--ui-font); font-size: 12px;
  padding: 0 2px 0 7px;
  color: #201f1e;
}
.nbdrop {
  width: 20px; border: none; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.nbdrop:hover { background: #efeeed; }

#fxButton {
  font-style: italic; font-family: Georgia, serif;
  width: 27px; height: 21px; margin-right: 5px;
  border: 1px solid transparent; background: transparent;
  color: #333; font-size: 12px; cursor: pointer; border-radius: 2px;
}
#fxButton:hover { border-color: #bbb; background: #fbfbfa; }

#checkBox {
  flex: 1; min-width: 60px; height: 21px;
  border: 1px solid #c7c3bd; border-radius: 2px; outline: none;
  font-family: var(--cell-font); font-size: 12.5px;
  padding: 0 5px; color: #111;
  caret-color: #111;
}
#checkBox:focus { border-color: var(--xl-green); }
#fxChevron { width: 18px; height: 20px; border: none; background: transparent; cursor: pointer; }

/* formula-row expansion (Ctrl+Shift+U) */
#gridWrap.expanded-with-fxbar #formulaRow-expandedBox { display: block; }

/* --------------------------- grid wrapper -------------------------------- */
#gridWrap {
  flex: 1;
  position: relative;
  min-height: 80px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr;
  background: #fff;
}
#scrollerHost { grid-area: 2 / 2; position: relative; overflow: hidden; }
#cornerBox {
  grid-area: 1 / 1;
  width: 30px; height: 20px;
  background: linear-gradient(#fdfdfd,#f3f2f1);
  border-right: 1px solid #b6b3ae;
  border-bottom: 1px solid #b6b3ae;
  position: relative; z-index: 4;
}
#colStrip {
  grid-area: 1 / 2;
  overflow: hidden;
  position: relative; z-index: 3;
  background: linear-gradient(#fdfdfd,#f3f2f1);
}
#rowStrip {
  grid-area: 2 / 1;
  overflow: hidden;
  position: relative; z-index: 3;
  width: 30px;
  background: linear-gradient(#fdfdfd,#f3f2f1);
}
#rowStripInner, #colStripInner { position: absolute; inset: 0; }

#gridScroller {
  grid-area: 2 / 2;
  overflow: scroll;
  position: relative;
  outline: none;
  overscroll-behavior: none;
}
#spacer { position: absolute; top: 0; left: 0; width: 1px; height: 1px; }
#canvas {
  position: absolute; top: 0; left: 0;
  contain: strict;
}
#overlayLayer {
  position: absolute; inset: 0;
  pointer-events: none; z-index: 2;
}
#overlayLayer > * { pointer-events: auto; }

/* ---------------------------- sheet tabs ---------------------------------- */
#sheetbar {
  flex: none;
  height: 23px;
  display: flex;
  align-items: stretch;
  background: linear-gradient(180deg, #ececeb, #dedddb 88%);
  border-top: 1px solid #c9c6c2;
}
#sheetNav { display: flex; align-items: center; padding: 0 3px; gap: 1px; }
.shnav {
  width: 15px; height: 15px; border: none; background: transparent;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 2px; color: #55504b;
}
.shnav:hover { background: #fff; box-shadow: inset 0 0 0 1px #ccc; }

#sheetTabs {
  display: flex; align-items: flex-end;
  max-width: calc(100% - 90px);
  overflow-x: hidden;
  scrollbar-width: none;
}
.sheet-tab {
  height: 19px;
  padding: 0 10px 0 12px;
  display: inline-flex; align-items: center;
  font-size: 12px; color: #45433f;
  background: linear-gradient(#fbfbfa,#e8e7e5);
  border: 1px solid #c9c6c2; border-bottom: none;
  border-radius: 4px 4px 0 0;
  margin-right: 1px;
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  transform: translateY(-1px);
}
.sheet-tab.active {
  background: #fff;
  color: #17161a;
  font-weight: 600;
  border-color: #b9b6b1;
  box-shadow: 0 -1px 0 var(--xl-green) inset;
  height: 21px;
  z-index: 2;
}
.sheet-tab:not(.active):hover { background: linear-gradient(#fff,#eee); }
.sheet-tab .tabcolor-dot {
  width: 8px; height: 8px; border-radius: 2px; margin-right: 5px;
  outline: 1px solid rgba(0,0,0,.2);
}
.sheet-tab input.tabrename {
  position: absolute; inset: 1px 4px;
  font: inherit; color: inherit; border: 1px solid var(--xl-green);
  outline: none; width: calc(100% - 8px);
}

#addSheetBtn {
  width: 20px; margin: 1px 4px;
  border: none; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 3px; align-self: center; height: 18px;
}
#addSheetBtn:hover { background: #fff; box-shadow: inset 0 0 0 1px #ccc; }

#sheetHScroll { flex: 1; }

/* ----------------------------- status bar --------------------------------- */
#statusbar {
  flex: none;
  height: 24px;
  background: linear-gradient(180deg, #227a4a, #1c673f);
  color: #ecf6ef;
  display: flex;
  align-items: center;
  font-size: 11.5px;
  padding: 0 6px;
  gap: 10px;
  box-shadow: 0 -1px 0 rgba(0,0,0,.28) inset;
}
.sb-cell { min-width: 56px; }
#statusStats { opacity: .95; white-space: nowrap; overflow: hidden; }
#statusRight { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.zb, .sb-ic { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; opacity: .9; }
.zb:hover, .sb-ic:hover { opacity: 1; }
#zoomSlider { width: 108px; accent-color: #dfe9e2; cursor: pointer; }
.zb-lb { min-width: 34px; text-align: center; }

#viewShortcuts { display: inline-flex; gap: 4px; }
.vsc {
  width: 22px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 2px; cursor: pointer;
}
.vsc:hover { background: rgba(255,255,255,.16); }
.vsc.on { background: rgba(0,0,0,.22); }

/* misc */
button:focus-visible, input:focus-visible { outline: 2px solid #6ea88e; outline-offset: -1px; }

@media print {
  body > :not(#excelWindow) { display: none !important; }
  #desktop { padding: 0; }
  #excelWindow { box-shadow: none; border-radius: 0; }
  #tabstrip, #ribbonBody, #sheetbar, #statusbar, #winbtns { display: none !important; }
}
