/* The spreadsheet table. Column widths come from <col> elements set in js/grid.js. */
.grid {
  table-layout: fixed;
  /* "separate" keeps borders on sticky headers while the body scrolls under them. */
  border-collapse: separate;
  border-spacing: 0;
  user-select: none;
}

.grid th,
.grid td {
  height: var(--cell-height);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

/* ---- headers ---- */

.grid th {
  padding: 0;
  background: var(--paper-raised);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 400;
  text-align: center;
}

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom-color: var(--line-bright);
}

.grid .row-head {
  position: sticky;
  left: 0;
  z-index: 10;
  border-right-color: var(--line-bright);
}

.grid .corner {
  left: 0;
  z-index: 30;
  border-right-color: var(--line-bright);
}

.grid .active-head {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.resizer {
  position: absolute;
  top: 0;
  right: -4px;
  z-index: 1;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.resizer:hover {
  background: var(--accent);
  opacity: 0.4;
}

/* ---- cells ---- */

.grid td {
  position: relative;
  padding: 0 var(--space-2);
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
  /* Keeps a cell clear of the sticky headers when the keyboard scrolls it into view. */
  scroll-margin: calc(var(--cell-height) + 4px) 4px 4px 52px;
}

.grid td:hover {
  background-color: var(--paper-raised);
}

.grid td.active {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.grid td.wrap {
  padding-block: var(--space-1);
  white-space: normal;
  overflow-wrap: anywhere;
}

.grid td.header {
  border-bottom: 1px solid var(--ink);
  color: var(--ink-strong);
  font-weight: 600;
}

.grid td.large {
  overflow: visible;
  color: var(--accent);
  font-size: var(--text-md);
}

.grid td.bold {
  color: var(--ink-strong);
  font-weight: 600;
}

.grid td.italic {
  font-style: italic;
}

.grid td.underline {
  text-decoration: underline;
}

.grid td.strike {
  text-decoration: line-through;
}

.grid td.underline.strike {
  text-decoration: underline line-through;
}

.grid td.align-left {
  text-align: left;
}

.grid td.align-center {
  text-align: center;
}

.grid td.align-right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.grid td a {
  color: var(--accent);
}

.grid td a:hover {
  color: var(--ink-strong);
}

.grid.no-gridlines td {
  border-color: transparent;
}

.grid.no-gridlines td.header {
  border-bottom-color: var(--ink);
}

.cell-editor {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  padding: 0 var(--space-2);
  border: 0;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--paper);
  color: var(--ink-strong);
  user-select: text;
}

/* ---- phone and touch ---- */

.grid-scroll {
  /* Stops double-tap zoom, so a second tap can start an edit. */
  touch-action: manipulation;
}

@media (max-width: 40rem) {
  /* Columns are narrow here (see js/grid.js), so every cell wraps. Nothing is cut off. */
  .grid td {
    padding: var(--space-1) 6px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .grid td.large {
    white-space: nowrap;
  }

  .resizer {
    display: none;
  }
}
