/* ==========================================================
   SOLENGOA — Interfaz interna
   Sistema de diseño basado en cards, espacios generosos,
   tipografía Inter y paleta slate + azul.
   ========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;

  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0284c7;
  --info-bg: #e0f2fe;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
  --shadow: 0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 6px rgba(15,23,42,0.05), 0 2px 4px rgba(15,23,42,0.04);
  --shadow-lg: 0 10px 30px rgba(15,23,42,0.08);

  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }

[data-lucide] { width: 18px; height: 18px; stroke-width: 2; }

/* ==========================================================
   LAYOUT
   ========================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.sidebar .brand img { height: 38px; }
.sidebar .brand-text { font-weight: 700; color: var(--primary); font-size: 15px; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s;
}
.sidebar nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--primary-50);
  color: var(--primary);
  font-weight: 600;
}
.sidebar nav a.active [data-lucide] { color: var(--primary); }

.sidebar-incidencia {
  margin-top: auto;
  background: none;
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 12px;
  transition: all 0.15s;
}
.sidebar-incidencia [data-lucide] { width: 14px; height: 14px; }
.sidebar-incidencia:hover {
  background: var(--surface-2);
  border-style: solid;
  color: var(--text);
  border-color: var(--border-strong);
}

.user-box {
  padding: 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-box .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary-100);
  color: var(--primary);
  display: grid; place-items: center;
  font-weight: 600; font-size: 13px;
  flex-shrink: 0;
}
.user-box .info { flex: 1; min-width: 0; }
.user-box .name { font-weight: 600; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .email { font-size: 11px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box button {
  background: none; border: none;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
}
.user-box button:hover { background: var(--surface-2); color: var(--danger); }

.main { padding: 28px 36px; overflow-x: hidden; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 14px;
}
.page-header h1 { display: flex; align-items: center; gap: 10px; }
.page-header h1 [data-lucide] { width: 24px; height: 24px; color: var(--primary); }
.page-header .subtitle { color: var(--text-muted); margin-top: 4px; font-size: 13px; }

/* ==========================================================
   BOTONES
   ========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn [data-lucide] { width: 16px; height: 16px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border);
}
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.btn-success:hover { background: #15803d; border-color: #15803d; }

.btn-danger-solid {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger-solid:hover { background: #b91c1c; border-color: #b91c1c; }

.btn-dark {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}
.btn-dark:hover { background: #1e293b; border-color: #1e293b; }

.btn-icon {
  width: 32px; height: 32px;
  padding: 0;
  display: grid; place-items: center;
}

.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-lg { padding: 11px 18px; font-size: 14px; }

/* ==========================================================
   CARDS Y CONTENEDORES
   ========================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { display: flex; align-items: center; gap: 8px; }
.card-header h2 [data-lucide] { color: var(--primary); }

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.section-title .num {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}

/* ==========================================================
   FORMULARIOS
   ========================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid .col-3 { grid-column: span 1; }

@media (min-width: 1100px) {
  .form-grid.three { grid-template-columns: repeat(3, 1fr); }
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.field label .required { color: var(--danger); margin-left: 2px; }
.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.field input:disabled {
  background: var(--surface-2);
  color: var(--text-soft);
  cursor: not-allowed;
}
.field .hint { font-size: 11px; color: var(--text-soft); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ==========================================================
   LOGIN
   ========================================================== */
.login-bg {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.login-card .brand { text-align: center; margin-bottom: 24px; }
.login-card .brand img { height: 64px; }
.login-card h1 {
  text-align: center;
  font-size: 18px;
  margin: 0 0 6px;
  color: var(--text);
}
.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}
.login-card .field { margin-bottom: 14px; }
.login-card .btn-primary { width: 100%; padding: 12px; margin-top: 8px; justify-content: center; }
.login-footer {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 11px;
  color: var(--text-soft);
  letter-spacing: 0.02em;
}

/* ==========================================================
   ALERTAS
   ========================================================== */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert [data-lucide] { flex-shrink: 0; margin-top: 1px; }
