/* ─────────────────────────────────────────────────────────────────────────────
   fee-calc.css — the fee-proposal calculator on the Create Project form and the
   read-only proposal breakdown on the project Detail page.
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Optional disclosure wrapper (collapsed by default) ───────────────────── */

/* The disclosure fills the form column and keeps that same width when opened (it no longer breaks out),
   so the calculator stays in line with the rest of the form. */
.fee-calc-disclosure {
  margin-top: var(--spacing-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
}

.fee-calc-disclosure[open] {
  background: var(--color-surface);
}

.fee-calc-disclosure__summary {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
  padding: var(--spacing-4);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

/* Hide the native disclosure triangle (we use our own chevron). */
.fee-calc-disclosure__summary::-webkit-details-marker { display: none; }
.fee-calc-disclosure__summary::marker { content: ""; }

.fee-calc-disclosure__icon { color: var(--color-primary); }

.fee-calc-disclosure__text {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-05);
  flex: 1;
  min-width: 0;
}

.fee-calc-disclosure__label {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.fee-calc-disclosure__hint {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.fee-calc-disclosure__chevron {
  color: var(--color-text-muted);
  transition: transform 0.15s ease;
}

.fee-calc-disclosure[open] .fee-calc-disclosure__chevron {
  transform: rotate(180deg);
}

.fee-calc {
  padding: 0 var(--spacing-4) var(--spacing-4);
  border-top: 1px solid var(--color-border);
}

.fee-calc__head {
  margin: var(--spacing-4) 0;
}

.fee-calc__subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin: var(--spacing-1) 0 0;
}

/* ── Per-calculation panel ────────────────────────────────────────────────── */

.fee-calc__panels {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-4);
}

/* A single, un-boxed calculation — the "type of work" select just sources items into the pickers. */
.fee-calc-panel {
  position: relative;
}

.fee-calc-panel__head {
  display: flex;
  gap: var(--spacing-4);
  align-items: flex-end;
}

.fee-calc-panel__type { flex: 2; }
.fee-calc-panel__rate { flex: 1; }

/* Pinned to the panel's top-right corner so it never reserves space in the head row (which left an
   empty gap beside the rate field when there was only one calculation). */
.fee-calc-panel__remove {
  position: absolute;
  top: var(--spacing-3);
  right: var(--spacing-3);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--font-size-xl);
  line-height: 1;
  cursor: pointer;
  padding: 0 var(--spacing-1);
}

.fee-calc-panel__remove:hover { color: var(--color-danger); }

/* The per-calculation subtotal is redundant with the summary below for a single calculation. */
.fee-calc-panel__subtotal {
  display: none;
}

.fee-calc__add-panel {
  margin-top: var(--spacing-4);
}

.fee-calc__vat-row {
  margin-top: var(--spacing-5);
}

.fee-calc__summary--combined {
  border-top: 2px solid var(--color-border-strong);
  padding-top: var(--spacing-3);
}

/* Read-only breakdown (project Detail page) */
.fee-calc-readout + .fee-calc-readout {
  margin-top: var(--spacing-5);
  padding-top: var(--spacing-5);
  border-top: 1px solid var(--color-border);
}

.fee-calc-readout__head {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--spacing-2);
}

.fee-calc__group {
  margin-top: var(--spacing-5);
}

.fee-calc__group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-3);
  margin-bottom: var(--spacing-2);
}

.fee-calc__group-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  flex-shrink: 0;
}

/* The "typical item" picker sizes to its content rather than stretching like the table inputs
   (out-specify the `.select--sm { width: 100% }` rule). */
.fee-calc__group-actions .fee-calc__suggest {
  width: auto;
  max-width: 16rem;
}

.fee-calc__group-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0;
}

.fee-calc__table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.fee-calc__table th {
  text-align: left;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-label);
  padding: var(--spacing-1) var(--spacing-2);
  border-bottom: 1px solid var(--color-border);
}

.fee-calc__table td {
  padding: var(--spacing-1) var(--spacing-2);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.fee-calc__table tfoot td {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  border-bottom: none;
}

/* Numeric columns: right-aligned (headers too — out-specify `.fee-calc__table th`) and shrunk to a
   consistent narrow width so the numbers line up and the text columns take the remaining room. */
.fee-calc__num {
  text-align: right;
  white-space: nowrap;
  width: 1%;
}

.fee-calc__table th.fee-calc__num {
  text-align: right;
}

/* Compact inputs inside the calculator tables. */
.input--sm,
.select--sm {
  padding: var(--spacing-1) var(--spacing-2);
  font-size: var(--font-size-sm);
  width: 100%;
  min-width: 0;
}

/* Compact selects keep room for the dropdown chevron (the base .select padding is overridden above) so
   the Role dropdown clearly reads as a changeable control. */
.select--sm {
  padding-right: var(--spacing-6);
  background-position: right var(--spacing-2) center;
  cursor: pointer;
}

.fee-calc__table td.fee-calc__num input {
  width: 5.5rem;
  text-align: right;
}

/* Trim the per-row remove (×) column to its content so it doesn't pad out the row. */
.fee-calc__table td:last-child { width: 1%; white-space: nowrap; }

.btn--sm {
  padding: var(--spacing-1) var(--spacing-3);
  font-size: var(--font-size-sm);
}

.fee-calc__remove {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--font-size-lg);
  line-height: 1;
  cursor: pointer;
  padding: 0 var(--spacing-2);
}

