/* ==========================================================================
   FERRER ATIVOS · MNI WORKBENCH
   Design System inspired by shadcn/ui (Slate / Emerald / Zinc)
   ========================================================================== */

:root {
  /* Color Tokens */
  --background: #f8fafc;
  --foreground: #0f172a;
  --card: #ffffff;
  --card-foreground: #0f172a;
  --popover: #ffffff;
  --popover-foreground: #0f172a;

  --primary: #0f172a;
  --primary-hover: #1e293b;
  --primary-foreground: #ffffff;

  --secondary: #f1f5f9;
  --secondary-hover: #e2e8f0;
  --secondary-foreground: #0f172a;

  --muted: #f8fafc;
  --muted-foreground: #475569;
  --muted-subtle: #64748b;

  --accent: #f1f5f9;
  --accent-foreground: #0f172a;

  --border: #e2e8f0;
  --border-subtle: #f1f5f9;
  --input: #cbd5e1;
  --ring: rgba(15, 23, 42, 0.12);

  /* Status & Semantic Accents */
  --emerald: #059669;
  --emerald-light: #ecfdf5;
  --emerald-border: #a7f3d0;
  --emerald-text: #065f46;

  --blue: #2563eb;
  --blue-light: #eff6ff;
  --blue-border: #bfdbfe;
  --blue-text: #1d4ed8;

  --purple: #7c3aed;
  --purple-light: #f5f3ff;
  --purple-border: #ddd6fe;
  --purple-text: #5b21b6;

  --amber: #d97706;
  --amber-light: #fffbeb;
  --amber-border: #fde68a;
  --amber-text: #92400e;

  --red: #dc2626;
  --red-light: #fef2f2;
  --red-border: #fecaca;
  --red-text: #991b1b;

  /* Typography & Sizing */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  --radius-sm: 4px;
  --radius: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* ==========================================================================
   BASE & RESET
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100vh;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  display: block;
  flex-shrink: 0;
}

:target, :focus {
  scroll-margin-top: 76px;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

h1, h2, h3, h4, h5, h6 {
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

/* Accessibility skip link */
.skip-link {
  position: absolute;
  top: -120px;
  left: 20px;
  background: var(--primary);
  color: var(--primary-foreground);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.skip-link:focus,
.skip-link:focus-visible {
  top: 14px;
  transform: translateY(0);
}

/* Screen reader only utility */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.cnj-number,
.metric-value,
.metric-sub,
.titular-doc,
.party-doc,
.doc-id-pill,
.timeline-date-col,
.pdf-page-indicator,
.pdf-zoom-level,
.badge-mini,
.tab-pill,
.fact-val,
.sample-cnj-btn,
.entry-time {
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   APP SHELL & TOP NAVIGATION
   ========================================================================== */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-xs);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  height: 42px;
  width: auto;
  object-fit: contain;
}

.brand-details {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--foreground);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-tagline {
  font-size: 11px;
  color: var(--muted-foreground);
  font-weight: 500;
}

.header-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--secondary);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--foreground);
}

.system-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 0 2px var(--emerald-light);
}

.system-status-text {
  letter-spacing: 0.02em;
}

/* ==========================================================================
   MAIN CONTAINER & SEARCH PANEL
   ========================================================================== */

.app-main {
  flex: 1;
  padding: 24px 0 60px;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.search-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
}

.search-form {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

.search-input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.search-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--foreground);
  letter-spacing: -0.01em;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-ico {
  position: absolute;
  left: 12px;
  color: var(--muted-foreground);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 14px 0 40px;
  background: var(--card);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--foreground);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.search-submit, .primary {
  height: 44px;
  padding: 0 20px;
  background: var(--primary);
  color: var(--primary-foreground);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.search-submit:hover, .primary:hover {
  background: var(--primary-hover);
}

.search-submit:disabled, .primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ==========================================================================
   RESULTS SURFACE & EMPTY / LOADING STATES
   ========================================================================== */

.results-surface {
  min-height: 360px;
  display: flex;
  flex-direction: column;
}

.empty-state {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.empty-icon-wrap {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--secondary);
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--foreground);
}

.empty-state p, .muted {
  font-size: 13px;
  color: var(--muted-foreground);
  max-width: 520px;
  line-height: 1.5;
}

