:root {
  --plum: #ab4889;
  --plum-dark: #4a1b3c;
  --plum-deep: #2e0f26;
  --plum-soft: #f3dcea;
  --cream: #f4d1a7;
  --paper: #fbf3e8;
  --card: #fffdf9;
  --line: #ecdcc8;
  --ink: #3a1a32;
  --muted: #7c6073;
  --ok: #2f7d5b;
  --ok-soft: #dcefe5;
  --warn: #b8741a;
  --warn-soft: #fbe9c8;
  --bad: #b3341f;
  --bad-soft: #f8dcd6;
  --radius: 20px;
  --shadow: 0 1px 0 rgba(74, 27, 60, 0.04), 0 8px 24px -12px rgba(74, 27, 60, 0.18);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 'Montserrat', system-ui, sans-serif;
}
h1, h2, h3 { font-family: 'DM Serif Display', Georgia, serif; font-weight: 400; margin: 0; letter-spacing: 0.01em; }
h1 { font-size: 2rem; line-height: 1.15; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
a { color: var(--plum); }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- login ---------- */
#login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--plum); }
.login-card { background: var(--card); border-radius: 28px; padding: 36px 32px; width: min(380px, 100%); text-align: center; box-shadow: 0 30px 60px -30px rgba(46, 15, 38, 0.6); }
.login-card img { width: 120px; height: 120px; border-radius: 50%; display: block; margin: 0 auto 18px; }
.login-card form { display: grid; gap: 12px; margin-top: 18px; }

/* ---------- header ---------- */
.topbar { background: var(--plum); color: var(--cream); position: sticky; top: 0; z-index: 20; }
.topbar-in { max-width: 1240px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 18px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--cream); flex-shrink: 0; }
.brand img { width: 46px; height: 46px; border-radius: 50%; display: block; }
.brand b { font-family: 'DM Serif Display', serif; font-weight: 400; font-size: 1.35rem; display: block; line-height: 1.1; }
.brand span { font-size: 0.68rem; letter-spacing: 0.32em; text-transform: uppercase; opacity: 0.85; }
.nav { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; padding: 2px; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--cream); text-decoration: none; padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: 0.9rem; white-space: nowrap; border: 1.5px solid transparent; }
.nav a:hover { border-color: rgba(244, 209, 167, 0.5); }
.nav a.on { background: var(--cream); color: var(--plum-dark); }
.savestate { font-size: 0.8rem; font-weight: 600; padding: 7px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); white-space: nowrap; border: 0; color: var(--cream); }
.savestate.error { background: var(--bad); color: #fff; }

/* ---------- layout ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 28px 20px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.card > h3 { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 22px; align-items: start; }
.sticky { position: sticky; top: 92px; }

/* ---------- forms ---------- */
.fld { display: grid; gap: 5px; font-size: 0.78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.fld > span { display: block; }
input, select, textarea {
  font: inherit; font-size: 1rem; color: var(--ink); width: 100%; min-width: 0;
  background: #fff; border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 14px;
  text-transform: none; letter-spacing: 0; font-weight: 500;
}
::placeholder { color: #bfa9b8; opacity: 1; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(171, 72, 137, 0.25); border-color: var(--plum); }
input[type='range'] { padding: 0; accent-color: var(--plum); }
textarea { resize: vertical; min-height: 84px; }
input.num { text-align: right; }

.btn { border: 1.5px solid var(--plum); background: var(--plum); color: #fff; border-radius: 999px; padding: 10px 20px; font-weight: 700; font-size: 0.95rem; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; line-height: 1.2; }
.btn:hover { background: var(--plum-dark); border-color: var(--plum-dark); }
.btn.ghost { background: transparent; color: var(--plum); }
.btn.ghost:hover { background: var(--plum-soft); border-color: var(--plum); }
.btn.soft { background: var(--plum-soft); color: var(--plum-dark); border-color: var(--plum-soft); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad-soft); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 6px 14px; font-size: 0.85rem; }
.btn.block { width: 100%; justify-content: center; }
.x { border: 0; background: transparent; color: var(--muted); font-size: 1.3rem; line-height: 1; padding: 4px 8px; border-radius: 50%; }
.x:hover { background: var(--bad-soft); color: var(--bad); }
.heart { border: 0; background: transparent; font-size: 1.5rem; line-height: 1; color: #cdb6c4; padding: 4px; }
.heart.on { color: var(--plum); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; background: var(--plum-soft); color: var(--plum-dark); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.note { border-radius: 14px; padding: 10px 14px; font-size: 0.9rem; background: var(--warn-soft); color: #6d4710; }
.note.bad { background: var(--bad-soft); color: #7e2415; }
.note.info { background: var(--plum-soft); color: var(--plum-dark); }
.note + .note, .note + * { margin-top: 10px; }

/* ---------- tablas de filas ---------- */
.lines { display: grid; gap: 8px; }
.line { display: grid; gap: 8px; align-items: center; }
.line.piece { grid-template-columns: minmax(90px, 1fr) 64px 72px 72px 92px 32px; }
.line.trim { grid-template-columns: minmax(150px, 1.4fr) minmax(90px, 1fr) 76px 96px 32px; }
.line.extra { grid-template-columns: 1fr 140px 32px; }
.line.step { grid-template-columns: 34px minmax(110px, 0.7fr) minmax(160px, 2fr) 32px; align-items: start; }
.line.fixed { grid-template-columns: 1fr 160px 32px; }
.line.mat { grid-template-columns: minmax(150px, 2fr) 130px 150px 32px; }
.line.pay { grid-template-columns: 150px 1fr 150px 32px; }
.line.head { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; }
.line input, .line select { padding: 8px 10px; border-radius: 12px; font-size: 0.95rem; }
.badge-n { width: 28px; height: 28px; border-radius: 50%; background: var(--plum); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; margin-top: 6px; }
.fabric { border: 1.5px solid var(--line); border-radius: 18px; overflow: hidden; background: #fff; }
.fabric + .fabric { margin-top: 14px; }
.fabric-head { background: var(--plum-soft); padding: 12px 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.fabric-head select { max-width: 360px; background: #fff; }
.fabric-body { padding: 14px; display: grid; gap: 12px; }
.fabric-foot { background: var(--paper); padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 700; }

/* ---------- resumen de costos ---------- */
.sum-line { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 0.95rem; }
.sum-line b { font-variant-numeric: tabular-nums; }
.sum-line.total { border-bottom: 0; border-top: 1.5px solid var(--plum); margin-top: 6px; padding-top: 12px; font-size: 1.05rem; }
.price-box { background: var(--plum); color: var(--cream); border-radius: 18px; padding: 18px; text-align: center; margin-top: 14px; }
.price-box small { display: block; letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.7rem; font-weight: 700; opacity: 0.9; }
.price-box b { font-family: 'DM Serif Display', serif; font-weight: 400; font-size: 2.6rem; line-height: 1.1; display: block; margin-top: 4px; }

/* ---------- foto ---------- */
.photo { aspect-ratio: 4 / 3; border: 2px dashed var(--line); border-radius: 18px; display: grid; place-items: center; background: #fff; overflow: hidden; text-align: center; color: var(--muted); }
.photo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }

/* ---------- productos / favoritos ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.pcard { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform 0.2s, border-color 0.2s; position: relative; }
.pcard:hover { transform: translateY(-3px); border-color: var(--plum); }
.pcard .ph { aspect-ratio: 4 / 3; background: var(--plum-soft); display: grid; place-items: center; color: var(--plum); font-family: 'DM Serif Display', serif; font-size: 2.2rem; }
.pcard .ph img { width: 100%; height: 100%; object-fit: cover; }
.pcard .bd { padding: 14px 16px 16px; }
.pcard .bd b { display: block; font-size: 1.02rem; }
.pcard .heart { position: absolute; top: 8px; right: 8px; background: rgba(255, 253, 249, 0.9); border-radius: 50%; width: 38px; height: 38px; display: grid; place-items: center; padding: 0; }
.empty { text-align: center; padding: 48px 20px; border: 2px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

/* ---------- kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; align-items: start; }
.col { background: #f4e7d7; border-radius: var(--radius); padding: 14px; min-height: 220px; }
.col.over { outline: 3px dashed var(--plum); }
.col-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 700; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em; }
.col-head .count { background: #fff; border-radius: 999px; padding: 2px 10px; }
.ocard { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 14px; display: grid; gap: 8px; cursor: grab; }
.ocard + .ocard { margin-top: 10px; }
.ocard.dragging { opacity: 0.4; }
.ocard .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.ocard .top b { font-size: 1.02rem; }
.ocard .meta { display: flex; justify-content: space-between; gap: 8px; font-size: 0.88rem; }
.ocard .acts { display: flex; justify-content: space-between; align-items: center; gap: 6px; border-top: 1px solid var(--line); padding-top: 8px; }
.ocard select { padding: 5px 8px; font-size: 0.82rem; width: auto; }

/* ---------- finanzas ---------- */
.stat { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.stat small { display: block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat b { font-family: 'DM Serif Display', serif; font-weight: 400; font-size: 1.9rem; display: block; margin-top: 4px; line-height: 1.15; }
.stat.hero { background: var(--plum); border-color: var(--plum); color: var(--cream); }
.stat.hero small { color: var(--cream); opacity: 0.9; }
.bar { height: 12px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--plum); border-radius: 999px; }
table.t { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.t th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); padding: 8px 10px; border-bottom: 1.5px solid var(--line); }
table.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.scroll-x { overflow-x: auto; }

/* ---------- modal / toast ---------- */
dialog { border: 0; border-radius: 26px; padding: 0; width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 24px); background: var(--card); color: var(--ink); box-shadow: 0 40px 80px -30px rgba(46, 15, 38, 0.6); }
dialog::backdrop { background: rgba(46, 15, 38, 0.55); }
.dlg-in { padding: 26px; display: grid; gap: 16px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; border-top: 1.5px solid var(--line); padding-top: 16px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: var(--plum-deep); color: #fff; padding: 12px 22px; border-radius: 999px; font-weight: 600; font-size: 0.92rem; opacity: 0; pointer-events: none; transition: 0.25s; z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- impresión ---------- */
#print-sheet { display: none; }
@media print {
  body { background: #fff; }
  #app, #login, dialog, #toast { display: none !important; }
  #print-sheet { display: block; padding: 8mm; color: #000; }
  #print-sheet h1 { font-size: 26pt; }
  #print-sheet table { width: 100%; border-collapse: collapse; margin: 6px 0 16px; font-size: 10.5pt; }
  #print-sheet th, #print-sheet td { border-bottom: 1px solid #bbb; padding: 5px 6px; text-align: left; }
  #print-sheet img { max-width: 100%; max-height: 90mm; object-fit: contain; }
}

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .editor-grid { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .kanban { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 680px) {
  main { padding: 20px 14px 80px; }
  h1 { font-size: 1.6rem; }
  .topbar-in { flex-wrap: wrap; padding: 8px 14px; gap: 8px; }
  .brand span { display: none; }
  .nav { order: 3; flex-basis: 100%; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .line.piece { grid-template-columns: 1fr 1fr 1fr 28px; }
  .line.piece input:first-child { grid-column: 1 / -1; }
  .line.piece .area { display: none; }
  .line.trim, .line.mat, .line.mat.tela { grid-template-columns: 1fr 1fr; }
  .line.step { grid-template-columns: 30px 1fr 28px; }
  .line.step input.desc { grid-column: 2 / 3; }
  .line.pay { grid-template-columns: 1fr 1fr; }
  .line.head { display: none; }
  .dlg-in { padding: 18px; }
}
