:root {
  --bg:#f6f4f1; --card:#fff; --txt:#231f1b; --sub:#655d56; --line:#e8e3dd; --soft:#faf8f6;
  --brand:#a34d10; --brand-d:#873f0b; --sobre:#fff; --borde:#908679; --brand-soft:#fbeee2; --ok:#17803d; --ok-soft:#e5f4ea; --bad:#b42318; --bad-soft:#fdecea;
  --sombra:0 1px 2px rgba(35,31,27,.06), 0 4px 14px rgba(35,31,27,.05); --r:14px;
}
@media (prefers-color-scheme: dark) { :root {
  --bg:#171412; --card:#211d1a; --txt:#f3eee9; --sub:#a39a92; --line:#352f2a; --soft:#2a2521;
  --brand:#e8964f; --brand-d:#f1ab6c; --sobre:#1c1207; --borde:#7d7268; --brand-soft:#3a2a1d; --ok:#5fcf86; --ok-soft:#1d3226; --bad:#ff8a80; --bad-soft:#3b2220;
  --sombra:0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.25); } }
* { box-sizing:border-box; }
body { margin:0; font-family:"Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background:var(--bg); color:var(--txt); font-size:15px; line-height:1.45; -webkit-font-smoothing:antialiased; }
svg.i { width:18px; height:18px; flex:none; stroke:currentColor; fill:none; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }

/* Cabecera */
header { background:var(--card); border-bottom:1px solid var(--line); position:sticky; top:0; z-index:20; }
.hd { max-width:1180px; margin:0 auto; padding:0 20px; display:flex; align-items:center; gap:22px; height:62px; }
.marca { display:flex; align-items:center; gap:10px; font-weight:700; letter-spacing:-.01em; }
.marca img { height:36px; width:auto; border-radius:6px; }
.marca small { display:block; font-weight:500; color:var(--sub); font-size:.72rem; letter-spacing:.04em; text-transform:uppercase; }
nav { display:flex; gap:4px; flex:1; height:100%; }
nav button { display:flex; align-items:center; gap:8px; border:0; background:none; color:var(--sub); padding:0 14px; height:100%; font:inherit; font-weight:600; cursor:pointer; border-bottom:3px solid transparent; }
nav button:hover { color:var(--txt); }
nav button.act { color:var(--brand); border-bottom-color:var(--brand); }

main { max-width:1180px; margin:0 auto; padding:26px 20px 60px; }
h2.t { font-size:1.55rem; margin:0; letter-spacing:-.02em; }
.cab { display:flex; align-items:center; gap:14px; flex-wrap:wrap; margin-bottom:18px; }
.cab .esp { flex:1; }

/* Botones */
.btn { display:inline-flex; align-items:center; justify-content:center; gap:8px; border:1px solid var(--line); background:var(--card); color:var(--txt); padding:9px 16px; border-radius:10px; cursor:pointer; font:inherit; font-weight:600; text-decoration:none; transition:.12s; }
.btn:hover { border-color:var(--brand); color:var(--brand); }
.btn.pri { background:var(--brand); color:var(--sobre); border-color:var(--brand); box-shadow:0 2px 8px rgba(184,90,24,.28); }
.btn.pri:hover { background:var(--brand-d); color:var(--sobre); }
.btn.mal { color:var(--bad); } .btn.mal:hover { background:var(--bad-soft); border-color:var(--bad); color:var(--bad); }
.btn.sm { padding:5px 10px; font-size:.85rem; }
.btn.block { width:100%; }

/* Formularios */
input, select, textarea { width:100%; min-height:44px; padding:10px 12px; border:1px solid var(--borde); border-radius:10px; background:var(--card); color:var(--txt); font:inherit; transition:.12s; }
input:focus, select:focus, textarea:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-soft); }
label { display:block; font-size:.78rem; font-weight:600; color:var(--sub); margin-bottom:5px; letter-spacing:.02em; }
.buscar { position:relative; flex:1; min-width:220px; max-width:460px; }
.buscar svg { position:absolute; left:12px; top:50%; transform:translateY(-50%); color:var(--sub); }
.buscar input { padding-left:40px; }