.loading-state {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 60px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--secondary);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-state h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--foreground);
}

/* ==========================================================================
   PROCESS HERO BANNER (NO NESTED BOX CLUTTER)
   ========================================================================== */

.process-view {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.process-hero {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.hero-badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  white-space: nowrap;
}

.badge-status {
  background: var(--emerald-light);
  color: var(--emerald-text);
  border: 1px solid var(--emerald-border);
}

.badge-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald);
}

.badge-secrecy.public {
  background: var(--secondary);
  color: var(--foreground);
  border: 1px solid var(--border);
}

.badge-secrecy.secret {
  background: var(--red-light);
  color: var(--red-text);
  border: 1px solid var(--red-border);
}

.badge-court {
  background: var(--blue-light);
  color: var(--blue-text);
  border: 1px solid var(--blue-border);
}

.badge-purple {
  background: var(--purple-light);
  color: var(--purple-text);
  border: 1px solid var(--purple-border);
}

.badge-blue {
  background: var(--blue-light);
  color: var(--blue-text);
  border: 1px solid var(--blue-border);
}

.badge-emerald {
  background: var(--emerald-light);
  color: var(--emerald-text);
  border: 1px solid var(--emerald-border);
}

.badge-amber {
  background: var(--amber-light);
  color: var(--amber-text);
  border: 1px solid var(--amber-border);
}

.badge-red {
  background: var(--red-light);
  color: var(--red-text);
  border: 1px solid var(--red-border);
}

.batch-download {
  height: 36px;
  padding: 0 14px;
  font-size: 12px;
}

.hero-cnj-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.cnj-interactive {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.cnj-number {
  font-size: 24px;
  font-weight: 800;
  color: var(--foreground);
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
  word-break: break-all;
}

.btn-copy-cnj {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  color: var(--foreground);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.btn-copy-cnj:hover {
  background: var(--secondary-hover);
  border-color: var(--input);
}

/* TITULAR DA CAUSA (FLOW STREAMLINED) */
.hero-titular-flow {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px;
  background: #f8fafc;
  border-left: 3px solid var(--emerald);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.titular-identity {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
}

.titular-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--emerald-text);
}

.titular-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--foreground);
}

.titular-doc {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-foreground);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: var(--radius-sm);
}

.titular-facts {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 12px;
  color: var(--foreground);
}

.fact-item {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.fact-lbl {
  color: var(--muted-foreground);
  font-weight: 500;
}

.hero-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 2px 0;
}

/* METRICS GRID */
.hero-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.metric-block {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.metric-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--muted-foreground);
}

.metric-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--foreground);
  line-height: 1.3;
}

.metric-sub {
  font-size: 11px;
  color: var(--muted-foreground);
}

.text-emerald {
  color: var(--emerald) !important;
}

.hero-submetrics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
}

.submetric-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.submetric-text {
  font-size: 12px;
  color: var(--foreground);
  line-height: 1.4;
}

.text-muted {
  color: var(--muted-foreground);
}

.assuntos-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-assunto {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--foreground);
}

.tag-assunto.principal {
  background: var(--blue-light);
  border-color: var(--blue-border);
  color: var(--blue-text);
  font-weight: 600;
}

.tag-assunto small {
  color: var(--muted-foreground);
  font-family: var(--font-mono);
}

/* ==========================================================================
   SHADCN/UI TABS
   ========================================================================== */

.tabs-wrapper {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tabs-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs-nav::-webkit-scrollbar {
  display: none;
}

.tab-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted-foreground);
  white-space: nowrap;
  transition: color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.tab-trigger:hover {
  color: var(--foreground);
}

.tab-trigger.active {
  background: var(--card);
  color: var(--foreground);
  box-shadow: var(--shadow-xs);
}

.tab-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 9999px;
  background: var(--secondary);
  color: var(--muted-foreground);
}

.tab-trigger.active .tab-pill {
  background: var(--primary);
  color: var(--primary-foreground);
}

.tab-content, .tab-panel {
  display: none;
}

.tab-content.active, .tab-panel.active {
  display: block;
  animation: tabFadeIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   TAB 1: TIMELINE & DOCUMENTS
   ========================================================================== */

.timeline-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: var(--shadow-xs);
}

.toolbar-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 260px;
}

