/* worksheet_viewer.css -- Worksheet DOM renderer styles.
 *
 * Self-contained. No imports. No build step.
 * Customize via CSS variables on .ws-viewer or :root.
 */

/* ────────────────────────────────────────────────────────────────
   CSS variables (defaults)
   ──────────────────────────────────────────────────────────────── */

.ws-viewer {
  --ws-font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --ws-font-size: 12px;
  --ws-font-mono: 'JetBrains Mono', 'SF Mono', ui-monospace, 'Cascadia Code', 'Consolas', monospace;
  --ws-bg: #FFFFFF;
  --ws-header-bg: #F3F3F3;
  --ws-header-border: #D4D4D4;
  --ws-cell-border: #F2F2F2;
  --ws-row-hover-bg: #F5F8F5;
  --ws-error-bg: #fff0f0;
  --ws-error-color: #cc0000;
  --ws-flag-info-color: #0066cc;
  --ws-flag-warning-color: #cc8800;
  --ws-flag-error-color: #cc0000;
  --ws-summary-bg: #fff8f0;
  --ws-summary-border: #e8d8c0;
  --ws-provenance-bg: #F9F9F9;
  --ws-provenance-border: #E6E6E6;
  --ws-sticky-z: 10;
  --ws-text-color: #111111;
  --ws-text-dim: #666666;
  --ws-text-soft: #222222;
  --ws-select: #107C41;
}

/* ────────────────────────────────────────────────────────────────
   Container
   ──────────────────────────────────────────────────────────────── */

.ws-viewer {
  font-family: var(--ws-font-family);
  font-size: var(--ws-font-size);
  color: var(--ws-text-color);
  background: var(--ws-bg);
  line-height: 1;
}

/* ────────────────────────────────────────────────────────────────
   Error summary banner
   ──────────────────────────────────────────────────────────────── */

.ws-error-summary {
  background: var(--ws-summary-bg);
  border: 1px solid var(--ws-summary-border);
  border-radius: 4px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: calc(var(--ws-font-size) - 1px);
}

.ws-error-summary-title {
  font-weight: 600;
  color: var(--ws-error-color);
}

.ws-error-summary-detail {
  margin-top: 4px;
  color: var(--ws-text-dim);
}

/* ────────────────────────────────────────────────────────────────
   Scrollable table container
   ──────────────────────────────────────────────────────────────── */

.ws-table-container {
  overflow: auto;
  max-height: 80vh;
  border: 1px solid var(--ws-cell-border);
  border-radius: 4px;
}

/* ────────────────────────────────────────────────────────────────
   Table
   ──────────────────────────────────────────────────────────────── */

.ws-table {
  border-collapse: collapse;
  width: 100%;
  font-variant-numeric: tabular-nums;
}

/* ────────────────────────────────────────────────────────────────
   Sticky headers
   ──────────────────────────────────────────────────────────────── */

.ws-table thead th {
  position: sticky;
  z-index: var(--ws-sticky-z);
  background: var(--ws-header-bg);
  border-bottom: 1px solid var(--ws-header-border);
  padding: 0 4px;
  height: 18px;
  text-align: left;
  font-family: var(--ws-font-family);
  font-weight: 500;
  font-size: 11px;
  color: #333333;
  white-space: nowrap;
}

.ws-header-group-row th {
  top: 0;
  border-bottom: 1px solid var(--ws-header-border);
  text-align: center;
  font-weight: 500;
  color: var(--ws-text-dim);
}

.ws-header-group-row th.ws-group-spacer {
  background: var(--ws-header-bg);
}

/* When group row exists, column headers sit below it */
.ws-table thead .ws-header-row th {
  border-bottom: 1px solid var(--ws-header-border);
}

/* Dynamic top offset set via JS for correct sticky stacking */

/* ────────────────────────────────────────────────────────────────
   Sort indicator on column headers
   ──────────────────────────────────────────────────────────────── */

.ws-sort-indicator {
  margin-left: 4px;
  font-size: 10px;
  color: var(--ws-text-dim);
}

