/* ============================================================
 *  Pesquisa Global + Modal de Detalhe — CSS
 * ============================================================ */

/* ── Trigger button no header ────────────────────────────── */
.global-search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  color: #64748b;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.global-search-trigger:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
  color: #334155;
}
.global-search-trigger .search-icon { font-size: 1rem; }
.global-search-trigger .search-shortcut {
  background: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #94a3b8;
  border: 1px solid #e2e8f0;
}

/* ── Shared overlay base ─────────────────────────────────── */
.search-overlay,
.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8vh;
  animation: searchFadeIn 0.15s ease;
}
.search-overlay.active,
.detail-overlay.active {
  display: flex;
}
.detail-overlay { z-index: 10000; padding-top: 4vh; }

@keyframes searchFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes searchSlideDown { from { opacity: 0; transform: translateY(-16px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Search Dialog ───────────────────────────────────────── */
.search-dialog {
  width: 95%;
  max-width: 680px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.25);
  overflow: hidden;
  animation: searchSlideDown 0.2s ease;
}

/* ── Input area ──────────────────────────────────────────── */
.search-input-area {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
}
.search-input-area .search-input-icon { font-size: 1.25rem; color: #218d8d; flex-shrink: 0; }
.search-input-area input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 1.05rem;
  font-family: inherit;
  color: #133452;
  background: transparent;
}
.search-input-area input::placeholder { color: #94a3b8; }
.search-input-area .search-close-btn {
  background: #f1f5f9;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: #64748b;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}
.search-input-area .search-close-btn:hover { background: #e2e8f0; }

/* ── Tabs ────────────────────────────────────────────────── */
.search-tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}
.search-tab {
  padding: 10px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}
.search-tab:hover { color: #218d8d; background: rgba(33,141,141,0.04); }
.search-tab.active { color: #218d8d; border-bottom-color: #218d8d; }
.search-tab .tab-count {
  background: #e2e8f0;
  color: #64748b;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
}
.search-tab.active .tab-count { background: rgba(33,141,141,0.15); color: #218d8d; }

/* ── Results ─────────────────────────────────────────────── */
.search-results {
  max-height: 420px;
  overflow-y: auto;
  padding: 8px 0;
}
.search-results::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-track { background: transparent; }
.search-results::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.search-category-label {
  padding: 8px 20px 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #94a3b8;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.12s;
  border-left: 3px solid transparent;
}
.search-result-item:hover,
.search-result-item.focused {
  background: #f8fafc;
  border-left-color: #218d8d;
}
.search-result-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.search-result-icon.cliente { background: linear-gradient(135deg,rgba(33,141,141,0.12),rgba(33,141,141,0.06)); color: #218d8d; }
.search-result-icon.produto { background: linear-gradient(135deg,rgba(99,102,241,0.12),rgba(99,102,241,0.06)); color: #6366f1; }
.search-result-icon.documento { background: linear-gradient(135deg,rgba(245,158,11,0.12),rgba(245,158,11,0.06)); color: #f59e0b; }

.search-result-body { flex: 1; min-width: 0; }
.search-result-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #133452;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-title mark {
  background: rgba(33,141,141,0.15);
  color: #218d8d;
  border-radius: 2px;
  padding: 0 2px;
}
.search-result-subtitle {
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-meta { text-align: right; flex-shrink: 0; }
.search-result-value { font-size: 0.85rem; font-weight: 700; color: #218d8d; }
.search-result-date { font-size: 0.72rem; color: #94a3b8; margin-top: 2px; }

/* ── Empty / Loading ─────────────────────────────────────── */
.search-empty { padding: 40px 20px; text-align: center; color: #94a3b8; }
.search-empty .search-empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.5; }
.search-empty .search-empty-text { font-size: 0.9rem; font-weight: 500; }
.search-empty .search-empty-hint { font-size: 0.8rem; margin-top: 4px; opacity: 0.7; }

.search-loading {
  padding: 32px 20px;
  text-align: center;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.9rem;
}
.search-loading .search-spinner {
  width: 20px; height: 20px;
  border: 3px solid #e2e8f0;
  border-top-color: #218d8d;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Footer ──────────────────────────────────────────────── */
.search-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  font-size: 0.75rem;
  color: #94a3b8;
}
.search-footer-keys { display: flex; gap: 12px; }
.search-footer-keys span { display: flex; align-items: center; gap: 4px; }
.search-footer-keys kbd {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.68rem;
  font-family: inherit;
  font-weight: 600;
  color: #64748b;
}

/* ════════════════════════════════════════════════════════════
 *  DETAIL MODAL
 * ════════════════════════════════════════════════════════════ */

.detail-dialog {
  width: 96%;
  max-width: 900px;
  max-height: 88vh;
  background: white;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: searchSlideDown 0.2s ease;
}

/* ── Header ──────────────────────────────────────────────── */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: linear-gradient(135deg, #f8fafc, #f1f5f9);
}
.detail-back-btn {
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 0.8rem;
  color: #64748b;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.15s;
}
.detail-back-btn:hover { background: #e2e8f0; color: #334155; }
.detail-title { flex: 1; font-size: 1.05rem; font-weight: 700; color: #133452; margin: 0; }
.detail-close-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
}
.detail-close-btn:hover { background: #fee2e2; color: #ef4444; }

/* ── Body ────────────────────────────────────────────────── */
.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 28px;
}
.detail-body::-webkit-scrollbar { width: 6px; }
.detail-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── Hero section ────────────────────────────────────────── */
.detail-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.detail-hero-left { display: flex; align-items: center; gap: 16px; }
.detail-avatar {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  flex-shrink: 0;
}
.detail-avatar.cliente-bg { background: linear-gradient(135deg,#218d8d,#1a7070); color: white; }
.detail-avatar.produto-bg { background: linear-gradient(135deg,#6366f1,#4f46e5); color: white; }
.detail-avatar.documento-bg { background: linear-gradient(135deg,#f59e0b,#d97706); color: white; }

.detail-name { margin: 0; font-size: 1.15rem; font-weight: 700; color: #133452; }
.detail-code { font-size: 0.82rem; color: #64748b; margin-top: 2px; }
.detail-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 4px;
}
.detail-hero-total {
  font-size: 1.6rem;
  font-weight: 800;
  color: #218d8d;
  white-space: nowrap;
}

/* ── KPI Grid ────────────────────────────────────────────── */
.detail-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.detail-kpi-grid.four-col { grid-template-columns: repeat(4, 1fr); }

.detail-kpi {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 16px;
  text-align: center;
  transition: transform 0.15s, box-shadow 0.15s;
}
.detail-kpi:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
.detail-kpi-icon { font-size: 1.3rem; margin-bottom: 4px; }
.detail-kpi-label { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; color: #94a3b8; margin-bottom: 4px; }
.detail-kpi-value { font-size: 1rem; font-weight: 800; color: #133452; }

/* ── Info Grid ───────────────────────────────────────────── */
.detail-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.detail-info-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
}
.detail-info-card h4 {
  margin: 0 0 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #133452;
}
.detail-info-rows { display: flex; flex-direction: column; gap: 6px; }
.detail-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(0,0,0,0.04);
}
.detail-info-row:last-child { border-bottom: none; }
.detail-info-label { color: #64748b; font-weight: 500; }
.detail-info-value { color: #133452; font-weight: 600; text-align: right; max-width: 60%; word-break: break-word; }

.detail-no-data {
  padding: 20px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.85rem;
}

/* ── Section ─────────────────────────────────────────────── */
.detail-section { margin-bottom: 20px; }
.detail-section h4 {
  margin: 0 0 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #133452;
}

/* ── Tables ──────────────────────────────────────────────── */
.detail-table-wrap { overflow-x: auto; }

.detail-ranking-table,
.detail-lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.detail-ranking-table th,
.detail-lines-table th {
  background: #f1f5f9;
  color: #64748b;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 8px 10px;
  text-align: left;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}
.detail-ranking-table th.num,
.detail-lines-table th.num { text-align: right; }

.detail-ranking-table td,
.detail-lines-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
  vertical-align: middle;
}
.detail-ranking-table td.num,
.detail-lines-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.detail-ranking-table td.total-col,
.detail-lines-table td.total-col { font-weight: 700; color: #218d8d; }

.detail-ranking-table tr:hover,
.detail-lines-table tbody tr:hover { background: rgba(33,141,141,0.03); }

.detail-lines-table td.line-num { color: #94a3b8; font-weight: 600; width: 30px; }
.detail-lines-table td.fam { color: #64748b; font-size: 0.75rem; }
.detail-lines-table td code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  color: #6366f1;
  font-weight: 600;
}
.detail-lines-table tfoot .total-row td {
  background: #f1f5f9;
  border-top: 2px solid #e2e8f0;
  font-size: 0.85rem;
}

.rank-num { color: #94a3b8; font-weight: 700; margin-right: 4px; }

/* ── Mini Chart ──────────────────────────────────────────── */
.detail-mini-chart {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
}
.mini-chart-container {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 160px;
  padding-top: 10px;
}
.mini-chart-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}
.mini-chart-value {
  font-size: 0.6rem;
  color: #64748b;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  text-align: center;
}
.mini-chart-bar {
  width: 100%;
  max-width: 40px;
  background: linear-gradient(180deg, #218d8d, #1a7070);
  border-radius: 4px 4px 0 0;
  transition: height 0.5s ease;
  min-height: 3px;
}
.mini-chart-label {
  font-size: 0.6rem;
  color: #94a3b8;
  margin-top: 4px;
  white-space: nowrap;
  font-weight: 600;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .search-overlay,
  .detail-overlay { padding-top: 3vh; }
  .search-dialog { max-width: 98%; border-radius: 12px; }
  .detail-dialog { max-width: 98%; max-height: 94vh; }
  .global-search-trigger .search-text,
  .global-search-trigger .search-shortcut { display: none; }
  .global-search-trigger { padding: 7px 10px; }
  .search-tabs { overflow-x: auto; }
  .detail-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-kpi-grid.four-col { grid-template-columns: repeat(2, 1fr); }
  .detail-info-grid { grid-template-columns: 1fr; }
  .detail-hero { flex-direction: column; align-items: flex-start; }
  .detail-hero-total { font-size: 1.2rem; }
}
