/* ============================================================
   Manual de la Distribuidora Mayorista · Cara Sur Consultoría
   Sistema visual "Estepa" v5 — tokens de Motor_CaraSur/brand_v5.py
   Fondos hueso, texto grafito, un único acento azul lago.
   ============================================================ */

:root {
  /* Colores Estepa */
  --bg-main: #F4F1EB;            /* Hueso — fondo de página */
  --bg-sidebar: #FAF8F2;         /* background-soft */
  --bg-deep: #E2DDD3;            /* background-deep — secciones */
  --bg-card: #FFFFFF;            /* Surface — tarjetas */
  --bg-card-hover: #FAF8F2;
  --border-color: #D6D1C6;       /* line */
  --border-soft: #ECE7DC;        /* line-2 */

  --text-main: #1A1F1C;          /* Grafito */
  --text-muted: #3D423E;         /* on-surface-2 */
  --text-dim: #7A7670;           /* on-surface-3 — notas */

  --accent-primary: #1E3A5C;     /* Azul lago — solo lo más importante */
  --accent-primary-soft: #DCE3EE;
  --accent-secondary: #B89968;   /* Arena — separadores / secundario */
  --accent-success: #2D5A3F;     /* Bosque */
  --accent-warning: #C9633A;     /* Terracota — alerta */
  --accent-danger: #A04428;      /* Error */
  --input-bg: #FFF9C4;           /* celda editable (convención Excel) */

  --font-heading: 'Inter Tight', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(26, 31, 28, 0.08);
  --shadow-md: 0 3px 10px rgba(26, 31, 28, 0.10);
}

/* Reset & Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-sidebar); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-secondary); }

.app-container {
  display: flex;
  width: 100%;
  height: 100%;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 320px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 24px 20px 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}

.brand-logo {
  display: block;
  width: 170px;
  max-width: 100%;
  margin-bottom: 14px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin-bottom: 10px;
}

.brand-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.3;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.search-box { padding: 16px 20px; }

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

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-dim);
}

.search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px 8px 36px;
  color: var(--text-main);
  font-size: 0.875rem;
  outline: none;
  transition: all 0.2s;
}

.search-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-primary-soft);
}

.nav-menu {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
}

.nav-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-secondary);
  padding: 14px 10px 6px 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.865rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  margin-bottom: 2px;
}

.nav-item:hover {
  background-color: var(--border-soft);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--accent-primary);
  color: #ffffff;
  font-weight: 600;
}

.nav-item .badge {
  margin-left: auto;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border-soft);
  color: var(--text-dim);
}

.nav-item.active .badge {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ---------- Main ---------- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.topbar {
  height: 64px;
  background-color: var(--bg-main);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  z-index: 5;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  cursor: pointer;
}

.current-path {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-dim);
}

.current-path span.current {
  color: var(--text-main);
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
}
.btn-primary:hover { opacity: 0.92; }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover { background: var(--bg-card-hover); }

.content-body {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- Markdown ---------- */
.markdown-body {
  color: var(--text-main);
  font-size: 1rem;
  line-height: 1.7;
}

.markdown-body h1 {
  font-family: var(--font-heading);
  font-size: 2.1rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--accent-secondary);
}

.markdown-body h2 {
  font-family: var(--font-heading);
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--text-main);
  margin-top: 36px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.markdown-body h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent-primary);
  margin-top: 24px;
  margin-bottom: 12px;
}

.markdown-body p {
  margin-bottom: 18px;
  color: var(--text-muted);
}

.markdown-body ul, .markdown-body ol {
  margin-bottom: 20px;
  padding-left: 24px;
}

.markdown-body li {
  margin-bottom: 8px;
  color: var(--text-muted);
}

.markdown-body a {
  color: var(--accent-primary);
  font-weight: 500;
}

.markdown-body blockquote {
  background: var(--accent-primary-soft);
  border-left: 4px solid var(--accent-primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 16px 20px;
  margin: 20px 0;
  color: var(--text-main);
}

.markdown-body blockquote p { color: var(--text-main); margin-bottom: 0; }
.markdown-body blockquote p + p { margin-top: 12px; }

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.markdown-body th, .markdown-body td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
}

.markdown-body th {
  background-color: var(--text-main);   /* header de tabla: grafito, texto blanco */
  color: #ffffff;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.markdown-body td {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.markdown-body code {
  font-family: var(--font-mono);
  background: var(--border-soft);
  color: var(--text-main);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.875em;
}

.markdown-body pre {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  overflow-x: auto;
  margin: 20px 0;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  color: var(--text-main);
}

/* Fórmulas KaTeX */
.katex-display {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin: 18px 0;
  overflow-x: auto;
}