.alert-error { background: var(--danger-bg); color: #991b1b; }
.alert-success { background: var(--success-bg); color: #166534; }
.alert-info { background: var(--info-bg); color: #075985; }

/* ==========================================================
   BADGES
   ========================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-emitida, .badge-info { background: var(--info-bg); color: var(--info); }
.badge-pagada, .badge-success { background: var(--success-bg); color: var(--success); }
.badge-pendiente, .badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-cancelada, .badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--text-muted); }

/* ==========================================================
   TOOLBAR & SEARCH
   ========================================================== */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  align-items: center;
}
.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 420px;
}
.search-box [data-lucide] {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-soft);
  width: 16px; height: 16px;
}
.search-box input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  font-family: inherit;
}
.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.pill {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.pill:hover { background: var(--surface-2); }
.pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Etiqueta del grupo de filtros */
.filter-label {
  font-size: 11px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  align-self: center;
  margin-right: 6px;
}

/* Punto de color siempre visible para identificar la opción */
.pill .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.pill-iberdrola .dot { background: #16a34a; }
.pill-solengoa  .dot { background: #f59e0b; }
.pill-ambos     .dot { background: linear-gradient(90deg, #f59e0b 0 50%, #16a34a 50% 100%); }

/* Estado activo sutil (fondo tintado, no sólido) para los pills con color */
.pill.pill-iberdrola.active {
  background: rgba(22,163,74,0.10);
  color: #15803d;
  border-color: #16a34a;
}
.pill.pill-solengoa.active {
  background: rgba(245,158,11,0.10);
  color: #b45309;
  border-color: #f59e0b;
}
.pill.pill-ambos.active {
  background: linear-gradient(90deg, rgba(245,158,11,0.10) 0 50%, rgba(22,163,74,0.10) 50% 100%);
  color: var(--text);
  border-color: var(--border-strong);
}

/* Pestañas dentro del side-panel */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.tab {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Lista compacta de facturas dentro del panel del cliente */
.client-invoices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.client-invoice-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.client-invoice-item:hover { border-color: var(--primary); background: var(--primary-50); }
.client-invoice-item .num {
  font-weight: 700;
  color: var(--primary);
  font-size: 14px;
  min-width: 60px;
}
.client-invoice-item .center { flex: 1; min-width: 0; }
.client-invoice-item .center .date { font-size: 12px; color: var(--text-muted); }
.client-invoice-item .total { font-weight: 600; }

/* ==========================================================
   KPIs
   ========================================================== */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
}
.kpi .icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--primary-50);
  color: var(--primary);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.kpi .icon [data-lucide] { width: 22px; height: 22px; }
.kpi.kpi-success .icon { background: var(--success-bg); color: var(--success); }
.kpi.kpi-warning .icon { background: var(--warning-bg); color: var(--warning); }
.kpi .label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.kpi .value { font-size: 20px; font-weight: 700; color: var(--text); }

/* ==========================================================
   GRID DE TARJETAS DE CLIENTE
   ========================================================== */
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.client-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.client-card.interes-iberdrola { border-left-color: #16a34a; }
.client-card.interes-solengoa  { border-left-color: #f59e0b; }
.client-card.interes-ambos     { border-left-color: #9333ea; }
.client-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.client-card .top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.client-card .avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  flex-shrink: 0;
}
.client-card .name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 2px;
}
.client-card .meta {
  font-size: 12px;
  color: var(--text-muted);
}
.client-card .info-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.client-card .info-row [data-lucide] { width: 14px; height: 14px; color: var(--text-soft); }
.client-card .badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ==========================================================
   GRID DE FACTURAS (tarjetas con miniatura del PDF)
   ========================================================== */
.invoice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.invoice-card-grid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
}
.invoice-card-grid:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.invoice-card-thumb {
  background: #fff;
  height: 320px;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.invoice-card-thumb .preview-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 800px;
  transform: scale(0.34);
  transform-origin: top left;
  pointer-events: none;
}
.invoice-card-thumb .thumb-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: #f8fafc;
}
.invoice-card-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.invoice-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.invoice-card-num {
  line-height: 1.1;
}
.invoice-card-num .lbl {
  font-size: 10px;
  color: var(--text-soft);
  display: block;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.invoice-card-num .val {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}
.invoice-card-num.rectificativa .val { color: var(--danger); }
.invoice-card-client {
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.invoice-card-dates {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.invoice-card-dates [data-lucide] { vertical-align: middle; }
.invoice-card-total {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

/* ==========================================================
   LISTADO DE FACTURAS (cards horizontales — legacy)
   ========================================================== */
.invoice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.invoice-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 100px 1fr auto auto auto;
  gap: 18px;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s;
}
.invoice-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.invoice-card .num {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}
.invoice-card .num.rectificativa { color: var(--danger); }
.invoice-card .num .label { font-size: 10px; color: var(--text-soft); display: block; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.invoice-card .client-info .name { font-weight: 600; font-size: 14px; }
.invoice-card .client-info .dates { font-size: 12px; color: var(--text-muted); margin-top: 2px; display: flex; gap: 14px; }
.invoice-card .badges { display: flex; gap: 6px; }
.invoice-card .total {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-align: right;
  white-space: nowrap;
}
.invoice-card .total .label { font-size: 10px; color: var(--text-soft); display: block; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.invoice-card .pdf-link {
  color: var(--text-muted);
  display: grid; place-items: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
}
.invoice-card .pdf-link:hover { background: var(--primary-50); color: var(--primary); }

@media (max-width: 900px) {
  .invoice-card { grid-template-columns: 80px 1fr auto; }
  .invoice-card .badges, .invoice-card .pdf-link { display: none; }
}

/* ==========================================================
   SLIDE-OUT PANEL
   ========================================================== */
.panel-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.4);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.panel-overlay.open { opacity: 1; pointer-events: auto; }

.side-panel {
  position: fixed;
  top: 0; right: 0;
  width: 100%;
  max-width: 520px;
  height: 100vh;
  background: var(--surface);
  box-shadow: -10px 0 30px rgba(15,23,42,0.1);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.side-panel.open { transform: translateX(0); }
.side-panel .panel-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.side-panel .panel-header h2 { display: flex; align-items: center; gap: 10px; }
.side-panel .panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px;
}
.side-panel .panel-footer {
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

/* ==========================================================
   MODAL
   ========================================================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.5);
  z-index: 200;
  display: none;
  place-items: center;
  padding: 20px;
}
.modal-overlay.open { display: grid; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 900px;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-body.no-padding { padding: 0; }
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ==========================================================
   CHIPS DE INFO EN LA CABECERA DE FACTURA
   ========================================================== */
.invoice-header-info {
  display: flex;
  gap: 18px;
  margin-top: 14px;
  flex-wrap: wrap;
  align-items: center;
}
.inv-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.inv-chip .lbl {
  font-size: 10px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  white-space: nowrap;
}
.inv-chip input {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  width: auto;
}
.inv-chip input[type="text"] {
  min-width: 80px;
  text-align: center;
}
.inv-chip input[type="date"] {
  min-width: 130px;
}
.inv-chip input:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}
.inv-chip input[type="date"]:not(:disabled):focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.inv-chip #estado-actual {
  display: inline-flex;
  align-items: center;
}

/* ==========================================================
   COMBOBOX (input con sugerencias en vivo)
   ========================================================== */
.combobox { position: relative; }
.combobox input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
}
.combobox input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.combobox-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  margin: 4px 0 0;
  padding: 4px 0;
  list-style: none;
  box-shadow: var(--shadow-md);
}
.combobox-list[hidden] { display: none; }
.combobox-list li {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.combobox-list li:hover, .combobox-list li.active {
  background: var(--primary-50);
}
.combobox-list li .name { font-weight: 500; color: var(--text); }
.combobox-list li .secondary { color: var(--text-muted); font-size: 12px; }
.combobox-list li.no-results { color: var(--text-muted); cursor: default; font-style: italic; }
.combobox-list li.no-results:hover { background: transparent; }

/* ==========================================================
   CREADOR DE FACTURA — líneas dinámicas
   ========================================================== */
.invoice-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px 120px 110px 32px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}
.invoice-line > * { min-width: 0; }
.invoice-line:last-of-type { border-bottom: none; }
.invoice-line input {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
}
.invoice-line input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.invoice-line .importe {
  text-align: right;
  font-weight: 600;
  color: var(--text);
  padding: 9px 0;
}
.invoice-line .delete {
  background: none;
  border: none;
  color: var(--text-soft);
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
}
.invoice-line .delete:hover { background: var(--danger-bg); color: var(--danger); }

.line-headers {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px 120px 110px 32px;
  gap: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.line-headers .right { text-align: right; }
.line-headers .center { text-align: center; }

.add-line-btn {
  width: 100%;
  padding: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 14px;
  transition: all 0.15s;
}
.add-line-btn:hover {
  background: var(--primary-50);
  color: var(--primary);
  border-color: var(--primary);
}

/* Resumen totales */
.totales-box {
  margin-top: 20px;
  margin-left: auto;
  max-width: 360px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.totales-box .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
}
.totales-box .row.total {
  border-top: 2px solid var(--border-strong);
  padding-top: 12px;
  margin-top: 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}
.totales-box .totales-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}
.totales-box .totales-toggle input[type="checkbox"] { cursor: pointer; }
.totales-box .pct-input {
  width: 60px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  text-align: right;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.totales-box .pct-input:focus {
  outline: none;
  border-color: var(--primary);
}
.totales-box .pct-suffix {
  color: var(--text-muted);
  font-size: 13px;
}

/* Bloques informativos (modo "factura emitida", read-only) */
.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 24px;
}
.info-grid.three-col { grid-template-columns: repeat(3, 1fr); }
.info-grid .full { grid-column: 1 / -1; }

.info-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 22px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.info-section-title:first-child { margin-top: 0; }

/* Modal del cliente — vista visual minimalista */
.avatar-md {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}
.cliente-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.cliente-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.cliente-section {
  margin-top: 22px;
}
.cliente-section:first-of-type { margin-top: 0; }
.cliente-section h4 {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 10px;
}
.cl-line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  font-size: 14px;
  color: var(--text);
}
.cl-line [data-lucide] {
  width: 16px; height: 16px;
  color: var(--text-soft);
  flex-shrink: 0;
}
.cl-line a { color: var(--primary); }
.cl-tech {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 24px;
  font-size: 14px;
}
.cl-tech > div {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 4px 0;
}
.cl-tech-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-soft);
  font-weight: 600;
  min-width: 110px;
}
.cl-tech-value {
  color: var(--text);
  font-weight: 500;
  word-break: break-all;
}

@media (max-width: 900px) {
  .info-grid.three-col { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .info-grid.three-col, .info-grid { grid-template-columns: 1fr; }
}
.info-grid .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  margin-bottom: 4px;
}
.info-grid .value {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}
.info-grid .value.big {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.01em;
}
.info-grid .value.total {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.view-block .section-title [data-lucide] {
  width: 20px; height: 20px; color: var(--primary);
}

/* ====== Resumen de pagos en cards de listado ====== */
.invoice-card-pagos {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.invoice-card-pagos-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.invoice-card-pagos-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success, #16a34a), var(--success, #22c55e));
  transition: width 0.3s ease;
}
.invoice-card-pagos-text {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}
.invoice-card-pagos.warn .invoice-card-pagos-text {
  color: var(--warning, #d97706);
}

/* ====== Pagos (multi-pago) ====== */
.pagos-resumen {
  margin-bottom: 16px;
}
.pagos-summary {
  background: var(--bg-soft, #f8f9fc);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.pagos-summary-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 12px;
}
.pagos-summary-row > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pagos-summary-row .lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.pagos-summary-row strong {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}
.pagos-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.pagos-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success, #16a34a) 0%, var(--success, #22c55e) 100%);
  transition: width 0.3s ease;
}

.pagos-lista {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pago-item {
  display: grid;
  grid-template-columns: 110px 130px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pago-item .pago-fecha {
  font-size: 13px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.pago-item .pago-importe {
  font-weight: 600;
  font-size: 15px;
  color: var(--success, #16a34a);
}
.pago-item .pago-ref {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pago-item .pago-acciones {
  display: flex;
  gap: 6px;
}
.pagos-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 20px;
  text-align: center;
  background: var(--bg-soft, #f8f9fc);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.pagos-empty p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* Historial de envíos */
.envios-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.envios-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
}
.envios-list li:last-child { border-bottom: none; }
.envios-list li:first-child {
  font-weight: 600;
  color: var(--primary);
}

/* Ficha resumen del cliente seleccionado */
.client-preview {
  background: var(--primary-50);
  border: 1px solid var(--primary-100);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-top: 12px;
  display: none;
}
.client-preview.show { display: block; }
.client-preview .grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 18px;
  font-size: 13px;
}
.client-preview .label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.client-preview .value { color: var(--text); font-weight: 500; }

/* ==========================================================
   ESTADOS VACÍOS Y LOADERS
   ========================================================== */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 30px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty [data-lucide] {
  width: 44px; height: 44px;
  color: var(--text-soft);
  margin-bottom: 12px;
}
.empty h3 { color: var(--text); margin-bottom: 6px; text-transform: none; letter-spacing: normal; font-size: 16px; }

.loader {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  text-align: center;
  padding: 60px;
}

/* ==========================================================
   PREVIEW DEL PDF
   ========================================================== */
.pdf-preview-frame {
  width: 100%;
  background: #f1f5f9;
  padding: 30px;
  display: flex;
  justify-content: center;
}
.pdf-preview-frame .paper {
  background: #fff;
  width: 800px;
  max-width: 100%;
  box-shadow: var(--shadow-lg);
}

/* ==========================================================
   CREADOR DE FACTURA — split (form izq, preview drcha)
   ========================================================== */
.main-wide { padding: 28px 28px; }

.invoice-editor {
  display: grid;
  grid-template-columns: minmax(440px, 1fr) minmax(520px, 1.2fr);
  gap: 20px;
  align-items: start;
}

.invoice-form { min-width: 0; }

.invoice-preview-pane {
  position: sticky;
  top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
}
.invoice-preview-pane .preview-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.invoice-preview-pane .preview-header span {
  display: flex;
  align-items: center;
  gap: 6px;
}
.invoice-preview-pane .preview-header [data-lucide] { width: 14px; height: 14px; }
.invoice-preview-pane .preview-scroll {
  flex: 1;
  overflow-y: auto;
  background: #f1f5f9;
  padding: 18px;
}
.invoice-preview-pane .preview-paper {
  background: #fff;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  box-shadow: var(--shadow);
  border-radius: 4px;
  min-height: 200px;
}
.invoice-preview-pane .preview-paper .empty {
  border: none;
  background: transparent;
}

@media (max-width: 1100px) {
  .invoice-editor { grid-template-columns: 1fr; }
  .invoice-preview-pane {
    position: static;
    max-height: none;
  }
}
