/* money-view.css — P4-03 Money review & confirm UI
   CSS prefix: mv-
   All colors reference CSS variables from styles.css for theme consistency.
*/

/* -------------------------------------------------------------------------
   View container — mirrors .crm-view
------------------------------------------------------------------------- */

.money-view {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height, 56px) - 4px);
  overflow: hidden;
}

/* -------------------------------------------------------------------------
   Root layout
------------------------------------------------------------------------- */

.mv-root {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 0;
}

.mv-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color, #475569);
  background: var(--bg-card, #334155);
  flex-shrink: 0;
}

.mv-heading {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  flex: 1 1 auto;
  color: var(--text-primary, #f8fafc);
}

.mv-status-filter {
  min-width: 180px;
}

/* -------------------------------------------------------------------------
   Two-pane body
------------------------------------------------------------------------- */

.mv-body {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.mv-list-pane {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-color, #475569);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mv-detail-pane {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 1rem;
  min-width: 0;
}

/* -------------------------------------------------------------------------
   Queue list
------------------------------------------------------------------------- */

.mv-list-header {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted, #9aa7b4);
  border-bottom: 1px solid var(--border-color, #475569);
  background: var(--bg-light, #475569);
}

.mv-list {
  flex: 1 1 0;
  overflow-y: auto;
}

.mv-list-item {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-color, #475569);
  cursor: pointer;
  transition: background 0.12s;
  color: var(--text-primary, #f8fafc);
}

.mv-list-item:hover {
  background: var(--bg-light, #475569);
}

.mv-list-item--active {
  background: rgba(59, 130, 246, 0.18);
  border-left: 3px solid var(--primary, #3b82f6);
}

.mv-list-item:focus {
  outline: 2px solid var(--primary, #3b82f6);
  outline-offset: -2px;
}

.mv-item-title {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mv-item-meta {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.2rem;
}

.mv-item-amount {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary, #f8fafc);
}

.mv-item-date {
  font-size: 0.75rem;
  color: var(--text-muted, #9aa7b4);
}

.mv-item-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.3rem;
}

.mv-list-empty,
.mv-list-error {
  padding: 1rem 0.75rem;
  color: var(--text-muted, #9aa7b4);
  font-size: 0.85rem;
}

.mv-list-error {
  color: var(--danger, #ef4444);
}

/* -------------------------------------------------------------------------
   Pagination
------------------------------------------------------------------------- */

.mv-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-top: 1px solid var(--border-color, #475569);
  background: var(--bg-light, #475569);
  flex-shrink: 0;
}

.mv-page-info {
  font-size: 0.8rem;
  color: var(--text-muted, #9aa7b4);
}

/* -------------------------------------------------------------------------
   Detail pane
------------------------------------------------------------------------- */

.mv-detail-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.mv-detail-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  flex: 1 1 auto;
  color: var(--text-primary, #f8fafc);
}

.mv-detail--loading {
  opacity: 0.6;
  pointer-events: none;
}

.mv-detail-error {
  color: var(--danger, #ef4444);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  min-height: 1.2em;
}

.mv-empty-detail {
  color: var(--text-muted, #9aa7b4);
  font-style: italic;
}

.mv-no-entries {
  color: var(--text-muted, #9aa7b4);
  font-size: 0.85rem;
}

/* -------------------------------------------------------------------------
   Status badges
------------------------------------------------------------------------- */

.mv-status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mv-status-new      { background: rgba(6, 182, 212, 0.18);   color: #67e8f9; }
.mv-status-extracted { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.mv-status-confirmed { background: rgba(34, 197, 94, 0.18);  color: #86efac; }
.mv-status-rejected  { background: rgba(239, 68, 68, 0.18);  color: #fca5a5; }
.mv-status-draft     { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.mv-status-paid      { background: rgba(34, 197, 94, 0.18);  color: #86efac; }

/* Needs-review badge */
.mv-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 0.2rem;
  font-size: 0.7rem;
  font-weight: 500;
}

.mv-badge--review {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* -------------------------------------------------------------------------
   Document preview
------------------------------------------------------------------------- */

.mv-preview-section {
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-light, #475569);
  border-radius: 0.25rem;
  border: 1px solid var(--border-color, #475569);
  font-size: 0.9rem;
  color: var(--text-primary, #f8fafc);
}

.mv-preview-label {
  font-weight: 500;
  margin-right: 0.25rem;
  color: var(--text-secondary, #94a3b8);
}

.mv-preview-link {
  color: var(--primary, #3b82f6);
  text-decoration: underline;
  word-break: break-all;
}

.mv-preview-link:hover {
  text-decoration: none;
}

/* -------------------------------------------------------------------------
   Entry tabs
------------------------------------------------------------------------- */

.mv-entry-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color, #475569);
  flex-wrap: wrap;
}

.mv-entry-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted, #9aa7b4);
  margin-bottom: -1px;
}

.mv-entry-tab--active {
  border-bottom-color: var(--primary, #3b82f6);
  color: var(--primary, #3b82f6);
  font-weight: 500;
}

/* -------------------------------------------------------------------------
   Entry section
------------------------------------------------------------------------- */

.mv-entry-section {
  background: var(--bg-card, #334155);
  border: 1px solid var(--border-color, #475569);
  border-radius: 0.375rem;
  padding: 1rem;
}

.mv-entry-status-row {
  margin-bottom: 0.75rem;
}

.mv-review-banner {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 0.25rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  color: #fcd34d;
}

/* -------------------------------------------------------------------------
   Entry form fields
------------------------------------------------------------------------- */

.mv-entry-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
}

.mv-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.mv-field-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted, #9aa7b4);
}

.mv-field-readonly {
  font-size: 0.95rem;
  color: var(--text-primary, #f8fafc);
  padding: 0.25rem 0;
}

.mv-field-group--review label {
  color: #fcd34d;
}

.mv-field--needs-review {
  border-color: var(--warning, #f59e0b) !important;
  background: rgba(245, 158, 11, 0.1) !important;
}

/* -------------------------------------------------------------------------
   Action buttons
------------------------------------------------------------------------- */

.mv-action-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.mv-save-row {
  border-top: 1px solid var(--border-color, #475569);
  padding-top: 0.75rem;
  margin-top: 0.75rem;
  justify-content: flex-end;
}

.mv-save-status {
  font-size: 0.8rem;
}

.mv-btn-confirm {
  background: var(--success, #22c55e);
  color: #fff;
  border-color: var(--success, #22c55e);
}

.mv-btn-confirm:hover:not(:disabled) {
  background: #16a34a;
  border-color: #15803d;
}

.mv-btn-reject {
  background: var(--danger, #ef4444);
  color: #fff;
  border-color: var(--danger, #ef4444);
}

.mv-btn-reject:hover:not(:disabled) {
  background: #dc2626;
  border-color: #b91c1c;
}

.mv-btn-reverse {
  background: var(--secondary, #64748b);
  color: #fff;
  border-color: var(--secondary, #64748b);
}

.mv-btn-reverse:hover:not(:disabled) {
  background: #475569;
  border-color: #334155;
}

/* -------------------------------------------------------------------------
   Responsive — tablet (768–1023 px)
   List pane shrinks but stays side-by-side.
------------------------------------------------------------------------- */

@media (min-width: 768px) and (max-width: 1023px) {
  .mv-list-pane {
    width: 260px;
  }

  .mv-entry-form {
    grid-template-columns: 1fr;
  }
}

/* -------------------------------------------------------------------------
   Responsive — phone (<768 px)
   Strategy: list pane stacks above detail pane.
   On phone the list pane shows a fixed portion of the viewport so the user
   can still see the queue, then scrolls the detail pane below it.
   Choosing stack-under (not a slide-over) because the module only manages
   a single container div (#moneyView) with no backdrop / sheet infra — a
   slide-over would need overlay DOM that belongs to the shell.  The stacked
   layout is also more thumb-friendly and avoids hiding context.
------------------------------------------------------------------------- */

@media (max-width: 767px) {
  .money-view {
    /* Full height, flex column — list + detail stack vertically */
    height: auto;
    min-height: calc(100vh - var(--header-height, 56px) - var(--bottom-nav-height, 56px) - 4px);
    overflow: visible;
  }

  .mv-root {
    height: auto;
    overflow: visible;
  }

  .mv-header {
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
  }

  .mv-status-filter {
    min-width: 0;
    flex: 1 1 auto;
  }

  .mv-body {
    flex-direction: column;
    overflow: visible;
    height: auto;
  }

  /* List pane: fixed height strip at the top */
  .mv-list-pane {
    width: 100%;
    /* Enough to show ~3-4 cards without dominating the screen */
    height: 220px;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-color, #475569);
  }

  /* List items become taller touch targets on mobile */
  .mv-list-item {
    min-height: 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--space-3) var(--space-4);
  }

  /* Detail pane: full-width below the list; naturally scrollable */
  .mv-detail-pane {
    flex: none;
    width: 100%;
    overflow-y: visible;
    padding: var(--space-4);
    /* Bottom padding clears the fixed bottom-nav */
    padding-bottom: calc(var(--space-4) + var(--bottom-nav-height, 56px) + env(safe-area-inset-bottom));
  }

  /* Entry form: single column */
  .mv-entry-form {
    grid-template-columns: 1fr;
  }

  /* Action row: full-width buttons on phone */
  .mv-action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .mv-action-row .btn {
    min-height: 44px;
    justify-content: center;
  }

  /* Header inside detail pane: wrap on small screens */
  .mv-detail-header {
    flex-wrap: wrap;
  }

  /* Pagination buttons: generous touch targets */
  .mv-pagination .btn {
    min-height: 44px;
    min-width: 44px;
  }
}
