:root {
  --sidebar-w: 300px;
  --task-row-h: 36px;
  --group-row-h: 40px;
  --bg: #ffffff;
  --bg-alt: #f6f7f9;
  --ink: #1c2129;
  --ink-soft: #5b6472;
  --border: #dde1e6;
  --accent: #4c6ef5;
  --grid-week: #ebedf0;
  --connector: #8a93a3;
  --connector-conflict: #e03131;
  --today: #e03131;
  --panel-shadow: 0 12px 32px rgba(20, 24, 32, 0.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex: none;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-status {
  flex: 1;
  min-width: 200px;
}

.tab-btn {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
  font-weight: 600;
}
.tab-btn.active {
  background: var(--bg-alt);
  border-color: var(--border);
  color: var(--ink);
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.hide-completed-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}
.hide-completed-toggle input {
  cursor: pointer;
}

.save-status {
  font-size: 12.5px;
  color: var(--ink-soft);
}
.save-status[data-kind="error"] { color: var(--today); font-weight: 600; }
.save-status[data-kind="connecting"] { color: var(--accent); }
.save-status[data-kind="offline"] { color: #f08c00; font-weight: 600; }
.save-status[data-kind="live"]::before { content: "●"; color: #12b886; margin-right: 5px; }

.toolbar-stats {
  gap: 10px;
}
.stat-pill {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: default;
}
.stat-pill-label {
  font-size: 11.5px;
  color: var(--ink-soft);
  font-weight: 600;
  white-space: nowrap;
}
.stat-pill-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-soft);
}
.user-badge img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-alt);
}

button.secondary-btn {
  background: var(--bg-alt);
}

#authGate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-alt);
  z-index: 30;
}
.auth-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 40px;
  max-width: 380px;
  width: 90vw;
  text-align: center;
  box-shadow: var(--panel-shadow);
}
.auth-card h1 {
  font-size: 20px;
  margin: 0 0 10px;
}
.auth-card p {
  color: var(--ink-soft);
  font-size: 13.5px;
  margin: 0 0 20px;
}
.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  font-weight: 600;
}

button {
  font: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}
