* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  color: #222;
  background: #fff;
  font-family: Calibri, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

.sheet {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 640px;
}

.ribbon {
  flex: none;
  background: #f3f3f3;
  border-bottom: 1px solid #d0d0d0;
  user-select: none;
}

.ribbon-tabs {
  display: flex;
  gap: 2px;
  height: 30px;
  padding: 4px 8px 0;
}

.ribbon-tab {
  height: 26px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #8a8a8a;
  cursor: default;
}

.ribbon-tab.is-current {
  color: #217346;
  border-bottom-color: #217346;
  background: #fff;
}

.ribbon-body {
  display: flex;
  align-items: center;
  height: 42px;
  padding: 0 4px 6px;
  overflow-x: auto;
}

.ribbon-group {
  display: flex;
  flex: none;
  align-items: center;
  gap: 2px;
  height: 32px;
  padding: 0 8px;
  border-right: 1px solid #e1e1e1;
}

.ribbon-group:last-child {
  border-right: 0;
}

.ribbon button,
.ribbon select {
  height: 26px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: #8d8d8d;
  font-size: 12px;
  white-space: nowrap;
  opacity: 1;
  cursor: default;
}

.ribbon-tab.is-current:disabled {
  color: #217346;
  border-bottom-color: #217346;
  background: #fff;
  opacity: 1;
}

.ribbon select {
  width: 72px;
}

.ribbon .mark {
  width: 26px;
  padding: 0;
  font-weight: 700;
}

.ribbon .italic {
  font-style: italic;
  font-weight: 500;
}

.ribbon .underline {
  text-decoration: underline;
}

.formula {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 8px;
  border-bottom: 1px solid #d0d0d0;
  background: #fff;
}

.name-box, .formula-input, #editor {
  border: 1px solid #b4b4b4;
  background: #fff;
  outline: none;
}

.name-box {
  width: 96px;
  height: 24px;
  text-align: center;
  user-select: text;
}

.name-box:focus, .formula-input:focus, #editor:focus {
  border-color: #107c41;
}

.fx {
  width: 22px;
  color: #6f6f6f;
  font-family: "Times New Roman", serif;
  font-style: italic;
  text-align: center;
}

.formula-input {
  flex: 1;
  height: 24px;
  padding: 0 6px;
  resize: none;
  overflow: hidden;
  line-height: 20px;
  color: #111;
  caret-color: transparent;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

.grid-area {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  grid-template-rows: 25px minmax(0, 1fr);
}

.corner, .col-view, .row-view, .cell, .tabs, .status {
  user-select: none;
}

.corner, .col-view, .row-view {
  background: #f8f9fa;
  border-right: 1px solid #d0d0d0;
  border-bottom: 1px solid #d0d0d0;
}

.corner {
  position: relative;
  padding: 0;
  cursor: pointer;
}

.corner::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  border-style: solid;
  border-width: 0 0 8px 8px;
  border-color: transparent transparent #9aa0a6 transparent;
}

.col-view, .row-view, .cells-view {
  position: relative;
  overflow: hidden;
}

.cells-view {
  overflow: auto;
  outline: none;
  background: #fff;
}

.col-canvas, .row-canvas, .canvas {
  position: relative;
}

.col-head, .row-head {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  color: #5f6368;
  font-size: 12px;
  border-right: 1px solid #d0d0d0;
  border-bottom: 1px solid #d0d0d0;
}

.col-head.selected, .row-head.selected {
  background: #caead8;
  color: #0b5f33;
  font-weight: 700;
}

.resize-h, .resize-v {
  position: absolute;
  z-index: 2;
}

.resize-h {
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
}

.resize-v {
  left: 0;
  bottom: -3px;
  width: 100%;
  height: 6px;
  cursor: row-resize;
}

.cell {
  position: absolute;
  padding: 0 4px;
  overflow: hidden;
  white-space: pre;
  background: #fff;
  border-right: 1px solid #d9d9d9;
  border-bottom: 1px solid #d9d9d9;
}

.cell.in-range {
  background: #e7f4ee;
}

.cell.active {
  background: #fff;
}

.sel-box {
  position: absolute;
  z-index: 3;
  box-sizing: border-box;
  border: 2px solid #107c41;
  pointer-events: none;
}

#editor {
  position: absolute;
  z-index: 5;
  margin: 0;
  padding: 1px 4px 0;
  border: 0;
  outline: 2px solid #107c41;
  outline-offset: -2px;
  resize: none;
  overflow: hidden;
  line-height: 16px;
  color: #111;
  caret-color: transparent;
  background: #fff;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

#editor[hidden] {
  display: none !important;
}

#caret {
  position: fixed;
  z-index: 30;
  width: 2px;
  background: #111;
  pointer-events: none;
  animation: caret-blink 1.06s steps(1) infinite;
}

@keyframes caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.tabs {
  display: flex;
  align-items: flex-end;
  height: 32px;
  padding-left: 12px;
  background: #f3f3f3;
  border-top: 1px solid #d0d0d0;
}

.tab {
  min-width: 84px;
  padding: 5px 16px 4px;
  text-align: center;
  background: #fff;
  border: 1px solid #d0d0d0;
  border-bottom: 0;
  border-top: 2px solid #107c41;
}

.status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  color: #444;
  font-size: 12px;
  background: #f3f3f3;
  border-top: 1px solid #d0d0d0;
}