.toolbar-search svg {
  position: absolute;
  left: 10px;
  color: var(--muted-foreground);
  pointer-events: none;
}

.toolbar-search input {
  width: 100%;
  height: 36px;
  padding: 0 32px 0 34px;
  background: var(--card);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--foreground);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.toolbar-search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.btn-clear-search {
  position: absolute;
  right: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--muted-foreground);
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.btn-clear-search:hover {
  color: var(--foreground);
  background: var(--secondary);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn-sm {
  height: 34px;
  padding: 0 12px;
}

.btn-outline {
  background: var(--card);
  border-color: var(--border);
  color: var(--foreground);
}

.btn-outline:hover {
  background: var(--secondary);
  border-color: var(--input);
}

.btn-outline.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary);
  border-color: var(--border);
  color: var(--foreground);
}

.btn-secondary:hover {
  background: var(--secondary-hover);
}

.badge-mini {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 9999px;
  background: var(--secondary);
  color: var(--foreground);
}

.btn-outline.active .badge-mini {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.timeline-counter-row {
  padding: 8px 4px 2px;
  font-size: 12px;
  color: var(--muted-foreground);
  font-weight: 500;
}

/* TIMELINE FEED */
.timeline-feed {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  padding-left: 20px;
  border-left: 2px solid var(--border);
  margin-left: 10px;
  margin-top: 10px;
}

.timeline-entry {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
}

.timeline-entry.initial-entry {
  border-color: var(--blue-border);
  background: #fafcff;
}

.timeline-entry.has-attachments {
  border-left: 3px solid var(--primary);
}

.timeline-marker {
  position: absolute;
  left: -27px;
  top: 18px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--muted-subtle);
}

.timeline-marker.active {
  background: var(--primary);
  border-color: var(--primary);
}

.timeline-marker.initial {
  background: var(--blue);
  border-color: var(--blue);
}

.entry-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.entry-type-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--secondary);
  color: var(--muted-foreground);
}

.entry-type-tag.initial {
  background: var(--blue-light);
  color: var(--blue-text);
}

.entry-time {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--muted-foreground);
}

.entry-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--foreground);
  margin-bottom: 4px;
}

.entry-desc {
  font-size: 12px;
  color: #334155;
  line-height: 1.5;
  margin-bottom: 10px;
}

.entry-docs-block {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.docs-block-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--muted-foreground);
}

.docs-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* DOCUMENT ROW ITEM */
.doc-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.doc-item-row:hover {
  background: #f1f5f9;
  border-color: var(--input);
}

.doc-item-leading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.doc-icon-pill {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  background: var(--secondary);
}

.doc-icon-pill.pdf {
  background: var(--red-light);
  color: var(--red);
}

.doc-icon-pill.video {
  background: var(--blue-light);
  color: var(--blue);
}

.doc-icon-pill.html {
  background: var(--amber-light);
  color: var(--amber);
}

.doc-item-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.doc-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-submeta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted-foreground);
}

.doc-id {
  font-family: var(--font-mono);
}

.doc-format {
  text-transform: uppercase;
  font-weight: 600;
}

.doc-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ==========================================================================
   TAB 2: PARTES & ADVOGADOS
   ========================================================================== */

.parties-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pole-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pole-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pole-title {
  font-size: 15px;
  font-weight: 700;
}

.pole-title.pole-active {
  color: var(--blue-text);
}

.pole-title.pole-passive {
  color: var(--foreground);
}

.pole-title.pole-other {
  color: var(--purple-text);
}

.pole-count-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 9999px;
  background: var(--secondary);
  color: var(--muted-foreground);
}

.pole-entries {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.party-entry {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.party-entry:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.party-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.party-title-col {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.party-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--foreground);
}

.party-doc {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-foreground);
}

.party-type-tag {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--secondary);
  color: var(--muted-foreground);
}

.party-badges-wrap {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.party-facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px 14px;
  font-size: 12px;
}

.party-fact {
  display: flex;
  gap: 4px;
}

.party-fact.fact-full {
  grid-column: 1 / -1;
}

.fact-val {
  color: var(--foreground);
  font-weight: 500;
}

.party-lawyers-flow {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.lawyers-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
}

.lawyers-tags {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lawyer-pill {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lawyer-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
}

.lawyer-name {
  font-weight: 700;
  color: var(--foreground);
}

.oab-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--blue-text);
}

