/* The board keeps its spreadsheet look in light mode. Every colour goes
   through these variables so the same markup reads in dark mode too. */
.sheet-board {
  --sheet-bg: var(--surface-0);
  --sheet-fg: var(--fg);
  --sheet-fg-muted: var(--fg-secondary);
  --sheet-fg-faint: var(--fg-muted);
  --sheet-title: #1a365d;
  --sheet-accent: var(--accent);
  --sheet-accent-hover: var(--accent-hover);
  --sheet-accent-fg: var(--accent-fg);
  --sheet-link: var(--accent);
  --sheet-frame: #c7c7c7;
  --sheet-rule: #d9d9d9;
  --sheet-rule-soft: #ececec;
  --sheet-head-bg: #435e91;
  --sheet-head-fg: #fff;
  --sheet-head-rule: #3a527d;
  --sheet-row-closed: #d9ead3;
  --sheet-row-stub: #f8f9fa;
  --sheet-hover: var(--accent-subtle);
  --sheet-chip-bg: #e8eaed;
  --sheet-conflict-bg: #fff2cc;
  --sheet-conflict-border: #f6b26b;
  --sheet-danger: #c5221f;
  --sheet-danger-bg: #fce8e6;
  --sheet-shadow: rgba(32, 33, 36, 0.12);

  background: var(--sheet-bg);
  color: var(--sheet-fg);
  min-height: calc(100vh - 3.5rem);
  padding: 1.25rem 1.5rem 2rem;
}

[data-theme="dark"] .sheet-board {
  --sheet-title: var(--fg);
  --sheet-frame: var(--border-strong);
  --sheet-rule: var(--border-strong);
  --sheet-rule-soft: var(--border);
  --sheet-head-bg: #2b3a57;
  --sheet-head-fg: #e8eefb;
  --sheet-head-rule: #22304a;
  --sheet-row-closed: rgba(106, 168, 79, 0.16);
  --sheet-row-stub: var(--surface-1);
  --sheet-chip-bg: var(--surface-2);
  --sheet-conflict-bg: rgba(246, 178, 107, 0.14);
  --sheet-conflict-border: #b7793a;
  --sheet-danger: var(--danger);
  --sheet-danger-bg: var(--danger-subtle);
  --sheet-shadow: rgba(0, 0, 0, 0.5);
}

/* Inside a page, the board is a section, not the page itself. */
.sheet-board.is-embedded {
  min-height: auto;
  padding: 0;
  background: transparent;
}

.sheet-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--sheet-title);
  letter-spacing: -0.02em;
  margin: 0;
}

.sheet-kpis {
  display: flex;
  gap: 2.5rem;
  margin: 0.7rem 0 0.85rem;
  flex-wrap: wrap;
}

.sheet-kpi {
  min-width: 5.5rem;
}

.sheet-kpi-label {
  font-size: 0.75rem;
  color: var(--sheet-fg-muted);
  margin-bottom: 0.15rem;
}

.sheet-kpi-value {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--sheet-accent);
  line-height: 1.1;
}

.sheet-toolbar {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin: 0 0 0.55rem;
  flex-wrap: wrap;
}

.sheet-toolbar .input,
.sheet-toolbar .select {
  width: auto;
  min-width: 7.25rem;
  max-width: 11rem;
  flex: 0 0 auto;
  height: 1.85rem;
  padding: 0.15rem 0.45rem;
  font-size: 12px;
  border-radius: 4px;
  line-height: 1.2;
}

.sheet-toolbar .select {
  padding-right: 1.6rem;
  background-size: 1.1em 1.1em;
}

.sheet-toolbar .input[data-issue-grid-target="filter"] {
  min-width: 10rem;
  max-width: 16rem;
  flex: 1 1 10rem;
}

.sheet-check {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 12px;
  color: var(--sheet-fg);
  white-space: nowrap;
  margin-left: 0.15rem;
  cursor: pointer;
}

.sheet-check input {
  width: 0.85rem;
  height: 0.85rem;
  accent-color: var(--sheet-accent);
  margin: 0;
}

.sheet-toolbar-apply {
  height: 1.85rem;
  padding: 0 0.65rem;
  font-size: 12px;
  font-weight: 600;
  color: var(--sheet-accent-fg);
  background: var(--sheet-accent);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.sheet-toolbar-apply:hover {
  background: var(--sheet-accent-hover);
}

.sheet-toolbar-reset {
  font-size: 12px;
  color: var(--sheet-accent);
  text-decoration: none;
  padding: 0.15rem 0.35rem;
  white-space: nowrap;
}

.sheet-toolbar-reset:hover {
  text-decoration: underline;
}

.sheet-toolbar-reset.is-muted {
  color: var(--sheet-fg-faint);
  pointer-events: none;
  text-decoration: none;
}

.sheet-toolbar .form-label {
  font-size: 0.7rem;
  color: var(--sheet-fg-muted);
}

.issue-grid-wrap {
  max-height: calc(100vh - 14rem);
  overflow: auto;
  border: 1px solid var(--sheet-frame);
  background: var(--sheet-bg);
}

.issue-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: Arial, Helvetica, sans-serif;
}

