:root {
  /* Institutional Palette — SURA Panamá + Limestone / TECNASA Design System */
  --sura-navy: #0033a0;
  --sura-navy-dark: #00226b;
  --sura-navy-light: #eff4ff;
  --sura-cyan: #00aec7;
  --sura-cyan-light: #ecfeff;

  /* Sidebar — Dark institutional shell matching Tecnasa-Reorder & AI Blueprint */
  --sidebar-bg: #0b1120;
  --sidebar-surface: #111827;
  --sidebar-hover: rgba(255, 255, 255, 0.05);
  --sidebar-active: rgba(0, 174, 199, 0.14);
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-text: #e2e8f0;
  --sidebar-muted: #94a3b8;

  /* Light Workspace Surface */
  --bg-canvas: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-elevated: #ffffff;
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Typography */
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  /* Semantic Status (IBCS / Financial precision) */
  --emerald-bg: #ecfdf5;
  --emerald-text: #047857;
  --emerald-border: #a7f3d0;
  --emerald-dot: #10b981;

  --amber-bg: #fffbeb;
  --amber-text: #b45309;
  --amber-border: #fde68a;
  --amber-dot: #f59e0b;

  --rose-bg: #fef2f2;
  --rose-text: #be123c;
  --rose-border: #fecdd3;
  --rose-dot: #f43f5e;

  --blue-bg: #eff6ff;
  --blue-text: #1d4ed8;
  --blue-border: #bfdbfe;
  --blue-dot: #3b82f6;

  --purple-bg: #f5f3ff;
  --purple-text: #6d28d9;
  --purple-border: #ddd6fe;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.06), 0 1px 2px -1px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Tabular numerals globally on data-heavy elements (matching cib-app & Tecnasa-Reorder) */
table, .tabular-nums, .kpi-value, .mono {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.mono {
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

/* ============================================================================
   APP SHELL LAYOUT (Sidebar + Main Workspace)
   ============================================================================ */
.app-shell {
  display: flex;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* Left Sidebar */
.app-sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  user-select: none;
  z-index: 30;
}

.sidebar-brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #0033a0 0%, #00aec7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 174, 199, 0.25);
  flex-shrink: 0;
}

.brand-title {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--sidebar-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-partner-pill {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 10.5px;
  color: #cbd5e1;
}

.brand-partner-pill span.version {
  font-family: var(--font-mono);
  color: #38bdf8;
  font-weight: 600;
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.nav-group-label {
  padding: 0 10px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
}

.nav-group-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  border: none;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--sidebar-muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.14s ease;
}

.nav-btn-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.nav-btn svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  color: #64748b;
  transition: color 0.14s ease;
}

.nav-btn:hover {
  background: var(--sidebar-hover);
  color: #ffffff;
}

.nav-btn:hover svg {
  color: #cbd5e1;
}

.nav-btn.active {
  background: var(--sidebar-active);
  color: #ffffff;
  border-left-color: var(--sura-cyan);
  font-weight: 600;
}

.nav-btn.active svg {
  color: var(--sura-cyan);
  filter: drop-shadow(0 0 6px rgba(0, 174, 199, 0.45));
}

.nav-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
}

.nav-btn.active .nav-badge {
  background: rgba(0, 174, 199, 0.25);
  color: #67e8f9;
}

.nav-badge.warn {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--sidebar-border);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-sys-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--sidebar-muted);
}

.sys-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
  margin-right: 5px;
}

/* ============================================================================
   MAIN WORKSPACE & TOP CONTEXT BAR
   ============================================================================ */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: radial-gradient(ellipse 65% 40% at 50% 0%, rgba(0, 51, 160, 0.035), transparent), var(--bg-canvas);
}

.topbar {
  height: 62px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.topbar-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-req-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.tenant-selector-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
}

.tenant-selector-wrap label {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tenant-selector-wrap select {
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--sura-navy);
  cursor: pointer;
  outline: none;
  max-width: 185px;
  text-overflow: ellipsis;
}

/* Scrollable View Container */
.workspace-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 48px;
}