button:hover { background: var(--bg-alt); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.danger-btn { color: #fff; background: var(--today); border-color: var(--today); }
button.danger-btn:hover { filter: brightness(0.92); }

/* ---------- Gantt scroll region ---------- */

.gantt-scroll {
  flex: 1;
  overflow: auto;
  position: relative;
  background: var(--bg);
}

.gantt-content {
  display: flex;
  flex-direction: column;
  width: fit-content;
  min-width: 100%;
}

.header-row {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 3;
}

.corner-cell {
  flex: none;
  width: var(--sidebar-w);
  position: sticky;
  left: 0;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-weight: 600;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  height: 48px;
}

.header-chart {
  flex: none;
  position: relative;
  height: 48px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

.header-months {
  position: relative;
  height: 26px;
  border-bottom: 1px solid var(--border);
}

.month-cell {
  position: absolute;
  top: 0;
  height: 26px;
  display: flex;
  align-items: center;
  padding-left: 6px;
  font-weight: 600;
  font-size: 12.5px;
  border-left: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
}

.header-weeks {
  position: relative;
  height: 22px;
}

.week-tick {
  position: absolute;
  top: 2px;
  font-size: 10.5px;
  color: var(--ink-soft);
  padding-left: 3px;
  border-left: 1px solid var(--grid-week);
  white-space: nowrap;
}

.body-row {
  display: flex;
  align-items: flex-start;
}

.sidebar-col {
  flex: none;
  width: var(--sidebar-w);
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg);
  border-right: 1px solid var(--border);
}

.chart-wrap {
  flex: none;
  position: relative;
}

.chart-col {
  position: relative;
}

.connectors {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* ---------- Rows ---------- */

.row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.group-row {
  background: var(--bg-alt);
  gap: 6px;
  padding: 0 6px;
}

.group-chart-row {
  background: var(--bg-alt);
}

.chevron {
  border: none;
  background: none;
  padding: 2px 4px;
  cursor: pointer;
  transform: rotate(0deg);
  transition: transform 0.12s ease;
  font-size: 11px;
  color: var(--ink-soft);
}
.chevron.collapsed { transform: rotate(-90deg); }

.group-name-input {
  flex: 1;
  border: none;
  background: transparent;
  font-weight: 600;
  padding: 4px 4px;
  border-radius: 4px;
  min-width: 0;
}
.group-name-input:hover, .group-name-input:focus { background: #fff; outline: 1px solid var(--border); }

.hidden-count-badge {
  flex: none;
  font-size: 11px;
  color: var(--ink-soft);
  background: #e9ebee;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.row-icon-btn {
  border: none;
  background: none;
  width: 22px;
  height: 22px;
  line-height: 1;
  border-radius: 4px;
  color: var(--ink-soft);
  font-size: 15px;
  padding: 0;
}
.row-icon-btn:hover { background: #e2e5ea; }
.row-icon-btn.danger { color: var(--today); }

.task-row {
  padding: 0 10px 0 28px;
  gap: 8px;
  cursor: grab;
}
.task-row:hover { background: var(--bg-alt); }
.task-row.dragging { opacity: 0.4; cursor: grabbing; }
.task-row.drag-over-top { box-shadow: inset 0 2px 0 0 var(--accent); }
.task-row.drag-over-bottom { box-shadow: inset 0 -2px 0 0 var(--accent); }
.group-row.drag-over-group { box-shadow: inset 0 0 0 2px var(--accent); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: #adb5bd;
}
.status-dot.status-in-progress { background: #4c6ef5; }
.status-dot.status-done { background: #12b886; }
.status-dot.status-blocked { background: #e03131; }
.status-dot.status-late { background: #f08c00; }

.task-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.assignee-badges {
  display: flex;
  gap: 2px;
  flex: none;
}

.badge {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.conflict-flag {
  color: #f08c00;
  font-size: 12px;
}

.status-note-flag {
  font-size: 11px;
  flex: none;
  cursor: default;
}

.task-chart-row {
  position: relative;
}

.month-divider {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--border);
}

.today-marker {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--today);
  z-index: 1;
}

/* ---------- Bars ---------- */

.bar {
  position: absolute;
  border-radius: 5px;
  background: #adb5bd;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.bar.status-not-started { background: #868e96; }
.bar.status-in-progress { background: #4c6ef5; }
.bar.status-done { background: #12b886; }
.bar.status-blocked { background: #e03131; }
.bar.status-late { background: #f08c00; }

.bar-body {
  position: absolute;
  inset: 0;
  cursor: grab;
  display: flex;
  align-items: center;
  padding: 0 8px;
  overflow: hidden;
}
.bar-body:active { cursor: grabbing; }

.bar-label {
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.bar-handle {
  position: absolute;
  top: 0;
  width: 7px;
  height: 100%;
  cursor: ew-resize;
}
.bar-handle.left { left: 0; }
.bar-handle.right { right: 0; }

.connector {
  fill: none;
  stroke: var(--connector);
  stroke-width: 1.5;
}
.connector.conflict {
  stroke: var(--connector-conflict);
}

/* ---------- Time & Cost view ---------- */

.time-cost-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 60px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.tc-summary {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}
.tc-stat {
  flex: 1;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tc-stat-label {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 600;
}
.tc-stat-value {
  font-size: 26px;
  font-weight: 700;
}

table.tc-breakdown, table.tc-entries {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 28px;
  font-size: 13px;
}
table.tc-breakdown th, table.tc-entries th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
table.tc-breakdown td, table.tc-entries td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.tc-entry-form {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}
.tc-entry-form h3 {
  margin: 0;
  font-size: 15px;
}
.tc-entry-form select, .tc-entry-form input {
  font: inherit;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
}
.tc-entry-form button {
  align-self: flex-start;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

.tc-section-title {
  margin: 0 0 10px;
  font-size: 15px;
}

.tc-entries-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 28px;
  background: var(--bg-alt);
}
.tc-entries-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  list-style: none;
}
.tc-entries-summary::-webkit-details-marker { display: none; }
.tc-entries-summary::before {
  content: "▾";
  flex: none;
  font-weight: 400;
  color: var(--ink-soft);
  transform: rotate(-90deg);
  transition: transform 0.12s ease;
}
.tc-entries-section[open] > .tc-entries-summary::before {
  transform: rotate(0deg);
}
.tc-entries-count {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: #e9ebee;
  padding: 2px 9px;
  border-radius: 999px;
}
.tc-entries-controls {
  display: flex;
  gap: 8px;
  padding: 0 14px 12px;
  flex-wrap: wrap;
}
.tc-search-input {
  flex: 1;
  min-width: 160px;
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.tc-sort-select {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.tc-entries-section table.tc-entries {
  background: var(--bg);
  margin: 0 14px 14px;
  width: calc(100% - 28px);
}

.tc-task-controls {
  padding: 0 0 10px;
}

.settings-backup-row {
  display: flex;
  gap: 8px;
}

.tc-task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 28px;
}

.tc-task-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-alt);
}

.tc-task-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  list-style: none;
}
.tc-task-summary::-webkit-details-marker { display: none; }
.tc-task-summary::after {
  content: "▾";
  flex: none;
  color: var(--ink-soft);
  transform: rotate(-90deg);
  transition: transform 0.12s ease;
}
.tc-task-item[open] > .tc-task-summary::after {
  transform: rotate(0deg);
}

.tc-task-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.tc-task-dates {
  flex: none;
  color: var(--ink-soft);
  font-size: 12px;
  white-space: nowrap;
}
.tc-task-hours, .tc-task-cost {
  flex: none;
  width: 80px;
  text-align: right;
  font-weight: 600;
}

.tc-task-notes {
  padding: 4px 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.tc-task-note-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 12.5px;
  padding-top: 8px;
}
.tc-task-note-date { flex: none; width: 78px; color: var(--ink-soft); }
.tc-task-note-member {
  flex: none;
  width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tc-task-note-hours, .tc-task-note-cost { flex: none; width: 56px; text-align: right; color: var(--ink-soft); }
.tc-task-note-text { flex: 1; min-width: 0; color: var(--ink-soft); }
.tc-task-note-empty {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 8px 0 4px;
}

/* ---------- Budget view ---------- */

.budget-view {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 20px 24px 60px;
  width: 100%;
}

.budget-table-wrap {
  border: 2px solid var(--ink);
  border-radius: 4px;
  margin-bottom: 16px;
}

table.budget-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
}
table.budget-table th {
  text-align: right;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  position: sticky;
  top: 0;
  z-index: 2;
}
table.budget-table th:first-child { text-align: left; }
table.budget-table td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
}
table.budget-table td:first-child { text-align: left; }

.budget-cat-row {
  background: var(--bg-alt);
}
.budget-cat-row td {
  font-weight: 700;
}
.budget-cat-name-input {
  font: inherit;
  font-weight: 700;
  border: none;
  background: transparent;
  padding: 5px 4px;
  border-radius: 4px;
  width: 100%;
}
.budget-cat-name-input:hover, .budget-cat-name-input:focus { background: #fff; outline: 1px solid var(--border); }

.budget-item-row:hover { background: var(--bg-alt); }
.budget-item-row td:first-child { padding-left: 24px; }
.budget-item-name-input {
  font: inherit;
  border: none;
  background: transparent;
  padding: 5px 4px;
  border-radius: 4px;
  width: 100%;
}
.budget-item-name-input:hover, .budget-item-name-input:focus { background: #fff; outline: 1px solid var(--border); }

.budget-num-input {
  font: inherit;
  border: 1px solid transparent;
  background: transparent;
  padding: 5px 6px;
  border-radius: 4px;
  width: 100%;
  min-width: 90px;
  text-align: right;
}
.budget-num-input:hover, .budget-num-input:focus { background: #fff; border-color: var(--border); }

.budget-readonly-cell {
  color: var(--ink-soft);
}
.budget-dash {
  color: var(--border);
  text-align: center !important;
}

.budget-grand-row {
  border-top: 2px solid var(--ink);
}
.budget-grand-row td {
  font-weight: 700;
  background: var(--bg-alt);
}

.budget-actions-cell {
  white-space: nowrap;
  width: 1%;
}

.budget-summary-row {
  display: flex;
  gap: 16px;
  margin: 0 0 28px;
}
.budget-summary-row .tc-stat { flex: 1; }
.budget-qty-input {
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  width: 100%;
  background: #fff;
}

/* ---------- Scrim / panels ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 32, 0.28);
  z-index: 10;
}

.panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(380px, 100vw);
  background: #fff;
  box-shadow: var(--panel-shadow);
  z-index: 11;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-header h2 { margin: 0; font-size: 16px; }

.panel-close {
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  color: var(--ink-soft);
}

.panel-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field > span:first-child {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}
.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.field-header span {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}
.link-btn {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.link-btn:hover {
  background: none;
  text-decoration: underline;
}
.field input[type="text"], .field input[type="date"], .field input[type="time"], .field select {
  font: inherit;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
}
.field textarea {
  font: inherit;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  resize: vertical;
}
.field-hint {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.field-row {
  display: flex;
  gap: 10px;
}
.field-row .field { flex: 1; }

.task-more {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.task-more summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}
.task-more[open] summary { margin-bottom: 10px; }
.task-more .field-row { margin-bottom: 10px; }
.task-more .field:last-child { margin-bottom: 0; }

.assignee-checks {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.assignee-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
}

.dep-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dep-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-alt);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
}
.dep-chip button {
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 15px;
  padding: 0 4px;
}
.dep-empty {
  font-size: 12.5px;
  color: var(--ink-soft);
  list-style: none;
}

.dep-add-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.dep-add-row select { flex: 1; }

.settings-member-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.settings-member-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.settings-member-row input[type="text"] {
  flex: 1;
  min-width: 90px;
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.settings-member-row input:disabled {
  background: var(--bg-alt);
  color: var(--ink-soft);
  border-color: transparent;
}
.rate-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 12.5px;
  color: var(--ink-soft);
  flex: none;
}
.rate-wrap input {
  width: 60px;
  font: inherit;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.role-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--bg-alt);
  flex: none;
}
.role-tag.admin {
  color: #fff;
  background: var(--accent);
}
.add-member-form {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.add-member-form input {
  flex: 1;
  min-width: 100px;
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c2129;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 20;
  max-width: 90vw;
}

/* ---------- FMEA view ---------- */

button.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary-btn:hover { background: var(--accent); filter: brightness(0.93); }

.fmea-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px 60px;
  width: 100%;
}

.fmea-notice {
  max-width: 720px;
  margin: 40px auto;
  background: #fff9db;
  border: 1px solid #ffe066;
  border-radius: 10px;
  padding: 16px 20px;
  font-size: 13.5px;
}
.fmea-notice p { margin: 0 0 12px; line-height: 1.5; }

.fmea-loading {
  color: var(--ink-soft);
  text-align: center;
  margin: 40px 0;
}

.fmea-empty {
  color: var(--ink-soft);
  font-size: 13.5px;
  margin: 20px 0;
}

/* List of FMEAs */

.fmea-list {
  max-width: 1200px;
  margin: 0 auto;
}
.fmea-list-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.fmea-list-header h2 { margin: 0 0 4px; font-size: 18px; }
.fmea-list-wrap { overflow-x: auto; }
table.fmea-list-table td { vertical-align: middle; }
.fmea-title-link {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  text-align: left;
}
.fmea-title-link:hover { background: none; text-decoration: underline; }
.fmea-type-pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: #e7f5ff;
  color: #1864ab;
}
.fmea-type-pill.fmea-type-process { background: #f3f0ff; color: #5f3dc4; }
.fmea-sub { font-size: 12px; color: var(--ink-soft); }
.fmea-list-when { white-space: nowrap; }
.fmea-list-actions { white-space: nowrap; text-align: right; }
.fmea-list-btn { padding: 4px 10px; font-size: 12.5px; margin-left: 4px; }
.fmea-list-btn.danger { color: var(--today); }

/* RPN color bands. The thresholds live in RPN_THRESHOLDS (src/state.js). */
.rpn-low { background: #d3f9d8; color: #1e6b31; }
.rpn-medium { background: #fff3bf; color: #7a4f00; }
.rpn-high { background: #ffe3e3; color: #b02525; }
.rpn-chip {
  display: inline-block;
  min-width: 44px;
  text-align: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12.5px;
}

/* Open sheet: header */

.fmea-sheet-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.fmea-title-input {
  flex: 1;
  min-width: 220px;
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  background: transparent;
}
.fmea-title-input:hover { border-color: var(--border); }
.fmea-title-input:focus { border-color: var(--accent); background: #fff; outline: none; }
.fmea-save-status { white-space: nowrap; }
.save-status[data-kind="saving"] { color: var(--accent); }
.save-status[data-kind="saved"]::before { content: "✓"; color: #12b886; margin-right: 5px; font-weight: 700; }

.fmea-meta {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.fmea-meta .field select,
.fmea-meta .field input[type="text"] { height: 36px; }
.fmea-meta-type { width: 140px; }
.fmea-meta-system { flex: 1; min-width: 200px; max-width: 380px; }
.fmea-meta-owner { width: 200px; }
.fmea-edited { margin-left: auto; padding-bottom: 8px; }

.fmea-sheet-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 20px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.fmea-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--ink-soft);
}
.fmea-legend-label { font-weight: 700; color: var(--ink); }
.fmea-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.fmea-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
.fmea-legend-swatch.fmea-legend-critical { background: #fff0f0; box-shadow: inset 3px 0 0 #e03131; }
.fmea-keys-hint { margin: 0; font-size: 12px; color: var(--ink-soft); }

.fmea-sort-banner {
  display: flex;
  align-items: center;
  gap: 6px 16px;
  flex-wrap: wrap;
  background: #edf2ff;
  border: 1px solid #bac8ff;
  color: #364fc7;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  margin-bottom: 8px;
}

/* Open sheet: the grid. Separate borders (not collapsed) so the sticky header
   and row numbers keep their gridlines while scrolling. */

.fmea-grid-wrap {
  overflow: auto;
  max-height: max(320px, calc(100vh - 250px));
  border: 1px solid #c9ced6;
  border-radius: 6px;
  background: #fff;
}

table.fmea-grid {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  line-height: 1.4;
}
.fmea-grid th,
.fmea-grid td {
  height: 1px; /* lets cell contents stretch to the full row height */
  padding: 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #fff;
  vertical-align: top;
}
.fmea-grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg-alt);
  border-bottom: 2px solid #c9ced6;
  vertical-align: bottom;
  text-align: left;
}
.fmea-grid .fmea-gutter-head,
.fmea-grid .fmea-gutter {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-alt);
  text-align: center;
}
.fmea-grid thead .fmea-gutter-head {
  z-index: 4;
  padding: 8px 0 7px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: center;
}

.fmea-sort-btn {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  width: 100%;
  height: 100%;
  padding: 8px 8px 7px;
  border: none;
  border-radius: 0;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}
.fmea-sort-btn:hover { background: #e9ecef; }
.fmea-sort-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fmea-th-rating .fmea-sort-btn,
.fmea-th-rpn .fmea-sort-btn {
  justify-content: center;
  text-align: center;
  padding-left: 2px;
  padding-right: 2px;
}
.fmea-sort-ind { flex: none; font-size: 9px; color: var(--accent); }
.fmea-grid thead th.sorted { background: #edf2ff; }
.fmea-col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  z-index: 1;
}
.fmea-col-resizer:hover,
.fmea-col-resizer.active { background: var(--accent); opacity: 0.45; }

.fmea-row-handle {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  height: 100%;
  min-height: 31px;
  padding-top: 7px;
  font-size: 12px;
  color: var(--ink-soft);
  cursor: grab;
  user-select: none;
}
.fmea-row-handle:hover { background: #e2e5ea; color: var(--ink); }
.fmea-row-handle:focus { outline: none; }
.fmea-row-handle:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }

.fmea-grid td.fmea-cell:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Text cells grow to fit wrapped text: the hidden ::after copy of the value
   sizes the grid area and the textarea stretches to fill it. */
.fmea-grow { display: grid; height: 100%; }
.fmea-grow::after {
  content: attr(data-value) " ";
  visibility: hidden;
  white-space: pre-wrap;
}
.fmea-grow > textarea,
.fmea-grow::after {
  grid-area: 1 / 1 / 2 / 2;
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 6px 7px;
  font: inherit;
  line-height: inherit;
  overflow-wrap: break-word;
  word-break: normal;
}
.fmea-grow > textarea {
  width: 100%;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: inherit;
  outline: none;
}

.fmea-rating-input {
  display: block;
  width: 100%;
  border: 0;
  padding: 6px 2px;
  background: transparent;
  font: inherit;
  font-weight: 600;
  text-align: center;
  color: inherit;
  outline: none;
}

.fmea-grid td.fmea-cell-rpn {
  padding: 6px 2px;
  text-align: center;
  font-weight: 700;
  cursor: default;
}

.fmea-grid tr.fmea-row-critical > td { background: #fff0f0; }
.fmea-grid tr.fmea-row-critical > td.fmea-gutter { background: #ffe3e3; box-shadow: inset 3px 0 0 #e03131; }
.fmea-grid tr.fmea-row-critical .fmea-row-handle { color: #c92a2a; font-weight: 700; }
.fmea-grid tr.fmea-row-critical > td[data-key="s"] .fmea-rating-input { color: #c92a2a; }
.fmea-grid tr.fmea-row-selected > td { background: #edf2ff; }
.fmea-grid td.fmea-cell-rpn.rpn-low { background: #d3f9d8; color: #1e6b31; }
.fmea-grid td.fmea-cell-rpn.rpn-medium { background: #fff3bf; color: #7a4f00; }
.fmea-grid td.fmea-cell-rpn.rpn-high { background: #ffe3e3; color: #b02525; }

.fmea-grid td.fmea-cell.fmea-invalid,
.fmea-grid td.fmea-cell.fmea-invalid:focus-within { background: #fff5f5; outline: 2px solid var(--today); outline-offset: -2px; }

.fmea-grid tr.dragging > td { opacity: 0.45; }
.fmea-grid tr.drag-over-top > td { box-shadow: inset 0 2px 0 0 var(--accent); }
.fmea-grid tr.drag-over-bottom > td { box-shadow: inset 0 -2px 0 0 var(--accent); }

.fmea-add-row { margin-top: 10px; }

/* Rating-scale tooltip and the row menu (both live on <body>) */

.fmea-tooltip {
  position: fixed;
  z-index: 15;
  max-width: 360px;
  background: #1c2129;
  color: #e9ecef;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--panel-shadow);
  pointer-events: none;
}
.fmea-tip-title { font-weight: 700; color: #fff; margin-bottom: 6px; }
.fmea-tip-error { color: #ffa8a8; font-weight: 600; margin-bottom: 6px; }
.fmea-tip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.fmea-tip-list li { display: flex; gap: 8px; padding: 2px 6px; border-radius: 4px; }
.fmea-tip-list li.active { background: rgba(116, 143, 252, 0.35); color: #fff; }
.fmea-tip-range { flex: none; width: 38px; font-weight: 700; color: #fff; }

.fmea-menu {
  position: fixed;
  z-index: 15;
  min-width: 210px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--panel-shadow);
  padding: 4px;
  display: flex;
  flex-direction: column;
}
.fmea-menu button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border: none;
  border-radius: 5px;
  background: none;
  padding: 7px 10px;
  text-align: left;
  font-size: 13px;
}
.fmea-menu button:hover:not(:disabled),
.fmea-menu button:focus-visible { background: var(--bg-alt); outline: none; }
.fmea-menu button.danger { color: var(--today); }
.fmea-menu-hint { font-size: 11.5px; color: var(--ink-soft); }
.fmea-menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.fmea-menu-note { margin: 2px 10px 6px; font-size: 11.5px; color: var(--ink-soft); max-width: 200px; }

/* Rating guide under the sheet: three blocks side by side, like the template */

.fmea-guide-title { margin: 28px 0 10px; font-size: 15px; }
.fmea-guide {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  max-width: 1200px;
}
.fmea-guide-block {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.fmea-guide-block h4 {
  margin: 0 0 8px;
  font-size: 13.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.fmea-guide-block ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  line-height: 1.4;
}
.fmea-guide-block li { display: flex; gap: 8px; }
.fmea-guide-range { flex: none; width: 40px; font-weight: 700; }

@media (max-width: 860px) {
  .fmea-guide { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .fmea-view { padding: 16px 16px 48px; }
  .fmea-edited { margin-left: 0; padding-bottom: 0; }
  .fmea-meta-type, .fmea-meta-owner { width: auto; flex: 1; min-width: 140px; }
}
