/**
 * Client Review Apps - Shared Styles
 * Used by: client-review, client-margin, client-review-missing
 * Replaces Tailwind CSS utilities from standalone iframe pages
 */

/* ============================================
   STAT CARDS
   ============================================ */
.cr-stats-row {
  display: grid;
  gap: 16px;
  margin-bottom: 24px;
}
.cr-stats-row.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cr-stats-row.cols-5 { grid-template-columns: repeat(5, 1fr); }

.cr-stat-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  padding: 16px;
}
.cr-stat-card .stat-label {
  font-size: 12px;
  text-transform: uppercase;
  opacity: 0.8;
  margin-bottom: 4px;
}
.cr-stat-card .stat-number {
  font-size: 28px;
  font-weight: 700;
}
.cr-stat-card .stat-sub {
  font-size: 12px;
  opacity: 0.8;
}
.cr-stat-card.green  { background: #28a745; color: white; }
.cr-stat-card.amber  { background: #ffc107; color: #212529; }
.cr-stat-card.red    { background: #dc3545; color: white; }
.cr-stat-card.blue   { background: #3b82f6; color: white; }
.cr-stat-card.blue-dark { background: #2563eb; color: white; }
.cr-stat-card.indigo { background: #6366f1; color: white; }
.cr-stat-card.indigo-dark { background: #4f46e5; color: white; }
.cr-stat-card.amber-text { color: #d97706; }

/* ============================================
   FILTER BAR
   ============================================ */
.cr-filter-bar {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  padding: 16px;
  margin-bottom: 24px;
  display: grid;
  gap: 16px;
}
.cr-filter-bar.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cr-filter-bar.cols-5 { grid-template-columns: repeat(5, 1fr); }

.cr-filter-bar label {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}
.cr-filter-bar input,
.cr-filter-bar select {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
}
.cr-filter-bar input:focus,
.cr-filter-bar select:focus {
  border-color: #538d83;
  box-shadow: 0 0 0 2px rgba(83, 141, 131, 0.2);
}
.cr-filter-bar .filter-actions {
  display: flex;
  align-items: flex-end;
}
.cr-btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
  text-decoration: none;
}
.cr-btn:hover { opacity: 0.85; }
.cr-btn-primary {
  background: #538d83;
  color: white;
  width: 100%;
}
.cr-btn-secondary {
  background: #47786f;
  color: white;
}
.cr-btn-white {
  background: white;
  color: #538d83;
  border: 1px solid #d1d5db;
}

/* ============================================
   TOOLBAR
   ============================================ */
.cr-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.cr-toolbar-title {
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
}
.cr-toolbar-actions {
  display: flex;
  gap: 8px;
}

/* ============================================
   DATA TABLE
   ============================================ */
.cr-table-wrapper {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  overflow: hidden;
}
.cr-table-scroll {
  overflow-x: auto;
}
.cr-table {
  width: 100%;
  border-collapse: collapse;
}
.cr-table thead {
  background: #f9fafb;
}
.cr-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  user-select: none;
}
.cr-table th.sortable {
  cursor: pointer;
  position: relative;
}
.cr-table th.sortable:hover {
  background: #e5e7eb;
}
.cr-table th.text-right { text-align: right; }
.cr-table th.text-center { text-align: center; }
.cr-table th.bg-yellow { background: #fefce8; }
.cr-table th.bg-green { background: #ecfdf5; }

.cr-table tbody tr {
  border-bottom: 1px solid #e5e7eb;
  transition: background-color 0.15s;
}
.cr-table tbody tr:hover {
  background-color: #f9fafb;
}
.cr-table tbody tr.clickable {
  cursor: pointer;
}
.cr-table td {
  padding: 12px 16px;
  font-size: 13px;
  color: #374151;
  white-space: nowrap;
}
.cr-table td.text-right { text-align: right; }
.cr-table td.text-center { text-align: center; }
.cr-table td.font-medium { font-weight: 500; color: #111827; }
.cr-table td.text-muted { color: #6b7280; }
.cr-table td.text-negative { color: #dc3545; }
.cr-table td.currency {
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}
.cr-table .empty-row td {
  padding: 32px 16px;
  text-align: center;
  color: #6b7280;
}
.cr-table .error-row td {
  padding: 32px 16px;
  text-align: center;
  color: #dc3545;
}

/* ============================================
   PAGINATION
   ============================================ */
.cr-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
  font-size: 13px;
  color: #6b7280;
}
.cr-pagination-btns {
  display: flex;
  gap: 8px;
}
.cr-pagination-btns button {
  padding: 4px 12px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 13px;
}
.cr-pagination-btns button:hover:not(:disabled) {
  background: #f3f4f6;
}
.cr-pagination-btns button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   CATEGORY BADGES
   ============================================ */
.cr-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.cr-badge.green  { background: #28a745; color: white; }
.cr-badge.amber  { background: #ffc107; color: #212529; }
.cr-badge.red    { background: #dc3545; color: white; }

/* ============================================
   MODALS
   ============================================ */
.cr-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}
.cr-modal-overlay.show {
  display: flex;
}
.cr-modal {
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-height: 90vh;
  overflow-y: auto;
  animation: crSlideIn 0.2s ease;
}
.cr-modal.wide { width: 720px; max-width: 90vw; }
.cr-modal.narrow { width: 420px; max-width: 90vw; }
.cr-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px 24px 0 24px;
}
.cr-modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
}
.cr-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #9ca3af;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.cr-modal-close:hover { color: #374151; }
.cr-modal-body {
  padding: 16px 24px 24px 24px;
}
.cr-modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.cr-modal-actions .cr-btn { flex: 1; text-align: center; }

@keyframes crSlideIn {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ============================================
   DETAIL SECTIONS (Client Review modal)
   ============================================ */
.cr-detail-section {
  margin-bottom: 24px;
}
.cr-detail-section h3 {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e5e7eb;
}
.cr-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.cr-detail-label {
  font-size: 11px;
  color: #6b7280;
}
.cr-detail-value {
  font-size: 13px;
  font-weight: 500;
  color: #111827;
}

/* Category history timeline */
.cr-history {
  position: relative;
  padding-left: 24px;
}
.cr-history::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #e5e7eb;
}
.cr-history-item {
  position: relative;
  padding-bottom: 12px;
}
.cr-history-item::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #538d83;
}
.cr-history-item.green::before  { background: #28a745; }
.cr-history-item.amber::before  { background: #ffc107; }
.cr-history-item.red::before    { background: #dc3545; }

/* ============================================
   EDITABLE CELLS (Client Margin)
   ============================================ */
.cr-table td.editable {
  cursor: pointer;
  position: relative;
}
.cr-table td.editable:hover {
  background: #fef08a;
}
.cr-table td.target-bg { background: #fefce8; }
.cr-table td.deposit-bg { background: #ecfdf5; }
.cr-table td.editable.deposit-bg:hover { background: #d1fae5; }

/* Spread variance */
.spread-up { color: #dc3545; font-size: 11px; margin-left: 4px; }
.spread-down { color: #28a745; font-size: 11px; margin-left: 4px; }

/* ============================================
   INFO BANNER (Missing Entity page)
   ============================================ */
.cr-info-banner {
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  padding: 16px;
  margin-bottom: 24px;
  border-radius: 0 8px 8px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.cr-info-banner .icon { font-size: 24px; color: #f59e0b; }
.cr-info-banner .title { font-weight: 600; color: #92400e; }
.cr-info-banner .text { font-size: 13px; color: #a16207; }

/* ============================================
   LOADING SPINNER
   ============================================ */
.cr-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #538d83;
  border-radius: 50%;
  animation: crSpin 1s linear infinite;
}
@keyframes crSpin {
  to { transform: rotate(360deg); }
}

/* ============================================
   FORM ELEMENTS (inside modals)
   ============================================ */
.cr-form-group {
  margin-bottom: 16px;
}
.cr-form-group label {
  display: block;
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 4px;
}
.cr-form-group input {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
}
.cr-form-group input:focus {
  border-color: #538d83;
  box-shadow: 0 0 0 2px rgba(83,141,131,0.2);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
  .cr-stats-row.cols-4,
  .cr-stats-row.cols-5 { grid-template-columns: repeat(2, 1fr); }
  .cr-filter-bar.cols-4,
  .cr-filter-bar.cols-5 { grid-template-columns: repeat(2, 1fr); }
}