/* Tarjetas y resumen */
.card { background:var(--card); border:1px solid var(--line); border-radius:var(--r); box-shadow:var(--sombra); padding:20px; margin-bottom:16px; }
.card.flush { padding:0; overflow:hidden; }
.card h3 { margin:0 0 14px; font-size:1rem; display:flex; align-items:center; gap:8px; }
.card h3 svg { color:var(--brand); }
.stats { display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); gap:14px; margin-bottom:18px; }
.stat { background:var(--card); border:1px solid var(--line); border-radius:var(--r); padding:14px 18px; box-shadow:var(--sombra); }
.stat span { display:block; font-size:.75rem; font-weight:600; color:var(--sub); text-transform:uppercase; letter-spacing:.05em; }
.stat b { font-size:1.5rem; letter-spacing:-.02em; }

/* Tablas */
table { width:100%; border-collapse:collapse; }
th, td { padding:12px 16px; border-bottom:1px solid var(--line); text-align:left; }
th { font-size:.72rem; color:var(--sub); text-transform:uppercase; letter-spacing:.06em; background:var(--soft); }
tbody tr:last-child td { border-bottom:0; }
tbody tr.fila { cursor:pointer; transition:.1s; } tbody tr.fila:hover { background:var(--brand-soft); }
td.r, th.r { text-align:right; white-space:nowrap; font-variant-numeric:tabular-nums; }
.num { display:inline-block; min-width:44px; text-align:center; padding:2px 9px; border-radius:99px; background:var(--brand-soft); color:var(--brand); font-weight:700; font-size:.85rem; }
.cli b { display:block; font-weight:600; } .cli small { color:var(--sub); }
.vacio { padding:46px; text-align:center; color:var(--sub); }

/* Editor */
.editor { display:grid; grid-template-columns:minmax(0,1fr) 320px; gap:20px; align-items:start; }
.lateral { position:sticky; top:82px; }
.grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:14px; }
.lineas { overflow-x:auto; }
.lineas table { min-width:640px; }
.lineas th { position:static; padding:8px 8px; background:none; }
.lineas td { padding:6px 6px; border:0; }
.lineas input { padding:8px 10px; }
.lineas td.imp { font-weight:600; font-variant-numeric:tabular-nums; text-align:right; white-space:nowrap; }
.lineas input.r { text-align:right; }
.resumen { display:flex; flex-direction:column; gap:8px; }
.resumen div { display:flex; justify-content:space-between; color:var(--sub); }
.resumen div.tt { border-top:2px solid var(--txt); margin-top:6px; padding-top:12px; color:var(--txt); font-size:1.15rem; font-weight:700; align-items:baseline; }
.resumen div.tt b { font-size:1.7rem; letter-spacing:-.02em; color:var(--brand); }
.acciones { display:flex; gap:10px; flex-wrap:wrap; margin-top:16px; }
.lateral .acciones { flex-direction:column; }
.etiqueta { display:inline-flex; align-items:center; gap:6px; padding:4px 12px; border-radius:99px; background:var(--brand-soft); color:var(--brand); font-weight:700; font-size:.85rem; }

/* Avisos y sugerencias */
.msg { padding:12px 16px; border-radius:12px; margin-bottom:16px; font-weight:500; }
.msg.ok { background:var(--ok-soft); color:var(--ok); } .msg.err { background:var(--bad-soft); color:var(--bad); }
.sug { position:absolute; left:0; right:0; background:var(--card); border:1px solid var(--line); border-radius:12px; z-index:9; box-shadow:0 12px 30px rgba(0,0,0,.18); overflow:hidden; margin-top:4px; }
.sug div { padding:10px 14px; cursor:pointer; } .sug div:hover { background:var(--brand-soft); }
.sug small { color:var(--sub); }

