:root {
	--bg: #f2f4f1;
	--surface: #ffffff;
	--surface-2: #f7f8f5;
	--border: #dde2d9;
	--border-strong: #c3cbbf;
	--ink: #17201c;
	--muted: #5d6a63;
	--muted-2: #8f9a93;

	--brand: #0f5e4f;
	--brand-dark: #0a4539;
	--brand-light: #dcede7;

	--amber: #a8661b;
	--amber-light: #f6e8d2;
	--ok: #2b7a4b;
	--ok-light: #dcefe2;
	--danger: #ab3b2f;
	--danger-light: #f7e0db;
	--info: #245f94;
	--info-light: #deeaf6;

	--radius-sm: 7px;
	--radius-md: 11px;

	--shadow-sm: 0 1px 2px rgba(23, 32, 28, .06);
	--shadow-md: 0 4px 14px rgba(23, 32, 28, .08);
	--shadow-lift: 0 8px 24px rgba(23, 32, 28, .14);

	--topbar-h: 58px;
	--sidebar-w: 230px;
	color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	background: var(--bg);
	color: var(--ink);
	-webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 {
	font-family: "Sora", "Inter", system-ui, sans-serif;
	font-weight: 700;
	letter-spacing: -.01em;
	text-wrap: balance;
}
h1 { font-size: 1.45rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }

.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .86em; }

/* --- Barra superior y navegación --- */
.topbar {
	display: flex; align-items: center; gap: .7rem;
	height: var(--topbar-h); padding: 0 1.1rem;
	background: var(--surface); border-bottom: 1px solid var(--border);
	position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .55rem; font-family: "Sora", sans-serif; font-weight: 700; color: var(--ink); }
.brand:hover { text-decoration: none; }
.mark {
	width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: #fff;
	display: flex; align-items: center; justify-content: center; font-size: .78rem; font-weight: 700; flex: none;
}
.topbar .despacho { color: var(--muted); font-size: .85rem; padding-left: .7rem; border-left: 1px solid var(--border); }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--muted); font-size: .85rem; font-weight: 500; }
.topbar form { margin: 0; }

.menu-toggle { background: none; border: 0; padding: .3rem; min-height: auto; color: var(--ink); cursor: pointer; display: flex; }
.menu-toggle svg { width: 22px; height: 22px; }
.menu-toggle:hover { background: none; color: var(--brand); }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 20, 18, .4); z-index: 35; }
.sidebar-backdrop.open { display: block; }
.sidebar {
	position: fixed; top: 0; bottom: 0; left: 0; width: var(--sidebar-w);
	background: var(--surface); border-right: 1px solid var(--border);
	padding: 1rem .6rem; display: flex; flex-direction: column; gap: .15rem;
	transform: translateX(-100%); transition: transform .2s ease; z-index: 40;
}
.sidebar.open { transform: none; box-shadow: var(--shadow-lift); }
.sidebar a {
	display: flex; align-items: center; gap: .75rem; padding: .65rem .85rem;
	border-radius: var(--radius-sm); font-size: .9rem; font-weight: 600; color: var(--muted);
}
.sidebar a svg { width: 19px; height: 19px; stroke: currentColor; flex: none; }
.sidebar a:hover { color: var(--brand); background: var(--surface-2); text-decoration: none; }
.sidebar a.active { color: var(--brand); background: var(--brand-light); }
.sidebar .nav-label {
	font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
	color: var(--muted-2); padding: 1rem .85rem .35rem;
}

@media (min-width: 1024px) {
	.menu-toggle { display: none; }
	.sidebar-backdrop { display: none !important; }
	.sidebar { top: var(--topbar-h); transform: none; box-shadow: none; }
}

.container { max-width: 1180px; margin: 0 auto; padding: 1.4rem 1rem 3rem; }
@media (min-width: 1024px) { .container { margin-left: var(--sidebar-w); padding: 1.6rem 2rem 3rem; } }

/* --- Tarjetas y formularios --- */
.card {
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
	box-shadow: var(--shadow-sm); padding: 1.15rem 1.25rem; margin-bottom: 1.1rem;
}
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 1rem 1.25rem 0; }
.card.auth { max-width: 420px; margin: 3rem auto; box-shadow: var(--shadow-md); }
.card.auth.ancho { max-width: 520px; }
.lockup { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.2rem; font-family: "Sora", sans-serif; font-weight: 700; }

