/* ========= Motor de Cobranzas — estilos globales (idénticos al demo) ========= */
:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #f9fafc;
    --border: #e4e8ee;
    --text: #1e2430;
    --text-muted: #6a7280;
    --primary: #1f4e79;
    --primary-2: #2a6aa8;
    --success: #2e7d32;
    --warning: #c27a00;
    --danger: #c0392b;
    --info: #2a6aa8;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
    --radius: 8px;
    /* compat con clases viejas */
    --panel: var(--surface);
    --panel-2: var(--surface-2);
    --primary-hover: var(--primary-2);
    --accent: #6f42c1;
    --sidebar-w: 240px;
    --topbar-h: 54px;
}
[data-theme="dark"] {
    --bg: #0f1419;
    --surface: #1a212b;
    --surface-2: #141a23;
    --border: #2a3341;
    --text: #e6eaf0;
    --text-muted: #8b95a5;
    --primary: #4a90d9;
    --primary-2: #5fa3eb;
    --shadow: 0 1px 3px rgba(0,0,0,.35), 0 2px 12px rgba(0,0,0,.3);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; color: var(--text); }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
h3 { font-size: 15px; font-weight: 600; }

/* ========== LAYOUT ========== */
.app, .app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 0; display: flex; flex-direction: column; }
.sidebar-brand { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.sidebar-brand .logo { font-weight: 700; font-size: 15px; color: var(--primary); display: flex; align-items: center; gap: 8px; }
.sidebar-brand .logo::before { content: "$"; display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; background: var(--primary); color: white; border-radius: 6px; font-weight: 800; }
.sidebar-brand .sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; padding-left: 34px; }
.nav { padding: 8px 0; flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.nav-section { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); padding: 14px 20px 6px; font-weight: 700; }
.nav-item, .sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 8px 20px; color: var(--text); cursor: pointer; border-left: 3px solid transparent; font-size: 13px; user-select: none; text-decoration: none; }
.nav-item:hover, .sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active, .sidebar nav a.active { background: var(--surface-2); border-left-color: var(--primary); color: var(--primary); font-weight: 600; }
.nav-item .icon { width: 16px; display: inline-flex; justify-content: center; opacity: .75; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center; }

.main { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: 54px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.breadcrumb { font-size: 13px; color: var(--text-muted); }
.breadcrumb strong { color: var(--text); }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }
.user-name { font-weight: 600; line-height: 1.2; }
.user-rol { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; line-height: 1.2; }

.content { padding: 24px; flex: 1; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-size: 22px; font-weight: 600; }
.page-header .subtitle { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ========== CARDS & KPIS ========== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-title { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .07em; margin-bottom: 4px; font-weight: 700; }
.card-subtle { color: var(--text-muted); font-size: 12px; }
.kpi { font-size: 28px; font-weight: 700; margin-top: 4px; line-height: 1.1; }
.kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 960px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}

/* ========== METRIC (compat) ========== */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
.metric-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.metric-value { font-size: 22px; font-weight: 700; }
.metric-value.success { color: var(--success); }
.metric-value.danger { color: var(--danger); }
.metric-value.warning { color: var(--warning); }