/* ────────────────────────────────────────────────────────────────
   Rows & cells
   ──────────────────────────────────────────────────────────────── */

.ws-table tbody td {
  padding: 0 4px;
  height: 18px;
  border-bottom: 1px solid var(--ws-cell-border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ws-row:hover td {
  background: var(--ws-row-hover-bg);
}

/* Numeric alignment */
.ws-cell--float64,
.ws-cell--int64 {
  text-align: right;
  padding-right: 6px;
}

/* Boolean */
.ws-cell--bool {
  text-align: center;
}

/* Null cells */
.ws-cell--null {
  color: var(--ws-text-dim);
  font-style: italic;
}

/* ────────────────────────────────────────────────────────────────
   Error cells
   ──────────────────────────────────────────────────────────────── */

.ws-cell--error {
  background: var(--ws-error-bg);
  color: var(--ws-error-color);
  font-weight: 600;
  font-size: 11px;
}

/* ────────────────────────────────────────────────────────────────
   Flag cells
   ──────────────────────────────────────────────────────────────── */

.ws-flag-cell {
  padding: 0 4px;
  height: 18px;
  border-bottom: 1px solid var(--ws-cell-border);
  white-space: nowrap;
  width: 1%;
}

.ws-flag {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 2px;
  vertical-align: middle;
}

.ws-flag--info {
  background: var(--ws-flag-info-color);
}

.ws-flag--warning {
  background: var(--ws-flag-warning-color);
}

.ws-flag--error {
  background: var(--ws-flag-error-color);
}

/* ────────────────────────────────────────────────────────────────
   Provenance footer
   ──────────────────────────────────────────────────────────────── */

.ws-provenance {
  margin-top: 8px;
  border: 1px solid var(--ws-provenance-border);
  border-radius: 4px;
  background: var(--ws-provenance-bg);
  font-size: calc(var(--ws-font-size) - 1px);
}

.ws-provenance summary {
  padding: 6px 12px;
  cursor: pointer;
  font-family: var(--ws-font-family);
  font-weight: 600;
  color: var(--ws-text-dim);
  user-select: none;
}

.ws-provenance summary:focus-visible {
  outline: 2px solid var(--ws-select);
  outline-offset: -2px;
}

.ws-provenance-details {
  padding: 8px 12px 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
}

.ws-provenance-details dt {
  font-weight: 600;
  color: var(--ws-text-dim);
}

.ws-provenance-details dd {
  margin: 0;
  font-family: var(--ws-font-mono);
  font-size: calc(var(--ws-font-size) - 1px);
}

/* ────────────────────────────────────────────────────────────────
   Semantic cell roles
   ──────────────────────────────────────────────────────────────── */

/* Numeric: right-aligned (supplements type-based alignment) */
.ws-cell--numeric {
  text-align: right;
  padding-right: 6px;
}

/* Text: left-aligned */
.ws-cell--text {
  text-align: left;
}

/* Label: dim, same family */
.ws-cell--label {
  color: var(--ws-text-dim);
}

/* Input: darkest value text */
.ws-cell--input {
  color: #000000;
}

/* Formula: slightly softer than inputs */
.ws-cell--formula {
  color: var(--ws-text-soft);
}

/* Lookup: same as formula unless distinguished */
.ws-cell--lookup {
  color: var(--ws-text-soft);
}

/* Key outputs: semibold + full black — wins over formula/lookup color */
.ws-cell--key-output {
  font-weight: 600;
  color: #000000;
}

/* Dense values — medium density */
.ws-cell--dense-md {
  font-size: 11px;
}

/* Dense values — high density */
.ws-cell--dense {
  font-size: 11px;
  letter-spacing: -0.01em;
}

/* ────────────────────────────────────────────────────────────────
   Title
   ──────────────────────────────────────────────────────────────── */

.ws-title {
  font-family: var(--ws-font-family);
  font-size: calc(var(--ws-font-size) + 3px);
  font-weight: 700;
  margin-bottom: 8px;
}
