/* =========================================================
   ServicioTec — Sistema de diseño "Slate & Steel"
   Tipografía técnica/arquitectónica: Inter
   ========================================================= */

:root {
  /* Slate & Steel palette */
  --bg:         #0f172a;   /* slate 900 - sidebar/topbar */
  --bg-2:       #1e293b;   /* slate 800 */
  --surface:    #ffffff;
  --surface-2:  #f1f5f9;   /* slate 100 */
  --border:     #e2e8f0;   /* slate 200 */
  --border-dk:  #334155;   /* slate 700 */

  --text:       #0f172a;
  --text-muted: #64748b;   /* slate 500 */
  --text-inv:   #e2e8f0;

  --primary:    #0284c7;   /* steel sky 600 */
  --primary-dk: #0369a1;
  --primary-soft:#e0f2fe;

  --accent:     #475569;   /* slate 600 */
  --success:    #16a34a;
  --warning:    #d97706;
  --danger:     #dc2626;

  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 1px 3px rgba(15,23,42,.08), 0 8px 24px rgba(15,23,42,.06);
  --shadow-lg:  0 20px 50px rgba(15,23,42,.25);
  --sidebar-w:  256px;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--text);
  background: var(--surface-2);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4,h5,.brand,.metric-value {
  font-family: 'Inter', system-ui, sans-serif;
  letter-spacing: -0.01em;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- Layout dashboard ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg);
  color: var(--text-inv);
  position: fixed; inset: 0 auto 0 0;
  display: flex; flex-direction: column;
  z-index: 40;
  transition: transform .25s ease;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px;
  font-size: 20px; font-weight: 700; color: #fff;
  border-bottom: 1px solid var(--border-dk);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #38bdf8);
  display: grid; place-items: center; font-size: 18px; flex: none;
}
.sidebar nav { padding: 12px; overflow-y: auto; flex: 1; }
.nav-section { color: #64748b; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; padding: 16px 12px 6px; font-weight: 600; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: #cbd5e1; font-weight: 500; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--bg-2); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link .ico { width: 20px; text-align: center; font-size: 16px; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 64px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; position: sticky; top: 0; z-index: 30;
}
.topbar .menu-toggle { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; }
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar .spacer { flex: 1; }

.usermenu { position: relative; }
.usermenu-btn {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
}
.usermenu-drop {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  min-width: 200px; padding: 6px; display: none;
}
.usermenu-drop.open { display: block; }
.usermenu-drop a { display: block; padding: 9px 12px; border-radius: 6px; color: var(--text); font-size: 14px; }
.usermenu-drop a:hover { background: var(--surface-2); text-decoration: none; }
.role-badge {
  font-size: 11px; font-weight: 600; color: var(--primary);
  background: var(--primary-soft); padding: 2px 8px; border-radius: 999px;
}

.content { padding: 24px; max-width: 1280px; width: 100%; }