/* ========== BUTTONS ========== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; cursor: pointer; font-size: 13px; font-family: inherit; transition: all .15s; text-decoration: none; }
.btn:hover { background: var(--surface-2); border-color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); color: white; }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #e54d3c; border-color: #e54d3c; color: white; }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-group { display: inline-flex; gap: 6px; }
.btn-ghost { background: transparent; border: 1px solid transparent; color: var(--text); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.btn-ghost:hover { background: var(--surface-2); }

/* ========== FORM ========== */
.input, select, textarea, input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=time] { width: 100%; padding: 7px 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; font-size: 13px; font-family: inherit; }
.input:focus, select:focus, textarea:focus, input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(31,78,121,.15); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; font-weight: 600; }
.filter-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; margin-bottom: 16px; }
.row-filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.row-filters > * { min-width: 160px; }
/* form-row: stack vertical (label arriba, input abajo) */
.form-row { display: block; margin-bottom: 12px; }
.form-row > label { display: block; margin-bottom: 4px; }
.form-row > input, .form-row > select, .form-row > textarea { width: 100%; }
.form-row > .help { margin-top: 4px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.flag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; font-weight: normal; color: var(--text); }
.field-error { color: var(--danger); font-size: 12px; }
.req { color: var(--danger); }
.help { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
/* inline-toggle: label + switch juntos a la izquierda */
.form-row.inline-toggle { display: flex; align-items: center; justify-content: flex-start; gap: 12px; }
.form-row.inline-toggle > label:first-child { margin-bottom: 0; flex: 0 0 auto; min-width: 140px; }
.inline-toggle { display: flex; align-items: center; gap: 12px; }

/* checkbox list (multi-select con scroll) */
.cbx-list { border: 1px solid var(--border); border-radius: 6px; max-height: 180px; overflow-y: auto; padding: 6px 8px; background: var(--surface); }
.cbx-list label { display: flex; align-items: center; gap: 8px; padding: 4px 2px; font-size: 13px; color: var(--text); font-weight: normal; cursor: pointer; margin: 0; }
.cbx-list label:hover { background: var(--surface-2); }
.cbx-list input[type=checkbox] { width: auto; margin: 0; }
.cbx-list-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.cbx-list-head label { font-weight: 600; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ========== TABLE ========== */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
.tbl th { text-align: left; padding: 10px 12px; background: var(--surface-2); color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid var(--border); }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:hover td { background: var(--surface-2); }
.tbl tr:last-child td { border-bottom: none; }
.tbl .mono { font-family: 'JetBrains Mono', 'Consolas', monospace; font-size: 12px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mono { font-family: 'JetBrains Mono', 'Consolas', monospace; font-size: 12px; }

/* ========== PILLS ========== */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--border); color: var(--text); }
.pill-success { background: rgba(46,125,50,.15); color: var(--success); }
.pill-warning { background: rgba(194,122,0,.15); color: var(--warning); }
.pill-danger { background: rgba(192,57,43,.15); color: var(--danger); }
.pill-info { background: rgba(42,106,168,.15); color: var(--info); }
.pill-muted { background: var(--border); color: var(--text-muted); }

/* ========== TOAST ========== */
.toast-stack, #toasts { position: fixed; top: 20px; right: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 6px; box-shadow: var(--shadow); min-width: 260px; font-size: 13px; animation: slideIn .25s ease; }
.toast.success { border-left-color: var(--success); }
.toast.danger, .toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }
@keyframes slideIn { from { transform: translateX(120%); } to { transform: translateX(0); } }

/* ========== MODAL ========== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 500; display: flex; align-items: center; justify-content: center; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 640px; max-width: 92vw; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }

/* ========== SWITCH ========== */
.switch { position: relative; display: inline-block; width: 48px; height: 26px; }
.switch input { display: none; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #cfd5dd; border-radius: 26px; transition: .2s; }
.slider::before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ========== TOGGLE (compat con _Form viejo) ========== */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: var(--border); border-radius: 22px; transition: .15s; cursor: pointer; }
.toggle-track::before { content: ""; position: absolute; left: 2px; top: 2px; width: 18px; height: 18px; background: white; border-radius: 50%; transition: .15s; }
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track::before { transform: translateX(18px); }

/* ========== WIZARD ========== */
.wizard-steps { display: flex; gap: 0; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding: 0; }
.wizard-step { flex: 1; padding: 12px 16px; cursor: pointer; text-align: center; font-size: 13px; color: var(--text-muted); border-bottom: 3px solid transparent; }
.wizard-step.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.wizard-step.done { color: var(--success); }
.wizard-step .step-num { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--border); color: var(--text-muted); align-items: center; justify-content: center; font-size: 11px; font-weight: 700; margin-right: 6px; }
.wizard-step.active .step-num { background: var(--primary); color: white; }
.wizard-step.done .step-num { background: var(--success); color: white; }
.wizard-actions { display: flex; justify-content: space-between; margin-top: 20px; gap: 8px; }

/* ========== TIMELINE ========== */
.timeline { position: relative; padding: 0 0 0 24px; list-style: none; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding: 0 0 20px; }
.timeline-item::before { content: ""; position: absolute; left: -21px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); }
.timeline-item.success::before { background: var(--success); }
.timeline-item.warning::before { background: var(--warning); }
.timeline-item.danger::before { background: var(--danger); }
.timeline-item .ti-head { font-weight: 600; margin-bottom: 2px; font-size: 13px; }
.timeline-item .ti-meta { color: var(--text-muted); font-size: 11px; margin-bottom: 6px; }
.timeline-item .ti-body { font-size: 12px; background: var(--surface-2); padding: 8px 12px; border-radius: 6px; }
.timeline-success::before { background: var(--success) !important; }
.timeline-danger::before { background: var(--danger) !important; }
.timeline-warning::before { background: var(--warning) !important; }
.timeline-muted::before { background: var(--text-muted) !important; }
.timeline-content pre { background: var(--surface-2); padding: 6px; border-radius: 4px; margin: 4px 0; }

