/*
 * RECKONER — surface styling.
 *
 * The blink test governs this file: at a glance, from across a room, this has
 * to read as A SPREADSHEET. That means the donor's load-bearing furniture —
 * lettered column heads, numbered rows, a formula bar with an fx sign, a hard
 * gridline lattice, right-aligned numerals, one heavy active-cell ring — is
 * kept exactly where a hand expects it. What is ours is the register: ink and
 * slate rather than office blue, and a chart-paper lattice rather than chrome.
 */

:root {
  --rk-ink: #16232a;
  --rk-ink-soft: #5b6b74;
  --rk-line: #d3dbdf;
  --rk-line-hard: #a9b6bd;
  --rk-paper: #ffffff;
  --rk-head: #eef2f4;
  --rk-accent: #0f5f6b;
  --rk-accent-soft: rgba(15, 95, 107, 0.12);
  --rk-err: #a3320f;
  --rk-formula: #0f5f6b;
  --rk-font: "Inter", "Helvetica Neue", Arial, sans-serif;
  --rk-mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --rk-row-h: 27px;
  --rk-col-w: 104px;
  /* Column A holds leg names, so it is wider ON PURPOSE. Without an explicit
     width the fixed-layout table distributed its slack into whichever column
     happened to hold the longest string, which is how the first hand-seat
     capture came back with a 250px column A nobody had asked for. */
  --rk-col-a: 236px;
  --rk-head-w: 44px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--rk-paper);
  color: var(--rk-ink);
  font-family: var(--rk-font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.rk {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

/* ------------------------------------------------------------------ bar */

.rk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--rk-line);
  background: var(--rk-head);
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.rk-brand {
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 13px;
}

.rk-sub {
  color: var(--rk-ink-soft);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.rk-tools {
  margin-left: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.rk-btn {
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid var(--rk-line-hard);
  border-radius: 4px;
  background: var(--rk-paper);
  color: var(--rk-ink);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.rk-btn:hover:not(:disabled) {
  background: var(--rk-accent-soft);
  border-color: var(--rk-accent);
}

.rk-btn:disabled {
  opacity: 0.42;
  cursor: default;
}

.rk-btn:focus-visible {
  outline: 2px solid var(--rk-accent);
  outline-offset: 1px;
}

.rk-file {
  position: relative;
  overflow: hidden;
}

.rk-file input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

.rk-fx {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--rk-line-hard);
  background: var(--rk-paper);
  flex: 0 0 auto;
}

.rk-fx-addr {
  width: 88px;
  flex: 0 0 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--rk-mono);
  font-size: 12px;
  border-right: 1px solid var(--rk-line);
  color: var(--rk-ink);
}

.rk-fx-sign {
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-style: italic;
  font-family: Georgia, serif;
  color: var(--rk-ink-soft);
  border-right: 1px solid var(--rk-line);
}

.rk-fx-input {
  flex: 1 1 auto;
  border: 0;
  padding: 7px 10px;
  font-family: var(--rk-mono);
  font-size: 13px;
  color: var(--rk-ink);
  background: transparent;
  min-width: 0;
}

.rk-fx-input:focus {
  outline: 2px solid var(--rk-accent);
  outline-offset: -2px;
}

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

.rk-wrap {
  position: relative;
  flex: 1 1 auto;
  overflow: auto;
  min-height: 0;
  background: var(--rk-paper);
}

.rk-grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  outline: none;
  /* Stated, not inferred: row head + wide column A + 11 standard columns. */
  width: calc(var(--rk-head-w) + var(--rk-col-a) + 11 * var(--rk-col-w));
}

.rk-colhead[data-col="0"],
.rk-cell[data-col="0"] {
  width: var(--rk-col-a);
}

.rk-grid th,
.rk-grid td {
  border-right: 1px solid var(--rk-line);
  border-bottom: 1px solid var(--rk-line);
  height: var(--rk-row-h);
  padding: 0 6px;
  font-weight: 400;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rk-corner,
.rk-colhead {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--rk-head);
  border-bottom: 1px solid var(--rk-line-hard);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--rk-ink-soft);
  text-align: center;
  width: var(--rk-col-w);
}

.rk-corner {
  left: 0;
  z-index: 4;
  width: 44px;
  border-right: 1px solid var(--rk-line-hard);
}

.rk-rowhead {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 44px;
  background: var(--rk-head);
  border-right: 1px solid var(--rk-line-hard);
  font-family: var(--rk-mono);
  font-size: 11px;
  color: var(--rk-ink-soft);
  text-align: center;
}

.rk-colhead.is-sel,
.rk-rowhead.is-sel {
  background: var(--rk-accent-soft);
  color: var(--rk-accent);
  font-weight: 600;
}

.rk-cell {
  width: var(--rk-col-w);
  background: var(--rk-paper);
  cursor: cell;
}

.rk-cell.is-num {
  text-align: right;
  font-family: var(--rk-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.rk-cell.is-err {
  color: var(--rk-err);
  font-weight: 600;
  text-align: right;
}

.rk-cell.is-sel {
  background: var(--rk-accent-soft);
}

.rk-cell.is-active {
  background: var(--rk-paper);
  box-shadow: inset 0 0 0 2px var(--rk-accent);
}

/* A formula cell is marked in the corner, not by colouring its value: the
   number has to stay readable as a number. */
.rk-cell.is-formula::after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
}

.rk-cell.is-formula {
  position: relative;
  background-image: linear-gradient(
    225deg,
    var(--rk-formula) 0,
    var(--rk-formula) 4px,
    transparent 4px
  );
  background-repeat: no-repeat;
  background-position: top right;
  background-size: 8px 8px;
}

.rk-cell.is-formula.is-sel {
  background-color: var(--rk-accent-soft);
}

.rk-editor {
  position: absolute;
  z-index: 6;
  border: 2px solid var(--rk-accent);
  padding: 0 5px;
  font-family: var(--rk-mono);
  font-size: 13px;
  color: var(--rk-ink);
  background: var(--rk-paper);
  outline: none;
  min-width: 0;
}

/* --------------------------------------------------------------- status */

.rk-status {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 7px 14px;
  border-top: 1px solid var(--rk-line-hard);
  background: var(--rk-head);
  font-size: 11.5px;
  color: var(--rk-ink-soft);
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.rk-receipt {
  font-family: var(--rk-mono);
  color: var(--rk-accent);
}

.rk-stats {
  font-family: var(--rk-mono);
}

.rk-proof {
  margin-left: auto;
  font-family: var(--rk-mono);
}

.rk-warn {
  color: var(--rk-err);
  font-weight: 700;
}

@media (max-width: 640px) {
  :root {
    --rk-col-w: 88px;
    --rk-col-a: 178px;
  }
  .rk-sub {
    display: none;
  }
  .rk-proof {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rk-btn {
    transition: none;
  }
}
