/* ── 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;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}

.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; }

/* ── Portfolio intelligence query UI ────────────────────────────────── */

.portfolio-intelligence {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 2px solid #e5e7eb;
}

.query-form-wrapper {
  margin-bottom: 24px;
}

.query-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.query-textarea {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}

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

.query-submit { min-width: 80px; white-space: nowrap; }
.query-submit.btn-loading { opacity: 0.7; cursor: not-allowed; }

/* Query entries */
.query-entry {
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
}

.query-entry--failed {
  border-color: #fca5a5;
  background: #fef2f2;
}

.query-prompt {
  font-size: 0.85rem;
  color: #6b7280;
  margin: 0 0 10px;
  font-style: italic;
}

.query-response {
  font-size: 0.95rem;
  line-height: 1.6;
  color: #111827;
}

.query-response p { margin: 0 0 8px; }
.query-response p:last-child { margin-bottom: 0; }

.query-response--error { color: #dc2626; }

.query-meta {
  margin-top: 10px;
  font-size: 0.75rem;
  color: #9ca3af;
  display: flex;
  gap: 12px;
}

.query-route {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: #6b7280;
}

.query-entry__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.query-entry__header .query-prompt {
  margin: 0;
  flex: 1;
}

.query-delete-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  color: #d1d5db;
  border-radius: 4px;
  line-height: 0;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.query-entry:hover .query-delete-btn {
  opacity: 1;
}

.query-delete-btn:hover {
  color: #ef4444;
}

/* ── 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);
}
