:root {
  --ink: #1b2430;
  --muted: #5e584f;
  --paper: #f3efe6;
  --card: #fffdf8;
  --line: #e4d9c8;
  --navy: #1b2838;
  --navy-2: #243447;
  --copper: #9a3d1d;
  --copper-dark: #7c2f14;
  --green: #1d6b48;
  --danger: #8d2424;
  --shadow: 0 10px 30px rgba(27, 36, 48, 0.06);
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

a { color: var(--copper-dark); }
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.02em; }
h1 { margin: 0 0 6px; font-size: 2rem; }
h2 { margin: 0; font-size: 1.25rem; }
p { margin: 0 0 8px; }

.shell { display: flex; min-height: 100vh; }
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.nav-burger {
  display: none;
  margin: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
}

.sidebar {
  width: 240px;
  flex: none;
  background: var(--navy);
  color: #f6f1e8;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
}
.marca {
  display: flex;
  gap: 10px;
  align-items: center;
  color: inherit;
  text-decoration: none;
  margin-bottom: 28px;
}
.marca strong { display: block; font-family: var(--serif); font-size: 1.2rem; }
.marca small { color: #c8bba8; letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.68rem; }
.marca-sigla {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid #c98462;
  color: #f3d2c2;
  font-family: var(--serif);
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  color: #e7dfd3;
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 8px;
}
.nav a.is-active, .nav a:hover { background: rgba(255, 255, 255, 0.08); }
.sidebar-user { margin-top: auto; display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; }
.sidebar-user span { color: #c8bba8; }
.btn-ghost {
  margin-top: 8px;
  background: transparent;
  color: #f6f1e8;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}

.main { flex: 1; min-width: 0; padding: 28px 32px 56px; }
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card, .panel, .form-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.login-card { width: min(420px, 100%); padding: 28px; }
.panel { padding: 18px; margin-top: 16px; }
.form-card { max-width: 720px; }

.page-head, .panel-head, .acciones {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.eyebrow { margin: 0 0 4px; color: var(--copper); letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.75rem; }
.lead, .help, .vacio { color: var(--muted); }
.help { font-size: 0.88rem; margin-top: 4px; }

.btn, .btn-secondary, .btn-danger, .btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  padding: 10px 14px;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  font: inherit;
}
.btn { background: var(--copper); color: white; }
.btn:hover { background: var(--copper-dark); }
.btn-secondary { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-danger { background: transparent; border-color: #e4b4b4; color: var(--danger); }
.btn-text { background: transparent; color: var(--danger); padding: 8px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field span, label { font-size: 0.92rem; font-weight: 600; }
.input, input:not([type="checkbox"]), select, textarea {
  width: 100%;
  border: 1px solid #d9cdb8;
  background: white;
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  color: var(--ink);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #e7c3b2; border-color: var(--copper); }
.checkline { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0 14px; font-weight: 600; }
.checkline input { width: auto; margin-top: 3px; }
.field ul { list-style: none; padding: 0; margin: 8px 0 0; }
.field li { margin: 6px 0; }
.field li label { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.errorlist { color: var(--danger); list-style: none; padding: 0; margin: 4px 0 0; font-size: 0.86rem; }
.banner-error, .messages .error { background: #fdecec; color: var(--danger); border-radius: 10px; padding: 10px 12px; }
.messages { list-style: none; padding: 0; margin: 0 0 12px; }
.messages li { border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.messages .success { background: #e7f6ee; color: var(--green); }
.messages .info { background: #e8eef8; color: #1e3a5f; }
.messages .warning { background: #fff4e0; color: #7a4b00; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 18px; }
.stats article, .buscar, .filtros { background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.stats article { padding: 14px 16px; }
.stats span, .stats small { color: var(--muted); display: block; }
.stats strong { font-family: var(--serif); font-size: 1.6rem; }
.buscar, .filtros { display: flex; gap: 10px; align-items: end; padding: 12px; margin-top: 14px; flex-wrap: wrap; }
.buscar .input, .filtros .field { margin: 0; min-width: 160px; flex: 1; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.acciones-celda { white-space: nowrap; }
.acciones-celda a { margin-right: 10px; }
.paginacion { display: flex; gap: 12px; align-items: center; margin-top: 12px; }

.layout-factura { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.resumen { position: sticky; top: 16px; }
.resumen .btn, .resumen .btn-secondary { width: 100%; margin-top: 8px; }
.total-row { display: flex; justify-content: space-between; gap: 12px; margin: 8px 0; }
.total-final { border-top: 1px solid var(--line); padding-top: 8px; font-size: 1.15rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lineas-panel { margin-top: 16px; }
.linea {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 90px 110px 140px 110px auto;
  gap: 8px;
  align-items: end;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.linea .field { margin: 0; }
.linea-total { display: block; padding: 9px 0; text-align: right; }

.detalle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.estado {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e8f1fb;
  color: #026ad0;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.4;
}
.estado-aceptada { background: #fff4d6; color: #8a5a00; }
.estado-pagada { background: #e7f6e4; color: #1f6b2a; }
.estado-anulada { background: #fde8e8; color: #9b1c1c; }
.totales-lectura { margin: 14px 0 0 auto; width: min(320px, 100%); }
.totales-lectura div { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.totales-lectura dt { color: var(--muted); }
.totales-lectura dd { margin: 0; font-weight: 700; }
.pdf-frame { width: 100%; height: 820px; border: 1px solid var(--line); border-radius: 10px; background: white; }

@media (max-width: 900px) {
  .nav-burger { display: inline-flex; }
  .shell { display: block; }
  .sidebar { display: none; width: auto; height: auto; position: static; }
  .nav-toggle:checked ~ .sidebar { display: flex; }
  .main { padding: 8px 14px 40px; }
  .stats, .layout-factura, .detalle-grid, .grid-2, .linea { grid-template-columns: 1fr; }
  .resumen { position: static; }
}

@media print {
  .sidebar, .nav-burger, .btn, .btn-secondary, .btn-danger, .buscar, .filtros { display: none !important; }
  .main { padding: 0; }
  body { background: white; }
}