.issue-grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--sheet-head-bg);
  color: var(--sheet-head-fg);
  font-size: 12px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  padding: 0.55rem 0.65rem;
  text-align: left;
  border-right: 1px solid var(--sheet-head-rule);
  white-space: nowrap;
}

.issue-grid td {
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--sheet-rule);
  border-right: 1px solid var(--sheet-rule-soft);
  vertical-align: top;
  background: inherit;
}

.issue-grid tbody tr:hover td {
  filter: brightness(0.98);
}

.issue-row.is-closed td {
  background: var(--sheet-row-closed);
}

.issue-row.is-open td {
  background: var(--sheet-bg);
}

.issue-row.is-stub td {
  background: var(--sheet-row-stub);
  color: var(--sheet-fg-faint);
}

.issue-row {
  cursor: pointer;
}

.issue-col-id {
  font-weight: 700;
  white-space: nowrap;
  width: 5.5rem;
}

.issue-ref-link {
  color: inherit;
  text-decoration: none;
  font-weight: 700;
}

.issue-ref-link:hover {
  color: var(--sheet-accent);
  text-decoration: underline;
}

.issue-col-component {
  width: 9rem;
}

.issue-col-title {
  min-width: 22rem;
  max-width: 32rem;
}

.issue-col-details {
  min-width: 14rem;
  max-width: 22rem;
}

.issue-col-priority,
.issue-col-status {
  width: 7.5rem;
}

.issue-col-person {
  width: auto;
  min-width: 9.5rem;
  white-space: nowrap;
}