/* Acceso */
.fondo { min-height:100vh; display:grid; place-items:center; padding:20px; background:radial-gradient(1000px 500px at 80% -10%, var(--brand-soft), transparent), var(--bg); }
.login { width:100%; max-width:380px; text-align:center; padding:34px 30px; }
.login img { height:74px; margin-bottom:6px; }
.login h1 { font-size:1.3rem; margin:6px 0 4px; letter-spacing:-.02em; }
.login p { margin:0 0 22px; color:var(--sub); }
.login form { text-align:left; }

@media (max-width:900px) { .editor { grid-template-columns:1fr; } .lateral { position:static; } }
@media (max-width:640px) {
  .card.flush table:not(.lineas table) thead { display:none; }
  .card.flush table:not(.lineas table), .card.flush table:not(.lineas table) tbody { display:block; }
  .card.flush tbody tr.fila { display:grid; grid-template-columns:auto 1fr auto; grid-template-areas:"n c t" "n f t"; column-gap:12px; align-items:center; padding:10px 12px; border-bottom:1px solid var(--line); }
  .card.flush tbody tr.fila td { border:0; padding:2px 0; }
  .card.flush tbody tr.fila td:nth-child(1) { grid-area:n; }
  .card.flush tbody tr.fila td:nth-child(2) { grid-area:f; color:var(--sub); font-size:.85rem; }
  .card.flush tbody tr.fila td:nth-child(3) { grid-area:c; }
  .card.flush tbody tr.fila td:nth-child(5) { grid-area:t; }
}
@media (max-width:640px) { .ocultar-m { display:none; } main { padding:18px 12px 50px; } .hd { gap:10px; padding:0 12px; } .marca small, nav button span { display:none; } .card { padding:16px; } td,th { padding:11px 10px; } }

/* Accesibilidad (WCAG 2.1 AA): objetivos de 44 px y foco visible */
.btn, nav button { min-height:44px; }
.btn.x { min-width:44px; padding:6px; }
button:focus-visible, a:focus-visible, input[type=file]:focus-visible { outline:3px solid var(--brand); outline-offset:2px; }
.abrir { min-width:48px; min-height:36px; border:0; cursor:pointer; font:inherit; font-weight:700; font-size:.9rem; }
.sug button { display:block; width:100%; min-height:44px; padding:10px 14px; border:0; background:none; color:var(--txt); font:inherit; text-align:left; cursor:pointer; }
.sug button:hover, .sug button:focus-visible { background:var(--brand-soft); }
.nota { color:var(--sub); margin:0 0 14px; }
.editor > * { min-width:0; }

@media (max-width:640px) {
  .hd { flex-wrap:wrap; height:auto; padding-top:8px; }
  .marca { margin-right:auto; }
  nav { order:3; flex-basis:100%; height:auto; gap:0; }
  nav button { flex:1; justify-content:center; padding:0 4px; }
  nav button span { display:inline; }
  .lineas { overflow:visible; }
  .lineas table { min-width:0; }
  .lineas thead { display:none; }
  .lineas table, .lineas tbody { display:block; }
  .lineas tr { display:grid; grid-template-columns:repeat(3, minmax(0,1fr)); gap:8px; border:1px solid var(--line); border-radius:12px; padding:10px; margin-bottom:10px; }
  .lineas td { display:block; padding:0; min-width:0; }
  .lineas td::before { content:attr(data-l); display:block; font-size:.75rem; font-weight:600; color:var(--sub); }
  .lineas td.ancho { grid-column:1 / -1; }
  .lineas td.imp { grid-column:1 / 3; text-align:left; align-self:center; }
  .lineas td.quitar { grid-column:3; text-align:right; align-self:center; }
  .cab .buscar { flex-basis:100%; max-width:none; }
  #nuevo { width:100%; }
}

@media (max-width:640px) { .stats { grid-template-columns:1fr 1fr; gap:10px; } .stat:nth-child(3) { display:none; } }