.lawyer-desc {
  font-size: 11px;
  color: var(--emerald-text);
  font-weight: 600;
}

.lawyer-sub {
  font-size: 11px;
  color: var(--muted-foreground);
}

/* ==========================================================================
   TAB 3: CATÁLOGO COMPLETO DE DOCUMENTOS
   ========================================================================== */

.docs-catalog-toolbar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.catalog-type-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  padding: 5px 12px;
  border-radius: 9999px;
  background: var(--secondary);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--foreground);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.filter-chip:hover {
  background: var(--secondary-hover);
}

.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}

.docs-catalog-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.no-results-box {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 20px;
  text-align: center;
}

/* ==========================================================================
   VIEWER / PREVIEW MODAL (SHADCN DIALOG)
   ========================================================================== */

.viewer {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.viewer-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: min(1100px, 100%);
  height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalScaleIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScaleIn {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  gap: 16px;
  flex-shrink: 0;
}

.viewer-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.viewer-title strong {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--foreground);
  letter-spacing: -0.01em;
}

.viewer-mime-pill {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  background: var(--secondary);
  color: var(--muted-foreground);
  flex-shrink: 0;
}

/* COMPACT HEADER PAGE PILL */
.pdf-page-pill {
  display: inline-flex;
  align-items: center;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 2px 5px;
  gap: 2px;
  flex-shrink: 0;
}

.btn-pdf-nav {
  background: transparent;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--foreground);
  cursor: pointer;
  transition: background-color 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.btn-pdf-nav:hover:not(:disabled) {
  background: var(--card);
  box-shadow: var(--shadow-xs);
}

.btn-pdf-nav:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pdf-page-indicator {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--foreground);
  padding: 0 4px;
  min-width: 44px;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* VIEWER ACTIONS */
.viewer-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.viewer-head-actions .btn {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.viewer-head .close,
.btn-icon-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-foreground);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.viewer-head .close:hover,
.btn-icon-close:hover {
  background: var(--secondary);
  color: var(--foreground);
}

/* PDF CANVAS WORKSPACE (CLEAN DRAFTING TABLE WITH SWIPE SUPPORT) */
.pdf-canvas-wrap {
  flex: 1;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  background: #f1f5f9;
  position: relative;
  touch-action: pan-y;
  user-select: none;
}

.pdf-page-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  will-change: transform, opacity;
}

.pdf-canvas {
  box-shadow: 0 12px 32px -4px rgba(15, 23, 42, 0.12), 0 4px 12px -2px rgba(15, 23, 42, 0.06), 0 0 0 1px rgba(15, 23, 42, 0.05);
  border-radius: 6px;
  background: #ffffff;
  max-width: 100%;
  height: auto !important;
  display: block;
  user-select: none;
}

.pdf-swipe-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 9999px;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 10;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}

.pdf-swipe-hint.fade-out {
  opacity: 0;
}

.pdf-loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted-foreground);
  margin: auto;
  padding: 40px;
}

.pdf-fallback-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  text-align: center;
  color: var(--foreground);
  margin: auto;
}

.viewer-media-wrap,
.pdf-viewer,
.viewer-card iframe,
.viewer-card object,
.viewer-card embed {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.video-container {
  width: 100%;
  height: 100%;
  background: #000000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.video-container video {
  flex: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000000;
}

.viewer-wmv-notice {
  background: #0f172a;
  border-top: 1px solid #334155;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  color: #f8fafc;
}

.wmv-notice-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.wmv-notice-text {
  flex: 1;
  min-width: 0;
}

.wmv-notice-text strong {
  display: block;
  font-size: 12px;
  color: #38bdf8;
  margin-bottom: 2px;
}

.wmv-notice-text p {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.4;
}

.wmv-notice-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.audio-container {
  width: 100%;
  height: 100%;
  background: var(--background);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.audio-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  width: min(440px, 100%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-md);
}

.audio-icon {
  font-size: 36px;
}

.audio-info h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--foreground);
  margin-bottom: 4px;
}

.audio-info p {
  font-size: 12px;
  color: var(--muted-foreground);
}

.audio-card audio {
  width: 100%;
  margin-top: 6px;
}

.audio-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.image-container {
  width: 100%;
  height: 100%;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}

