/* The 작업 tab's spreadsheet (js/worksheet.js): the toolbar, the formula bar, the grid, the
   line under it and the sheets' tabs. The app's own parts (bars, buttons, tabs) use the colour
   tokens of styles.css and so follow its theme. The grid itself is the sheet as the file shows
   it, and is white paper in both themes, as a document's pages are (workcanvas.css): a cell's
   fill and text colours are the ones the .xlsx file has. */

.ws {
  --ws-paper: #ffffff;
  --ws-ink: #1f2937;
  --ws-gridline: #e3e5ea;
  --ws-head: #f3f4f6;
  --ws-head-ink: #6b7280;
  --ws-head-on: #e0e3f7;
  --ws-rule: #1f2937; /* a border set on cells */
  --ws-sel: #4f46e5;
  --ws-err: #c62828;
  --ws-row: 25px;
}

.ws-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 0;
  min-width: 0;
  padding: 12px 16px 16px;
}
.ws-main > * {
  flex: none;
  min-width: 0;
}

/* ---------- the toolbar ---------- */

.ws-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.ws-tool {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.ws-tool:hover:not(:disabled) {
  border-color: var(--line-strong);
  color: var(--ink);
}
.ws-tool:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
.ws-tool:disabled {
  opacity: 0.45;
  cursor: default;
}
.ws-tool[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.ws-bold b {
  font-size: 14.5px;
  font-weight: 800;
}
.ws-fill-sw {
  width: 12px;
  height: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
}
.ws-fmt {
  min-width: 84px;
  justify-content: space-between;
}
.ws-fmt-name {
  white-space: nowrap;
}
.ws-sep {
  width: 1px;
  height: 20px;
  margin: 0 4px;
  background: var(--line);
}
.ws-gap {
  flex: 1;
}
.ws-toolbar .wc-saved {
  padding-top: 0;
}
.ws-stop {
  gap: 5px;
}
/* (a menu's swatch: the fill colours) */
.ws-menu-sw {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.ws-sw {
  width: 16px;
  height: 16px;
  border: 1px solid rgb(0 0 0 / 0.15);
  border-radius: 4px;
}

/* ---------- the formula bar ---------- */

.ws-fbar {
  display: flex;
  align-items: stretch;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}
.ws-addr {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 58px;
  padding: 0 8px;
  border-right: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.ws-fx {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
  font-weight: 650;
}
.ws-formula-input {
  flex: 1;
  min-width: 0;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-family: ui-monospace, "SF Mono", Consolas, var(--font);
  outline: none;
}
.ws-fbar:focus-within {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.ws-formula-input[readonly] {
  color: var(--ink-2);
}

/* ---------- the grid ---------- */

.ws-edit {
  position: relative;
  flex: 1 1 auto;
  min-height: 220px;
  display: flex;
}
.ws-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto; /* (only the grid scrolls sideways, never the page) */
  overscroll-behavior: contain;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--ws-paper);
  outline: none;
  isolation: isolate; /* (its own layers: the frozen letters and numbers over the chosen cells, the whole under .ws-over) */
}
.ws-wrap:focus-visible {
  box-shadow: var(--ring);
}
.ws-grid-in {
  position: relative;
  width: max-content;
  min-width: 100%;
}
.ws-grid {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--ws-ink);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.3;
  user-select: none;
  -webkit-user-select: none;
}
.ws-grid th,
.ws-grid td {
  height: var(--ws-row);
  padding: 0 6px;
  border-right: 1px solid var(--ws-gridline);
  border-bottom: 1px solid var(--ws-gridline);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
}
/* the frozen letters and numbers stay over the cells, the box of the chosen cells and the cell editor as the grid scrolls under them */
.ws-grid thead th {
  position: sticky;
  top: 0;
  z-index: 6;
}
.ws-grid th {
  background: var(--ws-head);
  color: var(--ws-head-ink);
  font-size: 11.5px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.ws-grid th.on {
  background: var(--ws-head-on);
  color: #312e81;
}
.ws-rh {
  position: sticky;
  left: 0;
  z-index: 5;
}
.ws-corner {
  left: 0;
  z-index: 7 !important;
}
.ws-ch {
  position: relative;
}
/* a column's right edge: dragged to make it wider or narrower */
.ws-col-edge {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 8px;
  z-index: 2;
  cursor: col-resize;
  touch-action: none;
}
.ws-col-edge::after {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  right: 0;
  width: 2px;
  border-radius: 1px;
  background: transparent;
}
.ws-col-edge:hover::after,
.ws-col-edge.wh-pressed::after,
.ws-sizing .ws-col-edge::after {
  background: var(--ws-sel);
}
.ws-sizing,
.ws-sizing * {
  cursor: col-resize !important;
}
.ws-readonly .ws-col-edge {
  cursor: default;
}

.ws-c {
  background: var(--ws-paper);
  cursor: cell;
}
.ws-readonly .ws-c {
  cursor: default;
}
.ws-c.ws-right {
  text-align: right;
}
.ws-c.ws-center {
  text-align: center;
}
.ws-c.ws-left {
  text-align: left;
}
.ws-c.ws-b {
  font-weight: 700;
}
.ws-c.ws-wrapped {
  white-space: normal;
  overflow-wrap: anywhere;
  height: auto;
  padding-block: 3px;
}
.ws-c.ws-err {
  color: var(--ws-err);
  font-weight: 600;
}
.ws-c.ws-right,
.ws-c.ws-center {
  font-variant-numeric: tabular-nums;
}
/* the cell the AI is typing in: its text as typed (a formula before it is worked out) */
.ws-c.ws-typing {
  outline: 2px dashed color-mix(in srgb, var(--ws-sel) 70%, transparent);
  outline-offset: -2px;
  overflow: visible;
  font-family: ui-monospace, "SF Mono", Consolas, var(--font);
  font-size: 12.5px;
  text-align: left;
}
.ws-c .wc-caret {
  color: var(--ws-sel);
}

/* the chosen cells */
.ws-selbox {
  position: absolute;
  z-index: 1;
  border: 2px solid var(--ws-sel);
  pointer-events: none;
}
.ws-selbox.range {
  background: color-mix(in srgb, var(--ws-sel) 10%, transparent);
}

/* the cell editor: over the chosen cell, unseen until a key is typed (so a Korean IME types into it from the first letter) */
.ws-cell-editor {
  position: absolute;
  z-index: 4;
  box-sizing: border-box;
  margin: 0;
  padding: 0 5px;
  border: 2px solid var(--ws-sel);
  border-radius: 0;
  background: var(--ws-paper);
  color: var(--ws-ink);
  font: inherit;
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  box-shadow: 0 2px 10px rgb(20 20 40 / 0.18);
}
.ws-cell-editor.ready {
  opacity: 0;
  pointer-events: none;
  caret-color: transparent;
}

/* a sheet not written yet: its planned name and what it is to hold, over the empty grid */
.ws-over {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: none;
}
.ws-over-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  max-width: 420px;
  padding: 18px 22px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  color: var(--ink-2);
  text-align: center;
  pointer-events: auto;
}
.ws-over-card .wc-skel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}
.ws-over-card .wc-skel-brief {
  font-size: 13px;
  color: var(--muted);
}
.ws-over-card.st-failed {
  border-color: var(--bad);
}

/* the line under the grid: what the sheet is for */
.ws-notes {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
}
.ws-notes:hover:not([readonly]) {
  border-color: var(--line);
}
.ws-notes:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.ws-notes[readonly] {
  cursor: default;
}

/* ---------- the sheets' tabs, at the bottom as in a spreadsheet ---------- */

.ws-tabs {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 4px;
  min-width: 0;
  padding: 2px 2px 4px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}
.ws-tabs > .wc-item {
  flex: none;
  flex-direction: row;
}
.ws-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  height: 34px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}
.ws-tab:hover {
  color: var(--ink);
}
.ws-tab[aria-selected="true"] {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--accent-text);
  box-shadow: inset 0 3px 0 var(--accent);
}
.ws-tab:focus-visible {
  box-shadow: var(--ring);
}
.ws-tab-name {
  min-width: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ws-tab.planned {
  border-style: dashed;
  border-top-style: none;
  background: transparent;
  color: var(--muted);
}
.ws-tab.st-failed {
  color: var(--bad);
}
.ws-tab .wc-marks {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.ws-tab .wc-marks:empty {
  display: none;
}
.ws-tab .wc-thumb-more {
  appearance: none;
  position: static;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}
.ws-tab:hover .wc-thumb-more,
.ws-tab:focus-within .wc-thumb-more,
.ws-tab[aria-selected="true"] .wc-thumb-more,
.ws-tab .wc-thumb-more.wh-show {
  opacity: 1;
}
.ws-tab .wc-thumb-more:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.ws-tab-ghost {
  width: 96px;
  padding: 0;
  cursor: default;
}
.ws-tab-ghost .wc-skel {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border: 0;
}
.ws-tabs .wc-add.ws-add {
  flex: none;
  width: 36px;
  height: 34px;
  margin: 0;
  border-top: 0;
  border-radius: 0 0 8px 8px;
}
.ws-tabs .wc-drop-line.across {
  top: 4px;
  bottom: 6px;
}

.ws-fb-slot:empty {
  display: none;
}

/* ---------- the AI's hands on a sheet (workhands.js) ---------- */

/* the range the hands drag over before they press B or a format */
.wh-sel.wh-cells {
  border: 2px solid var(--wh-ai, var(--accent));
  border-radius: 0;
  background: color-mix(in srgb, var(--wh-ai, var(--accent)) 14%, transparent);
}

/* ---------- narrow screens: the grid scrolls in its own box ---------- */

@container wc (max-width: 640px) {
  .ws-main {
    padding: 10px 10px 14px;
  }
  .ws-edit {
    min-height: 260px;
  }
  .ws-fmt {
    min-width: 0;
  }
  .ws-stop span {
    display: none;
  }
}
@media (pointer: coarse) {
  .ws {
    --ws-row: 30px;
  }
  .ws-tool {
    min-width: 38px;
    height: 38px;
  }
  .ws-col-edge {
    width: 14px;
  }
  .ws-tab .wc-thumb-more {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ws-tab .wc-thumb-more {
    transition: none;
  }
}