/* Columnas del editor en ordenador (de la otra revisión) */
@media (min-width:901px) { .editor { grid-template-columns:minmax(0,1fr) 300px; } .lineas table { min-width:600px; } }
@media (min-width:641px) { .lineas td:nth-child(1), .lineas td:nth-child(4), .lineas td:nth-child(5) { width:90px; } .lineas td:nth-child(2) { width:26%; } .lineas td:nth-child(3) { width:30%; } .lineas input.c, .lineas input.p, .lineas input.dt { min-width:84px; } }
@media (prefers-reduced-motion: reduce) { * { transition:none !important; animation:none !important; } }

/* Portada */
.inicio { max-width:980px; margin:0 auto; }
.inicio h2.t { font-size:1.9rem; margin-bottom:18px; }
.botones { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-bottom:18px; }
.gran { display:flex; flex-direction:column; align-items:flex-start; gap:4px; padding:26px 28px; border-radius:var(--r); border:1px solid var(--line); background:var(--card); color:var(--txt); font:inherit; text-align:left; cursor:pointer; box-shadow:var(--sombra); transition:.12s; min-height:130px; }
.gran svg.i { width:34px; height:34px; margin-bottom:6px; color:var(--brand); }
.gran b { font-size:1.45rem; letter-spacing:-.02em; }
.gran small { color:var(--sub); font-size:.9rem; }
.gran:hover { border-color:var(--brand); transform:translateY(-1px); }
.gran.pri { background:var(--brand); border-color:var(--brand); color:#fff; }
.gran.pri svg.i, .gran.pri small { color:#fff; }
.gran.pri:hover { background:var(--brand-d); }
.gran-b { max-width:none; margin-bottom:22px; }
.gran-b input { padding:18px 18px 18px 48px; font-size:1.15rem; border-radius:14px; }
.gran-b svg { left:16px; width:22px; height:22px; }
.dos { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.sub { padding:14px 18px 0; margin:0 0 6px !important; }
.rec { list-style:none; margin:0; padding:0 8px 8px; }
.rec button { display:grid; grid-template-columns:auto 1fr auto; gap:12px; align-items:center; width:100%; padding:12px 10px; border:0; background:none; font:inherit; color:var(--txt); text-align:left; cursor:pointer; border-radius:10px; min-height:56px; }
.rec button:hover { background:var(--brand-soft); }
.rec .cli small { display:block; } .rec .tot { white-space:nowrap; }
@media (max-width:760px) { .botones, .dos { grid-template-columns:1fr; } .gran { min-height:104px; padding:20px; } }
@media (prefers-color-scheme: dark) { .gran.pri, .gran.pri svg.i, .gran.pri small { color:#1a1008; } }
@media (max-width:440px) { .marca div { display:none; } .hd { gap:6px; } nav { min-width:0; overflow-x:auto; scrollbar-width:none; } nav button { padding:0 9px; gap:5px; font-size:.86rem; flex:none; } nav button svg.i { width:16px; height:16px; } }
@media (max-width:440px) { nav button:not(.act) span { display:none; } .hd { flex-wrap:nowrap; } .marca img { height:30px; } }
@media (max-width:440px) { .marca { order:1; } nav { order:2; } #salir { order:3; } }
/* Editor: la tabla de artículos ocupa todo el ancho para que quepan artículo y descripción */
@media (min-width:901px) {
  .editor { grid-template-columns:minmax(0,1fr) 300px; }
  .editor > div { display:contents; }
  .editor > div > .card:nth-child(1) { grid-column:1; grid-row:1; margin-bottom:0; }
  .editor > div > .card:nth-child(2) { grid-column:1 / -1; grid-row:2; margin-bottom:0; }
  .editor > .lateral { grid-column:2; grid-row:1; position:static; }
  .lineas table { min-width:0; }
  .lineas td:nth-child(2) { width:34%; } .lineas td:nth-child(3) { width:34%; }
}
@media (min-width:901px) { .editor { align-items:stretch; } .editor > .lateral .card { height:100%; margin-bottom:0; } .editor > div > .card:nth-child(1) { margin-bottom:0; } .editor { gap:16px 20px; } }
