/* =====================================================
   IndianElucidBiology — Live Spreadsheet Widget CSS
   Interactive Excel-like formula tables
   ===================================================== */

/* Container */
.live-sheet {
  margin: 1.5rem 0 2rem 0;
}

.ls-wrap {
  border: 1.5px solid var(--bs-border-color, #dee2e6);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  background: var(--bs-body-bg, #fff);
  font-size: 0.875rem;
}

/* Title bar */
.ls-title {
  background: linear-gradient(135deg, #1d6f42 0%, #217346 100%);
  color: #fff;
  padding: 0.6rem 1rem;
  font-weight: 700;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  letter-spacing: 0.01em;
}

/* Formula bar (like Excel name box + formula bar) */
.ls-formula-bar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bs-body-bg, #fff);
  border-bottom: 1.5px solid var(--bs-border-color, #dee2e6);
  padding: 0;
  min-height: 32px;
}

.ls-cell-ref {
  min-width: 56px;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--bs-body-color);
  padding: 0 0.5rem;
  border-right: 1.5px solid var(--bs-border-color, #dee2e6);
  height: 32px;
  line-height: 32px;
  background: var(--bs-tertiary-bg, #f8f9fa);
}

.ls-fx-label {
  padding: 0 0.6rem;
  font-size: 0.8rem;
  color: #6c757d;
  font-style: italic;
  border-right: 1px solid var(--bs-border-color, #dee2e6);
  height: 32px;
  line-height: 32px;
}

.ls-formula-display {
  flex: 1;
  padding: 0 0.75rem;
  font-size: 0.82rem;
  color: var(--bs-body-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  height: 32px;
  line-height: 32px;
}

.ls-formula-code {
  background: none;
  padding: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  color: #0d6efd;
  font-weight: 600;
}

[data-bs-theme="dark"] .ls-formula-code {
  color: #6ea8fe;
}

/* Table scroll wrapper */
.ls-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Main table */
.ls-table {
  width: 100%;
  min-width: 400px;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 0.82rem;
}

.ls-table thead th {
  background: var(--bs-tertiary-bg, #f0f0f0);
  border: 1px solid var(--bs-border-color, #dee2e6);
  padding: 5px 8px;
  text-align: center;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--bs-body-color);
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Row number gutter */
.ls-row-num {
  background: var(--bs-tertiary-bg, #f8f9fa);
  border: 1px solid var(--bs-border-color, #dee2e6);
  color: #6c757d;
  font-size: 0.72rem;
  padding: 4px 6px;
  text-align: center;
  width: 32px;
  user-select: none;
}

/* Section header row */
.ls-row-header td {
  background: rgba(13, 110, 253, 0.07);
  border: 1px solid var(--bs-border-color, #dee2e6);
  font-weight: 700;
  font-size: 0.78rem;
  color: #0d6efd;
  padding: 4px 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

[data-bs-theme="dark"] .ls-row-header td {
  background: rgba(110, 168, 254, 0.1);
  color: #6ea8fe;
}

/* Base cell */
.ls-cell {
  border: 1px solid var(--bs-border-color, #dee2e6);
  padding: 4px 8px;
  white-space: nowrap;
  vertical-align: middle;
  transition: background 0.15s;
  min-width: 80px;
}

/* Editable input cell — yellow (like Excel's input cells) */
.ls-cell-input {
  background: #fffde7;
  border-color: #f9a825 !important;
  position: relative;
}

[data-bs-theme="dark"] .ls-cell-input {
  background: #2d2600;
  border-color: #c8900a !important;
}

.ls-cell-input input[type="number"] {
  width: 100%;
  border: none;
  background: transparent;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--bs-body-color);
  outline: none;
  text-align: right;
  padding: 0;
  -moz-appearance: textfield;
}

.ls-cell-input input[type="number"]::-webkit-outer-spin-button,
.ls-cell-input input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.ls-cell-input input:focus {
  box-shadow: 0 0 0 2px #f9a825;
  border-radius: 2px;
}

/* Formula cell — light blue */
.ls-cell-formula {
  background: #e8f4fd;
  color: #0a4a7c;
  text-align: right;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

[data-bs-theme="dark"] .ls-cell-formula {
  background: #0a1e30;
  color: #6ea8fe;
}

.ls-cell-formula:hover {
  background: #cce5ff;
}

[data-bs-theme="dark"] .ls-cell-formula:hover {
  background: #0d2b45;
}

/* Focused / selected cell — green border like Excel */
.ls-cell-focused {
  outline: 2px solid #1d6f42 !important;
  outline-offset: -2px;
  z-index: 1;
  position: relative;
}

/* Text/static cell */
.ls-cell-text {
  color: var(--bs-body-color);
  font-style: normal;
}

/* Error value */
.ls-cell-formula[data-value="#ERR"] {
  color: #dc3545;
  background: #fff5f5;
}

/* Legend */
.ls-legend {
  display: flex;
  gap: 1.5rem;
  padding: 0.5rem 1rem;
  background: var(--bs-tertiary-bg, #f8f9fa);
  border-top: 1px solid var(--bs-border-color, #dee2e6);
  font-size: 0.75rem;
  color: #6c757d;
  flex-wrap: wrap;
}

.ls-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.ls-swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid #ccc;
  display: inline-block;
  flex-shrink: 0;
}

.ls-swatch-input  { background: #fffde7; border-color: #f9a825; }
.ls-swatch-formula { background: #e8f4fd; border-color: #74b9e8; }

/* Column descriptions */
.ls-col-desc {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--bs-border-color, #dee2e6);
  font-size: 0.8rem;
  color: var(--bs-secondary-color, #6c757d);
  background: var(--bs-body-bg, #fff);
}

.ls-col-desc p {
  margin: 0.2rem 0;
}

/* =====================================================
   FORMULA EXPLANATION BLOCK
   Used alongside live sheets to show the formula
   in full text with labels
   ===================================================== */
.formula-explain {
  background: linear-gradient(135deg, rgba(13,110,253,0.05) 0%, rgba(13,110,253,0.02) 100%);
  border: 1.5px solid rgba(13,110,253,0.2);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin: 1rem 0 1.5rem 0;
  font-size: 0.9rem;
}

.formula-explain .fe-title {
  font-weight: 700;
  color: #0d6efd;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.formula-explain .fe-equation {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--bs-body-color);
  background: var(--bs-tertiary-bg, #f8f9fa);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  margin: 0.5rem 0;
  border-left: 4px solid #0d6efd;
}

.formula-explain .fe-terms {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 1rem;
  margin-top: 0.5rem;
}

.formula-explain .fe-var {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: #0d6efd;
  font-size: 0.85rem;
}

.formula-explain .fe-def {
  font-size: 0.85rem;
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .formula-explain {
  background: rgba(110,168,254,0.06);
  border-color: rgba(110,168,254,0.2);
}

[data-bs-theme="dark"] .formula-explain .fe-title { color: #6ea8fe; }
[data-bs-theme="dark"] .formula-explain .fe-var   { color: #6ea8fe; }
