:root {
  --ink: #1d1512; --ink-2: #3a2c25; --gold: #c9962a; --gold-2: #e7c062; --cream: #f6f1ea;
  --bg: #f4f1ec; --card: #fff; --line: #e3dcd2; --muted: #7a6d64; --ok: #2e7d4f; --warn: #b7791f; --bad: #b3261e;
  --info: #2b6cb0; --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; } h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; } h3 { font-size: 1rem; margin: .8rem 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .center { text-align: center; }
.nowrap { white-space: nowrap; } .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88em; }
.hidden { display: none !important; }

/* Layout */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: var(--cream); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .6rem; padding: 1rem .9rem; border-bottom: 1px solid #ffffff14; }
.brand img { width: 58px; border-radius: 6px; }
.brand b { display: block; color: var(--gold-2); font-size: .95rem; letter-spacing: .02em; }
.brand span { font-size: .72rem; color: #cfc2b4; }
.nav { flex: 1; overflow: auto; padding: .5rem 0; }
.nav a { display: flex; gap: .65rem; align-items: center; color: #e9dfd3; padding: .55rem 1rem; font-size: .93rem; border-left: 3px solid transparent; }
.nav a:hover { background: #ffffff0d; text-decoration: none; }
.nav a.active { background: #ffffff14; border-left-color: var(--gold); color: #fff; }
.nav .sep { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #a8988a; padding: .9rem 1rem .3rem; }
.side-foot { padding: .8rem 1rem; border-top: 1px solid #ffffff14; font-size: .82rem; }
.side-foot a { color: var(--gold-2); }
.main { padding: 1.3rem 1.6rem 4rem; min-width: 0; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat { padding: .9rem 1rem; } .stat .n { font-size: 1.6rem; font-weight: 700; } .stat .l { color: var(--muted); font-size: .85rem; }
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: .48rem .85rem; border-radius: 8px; cursor: pointer; display: inline-flex; gap: .4rem; align-items: center; white-space: nowrap; }
button:hover, .btn:hover { border-color: #cbbfb1; background: #fbf9f6; text-decoration: none; }
button.primary, .btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
button.primary:hover { background: var(--ink-2); }
button.gold { background: var(--gold); border-color: var(--gold); color: #1d1512; font-weight: 600; }
button.danger { color: var(--bad); } button.danger:hover { border-color: var(--bad); }
button.sm { padding: .25rem .5rem; font-size: .83rem; } button.icon { padding: .3rem .45rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; background: #fff; width: 100%; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-2); border-color: var(--gold); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
.field { margin-bottom: .7rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .2rem .8rem; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: .4rem; color: var(--ink); font-size: .92rem; } .check input { width: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .55rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #faf8f5; }
tr.click { cursor: pointer; } tr.click:hover td { background: #fbf8f3; }
.table-wrap { overflow-x: auto; }
td input, td select { padding: .3rem .4rem; font-size: .88rem; }
tfoot td { font-weight: 700; }

.badge { display: inline-block; padding: .12rem .5rem; border-radius: 99px; font-size: .76rem; font-weight: 600; background: #eee; color: #444; text-transform: capitalize; }
.b-borrador { background: #ece7e1; color: #5d4f44; } .b-enviado { background: #e1ecf8; color: #2b6cb0; }
.b-aprobado { background: #dff1e6; color: #2e7d4f; } .b-rechazado, .b-anulado { background: #f8e1df; color: #b3261e; }
.b-pendiente { background: #ece7e1; color: #5d4f44; } .b-compras { background: #fdf0d5; color: #8a5a00; } .b-corte { background: #e1ecf8; color: #2b6cb0; }
.b-armado { background: #e6e1f8; color: #5b3fb0; } .b-vidriado { background: #dff4f4; color: #1d6f6f; } .b-listo { background: #dff1e6; color: #2e7d4f; }
.b-instalado, .b-entregado { background: #d6eadb; color: #1f5c38; }
.b-perfil { background:#e1ecf8;color:#2b6cb0 } .b-refuerzo{background:#e9e9e9;color:#444} .b-herraje{background:#fdf0d5;color:#8a5a00}
.b-vidrio{background:#dff4f4;color:#1d6f6f} .b-accesorio{background:#ece7e1;color:#5d4f44} .b-burlete{background:#e6e1f8;color:#5b3fb0} .b-mano_obra{background:#f8e1df;color:#b3261e}

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: .55rem .8rem; color: var(--muted); }
.tabs button.active { border-bottom-color: var(--gold); color: var(--ink); font-weight: 600; }

.alert { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-size: .92rem; }
.alert.warn { background: #fdf3dc; color: #6b4a00; border: 1px solid #f0d699; }
.alert.bad { background: #fbe5e3; color: #7d1a14; border: 1px solid #efb7b2; }
.alert.info { background: #e6f0fb; color: #1f4f85; border: 1px solid #b8d2ef; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,14,10,.5); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: min(720px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(1100px, 100%); }
.modal header { padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h3 { margin: 0; }
.modal .body { padding: 1.1rem; }
.modal footer { padding: .8rem 1.1rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: .5rem; }
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .65rem 1.1rem; border-radius: 8px; z-index: 99; box-shadow: var(--shadow); }
.toast.err { background: var(--bad); }

/* Galería de modelos */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; max-height: 330px; overflow: auto; padding: 2px; }
.gallery .tile { border: 2px solid var(--line); border-radius: 10px; padding: .5rem; text-align: center; cursor: pointer; background: #fff; font-size: .8rem; }
.gallery .tile:hover { border-color: var(--gold-2); } .gallery .tile.sel { border-color: var(--gold); background: #fff9ec; }
.gallery svg { width: 100%; height: 80px; }
.drawing svg { width: 100%; height: auto; max-height: 340px; }
.thumb svg { width: 64px; height: 52px; display: block; }

/* Totales */
.totals { min-width: 280px; }
.totals div { display: flex; justify-content: space-between; padding: .3rem 0; gap: 1rem; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: .3rem; padding-top: .5rem; font-size: 1.2rem; font-weight: 700; }

/* Kanban */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: .8rem; overflow-x: auto; padding-bottom: .5rem; }
.kcol { background: #ebe5dd; border-radius: 10px; padding: .6rem; min-height: 200px; }
.kcol h4 { margin: .1rem .2rem .6rem; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; }
.kcard { background: #fff; border-radius: 8px; padding: .6rem; margin-bottom: .5rem; box-shadow: var(--shadow); font-size: .87rem; }
.kcard.late { border-left: 4px solid var(--bad); } .kcard.soon { border-left: 4px solid var(--warn); }
.kcard select { margin-top: .4rem; font-size: .82rem; padding: .25rem; }

/* Optimización de corte */
.bar { display: flex; height: 26px; border: 1px solid #b9ad9f; border-radius: 4px; overflow: hidden; margin: .25rem 0 .7rem; background: repeating-linear-gradient(45deg,#f2ece4,#f2ece4 6px,#e6ddd2 6px,#e6ddd2 12px); }
.bar .pc { background: #8fb3d9; border-right: 2px solid #fff; font-size: .7rem; color: #102a43; display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap; }
.bar .pc:nth-child(even) { background: #a9c7e6; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 30% 20%, #3a2c25, #120c0a); padding: 1rem; }
.login .box { background: #fff; border-radius: 14px; padding: 2rem; width: min(380px, 100%); box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.login img { display: block; margin: 0 auto 1rem; width: 140px; border-radius: 8px; }

/* Impresión (presupuesto, informes) */
.doc { background: #fff; max-width: 900px; margin: 0 auto; padding: 2rem; border: 1px solid var(--line); }
.doc-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 3px solid var(--ink); padding-bottom: 1rem; margin-bottom: 1rem; }
.doc-head img { width: 120px; }
.doc table { font-size: .88rem; } .doc th { background: #f1ece5; }
.doc .lineimg svg { width: 110px; height: 90px; }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  .side, .no-print, .topbar, .toast { display: none !important; }
  .app { display: block; } .main { padding: 0; }
  .doc { border: none; padding: 0; max-width: none; }
  .card { box-shadow: none; border: none; padding: 0; }
  tr, .bar-block { page-break-inside: avoid; }
}

/* Responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: .7rem; background: var(--ink); color: #fff; padding: .55rem .8rem; position: sticky; top: 0; z-index: 30; }
  .topbar img { height: 34px; border-radius: 4px; } .topbar button { background: none; color: #fff; border: none; font-size: 1.4rem; padding: .1rem .4rem; }
  .main { padding: 1rem .8rem 4rem; }
  .g2, .g3, .g4 { grid-template-columns: 1fr 1fr; }
  .hide-sm { display: none; }
}
@media (max-width: 560px) { .g2, .g3 { grid-template-columns: 1fr; } }