.fee-calc__remove:hover {
  color: var(--color-danger);
}

/* Per-row actions: pin-to-type + remove. */
.fee-calc__row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--spacing-1);
  padding-left: var(--spacing-3);
}

.fee-calc__row-actions > * { flex: 0 0 auto; }

/* Save / Remove typical-item toggle — a small text button. */
.fee-calc__typical-btn {
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-sm);
  padding: var(--spacing-05) var(--spacing-2);
  cursor: pointer;
  white-space: nowrap;
}

.fee-calc__typical-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.fee-calc__typical-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Saved state: green to show the line is saved to the type; the button reads "Unsave" and turns red on
   hover to signal the remove action. */
.fee-calc__typical-btn--saved {
  border-color: var(--color-success);
  color: var(--color-success);
}

.fee-calc__typical-btn--saved:hover:not(:disabled) {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* Un-save confirmation modal (reuses the shared .modal/.modal__dialog from cashflow.css). */
.modal__dialog--sm { width: min(440px, 100%); }

.modal__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0 0 var(--spacing-3);
}

.modal__text {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin: 0 0 var(--spacing-5);
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-3);
}

/* Fee-letter preview popup — shows the real generated PDF in an iframe. Sized large (qualified with
   .modal__dialog to out-specify the shared 680px/90vh rule) so the A4 letter is readable without zooming. */
.modal__dialog.fee-letter-preview {
  width: min(1200px, 96vw);
  max-height: 96vh;
}

.fee-letter-preview__doc {
  position: relative;
  height: 80vh;
  margin-bottom: var(--spacing-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface-alt);
}

.fee-letter-preview__doc iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.fee-letter-preview__loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.fee-calc__summary {
  margin-top: var(--spacing-5);
  margin-left: auto;
  max-width: 22rem;
}

.fee-calc__summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-2) 0;
  font-size: var(--font-size-sm);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}

.fee-calc__summary-row--grand {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  border-bottom: none;
}

/* ---- Editable fee-letter body ------------------------------------------- */

.project-form__divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--spacing-5) 0;
}

.card__subtitle {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0;
}

.letter-body-head {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  margin-bottom: var(--spacing-3);
  cursor: pointer;
  user-select: none;
}

.letter-body-group.is-collapsed .letter-body-group__body {
  display: none;
}

.letter-body-group.is-collapsed .letter-body-head {
  margin-bottom: 0;
}

.letter-saved {
  margin-bottom: var(--spacing-4);
}

.letter-saved__row {
  display: flex;
  gap: var(--spacing-2);
  align-items: center;
}

.letter-saved__row .input {
  flex: 1 1 auto;
}

/* Template / proposal picker: fields sit inline with the Apply button, wrapping on narrow screens. */
.letter-picker__controls {
  display: flex;
  gap: var(--spacing-3);
  align-items: flex-end;
  flex-wrap: wrap;
}
.letter-picker__controls .field {
  flex: 1 1 220px;
  margin: 0;
}

.letter-body {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-3);
}

.letter-block {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--spacing-3);
  background: var(--color-surface);
}

.letter-block__text {
  width: 100%;
  resize: vertical;
}

/* Edited / added paragraphs — yellow, mirroring the highlight baked into the PDF. */
.letter-block__text.is-changed {
  background: #fff8c4;
  border-color: #e6d54a;
}

.letter-block__actions {
  display: flex;
  gap: var(--spacing-2);
  justify-content: flex-end;
  margin-top: var(--spacing-2);
}

.letter-block__remove {
  color: var(--color-danger, #b3261e);
}

/* Locked, non-editable boxes (the rate table) — can be moved but not edited. */
.letter-block--fixed {
  background: var(--color-surface-alt);
  border-style: dashed;
}

.letter-block__locked {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-style: italic;
}

.letter-block__actions {
  flex-wrap: wrap;
}

/* ---- Collapsible letter sections ---------------------------------------- */

.letter-section {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-3);
  background: var(--color-surface);
}

.letter-section.is-dragging {
  opacity: 0.5;
  outline: 2px dashed var(--color-primary, #2563eb);
}

.letter-section__head {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-2) var(--spacing-3);
  background: var(--color-surface-alt);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.letter-section__toggle {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  padding: 0 var(--spacing-1);
  line-height: 1;
}

.letter-section__title {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.letter-section__count {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0 var(--spacing-2);
}

.letter-section__head-actions {
  display: flex;
  gap: var(--spacing-1);
}

.letter-section__body {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-3);
  padding: var(--spacing-3);
}

.letter-section.is-collapsed .letter-section__body {
  display: none;
}

/* Heading boxes stand out from body paragraphs. */
.letter-block--heading .letter-block__text {
  font-weight: var(--font-weight-semibold);
}

/* Drag-to-reorder grip + the box being dragged. */
.letter-block__drag {
  cursor: grab;
  touch-action: none;
}

.letter-block__drag:active {
  cursor: grabbing;
}

.letter-block.is-dragging {
  opacity: 0.5;
  outline: 2px dashed var(--color-primary, #2563eb);
}

/* Blank-line boxes — kept visible so they can be positioned precisely, but compact and muted. */
.letter-block--blank {
  background: var(--color-surface-alt);
  opacity: 0.85;
}

.letter-block--blank .letter-block__text {
  min-height: 0;
  color: var(--color-text-muted);
}
