:root {
  /* Paleta oficial SEDOSCOM · derivada del color del logo #60A8A0 */
  --sd-teal-50:  #EDF7F6;
  --sd-teal-100: #D8E8E7;
  --sd-teal-200: #B7D6D3;
  --sd-teal-400: #7DB4AF;
  --sd-teal-500: #60A8A0;  /* color oficial del logo */
  --sd-teal-600: #4E8882;
  --sd-teal-700: #3D6A66;
  --sd-teal-800: #2C4D4A;
  --sd-teal-900: #183330;

  --sd-bg:        #FAFAF7;
  --sd-surface:   #FFFFFF;
  --sd-surface-2: #F1EFE8;
  --sd-border:    #D3D1C7;
  --sd-border-2:  #B4B2A9;
  --sd-text-900:  #1C1B17;
  --sd-text-600:  #5F5E5A;
  --sd-text-400:  #888780;

  --sd-success-bg:  #EAF3DE;
  --sd-success-fg:  #27500A;
  --sd-warning-bg:  #FAEEDA;
  --sd-warning-fg:  #854F0B;
  --sd-danger-bg:   #FCEBEB;
  --sd-danger-fg:   #791F1F;
  --sd-info-bg:     #E6F1FB;
  --sd-info-fg:     #0C447C;

  --sd-radius:   8px;
  --sd-radius-lg:12px;
  --sd-shadow:   0 1px 2px rgba(0,0,0,0.04), 0 1px 0 rgba(0,0,0,0.02);

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

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sd-font-ui);
  font-size: 14px;
  line-height: 1.55;
  color: var(--sd-text-900);
  background: var(--sd-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 500; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }

a { color: var(--sd-teal-600); text-decoration: none; }
a:hover { text-decoration: underline; }

.sd-app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sd-sidebar {
  background: var(--sd-surface);
  border-right: 1px solid var(--sd-border);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
}

.sd-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid var(--sd-border);
  margin-bottom: 12px;
}
.sd-brand-mark {
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--sd-teal-500);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.sd-brand-mark svg { width: 100%; height: 100%; display: block; }
.sd-brand-name { font-weight: 600; letter-spacing: 0.3px; }
.sd-brand-sub  { font-size: 11px; color: var(--sd-text-600); }

.sd-nav-group {
  font-size: 10px;
  color: var(--sd-text-400);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 10px 4px;
}
.sd-nav a {
  display: block;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--sd-text-600);
  border-radius: 6px;
  margin-bottom: 1px;
}
.sd-nav a:hover {
  background: var(--sd-surface-2);
  color: var(--sd-text-900);
  text-decoration: none;
}
.sd-nav a.active {
  background: var(--sd-info-bg);
  color: var(--sd-info-fg);
  font-weight: 500;
}

.sd-user {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--sd-border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--sd-text-600);
}
.sd-user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--sd-teal-50);
  color: var(--sd-teal-800);
  display: grid; place-items: center;
  font-weight: 500; font-size: 12px;
}
.sd-user-logout {
  margin-left: auto;
  background: none; border: none;
  color: var(--sd-text-600); cursor: pointer;
  font-size: 12px;
}
.sd-user-logout:hover { color: var(--sd-danger-fg); }

.sd-main {
  padding: 24px 28px;
  max-width: 1400px;
}

.sd-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 20px;
}
.sd-page-header h1 { margin-bottom: 4px; }
.sd-page-header .sd-sub { font-size: 13px; color: var(--sd-text-600); }

.sd-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 1000px) { .sd-kpi-grid { grid-template-columns: repeat(2, 1fr); } }

.sd-kpi {
  background: var(--sd-surface-2);
  padding: 14px 16px;
  border-radius: var(--sd-radius);
}
.sd-kpi-label { font-size: 11px; color: var(--sd-text-600); }
.sd-kpi-value { font-size: 24px; font-weight: 500; margin-top: 4px; letter-spacing: -0.02em; }
.sd-kpi-sub   { font-size: 11px; color: var(--sd-text-600); margin-top: 2px; }
.sd-kpi-sub.ok  { color: var(--sd-success-fg); }
.sd-kpi-sub.bad { color: var(--sd-danger-fg); }