label { display: block; margin-bottom: .85rem; font-size: .82rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
	width: 100%; padding: .58rem .7rem; margin-top: .3rem;
	border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
	font: 14px/1.4 "Inter", inherit; background: var(--surface); color: var(--ink);
}
textarea { min-height: 4rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--brand); }
input[type="file"] { padding: .45rem; background: var(--surface-2); }

.row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; }
.row > * { flex: 1 1 150px; }
.row > .shrink { flex: 0 0 auto; }
.field-hint { font-size: .76rem; color: var(--muted-2); margin-top: .3rem; font-weight: 400; }

.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; color: var(--ink); margin-bottom: .4rem; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .1rem 1rem; margin: .4rem 0 1rem; }
.check-grid .check { font-size: .84rem; }
.check-grid .clave { color: var(--muted-2); font-variant-numeric: tabular-nums; }

button, .btn {
	display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
	min-height: 40px; padding: .5rem 1.05rem; border: 0; border-radius: var(--radius-sm);
	background: var(--brand); color: #fff; font: 600 .88rem "Inter", inherit;
	cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--brand-dark); text-decoration: none; }
button.link { background: none; color: var(--brand); padding: 0; min-height: auto; font-weight: 600; }
button.link:hover { background: none; text-decoration: underline; }
.btn.ghost, button.ghost { background: transparent; color: var(--brand); border: 1px solid var(--border-strong); }
.btn.ghost:hover, button.ghost:hover { background: var(--surface-2); border-color: var(--brand); }
.btn.small, button.small { min-height: 32px; padding: .3rem .75rem; font-size: .8rem; }

.alert { padding: .7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem; font-size: .9rem; font-weight: 500; }
.alert.error { background: var(--danger-light); color: var(--danger); }
.alert.info { background: var(--brand-light); color: var(--brand-dark); }
.alert.warn { background: var(--amber-light); color: var(--amber); }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.section-title {
	font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
	color: var(--muted-2); margin: 1.5rem 0 .6rem;
}
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: .6rem 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: .2rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }

/* --- Pills de estado --- */
.pill {
	display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem;
	border-radius: 999px; font-size: .72rem; font-weight: 600; white-space: nowrap;
	background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-light); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--amber-light); color: var(--amber); border-color: transparent; }
.pill.bad { background: var(--danger-light); color: var(--danger); border-color: transparent; }
.pill.info { background: var(--info-light); color: var(--info); border-color: transparent; }
.tag { display: inline-block; padding: .05rem .45rem; border-radius: 5px; font-size: .72rem; font-weight: 700; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.tag.I { background: var(--ok-light); color: var(--ok); border-color: transparent; }
.tag.E { background: var(--amber-light); color: var(--amber); border-color: transparent; }
.tag.P { background: var(--info-light); color: var(--info); border-color: transparent; }
.tag.N { background: var(--brand-light); color: var(--brand-dark); border-color: transparent; }

/* --- Tablas --- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th {
	text-align: left; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
	color: var(--muted-2); padding: .6rem .75rem; border-bottom: 1px solid var(--border); white-space: nowrap;
	background: var(--surface-2);
}
td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbf8; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border-strong); }
td .sub { display: block; color: var(--muted); font-size: .78rem; }
tr.cancelado td { color: var(--muted-2); text-decoration: line-through; }
.empty { padding: 1.4rem 1.25rem; color: var(--muted); }

/* --- Indicadores --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1.3rem; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); padding: .9rem 1rem; }
.stat-tile .valor { font-family: "Sora", sans-serif; font-weight: 800; font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-tile .label { font-size: .78rem; color: var(--muted); margin-top: .25rem; }
.stat-tile.alerta .valor { color: var(--danger); }

/* --- Encabezado de RFC y pestañas --- */
.rfc-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: .3rem; }
.rfc-head h1 { margin: 0; font-size: 1.45rem; letter-spacing: .02em; }
.crumb { font-size: .84rem; color: var(--muted); margin-bottom: .5rem; }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin: 1rem 0 1.2rem; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a {
	padding: .6rem .9rem; font-size: .88rem; font-weight: 600; color: var(--muted);
	border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--brand); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

.filtros { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filtros label { margin: 0; flex: 0 1 150px; }
.filtros label.grow { flex: 1 1 220px; }

.paginacion { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1.25rem; border-top: 1px solid var(--border); font-size: .85rem; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem 1.4rem; margin: 0; }
.info-grid dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 700; margin-bottom: .15rem; }
.info-grid dd { margin: 0; font-size: .92rem; word-break: break-word; }

.grid-2 { display: grid; gap: 1.1rem; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; } }