/* ---------------- Componentes ---------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h2 { font-size: 22px; }
.page-head p { color: var(--text-muted); font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-body { padding: 20px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 16px; margin-bottom: 24px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.metric::before { content:''; position:absolute; left:0; top:0; bottom:0; width:4px; background: var(--primary); }
.metric .label { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.metric .metric-value { font-size: 30px; font-weight: 700; margin-top: 4px; }
.metric .ico { position:absolute; right:16px; top:16px; font-size:22px; opacity:.25; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; transition: background .15s, transform .05s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.35; }
table.data th, table.data td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { background: var(--surface-2); color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.data tbody tr:hover, table.data tr:hover td { background: #f8fafc; }
table.data td .actions { display: flex; gap: 6px; }

/* Badges de estado */
.badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; display: inline-block; }
.badge.pend { background: #fef3c7; color: #92400e; }
.badge.curso { background: #dbeafe; color: #1e40af; }
.badge.comp { background: #dcfce7; color: #166534; }
.badge.low { background: #fee2e2; color: #991b1b; }

/* Formularios */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 14px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { resize: vertical; min-height: 90px; }

/* Alertas */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.alert.error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert.info { background: var(--primary-soft); color: var(--primary-dk); border-color: #bae6fd; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 60; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); width: 100%; max-width: 640px; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal .close-x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--text-muted); }

.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty .ico { font-size: 40px; display: block; margin-bottom: 8px; opacity: .5; }

/* ---------------- Auth (login / reset) ---------------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero {
  background: radial-gradient(circle at 30% 20%, #1e293b, var(--bg));
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center;
}
.auth-hero .brand { font-size: 30px; font-weight: 700; display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.auth-hero h2 { font-size: 34px; line-height: 1.15; margin-bottom: 14px; }
.auth-hero p { color: #94a3b8; max-width: 420px; }
.auth-hero ul { list-style: none; margin-top: 28px; display: grid; gap: 12px; }
.auth-hero li { display: flex; gap: 10px; color: #cbd5e1; }
.auth-form-side { display: flex; align-items: center; justify-content: center; padding: 40px; background: var(--surface); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 26px; margin-bottom: 6px; }
.auth-card .sub { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }
.auth-card .field { margin-bottom: 16px; }
.auth-links { margin-top: 18px; text-align: center; font-size: 14px; }
.otp-input { letter-spacing: 8px; text-align: center; font-size: 22px !important; font-family: 'Inter', monospace; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-form-side { padding: 24px 16px; }
}
@media (max-width: 1024px) {
  .content { padding: 16px; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 24px rgba(0,0,0,.25); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar { height: auto; min-height: 56px; padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .topbar h1 { font-size: 16px; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .menu-toggle { display: block; }
  .topbar .spacer { display: none; }
  .usermenu-btn span:last-child { display: none; }
  .lang-switch { font-size: 11px; }
  .lang-switch a { padding: 3px 6px !important; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .actions { flex-wrap: wrap; }
  .modal { max-width: 100%; margin: 0 8px; }
  .modal-overlay { padding: 16px 8px; align-items: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  table.data th, table.data td { padding: 6px 8px; font-size: 13px; line-height: 1.3; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric { padding: 12px 14px; }
  .metric .metric-value { font-size: 22px; }
  .list-tools { flex-direction: column; align-items: stretch !important; }
  .list-tools > * { width: 100%; }
  .content { padding: 12px; }
}
@media (max-width: 480px) {
  .metrics { grid-template-columns: 1fr; }
  .btn { padding: 8px 12px; font-size: 13px; }
}

/* Backdrop cuando el sidebar está abierto en móvil */
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 39; display: none; }
@media (max-width: 768px) {
  .sidebar.open ~ .sidebar-backdrop,
  body.sidebar-open .sidebar-backdrop { display: block; }
}

/* ---------------- Impresión / PDF ---------------- */
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  html, body {
    background: #fff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  /* Ocultar chrome de la app */
  .sidebar, .sidebar-backdrop, .topbar, .company-banner,
  .list-tools, .page-head .actions, .actions,
  .btn, form[data-confirm], .no-print, .menu-toggle,
  .usermenu, .lang-switch { display: none !important; }
  /* Devolver el layout a flujo normal para no dejar página en blanco */
  .layout, .main, .content {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    min-height: 0 !important;
    background: #fff !important;
  }
  /* Impresión de listados: JS añade .printing al body y monta la print-area como hija directa */
  body.printing > *:not(.print-area) { display: none !important; }
  /* Impresión in-page (detalle de parte): sólo oculta hermanos si existe .print-area */
  .content:has(> .print-area) > *:not(.print-area):not(#print-company-header-src) { display: none !important; }
  .print-area { display: block !important; position: static !important; width: 100% !important; background: #fff !important; }
  .print-area img { max-width: 100% !important; height: auto !important; }
  .print-area table { width: 100%; border-collapse: collapse; font-size: 11px; page-break-inside: auto; }
  .print-area table thead { display: table-header-group; }
  .print-area table tr { page-break-inside: avoid; page-break-after: auto; }
  .print-area table th, .print-area table td {
    border: 1px solid #cbd5e1; padding: 6px 8px; text-align: left; vertical-align: top;
    word-break: break-word; overflow-wrap: anywhere;
  }
  .print-area table th { background: #f1f5f9 !important; color: #0f172a; font-weight: 700; }
  .print-area .card { box-shadow: none !important; border: 1px solid #ddd; break-inside: avoid; }
  .print-company-header { display: block !important; }
  a[href]:after { content: ""; }
}

/* ---------------- Temas seleccionables ---------------- */
/* Tema claro (por defecto ya definido en :root). Los siguientes temas se aplican
   con html[data-theme="..."]. La preferencia se memoriza por usuario en localStorage. */

html[data-theme="oscuro"] {
  --bg:          #020617;
  --bg-2:        #0f172a;
  --surface:     #0f172a;
  --surface-2:   #020617;
  --border:      #1e293b;
  --border-dk:   #334155;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --text-inv:    #e2e8f0;
  --primary:     #38bdf8;
  --primary-dk:  #0ea5e9;
  --primary-soft:#0c4a6e;
  --accent:      #94a3b8;
  --shadow:      0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  --shadow-lg:   0 20px 50px rgba(0,0,0,.6);
}
html[data-theme="oscuro"] body { background: var(--surface-2); }
html[data-theme="oscuro"] .card,
html[data-theme="oscuro"] .modal-content,
html[data-theme="oscuro"] .usermenu-drop,
html[data-theme="oscuro"] table thead th { background: var(--surface); color: var(--text); }
html[data-theme="oscuro"] input,
html[data-theme="oscuro"] select,
html[data-theme="oscuro"] textarea {
  background: #0b1220; color: var(--text); border-color: var(--border);
}

html[data-theme="azul"] {
  --bg:          #0c1a3a;
  --bg-2:        #12266b;
  --surface:     #ffffff;
  --surface-2:   #eef4ff;
  --border:      #cfd9ee;
  --text:        #0b1e4a;
  --text-muted:  #4b5f8a;
  --primary:     #2563eb;
  --primary-dk:  #1d4ed8;
  --primary-soft:#dbeafe;
  --accent:      #4338ca;
}

html[data-theme="esmeralda"] {
  --bg:          #052e2b;
  --bg-2:        #064e3b;
  --surface:     #ffffff;
  --surface-2:   #ecfdf5;
  --border:      #c9ecdc;
  --text:        #052e2b;
  --text-muted:  #4b6b60;
  --primary:     #059669;
  --primary-dk:  #047857;
  --primary-soft:#d1fae5;
  --accent:      #0f766e;
}

html[data-theme="sepia"] {
  --bg:          #3b2a1e;
  --bg-2:        #5c4230;
  --surface:     #fbf5ec;
  --surface-2:   #f3e8d3;
  --border:      #e2d2b3;
  --text:        #3b2a1e;
  --text-muted:  #7a6a56;
  --primary:     #b45309;
  --primary-dk:  #92400e;
  --primary-soft:#fde9c8;
  --accent:      #a16207;
}

html[data-theme="violeta"] {
  --bg:          #2b1055;
  --bg-2:        #3b1687;
  --surface:     #ffffff;
  --surface-2:   #f5f1ff;
  --border:      #ded4f5;
  --text:        #1f0d47;
  --text-muted:  #5b4a86;
  --primary:     #7c3aed;
  --primary-dk:  #6d28d9;
  --primary-soft:#ede9fe;
  --accent:      #a21caf;
}

/* Auto: si el sistema pide dark, aplicar el tema oscuro */
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg:          #020617;
    --bg-2:        #0f172a;
    --surface:     #0f172a;
    --surface-2:   #020617;
    --border:      #1e293b;
    --border-dk:   #334155;
    --text:        #e2e8f0;
    --text-muted:  #94a3b8;
    --text-inv:    #e2e8f0;
    --primary:     #38bdf8;
    --primary-dk:  #0ea5e9;
    --primary-soft:#0c4a6e;
    --accent:      #94a3b8;
  }
  html[data-theme="auto"] body { background: var(--surface-2); }
  html[data-theme="auto"] .card,
  html[data-theme="auto"] .modal-content,
  html[data-theme="auto"] .usermenu-drop,
  html[data-theme="auto"] table thead th { background: var(--surface); color: var(--text); }
  html[data-theme="auto"] input,
  html[data-theme="auto"] select,
  html[data-theme="auto"] textarea {
    background: #0b1220; color: var(--text); border-color: var(--border);
  }
}

/* Combo de tema en la topbar */
.theme-combo {
  display: inline-flex; align-items: center; gap: 6px;
  margin-right: 8px; padding: 4px 8px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
}
.theme-combo select {
  border: none; background: transparent; color: inherit;
  font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 2px 4px; outline: none; min-width: 130px;
}

/* Refuerzos para que los temas se noten claramente en TODOS los temas */
html[data-theme] body { background: var(--surface-2) !important; color: var(--text) !important; }
html[data-theme] .sidebar { background: var(--bg) !important; }
html[data-theme] .topbar { background: var(--surface) !important; border-bottom-color: var(--border) !important; color: var(--text) !important; }
html[data-theme] .topbar h1 { color: var(--text) !important; }
html[data-theme] .nav-link.active { background: var(--primary) !important; color: #fff !important; }
html[data-theme] .card,
html[data-theme] .company-banner { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
html[data-theme] .brand-mark { background: linear-gradient(135deg, var(--primary), var(--primary-dk)) !important; }
html[data-theme="claro"] body { background: #f1f5f9 !important; }

/* Refuerzos específicos oscuro/auto */
html[data-theme="oscuro"] .topbar,
html[data-theme="auto"] .topbar { background: var(--surface); border-bottom-color: var(--border); color: var(--text); }
html[data-theme="oscuro"] .topbar h1,
html[data-theme="auto"] .topbar h1 { color: var(--text); }
html[data-theme="oscuro"] .content,
html[data-theme="auto"] .content { color: var(--text); }
html[data-theme="oscuro"] table.data tbody tr:hover,
html[data-theme="oscuro"] table.data tr:hover td,
html[data-theme="auto"] table.data tbody tr:hover,
html[data-theme="auto"] table.data tr:hover td { background: #0b1220; }
html[data-theme="oscuro"] .company-banner,
html[data-theme="auto"] .company-banner { background: var(--surface); }


/* ---------------- Barra de progreso de subida (uploader.js) ---------------- */
.upx {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.upx-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.upx-label { font-size: 13px; font-weight: 600; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upx-pct { font-size: 13px; font-weight: 700; color: var(--primary); flex: 0 0 auto; }
.upx-track { height: 10px; margin-top: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.upx-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--primary-dk));
  transition: width .18s ease;
}
.upx-files { margin-top: 6px; font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
@media print { .upx { display: none !important; } }

/* ---------------- Refuerzos móviles (mínimos, sin deformar el layout) ---------------- */
@media (max-width: 768px) {
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .modal-foot .btn { flex: 1 1 auto; }
  input[type="file"] { max-width: 100%; }
  .card-body { overflow-wrap: anywhere; }
}

/* ---------------- Paginación de listados (10 por página) ---------------- */
table tbody tr[data-lt-match="0"] { display: none !important; }
table tbody tr[data-page-hidden="1"] { display: none; }

.table-pager {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border);
}
.table-pager .tp-pages { display: flex; flex-wrap: wrap; gap: 4px; }
.table-pager .tp-num {
  min-width: 32px; padding: 6px 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: 8px;
  font-size: 13px; cursor: pointer;
}
.table-pager .tp-num:hover { border-color: var(--primary); color: var(--primary); }
.table-pager .tp-num.is-active {
  background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600;
}
.table-pager .tp-dots { padding: 0 2px; color: var(--text-muted); }
.table-pager .tp-info { margin-left: auto; font-size: 12px; color: var(--text-muted); }
.table-pager button[disabled] { opacity: .45; cursor: not-allowed; }

/* La impresión y el PDF incluyen TODAS las filas filtradas, no sólo la página */
@media print {
  .table-pager { display: none !important; }
  table tbody tr[data-page-hidden="1"] { display: table-row !important; }
}

/* -------- Listados como tarjetas en móvil (estilo panel) -------- */
@media screen and (max-width: 768px) {
  .table-wrap { overflow-x: visible; }
  table.mobile-cards,
  table.mobile-cards tbody { display: block; width: 100%; }
  table.mobile-cards thead { display: none; }
  table.mobile-cards tbody tr {
    display: block; background: var(--surface);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 7px 10px; margin-bottom: 7px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
  }
  table.mobile-cards tbody tr[data-page-hidden="1"],
  table.mobile-cards tbody tr[data-lt-match="0"] { display: none !important; }
  table.mobile-cards tbody td {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 12px; width: auto; padding: 3px 0; border: 0;
    font-size: 13px; text-align: right; overflow-wrap: anywhere; line-height: 1.25;
  }
  table.mobile-cards tbody td::before {
    content: attr(data-label);
    flex: 0 0 40%; text-align: left;
    color: var(--text-muted); font-size: 12px; font-weight: 600;
  }
  table.mobile-cards tbody td[data-label=""]::before,
  table.mobile-cards tbody td.cell-nolabel::before { content: ""; flex: 0; }
  table.mobile-cards tbody td.cell-nolabel { justify-content: flex-end; }
  table.mobile-cards tbody td .actions {
    display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end;
  }
  table.mobile-cards tbody td:has(> .empty) { display: block; text-align: center; }
  table.mobile-cards tbody td:has(> .empty)::before { content: ""; }
  .table-pager .tp-info { margin-left: 0; width: 100%; }
}

/* =========================================================
   Ajuste integral para teléfonos (v16)
   Objetivo: que NADA desborde la pantalla y que los datos
   no se deformen. Sólo afecta a pantallas <= 768px.
   ========================================================= */
@media screen and (max-width: 768px) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  /* iOS: overflow-x:hidden en <html> rompe position:fixed (menú lateral).
     Se limita al <body> y con overflow-x:clip cuando el navegador lo soporta. */
  html { max-width: 100%; }
  body { max-width: 100%; overflow-x: hidden; }
  @supports (overflow-x: clip) { body { overflow-x: clip; } }

  /* Contenedores base: nunca más anchos que la pantalla */
  .layout, .main, .content, .card, .card-body, .metric, .modal, form, section, article {
    min-width: 0; max-width: 100%;
  }
  .content {
    padding: 12px 10px calc(24px + env(safe-area-inset-bottom));
    width: 100%;
  }

  /* Medios y lienzos siempre contenidos */
  img, canvas, video, iframe, svg, embed, object { max-width: 100% !important; height: auto; }
  pre, code { white-space: pre-wrap; overflow-wrap: anywhere; }

  /* Textos largos (emails, URLs, referencias) no rompen la caja */
  .card, .card-body, .metric, td, th, li, p, h1, h2, h3, h4 { overflow-wrap: anywhere; }

  /* Campos de formulario: ignoran min-width en línea y ocupan el ancho */
  input, select, textarea, .input, .searchable-select, .field { max-width: 100% !important; min-width: 0 !important; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  select, textarea { width: 100% !important; }
  /* Evita el zoom automático de iOS al enfocar un campo */
  input, select, textarea { font-size: 16px !important; }

  /* Rejillas declaradas en línea: se adaptan sin desbordar */
  [style*="grid-template-columns"] {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)) !important;
  }
  /* Filas flex en línea: permiten salto de línea */
  [style*="display:flex"], [style*="display: flex"] { flex-wrap: wrap; }

  /* Barra superior compacta */
  .topbar { padding: 8px 10px; row-gap: 6px; }
  .theme-combo { margin-right: 0; padding: 2px 6px; }
  .theme-combo select { min-width: 0 !important; width: auto !important; font-size: 12px !important; max-width: 108px; }
  .topbar .usermenu-btn { padding: 4px 8px; }
  .usermenu-drop { min-width: 0; width: min(88vw, 260px); }

  /* Tablas de detalle (parte, factura, cobros): scroll horizontal contenido */
  .table-wrap, .table-scroll { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap > table { max-width: none; }
  /* Cualquier tabla suelta se hace desplazable en vez de estirar la página */
  .card-body > table:not(.mobile-cards) { display: block; overflow-x: auto; width: 100%; }

  /* Documento de factura / parte imprimible */
  .doc-wrap { padding: 0 0 24px; }
  .fdoc { width: 100% !important; max-width: 100%; padding: 18px 14px; font-size: 12px; box-shadow: none; }
  .fdoc-head, .fdoc-parties { flex-direction: column; gap: 12px; }
  .fdoc-meta { text-align: left; min-width: 0 !important; }
  .fdoc-metatable { margin-left: 0; }
  .fdoc-metatable td { text-align: left; padding-left: 0; padding-right: 12px; }
  .fdoc-emisor { max-width: 100%; }
  .fdoc-table, .print-area table, .pc-table { font-size: 11.5px; }
  .fdoc-totals table { min-width: 0 !important; width: 100%; }

  /* Botonera y acciones: se apilan sin salirse */
  .page-head .actions, .list-tools, .modal-foot, .actions { flex-wrap: wrap; }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
  .btn { max-width: 100%; }

  /* Paginador legible en pantallas pequeñas */
  .table-pager { justify-content: center; }
  .table-pager .tp-info { width: 100%; text-align: center; margin-left: 0; }

  /* Sidebar deslizante ocupa como mucho el 84% de la pantalla */
  .sidebar { width: min(84vw, var(--sidebar-w)); }

  /* Calendario: sin anchos mínimos que desborden */
  .cal-toolbar .month { min-width: 0 !important; font-size: 16px; }
  .cal-grid { font-size: 11px; }
}

/* Teléfonos estrechos (<= 430px) */
@media screen and (max-width: 430px) {
  .content { padding: 10px 8px calc(20px + env(safe-area-inset-bottom)); }
  .card-body { padding: 14px 12px; }
  table.mobile-cards tbody td { font-size: 13px; }
  table.mobile-cards tbody td::before { flex: 0 0 42%; }
  .page-head h2 { font-size: 19px; }
  .metric .metric-value { font-size: 24px; }
  .topbar h1 { font-size: 15px; }
}

/* Las tablas en modo tarjeta ignoran anchos fijos declarados en línea */
@media screen and (max-width: 768px) {
  table.mobile-cards { min-width: 0 !important; width: 100% !important; }
  table.mobile-cards td, table.mobile-cards th {
    width: auto !important; min-width: 0 !important; max-width: 100% !important;
    white-space: normal !important;
  }
  table.mobile-cards td > div { max-width: 100% !important; }
}

@media screen and (max-width: 430px) {
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
}

/* =========================================================
   v20 · Botonera de acciones en listados
   Los botones de la última columna deben verse SIEMPRE,
   ajustándose en varias líneas si no caben.
   ========================================================= */
table.data td .actions,
.table-wrap .actions {
  display: flex;
  flex-wrap: wrap;          /* nunca se recortan: bajan de línea */
  align-items: center;
  gap: 6px;
  justify-content: flex-start;
}
table.data td .actions form { display: inline-flex; margin: 0; }
table.data td .actions .btn,
table.data td .actions form .btn {
  white-space: nowrap;
  flex: 0 0 auto;
  min-width: 34px;
  padding: 6px 9px;
  font-size: 13px;
  line-height: 1.1;
}
/* La columna de acciones no se comprime ni se corta */
table.data td:last-child { white-space: normal; min-width: 148px; }
table.data th:last-child, table.data td:last-child { text-align: left; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media screen and (max-width: 768px) {
  /* En modo tarjeta las acciones ocupan toda la fila de la tarjeta */
  table.mobile-cards tbody td:has(> .actions) { display: block; padding-top: 8px; }
  table.mobile-cards tbody td:has(> .actions)::before {
    display: block; flex: none; margin-bottom: 6px;
  }
  table.mobile-cards tbody td .actions {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; width: 100%;
  }
  table.mobile-cards tbody td .actions .btn {
    flex: 0 1 auto; min-height: 36px; padding: 8px 10px;
  }
  table.data td:last-child { min-width: 0; }
}

/* Filas de partes anulados: siguen visibles, pero claramente marcadas */
tr.row-anulada > td { background: #fef2f2; }
tr.row-anulada:hover > td { background: #fee2e2; }
tr.row-anulada td a strong { text-decoration: line-through; color: #991b1b; }
@media screen and (max-width: 768px) {
  table.mobile-cards tbody tr.row-anulada {
    background: #fef2f2; border-color: #fecaca;
  }
}

/* =========================================================
   v24 · Exportación PDF idéntica en móvil y en PC
   El contenedor que se rasteriza recibe .pdf-desktop: se
   neutralizan las reglas responsivas (tarjetas, columnas
   apiladas, anchos al 100%) para que el documento generado
   desde un teléfono sea igual que el generado desde un PC.
   ========================================================= */
.pdf-desktop {
  width: 794px !important;
  min-width: 794px !important;
  max-width: none !important;
  font-size: 13px !important;
  overflow: visible !important;
  box-shadow: none !important;
}
.pdf-desktop * { overflow: visible !important; }
.pdf-desktop table {
  display: table !important; width: 100% !important; min-width: 0 !important;
  max-width: none !important; border-collapse: collapse !important;
}
.pdf-desktop thead { display: table-header-group !important; }
.pdf-desktop tbody { display: table-row-group !important; }
.pdf-desktop tr {
  display: table-row !important; background: transparent !important;
  border: 0 !important; border-radius: 0 !important; box-shadow: none !important;
  margin: 0 !important; padding: 0 !important;
}
.pdf-desktop th, .pdf-desktop td {
  display: table-cell !important; width: auto !important; max-width: none !important;
  text-align: left !important; padding: 6px 8px !important;
  border: 1px solid #cbd5e1 !important; font-size: 11.5px !important;
  vertical-align: top !important; white-space: normal !important;
}
.pdf-desktop th { background: #f1f5f9 !important; font-weight: 700 !important; }
.pdf-desktop td::before, .pdf-desktop th::before { content: none !important; display: none !important; }
.pdf-desktop tbody tr[data-page-hidden="1"] { display: table-row !important; }
.pdf-desktop .fdoc { width: 794px !important; max-width: none !important; padding: 32px 28px !important; font-size: 13px !important; }
.pdf-desktop .fdoc-head, .pdf-desktop .fdoc-parties { flex-direction: row !important; }
.pdf-desktop .fdoc-meta { text-align: right !important; }
.pdf-desktop .fdoc-metatable td { text-align: right !important; }
.pdf-desktop input, .pdf-desktop select, .pdf-desktop textarea { width: auto !important; font-size: 12px !important; }
.pdf-desktop img, .pdf-desktop canvas { max-width: 100% !important; height: auto !important; }
.pdf-desktop .table-pager, .pdf-desktop .list-tools, .pdf-desktop .no-print { display: none !important; }

/* ===== Campana de alertas de seguridad ===== */
.alertmenu{position:relative}
.alertmenu-btn{position:relative;background:transparent;border:1px solid var(--border);border-radius:10px;
  width:38px;height:38px;font-size:17px;cursor:pointer;color:var(--text);display:flex;align-items:center;justify-content:center}
.alertmenu-btn:hover{background:var(--bg-soft,rgba(0,0,0,.04))}
.alert-badge{position:absolute;top:-6px;right:-6px;background:#dc2626;color:#fff;font-size:10px;font-weight:700;
  line-height:1;padding:3px 5px;border-radius:999px;min-width:16px;text-align:center}
.alertmenu-drop{display:none;position:absolute;right:0;top:calc(100% + 8px);width:340px;max-width:88vw;z-index:80;
  background:var(--card,#fff);border:1px solid var(--border);border-radius:12px;box-shadow:0 12px 32px rgba(0,0,0,.18);overflow:hidden}
.alertmenu.open .alertmenu-drop{display:block}
.alertmenu-head{padding:10px 12px;font-weight:600;font-size:13px;border-bottom:1px solid var(--border)}
.alertmenu-empty{padding:14px 12px;font-size:13px;color:var(--text-muted)}
.alertmenu-item{display:block;padding:10px 12px;border-bottom:1px solid var(--border);text-decoration:none;color:var(--text);border-left:3px solid transparent}
.alertmenu-item:hover{background:var(--bg-soft,rgba(0,0,0,.04))}
.alertmenu-item.sev-critico{border-left-color:#dc2626}
.alertmenu-item.sev-aviso{border-left-color:#f59e0b}
.alertmenu-item.sev-info{border-left-color:#3b82f6}
.alertmenu-item .ttl{font-size:13px;font-weight:600}
.alertmenu-item .dsc{font-size:12px;color:var(--text-muted);margin-top:2px}
.alertmenu-item .tim{font-size:11px;color:var(--text-muted);margin-top:3px}
.alertmenu-foot{display:block;padding:10px 12px;font-size:12px;font-weight:600;text-align:center;text-decoration:none;color:var(--primary,#2563eb)}
@media (max-width:640px){.alertmenu-drop{position:fixed;left:8px;right:8px;width:auto;top:60px}}
@media print{.alertmenu{display:none !important}}


/* =========================================================
   v54 — Menú principal fiable en iOS / Android
   ========================================================= */
@media screen and (max-width: 768px) {
  .sidebar {
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    height: 100dvh;
    -webkit-transform: translateX(-100%);
    transform: translateX(-100%);
    -webkit-overflow-scrolling: touch;
    will-change: transform;
    z-index: 1200 !important;
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open,
  body.sidebar-open .sidebar {
    -webkit-transform: translateX(0) !important;
    transform: translateX(0) !important;
  }
  .sidebar nav { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .sidebar-backdrop { z-index: 1150 !important; }
  .topbar .menu-toggle {
    display: inline-flex !important;
    align-items: center; justify-content: center;
    width: 42px; height: 42px; flex: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    cursor: pointer;
  }
  body.sidebar-open { overflow: hidden; }
}

/* ---------------- Logotipo corporativo ---------------- */
.sidebar .brand.brand-logo { padding: 14px 16px; }
.sidebar .brand.brand-logo img { width: 100%; max-width: 210px; height: auto; display: block; }
.auth-hero .hero-logo img { width: min(360px, 78%); height: auto; display: block; margin-bottom: 22px; }
.auth-card .auth-logo { display: none; }
.auth-card .auth-logo img { width: 100%; max-width: 260px; height: auto; margin: 0 auto 18px; display: block; }
@media (max-width: 900px) {
  .auth-card .auth-logo { display: block; }
}

/* ---- Notificaciones push ---- */
.badge-push{display:inline-block;min-width:16px;padding:0 4px;margin-left:4px;border-radius:9px;
  background:#dc2626;color:#fff;font-size:10px;line-height:16px;text-align:center;font-weight:700;vertical-align:top}
[data-push-toggle]{white-space:nowrap}
[data-push-toggle].on{background:#059669;border-color:#059669;color:#fff}