.image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
}

.viewer-empty {
  padding: 48px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 60;
  background: var(--foreground);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.toast[data-tone="success"] {
  background: var(--emerald);
}

.toast[data-tone="error"] {
  background: var(--red);
}

/* ==========================================================================
   RESPONSIVENESS & MOBILE-FIRST AUDIT
   ========================================================================== */

@media (max-width: 1024px) {
  .hero-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }

  .header-content {
    padding: 10px 16px;
  }

  .app-container {
    padding: 0 14px;
    gap: 16px;
    max-width: 100vw;
  }

  .search-panel {
    padding: 16px;
  }

  .search-form {
    flex-direction: column;
    align-items: stretch;
  }

  .search-submit, .primary {
    width: 100%;
    height: 44px;
  }

  .process-hero {
    padding: 16px;
  }

  .hero-top-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .batch-download {
    width: 100%;
    justify-content: center;
    height: 44px;
  }

  .hero-cnj-row {
    width: 100%;
  }

  .cnj-interactive {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
  }

  .cnj-number {
    font-size: clamp(16px, 4.8vw, 20px) !important;
    line-height: 1.35;
    word-break: break-all !important;
    overflow-wrap: anywhere !important;
    max-width: 100%;
  }

  .btn-copy-cnj {
    height: 38px;
    padding: 0 14px;
    font-size: 12px;
  }

  .hero-titular-flow {
    padding: 12px;
    border-radius: var(--radius);
  }

  .titular-identity {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .titular-facts {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .hero-metrics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px;
  }

  .metric-block {
    min-width: 0;
  }

  .metric-value {
    font-size: clamp(13px, 3.8vw, 15px);
    word-break: break-word;
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
  }

  .metric-sub {
    font-size: 10px;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .hero-submetrics-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .tabs-nav {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab-trigger {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 12px;
  }

  .timeline-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    flex-direction: column;
    width: 100%;
  }

  .toolbar-actions .btn {
    width: 100%;
    height: 40px;
    justify-content: center;
  }

  .doc-item-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .doc-item-leading {
    width: 100%;
    min-width: 0;
  }

  .doc-item-meta {
    min-width: 0;
    flex: 1;
  }

  .doc-title {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: 13px;
    line-height: 1.35;
  }

  .doc-item-actions {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
  }

  .doc-item-actions .btn {
    flex: 1;
    height: 38px;
    justify-content: center;
  }

  .party-entry {
    min-width: 0;
    width: 100%;
  }

  .party-headline {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
  }

  .party-title-col {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    width: 100%;
  }

  .party-name {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .party-doc {
    word-break: break-all;
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
  }

  .party-facts-grid {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .party-fact {
    min-width: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .fact-val {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .lawyer-pill {
    min-width: 0;
    width: 100%;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  /* FULLSCREEN VIEWER ON MOBILE (NO DESKTOP ZOOMOUT) */
  .viewer {
    padding: 0 !important;
  }

  .viewer-card {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
  }

  .viewer-head {
    padding: 8px 12px;
    height: 48px;
    gap: 8px;
  }

  .viewer-head .viewer-title strong {
    max-width: 120px;
    font-size: 12px;
  }

  .btn-action-external span,
  .btn-action-download span {
    display: none;
  }

  .viewer-head-actions .btn {
    padding: 0 8px;
    height: 32px;
  }

  .pdf-canvas-wrap {
    padding: 10px 6px 24px;
    background: #f1f5f9;
  }
}

@media (max-width: 480px) {
  .hero-metrics-grid {
    grid-template-columns: 1fr !important;
  }

  .hero-badges .badge {
    font-size: 10px;
    padding: 2px 7px;
  }

  .toast {
    left: 14px;
    right: 14px;
    bottom: 14px;
    text-align: center;
  }
}

/* ==========================================================================
   QUICK ACTIONS & CRAFT FINISHING
   ========================================================================== */

.empty-quick-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.sample-cnj-btn {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--secondary);
  border: 1px solid var(--border);
  color: var(--foreground);
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.15s ease;
  box-shadow: var(--shadow-xs);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sample-cnj-btn:hover {
  background: var(--secondary-hover);
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.sample-cnj-btn:active {
  transform: translateY(0);
}

.btn-copy-cnj:active {
  transform: scale(0.96);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
