/* ── Draft review + Financial period pages ──────────────────────────── */

/* Source badges on committed line items */
.source-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 3px;
  padding: 1px 5px;
}
.source-manual       { background: #ede9fe; color: #6d28d9; }
.source-extracted    { background: #d1fae5; color: #065f46; }
.source-api_import   { background: #dbeafe; color: #1d4ed8; }

/* New line item form below each table */
.new-line-item-form {
  border-top: 2px dashed #e5e7eb;
  padding: 12px 0 4px;
}

.label-input {
  flex: 2;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 0.9rem;
  min-width: 180px;
}
.notes-input {
  flex: 1.5;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 0.9rem;
  min-width: 120px;
}

/* Delete button in line item rows */
.btn-delete {
  background: none;
  border: none;
  color: #dc2626;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0 4px;
  text-decoration: underline;
}
.btn-delete:hover { color: #991b1b; }

.flagged-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 4px;
  padding: 10px 16px;
  margin-bottom: 16px;
  color: #92400e;
  font-weight: 500;
}

/* Summary metrics */
.summary-bar {
  display: flex;
  gap: 16px;
  margin: 20px 0;
}

.metric-card {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.metric-value {
  font-size: 1.4rem;
  font-weight: 600;
  color: #111827;
}

.metric-positive .metric-value { color: #059669; }
.metric-negative .metric-value { color: #dc2626; }
.metric-flagged  { border-color: #f59e0b; background: #fffbeb; }
.metric-flagged .metric-value { color: #d97706; }

/* Line items table */
.line-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.line-items-table th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 2px solid #e5e7eb;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.sortable-th {
  display: inline-block;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.sortable-th:hover { color: #374151; text-decoration: none; }
.sortable-th.active { color: #1d4ed8; }

.line-items-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}

.line-item-row.flagged {
  background: #fffbeb;
}

.line-item-row.flagged:hover {
  background: #fef3c7;
}

/* Subtotal rows — visually separated, bold amount */
.subtotal-row td {
  border-top: 2px solid #d1d5db;
  background: #f9fafb;
  font-weight: 600;
  color: #111827;
}

/* Section header rows — muted category label */
.section-header-row td {
  padding: 20px 12px 4px;
  color: #6b7280;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  border-bottom: none;
  background: transparent;
}

.label-cell { width: 40%; }
.confidence-cell { width: 20%; }
.amount-cell { width: 25%; font-variant-numeric: tabular-nums; }
.action-cell { width: 15%; text-align: right; }

/* Confidence bar */
.confidence-bar {
  width: 100%;
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.2s ease;
}

.confidence-fill.high { background: #22c55e; }
.confidence-fill.low  { background: #f59e0b; }

/* Badges and icons */
.flag-icon   { color: #f59e0b; margin-left: 6px; font-style: normal; }
.edited-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #dbeafe;
  color: #1d4ed8;
  border-radius: 3px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
}
.item-note { color: #9ca3af; margin-left: 4px; cursor: help; }

/* Inline edit form */
.line-item-editing td {
  background: #f9fafb;
  padding: 8px 12px;
}

.inline-edit-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.edit-label { font-weight: 500; color: #374151; flex: 1; min-width: 120px; }

.amount-input {
  width: 140px;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.amount-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

/* Action buttons */
.draft-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.draft-actions .helper-text { margin: 0; }

/* Sticky review bar: sits just under the app nav (58px, or taller when the nav wraps). z-index 25 is below the nav
   (30, which holds the user dropdown), the detail drawer (50) and the Companion (1000). */
.review-bar {
  position: sticky;
  top: var(--app-nav-height, 58px); /* set from the nav's real height by review_bar_controller.js */
  z-index: 25;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 12px 0 16px;
  padding: 10px 16px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.07);
}
.review-bar__info { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-width: 0; }
.review-bar__name { font-weight: 600; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-bar__meta { color: #6b7280; font-size: 0.85rem; }
.review-bar__actions { display: flex; align-items: center; gap: 8px; }
.review-bar .btn-primary, .review-bar .btn-danger { padding: 8px 16px; font-size: 0.9rem; }

.btn-primary {
  background: #1d4ed8;
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-primary:hover { background: #1e40af; }

.btn-danger {
  background: #fff;
  color: #dc2626;
  border: 1px solid #dc2626;
  border-radius: 5px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-danger:hover { background: #fef2f2; }

.btn-save {
  background: #059669;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-save:hover { background: #047857; }

.edit-link  { color: #3b82f6; font-size: 0.875rem; }
.cancel-link { color: #6b7280; font-size: 0.875rem; }

/* ── Financials tab (Phase 3 snapshot redesign) ─────────────────────── */

/* Metric card color modifiers beyond the existing positive/negative pair —
   cash flow uses the accent (blue) rather than NOI's green when positive,
   and unavailable metrics ("—") get a muted value instead of default-dark. */
.metric-accent .metric-value { color: var(--color-lens-primary); }
.metric-muted  .metric-value { color: var(--color-lens-text-muted); }

/* Line item detail drawer — desktop: right-side panel, mobile: bottom sheet.
   Two distinct transform axes (X on desktop, Y on mobile) are why this needs
   real CSS rather than toggled Tailwind utility classes. */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  visibility: hidden;
}

.drawer--open {
  visibility: visible;
}

/* Dims the page but is deliberately not interactive: closing only happens via
   the header close button, the hide tab, or Escape — clicking through to the
   page underneath (e.g. to compare a figure) must not also close the drawer. */
.drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}

.drawer--open .drawer__backdrop {
  opacity: 1;
}

.drawer__panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 680px;
  max-width: 100vw;
  background: var(--color-lens-card);
  border-left: 1px solid var(--color-lens-border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 220ms ease;
  overflow: visible;
  pointer-events: auto;
}

.drawer--open .drawer__panel {
  transform: translateX(0);
}

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-lens-border);
  flex-shrink: 0;
}

.drawer__title {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-lens-text);
}

.drawer__close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-lens-text-muted);
  padding: 4px;
  line-height: 1;
  font-size: 22px;
}

.drawer__content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  -webkit-overflow-scrolling: touch;
}

/* Drag-to-resize grab strip, hugging the panel's true left edge from the
   outside — no visible decoration, just a wider cursor target than a 1px
   border would give. Sits above .drawer__hide-tab (z-index) since both
   occupy the same corner but must hit-test independently. */
.drawer__resize-handle {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  touch-action: none;
  background: transparent;
  z-index: 2;
}

/* Hide-tab sits flush against the panel's inner-left edge, immediately to
   the right of the resize handle above — a more discoverable "hide"
   affordance than the header's × alone. */
.drawer__hide-tab {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-lens-card);
  border: 1px solid var(--color-lens-border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  color: var(--color-lens-text-muted);
  cursor: pointer;
  padding: 0;
  z-index: 1;
}

.drawer__hide-tab:hover {
  color: var(--color-lens-text);
}

.drawer__hide-tab svg {
  width: 16px;
  height: 16px;
}

@media (max-width: 640px) {
  .drawer__panel {
    right: 0;
    left: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    height: 85vh;
    border-left: none;
    border-top: 1px solid var(--color-lens-border);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }

  .drawer--open .drawer__panel {
    transform: translateY(0);
  }

  /* No meaningful "left edge" (or resizable width) on a full-width bottom sheet. */
  .drawer__hide-tab,
  .drawer__resize-handle {
    display: none;
  }
}

/* ── Phase 4: Loan debt-service toggle (Financials tab snapshot cards) ── */
.loan-toggle-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  line-height: 0;
}

.loan-toggle-track {
  display: inline-block;
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: var(--color-lens-border);
  position: relative;
  transition: background-color 0.15s;
}

.loan-toggle-track--on {
  background: var(--color-lens-approved);
}

.loan-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}

.loan-toggle-track--on .loan-toggle-thumb {
  transform: translateX(14px);
}

/* ── Review summary header and check pills ─────────────────────────────── */
.review-summary { margin: 0 0 20px; }
.review-summary .summary-bar { flex-wrap: wrap; margin: 0 0 12px; gap: 12px; }
.review-summary .metric-card { flex: 1 1 150px; min-width: 0; padding: 12px 14px; }
.review-summary .metric-value { font-size: 1.2rem; overflow-wrap: anywhere; }

.review-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.review-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
}
.review-pill::before { content: ""; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: currentColor; }
.review-pill--ok    { color: #047857; background: #ecfdf5; border-color: #a7f3d0; }
.review-pill--warn  { color: #b45309; background: #fffbeb; border-color: #fcd34d; }
.review-pill--muted { color: #6b7280; background: #f9fafb; border-color: #e5e7eb; }
.review-pill:hover  { filter: brightness(0.96); text-decoration: underline; }

/* Pill targets scroll to just below the nav (58px) and the sticky review bar. */
#flagged-exceptions, #mapping-confirmation-notice, #property-code-warning, #line-items {
  scroll-margin-top: calc(var(--app-nav-height, 58px) + var(--review-bar-height, 64px) + 16px);
}

/* ── Collapsible review sections ───────────────────────────────────────── */
.review-sections-toolbar { display: flex; align-items: center; gap: 8px; margin: 16px 0 8px; }
.review-sections-toolbar__label { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin-right: auto; }
.review-sections-toolbar__btn {
  background: #fff; border: 1px solid #d1d5db; border-radius: 5px; padding: 4px 12px;
  font-size: 0.8rem; color: #374151; cursor: pointer;
}
.review-sections-toolbar__btn:hover { background: #f3f4f6; }

.review-section { border: 1px solid #e5e7eb; border-radius: 8px; margin-bottom: 12px; background: #fff; }
.review-section__summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  padding: 10px 16px; cursor: pointer; list-style: none;
}
.review-section__summary::-webkit-details-marker { display: none; }
.review-section__summary:hover { background: #f9fafb; border-radius: 8px; }
.review-section__chevron { color: #6b7280; transition: transform 0.15s; }
.review-section[open] > .review-section__summary .review-section__chevron { transform: rotate(90deg); }
.review-section__title { margin: 0; font-size: 1.05rem; }
.review-section__count { color: #6b7280; font-size: 0.85rem; }
.review-section__flag { color: #b45309; background: #fffbeb; border: 1px solid #fcd34d; border-radius: 999px; padding: 1px 10px; font-size: 0.78rem; font-weight: 600; }
.review-section__body { padding: 0 16px 16px; overflow-x: auto; }
.review-section__body > .draft-meta { margin-top: 0; }

/* ── Responsive: laptop, tablet, narrow ────────────────────────────────── */
@media (max-width: 1024px) {
  .review-summary .metric-card { flex-basis: 130px; }
  .review-bar__name { max-width: 260px; }
}
@media (max-width: 760px) {
  .review-bar { padding: 8px 12px; gap: 6px 12px; }
  .review-bar__info { flex: 1 1 100%; }
  .review-bar__name { max-width: 100%; }
  .review-bar__actions { flex: 1 1 100%; }
  .review-bar .draft-actions { flex: 1 1 100%; }
  .review-bar .draft-actions form { flex: 1 1 0; }
  .review-bar .draft-actions button { width: 100%; min-height: 44px; }
  .review-summary .metric-card { flex-basis: calc(50% - 12px); }
  .review-pill { font-size: 0.78rem; }
  .review-sections-toolbar__btn { min-height: 36px; }
}
/* On a phone a two-row sticky bar would cost too much of the screen: let it scroll. */
@media (max-width: 600px) {
  .review-bar { position: static; }
  .review-sections-toolbar { flex-wrap: wrap; }
}