.workspace-container {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.view-pane {
  display: none;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.16s ease-out;
}

.view-pane.active {
  display: flex;
}

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

/* ============================================================================
   KPI CARDS (Interactive Drill-down style from Tecnasa-Reorder)
   ============================================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}

.kpi-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 1360px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .kpi-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.pdf-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--sura-navy);
  text-decoration: none;
  transition: all 0.14s ease;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.pdf-pill span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-pill:hover {
  background: #eff6ff;
  border-color: var(--sura-navy);
  color: var(--sura-navy-hover);
}

.pdf-pill .pdf-tag {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 9.5px;
  font-weight: 700;
  flex-shrink: 0;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
  transition: all 0.16s ease;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-card:hover {
  border-color: #94a3b8;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.kpi-card.active {
  border-color: var(--sura-navy);
  box-shadow: 0 0 0 2px rgba(0, 51, 160, 0.14);
}

.kpi-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-value {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.kpi-sub {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.kpi-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-icon-box svg {
  width: 18px;
  height: 18px;
}

.kpi-icon-box.navy { background: #eff4ff; color: var(--sura-navy); }
.kpi-icon-box.emerald { background: var(--emerald-bg); color: var(--emerald-text); }
.kpi-icon-box.amber { background: var(--amber-bg); color: var(--amber-text); }
.kpi-icon-box.cyan { background: var(--sura-cyan-light); color: #0e7490; }
.kpi-icon-box.purple { background: var(--purple-bg); color: var(--purple-text); }
.kpi-icon-box.rose { background: var(--rose-bg); color: var(--rose-text); }

.kpi-footer-link {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #f1f5f9;
  font-size: 11px;
  font-weight: 600;
  color: var(--sura-navy);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============================================================================
   CARDS, GRIDS & PANELS
   ============================================================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.card-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #ffffff;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-body {
  padding: 18px 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 18px;
}

.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; }
.col-8 { grid-column: span 8; }
.col-12 { grid-column: span 12; }

@media (max-width: 1180px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .col-4, .col-5, .col-6, .col-7, .col-8 { grid-column: span 12; }
}

/* ============================================================================
   TABLES (High-density institutional style)
   ============================================================================ */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.75px;
}

table.data-table thead tr {
  background: #f8fafc;
  border-bottom: 1px solid var(--border-subtle);
}

table.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
}

table.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-secondary);
  vertical-align: middle;
}

table.data-table tbody tr {
  transition: background-color 0.12s ease;
}

table.data-table tbody tr:hover {
  background-color: #f8fafc;
}

table.data-table tbody tr.selected-row {
  background-color: #eff6ff;
}

/* ============================================================================
   BADGES & PILLS
   ============================================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2.5px 8.5px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

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

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

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

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

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

.badge-neutral {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

/* ============================================================================
   BUTTONS & FORM CONTROLS
   ============================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7.5px 14px;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.14s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--sura-navy);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 51, 160, 0.2);
}

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

.btn-cyan {
  background: var(--sura-cyan);
  color: #ffffff;
}

.btn-cyan:hover {
  background: #0891b2;
}

.btn-emerald {
  background: #059669;
  color: #ffffff;
}

.btn-emerald:hover {
  background: #047857;
}

.btn-rose {
  background: #e11d48;
  color: #ffffff;
}

.btn-rose:hover {
  background: #be123c;
}

.btn-outline {
  background: #ffffff;
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

.btn-outline:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.btn-xs {
  padding: 4px 9px;
  font-size: 11.5px;
  border-radius: 6px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-primary);
  background: #ffffff;
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.form-control:focus {
  border-color: var(--sura-navy);
  box-shadow: 0 0 0 3px rgba(0, 51, 160, 0.1);
}

textarea.code-editor {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 12px;
  width: 100%;
  resize: vertical;
}

/* ============================================================================
   VISUAL DOCUMENT BOUNDING-BOX VIEWER & WORKBENCH
   ============================================================================ */
.doc-visual-sheet {
  background: #f8fafc;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 14px;
  position: relative;
}

.doc-paper {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}

.doc-paper-banner {
  background: linear-gradient(90deg, #0033a0 0%, #0055cc 75%, #00aec7 100%);
  color: #ffffff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 700;
}

.doc-bbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-bottom: 1px dashed #e2e8f0;
  font-size: 12px;
}

.doc-bbox-highlight {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid #34d399;
  border-radius: 5px;
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #065f46;
  font-weight: 600;
}

.doc-bbox-highlight.mismatch {
  background: rgba(244, 63, 94, 0.1);
  border-color: #fb7185;
  color: #9f1239;
}

/* Dropzone */
.upload-dropzone {
  border: 2px dashed #94a3b8;
  border-radius: 10px;
  background: #f8fafc;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.upload-dropzone:hover {
  border-color: var(--sura-navy);
  background: #eff6ff;
}

/* Sub-tabs inside studios */
.subtab-bar {
  display: inline-flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  gap: 4px;
}

.subtab-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s ease;
}

.subtab-btn.active {
  background: #ffffff;
  color: var(--sura-navy);
  box-shadow: var(--shadow-xs);
}

/* Toast Notification */
.toast-banner {
  position: fixed;
  bottom: 22px;
  right: 24px;
  background: #0f172a;
  color: #ffffff;
  border-left: 4px solid var(--sura-cyan);
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  z-index: 9999;
  display: none;
  align-items: center;
  gap: 10px;
}

.toast-banner.show {
  display: flex;
  animation: fadeIn 0.2s ease-out;
}
