:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1b2236;
  --ink-2: #4a5470;
  --muted: #7a839b;
  --line: #e3e7f0;
  --line-2: #eef1f7;
  --navy: #141b3d;
  --navy-2: #1f2a6b;
  --accent: #3b2bff;
  --accent-soft: #eeecff;
  --ok: #0f8a5f;
  --ok-soft: #e3f6ee;
  --warn: #9a6400;
  --warn-soft: #fff4dc;
  --err: #c0362c;
  --err-soft: #fde9e7;
  --wa: #1fa855;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 27, 61, .06), 0 4px 16px rgba(20, 27, 61, .04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; color: var(--ink-2); margin-top: 18px; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.sm { font-size: 12.5px; } .xs { font-size: 11.5px; }
.r { text-align: right; } .c { text-align: center; } .nowrap { white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: 232px; flex: 0 0 232px; background: var(--navy); color: #c9cfe6; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: block; padding: 22px 20px 14px; color: #fff; font-weight: 750; font-size: 20px; letter-spacing: -.02em; }
.brand span, .brand-lg span { color: #7f74ff; }
.brand:hover { text-decoration: none; }
.who { margin: 0 12px 10px; padding: 10px 12px; background: rgba(255,255,255,.06); border-radius: 8px; }
.who-name { color: #fff; font-weight: 600; font-size: 13px; }
.who-role { font-size: 11.5px; color: #98a1c4; }
.side nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; flex: 1; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: #c9cfe6; font-size: 13.5px; }
.side nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.side nav a.on { background: var(--accent); color: #fff; }
.nav-sep { margin: 14px 10px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #7d86ab; }
.side-foot { padding: 14px 20px; font-size: 12.5px; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot a { color: #c9cfe6; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 18px 28px 6px; }
.top h1 { font-size: 21px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
.menu-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 16px; cursor: pointer; }
.content { padding: 12px 28px 40px; }
.main > .alert { margin: 8px 28px 0; }

/* ---------- Cards & layout ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.narrow { max-width: 720px; }
.cols { display: flex; gap: 16px; align-items: flex-start; }
.cols .grow { flex: 1; min-width: 0; }
.side-card { width: 320px; flex: 0 0 320px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar p { margin: 0; }
.actions-row { display: flex; gap: 8px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 6px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-l { font-size: 12px; color: var(--muted); }
.kpi-v { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.kpi-v small { font-size: 13px; color: var(--ok); font-weight: 600; }

/* ---------- Forms ---------- */
.form label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }
.form label > input, .form label > select, .form label > textarea, .form > textarea, .form input[type=file] { margin-top: 5px; }
input, select, textarea { width: 100%; font: inherit; font-size: 14px; color: var(--ink); padding: 8px 10px; border: 1px solid #cfd5e3; border-radius: 7px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox], input[type=radio] { width: auto; margin: 0; accent-color: var(--accent); }
.form small { display: block; font-weight: 400; margin-top: 3px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px 2px; margin: 0 0 14px; }
legend { font-size: 12px; font-weight: 650; color: var(--ink-2); padding: 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip, .form label.chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; background: #fafbfe; font-size: 13px; font-weight: 500; color: var(--ink); margin: 0; cursor: pointer; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: #c9c3ff; }
details.adv { margin-bottom: 8px; } details.adv summary { cursor: pointer; font-size: 12.5px; color: var(--accent); margin-bottom: 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters.card { padding: 12px 14px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid #cfd5e3; background: #fff; color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: #aab3c9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2e1fe0; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--line-2); }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.danger { color: var(--err); border-color: #f0c2bd; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; margin-top: 10px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Alerts / badges ---------- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 13.5px; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.err { background: var(--err-soft); color: var(--err); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; vertical-align: middle; }
.st-nueva { background: #e8edff; color: #2f47c6; }
.st-revision { background: #fff1d6; color: #9a6400; }
.st-enviada { background: #e7e4ff; color: #4a2fd6; }
.st-aceptada { background: #ddf5ea; color: #0f8a5f; }
.st-operacion { background: #d8f1f7; color: #0b6f8a; }
.st-cerrada { background: #eceef3; color: #586179; }
.st-rechazada { background: #fde4e1; color: #b8352b; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; background: var(--line-2); font-size: 11px; color: var(--ink-2); }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #f8f9fd; }
.tbl tr.off td { opacity: .55; }
.tbl.compact td { padding: 6px 8px; }
.tbl.lines tr.grp td { background: #f3f5fb; font-weight: 650; color: var(--navy-2); font-size: 12.5px; padding: 6px 10px; }
.tbl.lines tfoot td { font-weight: 600; border-bottom: none; padding: 6px 10px; }
.tbl.lines tfoot tr.strong td { font-size: 15px; border-top: 1px solid var(--line); }
.tbl.edit td { padding: 4px 6px; } .tbl.edit input, .tbl.edit select { padding: 6px 8px; font-size: 13px; }
.tbl.edit tr.new td { background: #fafbfe; }
.w60 { width: 60px; } .w90 { width: 90px; } .w110 { width: 120px; }
input.r { text-align: right; }

/* ---------- Cotizador ---------- */
.cot-layout { display: flex; gap: 16px; align-items: flex-start; }
.cot-main { flex: 1; min-width: 0; }
.cot-side { width: 400px; flex: 0 0 400px; }
.sticky { position: sticky; top: 14px; max-height: calc(100vh - 28px); overflow-y: auto; }
.step { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; align-items: center; justify-content: center; margin-right: 6px; }
.sub { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 2px; }
.extra-row { display: grid; grid-template-columns: 1fr 140px 84px 36px; gap: 8px; margin-bottom: 8px; }
.res-g { font-size: 11.5px; font-weight: 700; color: var(--navy-2); text-transform: uppercase; letter-spacing: .04em; margin: 12px 0 4px; }
.res-l { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 3px 0; }
.res-l .d { font-size: 11px; color: var(--muted); }
.res-l .v { white-space: nowrap; font-weight: 600; }
.res-l .v small { display: block; text-align: right; color: var(--muted); font-weight: 400; font-size: 11px; }
.res-t { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 8px; }
.res-t .res-l { font-size: 13.5px; }
.res-t .big { font-size: 18px; font-weight: 750; color: var(--navy); }
.res-av { background: var(--warn-soft); color: var(--warn); font-size: 12px; padding: 8px 10px; border-radius: 7px; margin-bottom: 8px; }
.res-util { display: flex; justify-content: space-between; font-size: 12px; background: var(--ok-soft); color: var(--ok); padding: 6px 10px; border-radius: 7px; margin-top: 8px; }
.loading { opacity: .5; transition: opacity .15s; }

/* ---------- Detalle ---------- */
.cot-head { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.cot-title { font-size: 20px; font-weight: 700; margin: 4px 0; }
.cot-head-total { text-align: right; }
.big-num { font-size: 26px; font-weight: 750; color: var(--navy); letter-spacing: -.01em; }
.util { display: flex; gap: 20px; justify-content: flex-end; font-size: 13px; color: var(--ok); margin-top: 10px; }
.thread { margin-bottom: 12px; }
.msg { padding: 10px 12px; border-radius: 8px; background: #f6f7fb; margin-bottom: 8px; font-size: 13.5px; }
.msg.interno { background: #fff8e8; border-left: 3px solid #f0c060; }
.msg-h { margin-bottom: 3px; }
.file { display: flex; flex-direction: column; padding: 6px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.hist { list-style: none; padding: 0; margin: 0 0 10px; font-size: 12.5px; }
.hist li { padding: 5px 0; border-bottom: 1px solid var(--line-2); }
.dlg { border: none; border-radius: 12px; padding: 22px; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(20, 27, 61, .45); }
.cred pre { background: #f6f7fb; padding: 12px; border-radius: 8px; white-space: pre-wrap; font-size: 13px; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding: 12px 0 10px; align-items: start; }
.kcol { background: #eceff6; border-radius: 10px; padding: 10px; min-height: 200px; }
.kcol.over { background: #e1e3ff; outline: 2px dashed var(--accent); }
.kcol-h { font-weight: 650; font-size: 13px; margin: 2px 4px 10px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.kcol-b { display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.kcard { display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; color: var(--ink); box-shadow: 0 1px 2px rgba(20,27,61,.05); cursor: grab; }
.kcard:hover { text-decoration: none; border-color: #b9c0d6; }
.kcard.drag { opacity: .4; }
.kcard-t { font-weight: 650; font-size: 13.5px; }
.kcard-m { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; }
.kcard-f { display: flex; justify-content: space-between; align-items: center; gap: 6px; }

/* ---------- Auth ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(140deg, #141b3d 0%, #26307a 55%, #3b2bff 120%); padding: 16px; }
.auth-card { background: #fff; border-radius: 14px; padding: 30px 30px 24px; width: 100%; max-width: 400px; box-shadow: 0 24px 70px rgba(0,0,0,.3); }
.auth-card h1 { font-size: 20px; }
.brand-lg { font-size: 26px; font-weight: 800; letter-spacing: -.02em; color: var(--navy); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .cot-layout { flex-direction: column; }
  .cot-side { width: 100%; flex: none; }
  .sticky { position: static; max-height: none; }
}
@media (max-width: 960px) {
  .cols { flex-direction: column; } .side-card { width: 100%; flex: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .side { position: fixed; left: -240px; z-index: 50; transition: left .2s; }
  .side.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-btn { display: inline-block; }
  .top { padding: 14px 16px 4px; } .content { padding: 10px 16px 30px; } .main > .alert { margin: 8px 16px 0; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .cot-head { flex-direction: column; align-items: flex-start; } .cot-head-total { text-align: left; }
  .extra-row { grid-template-columns: 1fr 100px 70px 32px; }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
  .card { padding: 14px; }
}
.cot-layout.form .chip { margin: 0; }
.dot.st-nueva { background: #2f47c6; } .dot.st-revision { background: #d99400; } .dot.st-enviada { background: #4a2fd6; }
.dot.st-aceptada { background: #0f8a5f; } .dot.st-operacion { background: #0b6f8a; } .dot.st-cerrada { background: #8a92a8; } .dot.st-rechazada { background: #b8352b; }