.sd-card {
  background: var(--sd-surface);
  border: 1px solid var(--sd-border);
  border-radius: var(--sd-radius-lg);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.sd-card-title {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sd-card-title .sd-meta { font-size: 11px; color: var(--sd-text-600); font-weight: 400; }

.sd-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--sd-font-ui);
  background: var(--sd-surface);
  border: 1px solid var(--sd-border-2);
  border-radius: 6px;
  color: var(--sd-text-900);
  cursor: pointer;
  transition: all 0.15s ease;
}
.sd-btn:hover { background: var(--sd-surface-2); }
.sd-btn:active { transform: scale(0.98); }
.sd-btn-primary {
  background: var(--sd-teal-600);
  border-color: var(--sd-teal-600);
  color: #fff;
}
.sd-btn-primary:hover { background: var(--sd-teal-800); border-color: var(--sd-teal-800); }
.sd-btn-ghost { background: transparent; border-color: transparent; color: var(--sd-text-600); }

.sd-form-group { margin-bottom: 14px; }
.sd-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--sd-text-600);
  margin-bottom: 5px;
}
.sd-input, .sd-file {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  font-family: var(--sd-font-ui);
  border: 1px solid var(--sd-border-2);
  border-radius: 6px;
  background: var(--sd-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sd-input:focus, .sd-file:focus {
  outline: none;
  border-color: var(--sd-teal-600);
  box-shadow: 0 0 0 3px rgba(15,110,86,0.15);
}
.sd-input.mono { font-family: var(--sd-font-mono); letter-spacing: 2px; font-size: 18px; }

.sd-alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}
.sd-alert-danger  { background: var(--sd-danger-bg);  color: var(--sd-danger-fg); }
.sd-alert-warning { background: var(--sd-warning-bg); color: var(--sd-warning-fg); }
.sd-alert-success { background: var(--sd-success-bg); color: var(--sd-success-fg); }
.sd-alert-info    { background: var(--sd-info-bg);    color: var(--sd-info-fg); }

.sd-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.sd-table th, .sd-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--sd-border);
  text-align: left;
  vertical-align: middle;
}
.sd-table th {
  font-weight: 500;
  color: var(--sd-text-600);
  background: var(--sd-surface-2);
}
.sd-table tbody tr:hover { background: var(--sd-surface-2); }
.sd-table .mono { font-family: var(--sd-font-mono); font-size: 11px; }

.sd-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.sd-pill-ok   { background: var(--sd-success-bg); color: var(--sd-success-fg); }
.sd-pill-av   { background: var(--sd-warning-bg); color: var(--sd-warning-fg); }
.sd-pill-err  { background: var(--sd-danger-bg);  color: var(--sd-danger-fg); }
.sd-pill-info { background: var(--sd-info-bg);    color: var(--sd-info-fg); }

.sd-auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(15,110,86,0.08), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(15,110,86,0.05), transparent 40%),
    var(--sd-bg);
  padding: 20px;
}
.sd-auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--sd-surface);
  border: 1px solid var(--sd-border);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.03);
}
.sd-auth-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--sd-border);
}
.sd-auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.sd-auth-card p.sub { color: var(--sd-text-600); margin: 0 0 20px; font-size: 13px; }

.sd-chart-bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding: 10px 0; }
.sd-chart-bars .bar-group { display: flex; gap: 3px; align-items: flex-end; flex: 1; justify-content: center; }
.sd-chart-bars .bar { width: 12px; border-radius: 3px 3px 0 0; }
.sd-chart-bars .bar.coste  { background: var(--sd-teal-600); }
.sd-chart-bars .bar.margen { background: var(--sd-teal-200); }
.sd-chart-bars .bar-label { text-align: center; font-size: 10px; color: var(--sd-text-600); margin-top: 6px; }

.sd-preview-table { font-family: var(--sd-font-mono); font-size: 11px; }
.sd-preview-table tr.ok    { background: rgba(234,243,222,0.4); }
.sd-preview-table tr.aviso { background: rgba(250,238,218,0.5); }
.sd-preview-table tr.err   { background: rgba(252,235,235,0.5); }