/* ---------- Dashboard KPI ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin: 24px 0;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.kpi-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-card .kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.kpi-card .kpi-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-card .kpi-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 600;
  text-transform: uppercase;
}

.tag-diario  { background: var(--accent-primary-soft); color: var(--accent-primary); }
.tag-semanal { background: #E3EBE4; color: var(--accent-success); }
.tag-mensual { background: #F2E4D6; color: var(--accent-warning); }

.kpi-card .kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.kpi-card .kpi-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-main);
}

.kpi-card .kpi-target {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--border-soft);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.fill-green  { background: var(--accent-success); }
.fill-yellow { background: var(--accent-warning); }
.fill-red    { background: var(--accent-danger); }

/* ---------- Checklist ---------- */
.checklist-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 24px 0;
}

.checklist-score-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
}

.score-number {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.score-badge {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  cursor: pointer;
}

.checklist-item:hover { background: var(--bg-sidebar); }

.checklist-checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--accent-primary);
  cursor: pointer;
  margin-top: 2px;
}

.checklist-label {
  font-size: 0.92rem;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
}

.checklist-item.completed .checklist-label {
  color: var(--text-dim);
  text-decoration: line-through;
}

.checklist-cta {
  margin-top: 32px;
  padding: 24px;
  background: var(--accent-primary-soft);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-md);
}

.checklist-cta h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  color: var(--accent-primary);
  margin-bottom: 12px;
}

.checklist-cta p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.checklist-cta .btn {
  display: inline-flex;
  text-decoration: none;
  margin-top: 4px;
}

/* ---------- Calculadoras ---------- */
.calculator-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 24px 0;
  box-shadow: var(--shadow-sm);
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

.calc-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.calc-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.calc-input {
  background: var(--input-bg);   /* amarillo input: celda editable */
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-main);
  font-size: 1rem;
  font-family: var(--font-mono);
  text-align: right;
  outline: none;
  transition: border-color 0.2s;
}

.calc-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-primary-soft);
}

.calc-result-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}

.calc-result-title {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

.calc-result-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent-primary);
  font-family: var(--font-mono);
}

.calc-result-subtext {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.report-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--accent-primary-soft);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: -320px;
    height: 100%;
  }
  .sidebar.open { transform: translateX(320px); }
  .mobile-toggle { display: block; }
  .content-body { padding: 20px 16px; }
}

/* ---------- Impresión (Chrome → PDF) ---------- */
/* ============================================================
   Diagrama de flujo (bloques ```flow del markdown)
   Reemplaza los cuadros ASCII: tarjetas numeradas y conectadas.
   ============================================================ */
.flow-diagram {
  list-style: none;
  margin: 32px 0;
  padding: 0;
  counter-reset: none;
}

.flow-step {
  position: relative;
  display: flex;
  gap: 18px;
  align-items: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent-primary);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
}

/* Conector entre pasos: línea vertical + punta de flecha */
.flow-step:not(:last-child) {
  margin-bottom: 34px;
}

.flow-step:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 39px;
  bottom: -34px;
  width: 2px;
  height: 34px;
  background: var(--border-color);
}

.flow-step:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 34px;
  bottom: -13px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--accent-secondary);
}

.flow-num {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  color: #FFFFFF;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.flow-text { min-width: 0; }

.flow-title {
  font-family: var(--font-heading);
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 5px 0 0 0;
  line-height: 1.35;
}

.flow-desc {
  font-size: 0.93rem;
  color: var(--text-muted);
  margin: 6px 0 0 0;
  line-height: 1.55;
}

@media (max-width: 640px) {
  .flow-step { padding: 15px 16px; gap: 13px; }
  .flow-step:not(:last-child)::before { left: 31px; }
  .flow-step:not(:last-child)::after { left: 26px; }
  .flow-num { width: 28px; height: 28px; font-size: 0.85rem; }
  .flow-title { font-size: 0.97rem; }
}

@media print {
  body {
    display: block;
    height: auto;
    overflow: visible;
    background: #ffffff;
  }
  .sidebar, .topbar, .mobile-toggle, .btn, .report-actions { display: none !important; }
  .app-container, .main-content {
    display: block;
    height: auto;
    overflow: visible;
  }
  .content-body {
    overflow: visible;
    max-width: 100%;
    padding: 0;
  }
  .flow-step {
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #999999;
    border-left: 3px solid var(--accent-primary);
  }
  .flow-num {
    background: var(--accent-primary) !important;
    color: #ffffff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .markdown-body h1 { font-size: 1.7rem; }
  .markdown-body h2 { page-break-after: avoid; }
  .markdown-body table, .kpi-card, .checklist-item, .calculator-container, .katex-display, .markdown-body blockquote, .markdown-body pre {
    page-break-inside: avoid;
  }
  .markdown-body th {
    background-color: var(--text-main) !important;
    color: #ffffff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .markdown-body blockquote {
    background: var(--accent-primary-soft) !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .checklist-checkbox { accent-color: var(--accent-primary); }
}