.nota { font-size: .8rem; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: .6rem .8rem; margin-top: .8rem; }

details.user-edit summary { cursor: pointer; color: var(--brand); font-weight: 600; font-size: .84rem; }
details.user-edit[open] { background: var(--surface-2); border-radius: var(--radius-sm); padding: .6rem; }

/* --- Vista tipo factura --- */
.factura {
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
	box-shadow: var(--shadow-md); padding: 1.6rem 1.8rem; display: flex; flex-direction: column; gap: 1.3rem;
	border-top: 4px solid var(--brand);
}
.factura-head { display: grid; gap: 1rem 2rem; }
@media (min-width: 800px) { .factura-head { grid-template-columns: 1.3fr 1fr; } }
.factura-emisor { font-family: "Sora", sans-serif; font-weight: 800; font-size: 1.25rem; color: var(--brand); }
.factura-meta { margin: 0; background: var(--surface-2); border-radius: var(--radius-sm); padding: .8rem 1rem; display: grid; gap: .5rem; }
.factura-meta dt, .factura .etiqueta { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); }
.factura-meta dd { margin: 0; font-size: .88rem; word-break: break-all; }
.factura-receptor { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: .8rem 0; }
.factura-conceptos th { background: var(--brand); color: #fff; }
.factura-pie { display: grid; gap: 1rem 2rem; }
@media (min-width: 800px) { .factura-pie { grid-template-columns: 1.3fr 1fr; } }
.factura-pago { margin: 0; display: grid; gap: .5rem; font-size: .88rem; }
.factura-pago dt { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); }
.factura-pago dd { margin: 0; }
.factura-totales { font-size: .92rem; }
.factura-totales td { border: 0; padding: .3rem .5rem; }
.factura-totales tr.total td { background: var(--brand); color: #fff; font-weight: 800; font-size: 1.05rem; font-family: "Sora", sans-serif; }
.factura-timbre { display: flex; gap: 1.2rem; align-items: flex-start; border-top: 1px dashed var(--border-strong); padding-top: 1rem; font-size: .8rem; }
.factura-timbre .qr svg { width: 118px; height: 118px; display: block; }
.factura-timbre .sellos { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .5rem; }
.factura-timbre code { display: block; font-size: .68rem; word-break: break-all; background: var(--surface-2); padding: .4rem .5rem; border-radius: 5px; margin: .2rem 0 .5rem; }
.factura-timbre summary { cursor: pointer; color: var(--brand); font-weight: 600; }

/* --- Gráficas y KPIs --- */
.chart-card { position: relative; }
.chart-box { position: relative; height: 280px; }
.kpi-sub { font-size: .75rem; color: var(--muted-2); margin-top: .2rem; }
.stat-tile.pos .valor { color: var(--ok); }
.stat-tile.neg .valor { color: var(--danger); }
.leyenda { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .8rem; color: var(--muted); margin-bottom: .6rem; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }

/* --- Declaraciones --- */
.decl-resumen { display: grid; gap: 1rem; margin-bottom: 1.2rem; }
@media (min-width: 900px) { .decl-resumen { grid-template-columns: 1.2fr 1fr; } }
.decl-total { background: var(--brand); color: #fff; border-radius: var(--radius-md); padding: 1.2rem 1.4rem; box-shadow: var(--shadow-md); }
.decl-total .label { font-size: .78rem; opacity: .85; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.decl-total .valor { font-family: "Sora", sans-serif; font-weight: 800; font-size: 2.2rem; line-height: 1.15; margin: .2rem 0; font-variant-numeric: tabular-nums; }
.decl-total ul { list-style: none; margin: .7rem 0 0; padding: 0; font-size: .9rem; }
.decl-total li { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; border-top: 1px solid rgba(255,255,255,.18); }
.papel td:first-child { width: 55%; }
.papel tr.res td { font-weight: 800; background: var(--brand-light); color: var(--brand-dark); }
.papel .nota-linea { display: block; font-size: .74rem; color: var(--muted-2); }
.meses-bar { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1rem; }
.meses-bar a { padding: .35rem .6rem; border-radius: 6px; font-size: .8rem; font-weight: 600; color: var(--muted); border: 1px solid var(--border); background: var(--surface); }
.meses-bar a:hover { text-decoration: none; border-color: var(--brand); color: var(--brand); }
.meses-bar a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.meses-bar a.presentada { border-color: var(--ok); }
.meses-bar a.presentada::after { content: " ✓"; color: var(--ok); }
.meses-bar a.active.presentada::after { color: #fff; }
.descarga-masiva { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .8rem 1.1rem; }
.descarga-masiva .btn-row { margin-left: auto; }
td.acciones { white-space: nowrap; }
td.acciones a + a { margin-left: .4rem; }

/* --- Submenú de impuestos (Declaración) --- */
.impuestos-tabs { display: flex; gap: .5rem; overflow-x: auto; scrollbar-width: none; margin: 0 0 1.1rem; padding-bottom: .1rem; }
.impuestos-tabs a {
	flex: 0 0 auto; display: flex; flex-direction: column; gap: .1rem; min-width: 120px;
	padding: .55rem .9rem; border-radius: var(--radius-md); background: var(--surface);
	border: 1px solid var(--border); color: var(--muted); box-shadow: var(--shadow-sm);
}
.impuestos-tabs a span { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.impuestos-tabs a strong { font-family: "Sora", sans-serif; font-size: 1rem; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.impuestos-tabs a:hover { border-color: var(--brand); text-decoration: none; }
.impuestos-tabs a.active { background: var(--brand); border-color: var(--brand); color: rgba(255,255,255,.85); }
.impuestos-tabs a.active strong { color: #fff; }
.impuestos-tabs a.inactiva strong { color: var(--muted-2); font-size: .85rem; font-family: "Inter", sans-serif; }
.impuestos-tabs a.active.inactiva strong { color: #fff; }
tbody.grupo tr.grupo-titulo td { background: var(--surface-2); border-top: 1px solid var(--border-strong); }
tr.fila-activa td { background: var(--brand-light); }

/* --- Estado de sincronización con el SAT --- */
.sync-card { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 2rem; }
.sync-estado { display: flex; align-items: center; gap: .9rem; flex: 1 1 260px; }
.sync-icono { width: 46px; height: 46px; border-radius: 12px; background: var(--surface-2); color: var(--muted); display: flex; align-items: center; justify-content: center; flex: none; }
.sync-icono.ok { background: var(--ok-light); color: var(--ok); }
.sync-icono.bad { background: var(--danger-light); color: var(--danger); }
.sync-icono svg { width: 24px; height: 24px; }
.sync-fecha { font-family: "Sora", sans-serif; font-weight: 800; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.sync-card .etiqueta { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); }
.sync-auto { flex: 1 1 200px; font-size: .9rem; }
.sync-acciones form { margin: 0; }
.rfc-sync { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.rfc-sync a { color: inherit; }
.rfc-sync strong { color: var(--ink); font-weight: 600; }
.sync-ahora { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; }

/* --- Elección de plan en el registro y uso del plan en el menú --- */
.planes-registro { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.plan-opcion { margin: 0; cursor: pointer; }
.plan-opcion input { position: absolute; opacity: 0; pointer-events: none; }
.plan-opcion-cuerpo {
	display: flex; flex-direction: column; gap: .15rem; padding: .75rem .8rem; border-radius: var(--radius-md);
	border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.plan-opcion-cuerpo strong { font-family: "Sora", sans-serif; font-size: .95rem; }
.plan-opcion-rfcs { font-size: .8rem; color: var(--muted); font-weight: 500; }
.plan-opcion-precio { font-family: "Sora", sans-serif; font-weight: 800; font-size: 1.1rem; }
.plan-opcion-precio small { font-family: "Inter", sans-serif; font-weight: 500; font-size: .7rem; color: var(--muted); }
.plan-opcion input:checked + .plan-opcion-cuerpo { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
.plan-opcion input:focus-visible + .plan-opcion-cuerpo { outline: 2px solid var(--brand); outline-offset: 2px; }
.plan-uso { margin-top: auto; padding: .8rem .85rem; border-top: 1px solid var(--border); font-size: .8rem; color: var(--muted); }
.plan-uso strong { color: var(--ink); }
.plan-uso .barra { height: 6px; background: var(--surface-2); border-radius: 99px; margin: .45rem 0 .2rem; overflow: hidden; border: 1px solid var(--border); }
.plan-uso .barra i { display: block; height: 100%; background: var(--brand); }
.plan-uso .barra i.lleno { background: var(--amber); }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; min-width: 20px; height: 20px; border-radius: 99px; display: inline-flex; align-items: center; justify-content: center; padding: 0 .35rem; }
a.plan-uso { display: block; color: var(--muted); font-weight: 400; text-decoration: none; border-radius: 0; }
a.plan-uso:hover { background: var(--surface-2); text-decoration: none; }
