/* Planning tab. Colors, type and spacing come from styles.css. */
.sheet-scroll.is-planning {
  background: var(--color-page);
}

.plan-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-6);
}

.plan-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-sheet-title);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.plan-lock {
  display: inline-flex;
  margin-left: auto;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  font-size: var(--text-md);
  font-weight: 500;
  cursor: pointer;
}

.plan-lock input {
  width: 18px;
  height: 18px;
  margin: 0;
}

/* Plan versions */
.plan-stages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.plan-stage-tabs {
  margin-left: 0;
}

.plan-caption {
  flex-basis: 100%;
  margin: 0;
  color: var(--color-ink-muted);
  font-size: var(--text-sm);
}

/* The plan's currently active period */
.active-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--color-good);
  vertical-align: 1px;
}

.active-badge {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 1px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-good-soft);
  color: var(--color-good);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

/* Planned result */
.plan-result-grid {
  display: grid;
  grid-template-columns: 1.4fr 1.4fr 1fr 1fr;
  align-items: stretch;
  gap: var(--space-3);
}

.plan-result-grid .stat + .stat {
  margin-top: 0;
}

.plan-result-note {
  margin-top: var(--space-3);
}

.plan-result-note a {
  color: var(--color-accent-text);
  text-decoration: none;
}

.plan-result-note a:hover {
  text-decoration: underline;
}

@media (max-width: 860px) {
  .plan-result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* The small prompt to accept a row's suggested months */
.fill-popover {
  position: fixed;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-raised);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.fill-popover[hidden] {
  display: none;
}

.fill-popover-text {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.fill-popover-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.fill-popover-later {
  min-height: 32px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-ink-muted);
  font: inherit;
  cursor: pointer;
}

.fill-popover-later:hover {
  color: var(--color-ink);
}

/* Revenue allocation */
.plan-table td.plan-auto-cell {
  background: var(--color-surface);
}

.plan-allocation .plan-table {
  width: 100%;
}

.plan-table .plan-row-label {
  min-width: 150px;
  padding: 0 var(--space-2);
  font-weight: 500;
  white-space: nowrap;
}

.plan-card-note.plan-allocation-hint {
  margin-top: var(--space-3);
  color: var(--color-accent-text);
  font-weight: 500;
}

.plan-allocation-hint[hidden] {
  display: none;
}

.plan-allocation-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.plan-allocation-grid .stat + .stat {
  margin-top: 0;
}

.stat.is-good {
  background: var(--color-good-soft);
  color: var(--color-good);
}

.stat.is-bad {
  background: var(--color-bad-soft);
  color: var(--color-bad);
}

.stat.is-good .stat-label,
.stat.is-bad .stat-label {
  color: inherit;
}

@media (max-width: 700px) {
  .plan-allocation-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Cards */
.plan-card {
  padding: var(--space-5);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-rest);
}

.plan-card-header {
  margin-bottom: var(--space-3);
}

.plan-card-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.plan-card-note {
  margin: 2px 0 0;
  color: var(--color-ink-muted);
  font-size: var(--text-sm);
}

/* Single fields */
.plan-fields {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.plan-field {
  display: flex;
  flex: 0 1 280px;
  flex-direction: column;
  gap: var(--space-1);
}

.plan-field--short {
  flex-basis: 120px;
}

.plan-field-label {
  color: var(--color-ink-muted);
  font-size: var(--text-sm);
}

.plan-field-box {
  display: flex;
  align-items: center;
  min-height: 36px;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--color-editable);
  transition: background-color var(--motion);
}

.plan-field-box:hover:not(:has(:disabled)) {
  background: var(--color-editable-hover);
}

.plan-field-box:has(:disabled) {
  background: var(--color-auto);
}

.plan-field-box .plan-input,
.plan-field-box .plan-input:disabled {
  background: transparent;
}

.plan-field-box:focus-within {
  box-shadow: inset 0 0 0 2px var(--color-accent);
}


.plan-field-note {
  color: var(--color-ink-muted);
  font-size: var(--text-xs);
}

.plan-field-unit {
  flex: none;
  padding-right: var(--space-3);
  color: var(--color-ink-muted);
  font-size: var(--text-sm);
}

.plan-field-total {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 36px;
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Tables */
.plan-table-wrap {
  overflow-x: auto;
}

.plan-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.plan-table th {
  height: 30px;
  padding: 0 var(--space-2);
  border-bottom: 1px solid var(--color-line-strong);
  background: var(--color-header);
  color: var(--color-ink);
  font-size: var(--text-xs);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.plan-table td {
  height: 32px;
  padding: 0;
  border-bottom: 1px solid var(--color-line);
  background: var(--color-surface);
}

.plan-table .is-number {
  padding: 0 var(--space-2);
  text-align: right;
  white-space: nowrap;
}

.plan-table .plan-month {
  min-width: 100px;
}

.plan-table td.is-total,
.plan-table tfoot td {
  background: var(--color-auto);
  font-weight: 600;
}

.plan-table tfoot .plan-row-action {
  background: var(--color-surface);
}

.plan-table .is-quarter-start {
  border-left: 1px solid var(--color-line-strong);
}

.plan-table th.is-past {
  color: var(--color-ink-muted);
}

.plan-table .is-sticky-start {
  position: sticky;
  left: 0;
  z-index: 1;
}

.plan-table.has-row-actions .is-sticky-start {
  left: 28px;
}

/* Quiet row controls: remove shows on hover, add sits under the table */
.plan-table .plan-row-action {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 28px;
  min-width: 28px;
  padding: 0;
  text-align: center;
}

.plan-remove-row {
  position: relative;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--color-control);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--motion), background-color var(--motion);
}

.plan-remove-row::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 5px;
  width: 8px;
  height: 2px;
  border-radius: 1px;
  background: var(--color-ink-muted);
}

