:root {
  --navy: #1E054A;
  --navy-light: #4A1478;
  --coral: #E8735C;
  --magenta: #C026D3;
  --teal: #6FBFC4;
  --cream: #ffffff;
  --cream-text: #F2EEDE;
  --card: #ffffff;
  --border: #e4e1ea;
  --text: #241338;
  --muted: #6b6478;
  --green: #1e7d4d;
  --red: #b3261e;
  --amber: #b8860b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--cream);
  color: var(--text);
}

.topbar {
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-light) 100%);
  color: var(--cream-text);
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.9rem 1.5rem;
}

.brand {
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
  color: var(--magenta);
}

.topbar nav { display: flex; align-items: center; flex: 1; }

.topbar nav a {
  color: var(--cream-text);
  text-decoration: none;
  margin-right: 1.2rem;
  font-size: 0.92rem;
  opacity: 0.85;
}

.topbar nav a:hover { opacity: 1; }

.nav-right { margin-left: auto; display: flex; }
.nav-right a { margin-right: 0; margin-left: 1.2rem; }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
main.main-wide { max-width: 1600px; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0.5rem; }
.table-scroll table { min-width: 1200px; }

h1 {
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
  font-weight: 800;
}

h1, h2 { position: relative; padding-bottom: 0.6rem; }
h1::after, h2::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--magenta), var(--coral));
}

.toolbar h1 { margin-bottom: 0; }

.flashes { margin-bottom: 1rem; }
.flash { padding: 0.6rem 0.9rem; border-radius: 6px; margin-bottom: 0.5rem; font-size: 0.9rem; }
.flash-ok { background: #e3f5ea; color: var(--green); }
.flash-error { background: #fbeaea; color: var(--red); }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

th, td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th { background: var(--navy); color: white; font-weight: 700; }

tr:last-child td { border-bottom: none; }

td a { color: var(--navy-light); text-decoration: none; }
td a:hover { color: var(--magenta); text-decoration: underline; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  background: var(--card);
  padding: 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.filters select, .filters input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.btn {
  display: inline-block;
  background: linear-gradient(90deg, var(--magenta), var(--coral));
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.08); }

.btn-secondary { background: var(--card); color: var(--navy); border: 1px solid var(--navy); }
.btn-danger { background: var(--red); }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

form.inline { display: inline; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem;
  max-width: 520px;
}

.field { margin-bottom: 0.9rem; }
.field label { display: block; margin-bottom: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.92rem;
}

.actions { display: flex; gap: 0.6rem; margin-top: 1rem; }

.pill {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.pill-pendiente { background: #fdf1d6; color: var(--amber); }
.pill-cobrado { background: #e3f5ea; color: var(--green); }
.pill-parcial { background: #eaf0fb; color: var(--navy-light); }
.pill-anulado { background: #f1f1f1; color: var(--muted); }

.margen-bajo { color: var(--red); font-weight: 700; }
.margen-ok { color: var(--green); font-weight: 700; }

.empty { color: var(--muted); font-style: italic; padding: 1rem; }

.cell-input {
  width: 100%;
  min-width: 90px;
  padding: 0.25rem 0.4rem;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
  background: transparent;
  color: inherit;
}
.cell-input:hover { border-color: var(--border); background: #fff; }
.cell-input:focus { border-color: var(--magenta); background: #fff; outline: none; }
.cell-desc { min-width: 220px; }
.cell-monto { min-width: 110px; }

.parte {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.parte input[name="monto"] { flex: 0 0 150px; }
.parte input[name="factura_txt"] { flex: 1; min-width: 0; }

.btn-x {
  flex: 0 0 auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.6rem;
  cursor: pointer;
}
.btn-x:hover { color: var(--red); border-color: var(--red); }

.hint-nuevo {
  font-size: 0.8rem;
  color: var(--magenta);
  margin-top: 0.3rem;
}
.parte select { flex: 1; min-width: 0; }
.parte input, .parte select {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.92rem;
  font-family: inherit;
}

.stat-row { display: flex; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1.2rem;
  min-width: 160px;
}
.stat .label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; }
.stat .value { font-size: 1.3rem; font-weight: 700; color: var(--navy); }

/* ---- Tarjetas de clientes ---- */
.cli-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.cli-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  text-align: left;
}
.cli-inactivo { opacity: 0.6; background: #f4f2f7; }
.cli-head { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.9rem; }
.logo-form { margin: 0; }
.logo-circle {
  width: 52px; height: 52px; border-radius: 50%;
  background: #ece8f3; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: pointer; flex: 0 0 auto;
}
.logo-circle img { width: 100%; height: 100%; object-fit: cover; }
.logo-inicial { font-weight: 800; color: var(--navy-light); font-size: 1.3rem; }
.cli-nombre { font-weight: 700; color: var(--navy); text-decoration: none; font-size: 1.02rem; }
.cli-nombre:hover { color: var(--magenta); }
.cli-stats { display: flex; flex-direction: column; gap: 0.5rem; }
.cli-stats > div { display: flex; flex-direction: column; }
.cli-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; }
.cli-val { font-size: 0.98rem; font-weight: 600; color: var(--text); }

/* ---- Tarjetas de freelancers ---- */
.fl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}
.fl-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 0.8rem;
  text-align: center;
}
.fl-avatar {
  width: 92px; height: 92px; border-radius: 14px;
  background: #ece8f3; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: pointer; margin: 0 auto 0.7rem;
}
.fl-avatar img { width: 100%; height: 100%; object-fit: cover; filter: grayscale(1); }
.fl-inicial { font-weight: 800; color: var(--navy-light); font-size: 2rem; }
.fl-avatar-sm { width: 42px; height: 42px; margin: 0; }
.fl-avatar-sm .fl-inicial { font-size: 1rem; }
.fl-avatar-redonda { border-radius: 50%; }
.fl-nombre { display: block; font-weight: 700; color: var(--navy); text-decoration: none; }
.fl-nombre:hover { color: var(--magenta); }
.fl-cuentas { font-size: 0.85rem; color: var(--muted); margin-top: 0.5rem; }

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  margin-top: 0.45rem;
}
.pill-esp {
  display: inline-block;
  padding: 0.24rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 400;
  color: #fff;
  background: linear-gradient(90deg, var(--magenta), var(--coral));
  white-space: nowrap;
}

.vista-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.vista-toggle a {
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--navy);
  background: var(--card);
}
.vista-toggle a.on { background: var(--navy); color: #fff; }

.subtabs { display: flex; gap: 0.3rem; margin-bottom: 1.4rem; border-bottom: 1px solid var(--border); }
.subtabs a {
  padding: 0.5rem 1rem;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  border-bottom: 2px solid transparent;
}
.subtabs a.on { color: var(--navy); border-bottom-color: var(--magenta); }

/* ---- Selector de período ---- */
.periodo {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1.2rem;
}
.periodo label { font-size: 0.8rem; color: var(--muted); }
.periodo input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}
.periodo-atajos { margin-left: auto; display: flex; gap: 0.8rem; }
.periodo-atajos a { font-size: 0.82rem; color: var(--navy-light); text-decoration: none; }
.periodo-atajos a:hover { color: var(--magenta); text-decoration: underline; }

/* ---- Gráfico de barras ---- */
.chart-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem 0.8rem;
  margin-bottom: 1.5rem;
}
.chart-legend { display: flex; gap: 1.2rem; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.8rem; }
.chart-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 0.35rem; }
.chart {
  display: flex;
  align-items: flex-end;
  gap: 0.8rem;
  overflow-x: auto;
  padding-top: 0.5rem;
}
.chart-col { flex: 1 1 0; min-width: 64px; text-align: center; }
.chart-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  height: 190px;
  border-bottom: 1px solid var(--border);
}
.bar { width: 18px; border-radius: 4px 4px 0 0; min-height: 2px; transition: opacity .15s; }
.bar:hover { opacity: 0.75; }
.bar-in { background: var(--teal); }
.bar-eg { background: var(--coral); }
.bar-op { background: var(--magenta); }
.dot.bar-in { background: var(--teal); }
.dot.bar-eg { background: var(--coral); }
.dot.bar-op { background: var(--magenta); }
.svg-chart { width: 100%; height: 230px; display: block; }
.chart-eje {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 0.35rem;
}
.chart-x { font-size: 0.75rem; color: var(--muted); margin-top: 0.4rem; }
.chart-neto { font-size: 0.72rem; font-weight: 700; }
.chart-hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.6rem; }

