/* ============================================================
   FactOS — estilos base
   Sistema visual minimalista, foco en formularios y listados.
   ============================================================ */

:root {
  --c-primary: #2563eb;
  --c-primary-hover: #1d4ed8;
  --c-bg: #f8fafc;
  --c-card: #ffffff;
  --c-text: #0f172a;
  --c-text-muted: #64748b;
  --c-border: #e2e8f0;
  --c-border-strong: #cbd5e1;
  --c-success: #10b981;
  --c-danger: #ef4444;
  --c-warning: #f59e0b;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--c-text);
  background: var(--c-bg);
  font-size: 14px;
  line-height: 1.5;
}

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

h1, h2, h3 { color: var(--c-text); margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

/* ── Layout autenticado ──────────────────────────────────── */
.topbar {
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  box-shadow: var(--shadow-sm);
}
.topbar-brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--c-primary);
  text-decoration: none;
}
.topbar-brand:hover { text-decoration: none; }
.topbar-nav {
  display: flex;
  gap: 4px;
  flex: 1;
}
.topbar-nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--c-text-muted);
  font-weight: 500;
}
.topbar-nav a:hover { background: var(--c-bg); color: var(--c-text); text-decoration: none; }
.topbar-nav a.active { background: var(--c-primary); color: #fff; }
.topbar-user {
  color: var(--c-text-muted);
  font-size: 13px;
}
.topbar-user a { margin-left: 12px; color: var(--c-text-muted); }

.container {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 24px;
}

.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--c-border);
}
.card-header h2 { margin: 0; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text);
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--c-text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.btn {
  display: inline-block;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.05s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-hover); color: #fff; }
.btn-secondary { background: #fff; color: var(--c-text); border: 1px solid var(--c-border-strong); }
.btn-secondary:hover { background: var(--c-bg); }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { display: block; width: 100%; }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  border-left: 4px solid;
  font-size: 14px;
}
.alert-error { background: #fef2f2; color: #991b1b; border-left-color: var(--c-danger); }
.alert-success { background: #f0fdf4; color: #166534; border-left-color: var(--c-success); }
.alert-info { background: #eff6ff; color: #1e40af; border-left-color: var(--c-primary); }

/* ── Tablas ──────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--c-border);
}
.table th {
  font-weight: 600;
  color: var(--c-text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--c-bg);
}
.table tbody tr:hover { background: var(--c-bg); }
.table-striped tbody tr:nth-child(odd) { background: #fafbfc; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-borrador { background: #f1f5f9; color: #475569; }
.badge-emitida { background: #d1fae5; color: #065f46; }
.badge-anulada { background: #fee2e2; color: #991b1b; }
.badge-delegado-ok       { background: #d1fae5; color: #065f46; }
.badge-delegado-pendiente{ background: #fef3c7; color: #92400e; }
.badge-procesando        { background: #fef3c7; color: #92400e; }

/* ── Tabla: fila resaltada (emisor no vinculado) ─────────── */
.table tr.highlight > td { background: #fef2f2 !important; }
.table tr.highlight > td:first-child { border-left: 3px solid var(--c-danger); }

/* ── Tooltip (CSS-only, sin jQuery) ──────────────────────── */
.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e2e8f0;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
  margin-left: 4px;
  cursor: help;
  position: relative;
}
.tip:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  white-space: normal;
  width: 240px;
  text-align: center;
  z-index: 100;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.4;
}

/* ── Spinner (CSS puro, sin FontAwesome) ─────────────────── */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid #fbbf24;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Auth pages (login, register) ────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0f4ff 0%, #faf5ff 100%);
  padding: 24px;
}
.auth-card {
  background: var(--c-card);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}
.auth-brand {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  color: var(--c-primary);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.auth-subtitle {
  text-align: center;
  color: var(--c-text-muted);
  margin-bottom: 28px;
  font-size: 14px;
}
.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--c-text-muted);
}

/* ── Dashboard cards ─────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.stat-card-label {
  font-size: 12px;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--c-text);
}

/* ── Utils ───────────────────────────────────────────────── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--c-text-muted); }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; gap: 8px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