.plan-table tr:hover .plan-remove-row,
.plan-table tr:focus-within .plan-remove-row,
.sheet-table tr:hover .plan-remove-row,
.plan-remove-row:focus-visible {
  opacity: 1;
}

.plan-remove-row:hover {
  background: var(--color-bad);
}

.plan-remove-row:hover::before {
  background: var(--color-surface);
}

@media (hover: none) {
  .plan-remove-row {
    opacity: 1;
  }
}

.plan-add-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  margin: var(--space-2) 0 0 var(--space-1);
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-accent-text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
}

.plan-add-row::before {
  content: "+";
  font-size: var(--text-lg);
  line-height: 1;
}

.plan-add-row:hover {
  background: var(--color-accent-soft);
}

.plan-add-row:disabled {
  color: var(--color-ink-muted);
  cursor: default;
}

.plan-table .is-sticky-end {
  position: sticky;
  right: 0;
  z-index: 1;
  min-width: 116px;
  border-left: 1px solid var(--color-line-strong);
}

.plan-table tfoot td {
  height: 34px;
  border-bottom: 0;
}

.plan-table tfoot .plan-foot-label {
  padding: 0 var(--space-3) 0 var(--space-2);
  background: var(--color-surface);
  color: var(--color-ink-muted);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.plan-table tfoot .plan-foot-label.is-sticky-name {
  position: sticky;
  z-index: 2;
}

.plan-table tfoot .plan-foot-label.is-stopped {
  color: var(--color-ink);
  text-align: left;
}

.plan-table tfoot td.plan-foot-blank {
  background: var(--color-surface);
}

.plan-input {
  display: block;
  width: 100%;
  height: 32px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  color: var(--color-ink);
  font: inherit;
  letter-spacing: inherit;
}

.plan-input--amount {
  text-align: right;
}

.plan-input::placeholder {
  color: var(--color-ink-muted);
  opacity: 1;
}

.plan-table .plan-input:not(:disabled) {
  background: var(--color-editable);
  transition: background-color var(--motion);
}

.plan-table .plan-input:not(:disabled):hover {
  background: var(--color-editable-hover);
}

.plan-table td:has(> .plan-input:not(:disabled)) {
  border-right: 2px solid var(--color-surface);
  border-bottom: 2px solid var(--color-surface);
}

.plan-table .plan-input:focus,
.plan-input:focus {
  box-shadow: inset 0 0 0 2px var(--color-accent);
}

.plan-input:disabled {
  color: var(--color-ink);
  opacity: 1;
  -webkit-text-fill-color: var(--color-ink);
}

.plan-input:disabled::placeholder {
  -webkit-text-fill-color: var(--color-ink-muted);
}

.is-past .plan-input,
.is-past .plan-input:disabled {
  color: var(--color-ink-muted);
  -webkit-text-fill-color: var(--color-ink-muted);
}

.plan-select {
  cursor: pointer;
}

.plan-select:disabled {
  cursor: default;
  appearance: none;
}

/* All plans */
.plan-summary {
  width: 100%;
}

.plan-summary td {
  height: auto;
  padding: var(--space-2);
  vertical-align: top;
}

.plan-summary tbody tr:last-child td {
  border-bottom: 0;
}

.plan-summary tr.is-current td {
  background: var(--color-auto);
}

.plan-summary tr.is-current td:first-child {
  box-shadow: inset 3px 0 0 var(--color-accent);
}

.plan-summary .plan-summary-name {
  font-weight: 600;
}

.plan-summary .plan-summary-change {
  display: block;
  color: var(--color-ink-muted);
  font-size: var(--text-xs);
}

@media (max-width: 700px) {
  .plan-page {
    padding: var(--space-4);
  }

  .plan-card {
    padding: var(--space-4);
  }

  .plan-table .is-sticky-start,
  .plan-table .is-sticky-end {
    position: static;
  }
}

/* Months picked from a calendar in the Payroll and Opex tables */
.plan-table .plan-date {
  border-radius: 0;
}

.plan-table td:has(> .plan-date) {
  border-right: 2px solid var(--color-surface);
  border-bottom: 2px solid var(--color-surface);
}

.plan-date.is-disabled {
  background: transparent;
}

.plan-date .date-input {
  font-size: var(--text-sm);
}

/* Department Plans: per department, its current state and its goal for the
   end of the year, in words. A row each; name and lead on the left. */
.dept-plans {
  display: flex;
  flex-direction: column;
}

.dept-plan {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
  padding: var(--space-4) 0;
  border-top: 1px solid var(--color-line);
}

.dept-plan:first-child {
  padding-top: 0;
  border-top: 0;
}

.dept-plan-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 22px;
}

.dept-plan-name {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-weight: 600;
  line-height: 1.3;
}

.dept-plan-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.dept-plan-lead {
  padding-left: 17px;
  color: var(--color-ink-muted);
  font-size: var(--text-sm);
}

.dept-plan-field {
  min-width: 0;
}

.plan-input.dept-plan-text {
  height: auto;
  min-height: 76px;
  padding: var(--space-2);
  line-height: 1.4;
  resize: none;
  overflow: hidden;
}

@media (max-width: 860px) {
  .dept-plan {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
  }

  .dept-plan-head {
    padding-top: 0;
  }
}