.demo-banner {
  background: linear-gradient(90deg, var(--magenta), var(--coral));
  color: #fff;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.4rem 1rem;
}

.mes-titulo {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin: 1.2rem 0 0.4rem;
}

.pill-sug {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--magenta);
  background: #f6e3fb;
  vertical-align: middle;
}

/* Subtítulos de sección ACTIVOS / INACTIVOS: jerarquía distinta al h1/h2 */
.subhead-activo, .subhead-inactivo {
  color: var(--magenta);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
  font-weight: 800;
  padding-bottom: 0;
}
.subhead-activo::after, .subhead-inactivo::after { display: none; }
.subhead-inactivo { color: #b58bc0; }

/* Perfil de freelancer */
.fl-perfil { display: flex; gap: 1.4rem; align-items: flex-start; margin-bottom: 1.5rem; }
.fl-avatar-hint { font-size: 0.72rem; color: var(--muted); text-align: center; margin-top: 0.35rem; }

/* Página pública de carga de facturas */
body.publica {
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-light) 100%);
  min-height: 100vh;
}
.pub-wrap { max-width: 520px; margin: 0 auto; padding: 2.5rem 1.2rem 3rem; }
.pub-brand { font-weight: 800; font-size: 1.4rem; color: var(--magenta); margin-bottom: 1.4rem; }
.pub-title { color: var(--cream-text); font-size: 1.6rem; font-weight: 800; margin: 0 0 0.4rem; padding: 0; }
.pub-title::after { display: none; }
.pub-sub { color: #cfc7dd; font-size: 0.95rem; margin: 0 0 1.4rem; }
.pub-card { background: #fff; border-radius: 12px; padding: 1.4rem; }
.pub-card .field input, .pub-card .field select { font-size: 0.95rem; }
.pub-info {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(242,238,222,0.2);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  margin-bottom: 1.4rem;
  color: #e8e2f0;
  font-size: 0.9rem;
}
.pub-info p { margin: 0.5rem 0; }
.pub-info hr { border: none; border-top: 1px solid rgba(242,238,222,0.2); margin: 0.8rem 0; }
.field-hint { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.pub-card .field-hint { color: #7a7488; }

/* ---- Dropdown de navegación ---- */
.nav-drop { position: relative; display: inline-block; }
.nav-drop > a::after { content: " ▾"; font-size: 0.75em; }
.nav-drop-menu {
  display: none; position: absolute; top: 100%; left: 0;
  background: var(--navy-light); border-radius: 8px; padding: 0.4rem 0;
  min-width: 190px; box-shadow: 0 6px 20px rgba(0,0,0,0.25); z-index: 20;
}
.nav-drop:hover .nav-drop-menu { display: block; }
.nav-drop-menu a { display: block; margin: 0 !important; padding: 0.5rem 1rem; white-space: nowrap; }