.issue-col-person .issue-cell,
.issue-col-person .issue-cell-value,
.issue-col-person .issue-cell-content {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.issue-col-notes {
  min-width: 16rem;
}

.issue-cell {
  display: block;
  min-height: 1.4rem;
  position: relative;
}

.issue-cell-value {
  display: block;
  position: relative;
  padding: 0.1rem 0.15rem;
  border-radius: 2px;
  color: inherit;
  text-decoration: none;
  white-space: normal;
  overflow-wrap: anywhere;
  min-height: 1.25rem;
}

.issue-cell-value:hover {
  background-color: var(--sheet-hover);
}

.issue-cell-edit {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.issue-cell-edit-hit {
  display: block;
  width: 100%;
  height: 100%;
}

.issue-cell-content {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

.issue-cell-content .sheet-link {
  pointer-events: auto;
  position: relative;
  z-index: 3;
}

.issue-cell.is-active .issue-cell-value,
.issue-cell:focus-within {
  outline: 2px solid var(--sheet-accent);
  outline-offset: -2px;
}

.issue-cell-form.is-auto-persist {
  padding: 0;
  gap: 0;
}

.issue-cell-form.is-auto-persist .select {
  width: 100%;
  min-width: 7rem;
  font-size: 13px;
  padding-top: 0.2rem;
  padding-bottom: 0.2rem;
}

.issue-cell-form.is-auto-persist .issue-cell-cancel {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.issue-cell-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.15rem;
}

.issue-cell-actions {
  display: flex;
  gap: 0.35rem;
}

.sheet-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.7rem;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}

.sheet-pill-high { background: #ea9999; color: #5b1a1a; }
.sheet-pill-medium { background: #ffe599; color: #5c4a00; }
.sheet-pill-low { background: #b6d7a8; color: #274e13; }
.sheet-pill-open { background: #e06666; color: #fff; }
.sheet-pill-progress { background: #ffd966; color: #5c4a00; }
.sheet-pill-devqa { background: #9fc5e8; color: #1c4587; }
.sheet-pill-qa { background: #6d9eeb; color: #fff; }
.sheet-pill-closed { background: #93c47d; color: #274e13; }
.sheet-pill-design { background: #d5a6bd; color: #4c1130; }
.sheet-pill-blocked { background: #e06666; color: #fff; }
.sheet-pill-reproduced { background: #f6b26b; color: #5c3a00; }

[data-theme="dark"] .sheet-pill-high { background: rgba(234, 153, 153, 0.22); color: #f4b8b8; }
[data-theme="dark"] .sheet-pill-medium { background: rgba(255, 229, 153, 0.18); color: #ffe599; }
[data-theme="dark"] .sheet-pill-low { background: rgba(182, 215, 168, 0.18); color: #c9e4bd; }
[data-theme="dark"] .sheet-pill-open { background: rgba(224, 102, 102, 0.28); color: #f8c4c4; }
[data-theme="dark"] .sheet-pill-progress { background: rgba(255, 217, 102, 0.18); color: #ffe08a; }
[data-theme="dark"] .sheet-pill-devqa { background: rgba(159, 197, 232, 0.2); color: #bcd7f0; }
[data-theme="dark"] .sheet-pill-qa { background: rgba(109, 158, 235, 0.26); color: #c4d7f7; }
[data-theme="dark"] .sheet-pill-closed { background: rgba(147, 196, 125, 0.2); color: #c2e0b4; }
[data-theme="dark"] .sheet-pill-design { background: rgba(213, 166, 189, 0.2); color: #e8c6d6; }
[data-theme="dark"] .sheet-pill-blocked { background: rgba(224, 102, 102, 0.28); color: #f8c4c4; }
[data-theme="dark"] .sheet-pill-reproduced { background: rgba(246, 178, 107, 0.2); color: #f9cc9a; }

.sheet-chip {
  display: inline-flex;
  align-items: center;
  background: var(--sheet-chip-bg);
  color: var(--sheet-fg);
  border-radius: 9999px;
  padding: 0.05rem 0.55rem;
  font-size: 12px;
  font-weight: 600;
  margin: 0.05rem 0.15rem 0.05rem 0;
  white-space: nowrap;
  flex-shrink: 0;
}

.sheet-link {
  color: var(--sheet-link);
  text-decoration: underline;
  overflow-wrap: anywhere;
}

.issue-conflict {
  padding: 0.4rem;
  border: 1px solid var(--sheet-conflict-border);
  background: var(--sheet-conflict-bg);
  border-radius: 4px;
}

.issue-conflict-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.issue-drawer {
  position: fixed;
  top: 3.5rem;
  right: 0;
  bottom: 0;
  width: min(30rem, 100vw);
  z-index: 40;
  background: var(--sheet-bg);
  border-left: 1px solid var(--sheet-frame);
  overflow: auto;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.issue-drawer.is-open {
  transform: translateX(0);
  box-shadow: -12px 0 32px var(--sheet-shadow);
}

.issue-drawer-panel {
  padding: 1rem 1.15rem 2rem;
  color: var(--sheet-fg);
}

.issue-drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.issue-drawer-ref {
  font-size: 12px;
  font-weight: 700;
  color: var(--sheet-fg-muted);
}

.issue-drawer-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0.2rem 0 0;
  line-height: 1.3;
}

.issue-drawer-close {
  border: 0;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--sheet-fg-muted);
}

.issue-drawer-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 0.85rem;
  margin: 0 0 1rem;
}

.issue-drawer-facts dt {
  font-size: 11px;
  color: var(--sheet-fg-muted);
}

.issue-drawer-facts dd {
  margin: 0.15rem 0 0;
  font-size: 13px;
}

.issue-drawer-section {
  margin-top: 1rem;
}

.issue-drawer-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sheet-fg-muted);
  margin: 0 0 0.35rem;
}

.issue-drawer-section p {
  font-size: 13px;
  margin: 0;
}

.issue-drawer-list {
  padding-left: 1.1rem;
  font-size: 13px;
}

.issue-drawer-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.issue-drawer-label {
  font-size: 12px;
  color: var(--sheet-fg-muted);
}

.issue-drawer-summary {
  font-size: 13px;
  color: var(--sheet-accent);
  margin: 0.35rem 0 0;
  font-weight: 600;
}

.issue-drawer-fields {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.issue-drawer-field-label {
  display: block;
  font-size: 11px;
  color: var(--sheet-fg-muted);
  margin-bottom: 0.15rem;
}

.issue-drawer-fresh {
  font-size: 11px;
  color: var(--sheet-fg-muted);
  margin: 0 0 0.35rem;
}

.issue-drawer-fresh.is-stale {
  color: var(--sheet-danger);
}

.issue-drawer-empty {
  font-size: 13px;
  color: var(--sheet-fg-muted);
}

.issue-people-lead {
  color: var(--sheet-fg-muted);
  font-size: 13px;
  margin: 0.4rem 0 1rem;
}

.issue-people-group {
  margin: 1rem 0 1.5rem;
}

.issue-people-group h2 {
  font-size: 1rem;
  margin: 0 0 0.4rem;
}

.issue-people-group li {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  font-size: 13px;
  margin: 0.25rem 0;
}

.issue-people-summary {
  color: var(--sheet-accent);
}

.issue-drawer-history {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
}

.issue-drawer-history li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--sheet-rule-soft);
}

.issue-drawer-history-type {
  font-weight: 700;
  margin-right: 0.35rem;
}

.issue-drawer-empty {
  color: var(--sheet-fg-muted);
  font-size: 13px;
}

.sheet-form-lead {
  color: var(--sheet-fg-muted);
  font-size: 13px;
  margin: 0.4rem 0 1rem;
}

.sheet-form {
  max-width: 42rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.sheet-form .input,
.sheet-form .select {
  width: 100%;
  border-color: var(--sheet-frame);
}

.sheet-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.sheet-form-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.35rem;
}

.sheet-form-errors {
  padding: 0.75rem 0.85rem;
  border-left: 4px solid var(--sheet-danger);
  background: var(--sheet-danger-bg);
  color: var(--sheet-fg);
  font-size: 13px;
}

.sheet-form-errors p {
  margin: 0 0 0.35rem;
  font-weight: 600;
}

.sheet-form-errors ul {
  margin: 0;
  padding-left: 1.1rem;
}

@media (max-width: 640px) {
  .sheet-form-row {
    grid-template-columns: 1fr;
  }
}