/* ========== MISC ========== */
.separator { height: 1px; background: var(--border); margin: 16px 0; }
.login-wrap, .login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1f4e79, #2a6aa8); padding: 20px; }
.login-card, .login-box { background: var(--surface); width: 400px; max-width: 100%; border-radius: 12px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-logo { text-align: center; font-size: 24px; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.login-sub, .login-box p.subtle { text-align: center; color: var(--text-muted); margin-bottom: 24px; font-size: 13px; }
.login-box h1 { margin: 0 0 6px; font-size: 20px; font-weight: 600; text-align: center; color: var(--primary); }
.login-box .field { margin-bottom: 14px; }
.login-box label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.login-box button { width: 100%; padding: 10px; justify-content: center; }
.hidden { display: none !important; }
.badge-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.badge-dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(46,125,50,.18); }
.badge-dot.off { background: #c0c4ca; }
.chart { height: 180px; display: flex; align-items: flex-end; gap: 6px; padding-top: 10px; }
.chart .bar { flex: 1; background: linear-gradient(180deg, var(--primary), var(--primary-2)); border-radius: 3px 3px 0 0; position: relative; min-height: 2px; }
.chart .bar::after { content: attr(data-label); position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-muted); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
code.k { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 12px; font-family: 'JetBrains Mono', monospace; }
.drag-handle { cursor: grab; color: var(--text-muted); padding-right: 8px; }
.drag-handle:active { cursor: grabbing; }
.dragging { opacity: .4; }
.drop-target { background: rgba(31,78,121,.08) !important; }
.pager { display: flex; gap: 4px; padding: 12px; justify-content: center; flex-wrap: wrap; }
.demo-banner { background: #fff8e1; border-bottom: 1px solid #f5d87a; padding: 6px 24px; font-size: 12px; color: #8a6400; text-align: center; }
[data-theme="dark"] .demo-banner { background: #2d2410; color: #e3b94f; border-color: #4a3a10; }

/* ========== Bar-row (compat con simulador / reportes) ========== */
.bar-row { display: grid; grid-template-columns: 140px 1fr 80px; gap: 10px; align-items: center; margin-bottom: 6px; font-size: 12px; }
.bar-track { height: 14px; background: var(--surface-2); border-radius: 7px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); }

/* ========== Indicador motor (compat) ========== */
.motor-indicator { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; letter-spacing: .04em; padding: 6px 10px; border-radius: 16px; background: var(--surface-2); }
.motor-indicator.on { color: var(--success); }
.motor-indicator.off { color: var(--text-muted); }
.motor-indicator .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ========== Schedule panels (form políticas) ========== */
.schedule-panel { display: none; }
.schedule-panel.active { display: block; }

/* ========== Overlay "Procesando, aguardá" ========== */
.busy-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 20, 25, 0.55);
    z-index: 9999;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: #fff; font-size: 18px; gap: 24px;
    backdrop-filter: blur(2px);
    animation: fadeIn .15s ease;
}
.busy-overlay .spinner {
    width: 64px; height: 64px;
    border: 6px solid rgba(255,255,255,.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
.busy-overlay .busy-msg {
    font-weight: 600;
    text-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.busy-overlay .busy-sub {
    font-size: 13px; color: rgba(255,255,255,.85);
    max-width: 400px; text-align: center; line-height: 1.4;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Botones-icono (acciones de tabla) ========== */
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; cursor: pointer; font-size: 14px; line-height: 1; transition: all .15s; text-decoration: none; }
.btn-icon:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-icon-danger:hover { border-color: var(--danger); color: var(--danger); }

/* ========== Icono info con tooltip ========== */
.info-tip { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; border-radius: 50%; background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); font-size: 10px; font-style: normal; cursor: help; margin-left: 4px; vertical-align: middle; font-weight: 700; }
.info-tip:hover { background: var(--primary); color: white; border-color: var(--primary); }
.info-tip[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%);
    background: #1e2430; color: #fff; padding: 8px 12px; border-radius: 6px;
    font-size: 12px; font-weight: normal; line-height: 1.4; white-space: pre-wrap;
    width: max-content; max-width: 360px; z-index: 1000;
    box-shadow: 0 4px 16px rgba(0,0,0,.25); pointer-events: none;
}
.info-tip[data-tip]:hover::before {
    content: ""; position: absolute; left: 50%; bottom: calc(100% + 2px); transform: translateX(-50%);
    border: 6px solid transparent; border-top-color: #1e2430; z-index: 1001;
}