/* Tour guiado overlay */
.sd-tour-backdrop {
  position: fixed; inset: 0;
  background: rgba(28,27,23,0.6);
  z-index: 998;
}
.sd-tour-card {
  position: fixed;
  z-index: 999;
  width: 340px;
  background: var(--sd-surface);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

/* ============================================================
 * MANUAL DE AYUDA (Iter 4)
 * ============================================================ */

.sd-ayuda-wrapper {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 30px;
  max-width: 1200px;
}

.sd-ayuda-toc {
  position: sticky;
  top: 20px;
  align-self: start;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.sd-ayuda-search { margin-bottom: 16px; }

.sd-ayuda-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sd-ayuda-nav a {
  padding: 7px 12px;
  text-decoration: none;
  color: var(--sd-text-600);
  font-size: 13px;
  border-radius: 4px;
  border-left: 2px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sd-ayuda-nav a:hover {
  background: var(--sd-surface-2);
  color: var(--sd-text-900);
}

.sd-ayuda-nav a.active {
  background: var(--sd-teal-50);
  color: var(--sd-teal-800);
  border-left-color: var(--sd-teal-500);
  font-weight: 500;
}

.sd-ayuda-content {
  max-width: 760px;
  line-height: 1.65;
}

.sd-ayuda-header h1 { margin-bottom: 6px; }

.sd-ayuda-section {
  margin-top: 50px;
  padding-top: 20px;
  border-top: 1px solid var(--sd-border);
}

.sd-ayuda-section:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 24px;
}

.sd-ayuda-section h2 {
  color: var(--sd-teal-800);
  margin-bottom: 18px;
  font-size: 22px;
}

.sd-ayuda-section h3 {
  margin-top: 26px;
  margin-bottom: 10px;
  font-size: 16px;
  color: var(--sd-text-900);
}

.sd-ayuda-section p,
.sd-ayuda-section ul,
.sd-ayuda-section ol { margin-bottom: 14px; font-size: 14px; }

.sd-ayuda-section li { margin-bottom: 4px; }

.sd-ayuda-section code {
  background: var(--sd-surface-2);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--sd-font-mono);
  font-size: 12px;
  color: var(--sd-teal-800);
}

.sd-ayuda-section pre.sd-ayuda-formula {
  background: var(--sd-surface-2);
  padding: 14px 18px;
  border-radius: 6px;
  border-left: 3px solid var(--sd-teal-500);
  font-family: var(--sd-font-mono);
  font-size: 13px;
  color: var(--sd-text-900);
  overflow-x: auto;
  margin: 14px 0;
  line-height: 1.5;
}

.sd-ayuda-section kbd {
  background: var(--sd-surface);
  border: 1px solid var(--sd-border-2);
  border-radius: 3px;
  padding: 1px 6px;
  font-family: var(--sd-font-mono);
  font-size: 11px;
  box-shadow: 0 1px 0 var(--sd-border-2);
}

.sd-ayuda-box {
  padding: 14px 18px;
  border-radius: 6px;
  margin: 16px 0;
  font-size: 13.5px;
}

.sd-ayuda-box ul,
.sd-ayuda-box ol { margin: 8px 0; padding-left: 22px; }

.sd-ayuda-box-info {
  background: var(--sd-info-bg);
  border-left: 3px solid var(--sd-info-fg);
}

.sd-ayuda-box-warning {
  background: var(--sd-warning-bg);
  border-left: 3px solid var(--sd-warning-fg);
}

.sd-ayuda-box-example {
  background: var(--sd-teal-50);
  border-left: 3px solid var(--sd-teal-500);
}

.sd-ayuda-flow {
  counter-reset: flow;
  list-style: none;
  padding-left: 0;
}

.sd-ayuda-flow li {
  counter-increment: flow;
  position: relative;
  padding-left: 40px;
  margin-bottom: 12px;
}

.sd-ayuda-flow li::before {
  content: counter(flow);
  position: absolute;
  left: 0; top: 0;
  width: 26px; height: 26px;
  background: var(--sd-teal-500);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.sd-ayuda-faq {
  margin: 8px 0;
  padding: 12px 16px;
  background: var(--sd-surface-2);
  border-radius: 6px;
  cursor: pointer;
}

.sd-ayuda-faq summary {
  font-weight: 500;
  font-size: 14px;
  color: var(--sd-text-900);
  cursor: pointer;
  user-select: none;
}

.sd-ayuda-faq[open] {
  background: var(--sd-teal-50);
  border-left: 3px solid var(--sd-teal-500);
}

.sd-ayuda-faq[open] summary { margin-bottom: 10px; }

.sd-ayuda-faq p,
.sd-ayuda-faq ul,
.sd-ayuda-faq ol { margin-top: 8px; }

@media (max-width: 900px) {
  .sd-ayuda-wrapper {
    grid-template-columns: 1fr;
  }
  .sd-ayuda-toc {
    position: static;
    max-height: none;
    border-bottom: 1px solid var(--sd-border);
    padding-bottom: 20px;
  }
}

/* ============================================================
 * TOUR INTERACTIVO (Driver.js) - overrides para paleta SEDOSCOM
 * ============================================================ */

.driver-popover.sedoscom-tour-popover {
  background: var(--sd-surface);
  border-radius: 8px;
  border: 1px solid var(--sd-border-2);
  box-shadow: 0 20px 50px rgba(0,0,0,0.18);
  max-width: 380px;
  font-family: var(--sd-font-ui);
}

.driver-popover.sedoscom-tour-popover .driver-popover-title {
  color: var(--sd-teal-800);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.driver-popover.sedoscom-tour-popover .driver-popover-description {
  color: var(--sd-text-600);
  font-size: 13px;
  line-height: 1.55;
}

.driver-popover.sedoscom-tour-popover .driver-popover-footer button {
  background: var(--sd-teal-500);
  color: white;
  border: none;
  padding: 7px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-shadow: none;
}

.driver-popover.sedoscom-tour-popover .driver-popover-footer button:hover {
  background: var(--sd-teal-600);
}

.driver-popover.sedoscom-tour-popover .driver-popover-prev-btn {
  background: var(--sd-surface-2) !important;
  color: var(--sd-text-600) !important;
}

.driver-popover.sedoscom-tour-popover .driver-popover-close-btn {
  background: transparent !important;
  color: var(--sd-text-600) !important;
  font-size: 18px;
  padding: 0 8px !important;
}

.driver-popover.sedoscom-tour-popover .driver-popover-progress-text {
  color: var(--sd-text-400);
  font-size: 11px;
}

.sd-tour-buttons {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid var(--sd-border);
  margin-top: 8px;
}

.sd-tour-buttons button {
  width: 100%;
  padding: 8px 12px;
  background: var(--sd-surface-2);
  color: var(--sd-text-900);
  border: 1px solid var(--sd-border);
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
}

.sd-tour-buttons button:hover {
  background: var(--sd-teal-50);
  border-color: var(--sd-teal-500);
  color: var(--sd-teal-800);
}

/* ============================================================
 * BANNER DEMO + TOGGLE (Iter 5)
 * ============================================================ */

.sd-demo-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  margin-bottom: 16px;
  background: linear-gradient(90deg, #FFF8E1, #FFE9A3);
  border: 1px solid #E0A800;
  border-left: 4px solid #E0A800;
  border-radius: 6px;
  flex-wrap: wrap;
}

.sd-demo-banner-info {
  font-size: 13px;
  color: #6B4F00;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sd-demo-banner-info strong {
  font-weight: 600;
  letter-spacing: 0.3px;
}

.sd-demo-banner-sub {
  font-size: 11px;
  color: #8A6F1F;
  font-weight: normal;
}

.sd-demo-banner-toggle {
  display: inline-flex;
  background: white;
  border: 1px solid #E0A800;
  border-radius: 4px;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.sd-demo-banner-toggle button {
  padding: 5px 12px;
  font-size: 11px;
  background: transparent;
  color: #8A6F1F;
  border: none;
  cursor: pointer;
  font-weight: 500;
}

.sd-demo-banner-toggle button:not(:last-child) {
  border-right: 1px solid #E0A800;
}

.sd-demo-banner-toggle button.active {
  background: #E0A800;
  color: white;
}

.sd-demo-banner-toggle button:hover:not(.active) {
  background: #FFE9A3;
}

.sd-demo-banner-link {
  margin-left: auto;
  font-size: 12px;
  color: #6B4F00;
  text-decoration: none;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 4px;
  background: white;
  border: 1px solid #E0A800;
}

.sd-demo-banner-link:hover {
  background: #E0A800;
  color: white;
}

/* Toggle 3 botones (en página /demo) */
.sd-demo-toggle {
  display: inline-flex;
  background: white;
  border: 1px solid var(--sd-border-2);
  border-radius: 6px;
  overflow: hidden;
}

.sd-demo-toggle button {
  padding: 8px 16px;
  font-size: 13px;
  background: transparent;
  color: var(--sd-text-600);
  border: none;
  cursor: pointer;
  font-weight: 500;
}

.sd-demo-toggle button:not(:last-child) {
  border-right: 1px solid var(--sd-border-2);
}

.sd-demo-toggle button.active {
  background: var(--sd-teal-500);
  color: white;
}

.sd-demo-toggle button:hover:not(.active) {
  background: var(--sd-teal-50);
}

/* Filas de tabla marcadas como demo (cuando mostramos en modo "todo") */
.sd-table tr.is-demo {
  background-color: #FFFDF5;
  position: relative;
}

.sd-table tr.is-demo td:first-child::before {
  content: "🎭 ";
}

/* ============================================================
 * RESPONSIVE (Iter 5 - mobile-friendly)
 * ============================================================ */

/* Mostrar/ocultar elementos según viewport */
.sd-mobile-only { display: none; }
.sd-desktop-only { display: block; }

/* Botón hamburguesa (solo móvil) */
.sd-mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1001;
  background: var(--sd-teal-500);
  color: white;
  border: none;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Overlay para cerrar sidebar en móvil */
.sd-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
}

.sd-sidebar-overlay.active { display: block; }

/* === Breakpoint: tablet pequeño y móvil (< 900px) === */
@media (max-width: 900px) {
  .sd-mobile-only { display: block; }
  .sd-desktop-only { display: none; }
  .sd-mobile-menu-btn { display: block; }

  /* Sidebar se oculta por defecto en móvil, se abre al pulsar hamburguesa */
  .sd-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: 260px;
    overflow-y: auto;
  }

  .sd-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  }

  .sd-main {
    margin-left: 0 !important;
    padding: 60px 14px 30px !important;
    width: 100%;
  }

  /* Page header se apila */
  .sd-page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  /* KPIs en 2 columnas */
  .sd-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
  }

  /* Grids 2 columnas → 1 columna */
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns:2fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns: 2fr 1fr"],
  div[style*="grid-template-columns:repeat(4,1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* Tablas con scroll horizontal */
  .sd-card .sd-table,
  .sd-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .sd-table thead, .sd-table tbody, .sd-table tr {
    display: table;
    table-layout: fixed;
    width: 100%;
    min-width: 600px;
  }

  /* Formularios: campos a ancho completo */
  .sd-form-group,
  form .sd-input,
  form select.sd-input,
  form textarea.sd-input {
    width: 100% !important;
    max-width: 100%;
  }

  /* Forms con display:grid del page-header → stack */
  form[style*="display:grid"] {
    grid-template-columns: 1fr !important;
  }

  /* Demo banner: layout vertical en móvil */
  .sd-demo-banner {
    flex-direction: column;
    align-items: stretch;
  }

  .sd-demo-banner-link {
    margin-left: 0;
    text-align: center;
  }

  /* Ayuda: TOC fuera de sticky en móvil */
  .sd-ayuda-wrapper {
    grid-template-columns: 1fr !important;
  }

  .sd-ayuda-toc {
    position: static !important;
    max-height: none !important;
    margin-bottom: 20px;
  }

  /* Botones full-width en formularios mobile */
  .sd-btn {
    min-height: 38px;
  }

  /* Page header h1 más pequeño */
  .sd-page-header h1 {
    font-size: 20px;
  }
}

/* === Breakpoint: móvil pequeño (< 480px) === */
@media (max-width: 480px) {
  /* KPIs en 1 columna */
  .sd-kpi-grid {
    grid-template-columns: 1fr !important;
  }

  .sd-card {
    padding: 14px 12px;
  }

  /* Reduce padding general */
  .sd-main {
    padding: 60px 10px 20px !important;
  }

  /* Page header sub: oculta meta secundaria */
  .sd-page-header .sd-sub {
    font-size: 12px;
  }

  /* Demo banner aún más compacto */
  .sd-demo-banner-toggle button {
    padding: 4px 9px;
    font-size: 10px;
  }
}

/* === Breakpoint: escritorio grande (> 1400px) === */
@media (min-width: 1400px) {
  .sd-main {
    max-width: 1320px;
  }
}
/* ============================================================
 * RESPONSIVE MEJORAS v1.4.1 - aprovechamiento de espacio horizontal
 * AÑADIR AL FINAL del archivo assets/css/app.css
 *
 * Soluciona:
 *  - Las tablas se quedaban con min-width: 600px y aspecto estrecho
 *  - El contenido principal tenía mucho padding lateral en móvil/tablet
 *  - Las cards no ocupaban el ancho completo
 * ============================================================ */

/* === Tablet y móvil grande (< 900px) === */
@media (max-width: 900px) {
  /* Main: padding mínimo y uso completo del viewport */
  .sd-main {
    padding: 56px 10px 24px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Cards: ancho completo siempre */
  .sd-card,
  .sd-kpi {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  /* Tablas: scroll horizontal natural sin min-width forzado */
  .sd-table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* QUITAR el min-width: 600px que rompía la disposición */
  .sd-table thead,
  .sd-table tbody,
  .sd-table tr {
    display: table !important;
    width: 100% !important;
    min-width: 0 !important;
    table-layout: auto !important;
  }

  /* Celdas: padding compacto y permitir wrap de texto */
  .sd-table th,
  .sd-table td {
    padding: 9px 11px !important;
    white-space: normal !important;
    word-wrap: break-word;
  }

  /* Page header: ocupa todo el ancho */
  .sd-page-header {
    width: 100%;
    box-sizing: border-box;
  }

  /* Forms grid → 1 col + ancho completo */
  form[style*="display:grid"],
  form[style*="display: grid"] {
    width: 100%;
    grid-template-columns: 1fr !important;
  }

  /* Inputs y selects: ancho completo en móvil */
  .sd-input,
  select.sd-input,
  textarea.sd-input {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  /* Botones del page header: ocupan ancho útil */
  .sd-btn {
    box-sizing: border-box;
  }

  /* KPI grid sigue siendo responsive según tamaño */
  .sd-kpi-grid {
    width: 100%;
    box-sizing: border-box;
  }
}

/* === Móvil estándar (< 600px) === */
@media (max-width: 600px) {
  .sd-main {
    padding: 54px 8px 20px !important;
  }

  .sd-card {
    padding: 14px 12px !important;
  }

  /* KPIs: 2 columnas siempre */
  .sd-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  .sd-kpi {
    padding: 12px 10px;
  }

  .sd-kpi-value {
    font-size: 18px !important;
  }

  /* Tablas más compactas */
  .sd-table th,
  .sd-table td {
    padding: 7px 8px !important;
    font-size: 12.5px;
  }

  /* Page header: h1 más pequeño */
  .sd-page-header h1 {
    font-size: 18px !important;
  }
}

/* === Móvil pequeño (< 400px) === */
@media (max-width: 400px) {
  .sd-main {
    padding: 52px 5px 16px !important;
  }

  .sd-card {
    padding: 12px 10px !important;
    border-radius: 5px;
  }

  /* KPIs: 1 columna */
  .sd-kpi-grid {
    grid-template-columns: 1fr !important;
  }

  /* Tablas: aún más compactas */
  .sd-table th,
  .sd-table td {
    padding: 6px 7px !important;
    font-size: 12px;
  }
}
