:root {
  --brand: #253887;
  --brand-dark: #1b2a66;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --urgent: #c2410c;
  --ok: #15803d;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }

/* botones */
.btn { border: 0; border-radius: 8px; padding: 10px 16px; font-size: 15px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.primary:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5); }
.btn.link { background: none; color: var(--brand); padding: 8px 0; font-weight: 500; }
.btn.small { padding: 6px 12px; font-size: 13px; }

input, select, textarea { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 6px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand) 0%, var(--brand-dark) 100%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 32px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card .brand { color: var(--brand); font-weight: 800; letter-spacing: .5px; text-transform: uppercase; font-size: 13px; }
.login-card h1 { margin: 4px 0 20px; font-size: 22px; }
.login-card .btn.primary { width: 100%; margin-top: 16px; }
.msg { min-height: 20px; color: var(--urgent); font-size: 14px; margin: 12px 0 0; }

/* barra superior */
.topbar { background: var(--brand); color: #fff; display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; gap: 12px; }
.topbar .brand { font-weight: 800; }
.topbar .brand span { font-weight: 400; opacity: .8; }
.who { display: flex; align-items: center; gap: 12px; font-size: 14px; }

.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }

.seg { display: inline-flex; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--brand); color: #fff; }

.tabs { display: flex; gap: 4px; margin: 18px 0 12px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; white-space: nowrap; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count { display: inline-block; min-width: 22px; padding: 1px 7px; margin-left: 6px; border-radius: 999px; background: #e8ebf6; color: var(--brand); font-size: 12px; }
.tabs button[data-tab=esperando_pas] .count { background: #fde7d9; color: var(--urgent); }

.list { display: grid; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.card:hover { border-color: var(--brand); }
.card h3 { margin: 0; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 13px; }
.card .right { text-align: right; font-size: 12px; color: var(--muted); }
.card .novedad { grid-column: 1 / -1; background: #eef1fb; border-left: 3px solid var(--brand); padding: 6px 10px; font-size: 13px; border-radius: 4px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #e8ebf6; color: var(--brand); margin-right: 4px; }
.pill.urgent { background: #fde7d9; color: var(--urgent); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* panel lateral */
.drawer { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; justify-content: flex-end; z-index: 20; }
.drawer-panel { width: 100%; max-width: 560px; height: 100%; overflow-y: auto; background: #fff; padding: 24px; position: relative; }
.close { position: absolute; top: 10px; right: 14px; border: 0; background: none; font-size: 28px; cursor: pointer; color: var(--muted); }
.drawer h2 { margin: 0 32px 6px 0; font-size: 20px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 16px 0; }
.fields div span { display: block; font-size: 12px; color: var(--muted); }
.box { background: var(--bg); border-radius: 8px; padding: 12px; white-space: pre-wrap; font-size: 14px; }
.box.novedad { background: #eef1fb; border-left: 3px solid var(--brand); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 20px 0 8px; }
.thread { display: grid; gap: 8px; }
.bubble { padding: 10px 12px; border-radius: 10px; font-size: 14px; white-space: pre-wrap; max-width: 90%; }
.bubble.pas { background: #e8ebf6; justify-self: end; }
.bubble.ares { background: #f1f5f9; border: 1px solid var(--border); }
.bubble small { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.msg-form { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 8px; }
.msg-form .btn { margin-top: 8px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid .full { grid-column: 1 / -1; }
.grid .btn { margin-top: 16px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 30; }

@media (max-width: 640px) {
  .topbar .brand span { display: none; }
  .fields, .grid { grid-template-columns: 1fr; }
  .card { grid-template-columns: 1fr; }
  .card .right { text-align: left; }
}

/* ---------- campanita ---------- */
.bell-wrap { position: relative; }
.bell { position: relative; background: none; border: 0; color: #fff; cursor: pointer; padding: 6px; display: grid; place-items: center; }
.bell-count { position: absolute; top: 0; right: -2px; background: #ef4444; color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 4px; }
.bell-panel { position: absolute; right: 0; top: 42px; width: 360px; max-width: calc(100vw - 24px); max-height: 70vh; overflow-y: auto; background: #fff; color: var(--text); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.2); z-index: 25; }
.bell-head { padding: 12px 14px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; }
.notif { display: flex; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--border); padding: 10px 14px; cursor: pointer; font: inherit; color: inherit; }
.notif:hover { background: var(--bg); }
.notif.unread { background: #eef1fb; }
.notif-icon { font-size: 16px; width: 22px; flex: none; }
.notif-body { display: grid; gap: 2px; font-size: 13px; }
.notif-body small { color: var(--muted); font-size: 11px; }
.pad { padding: 14px; margin: 0; }

/* ---------- aviso para activar push ---------- */
.banner { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-size: 14px; }
.banner-actions { display: flex; gap: 8px; align-items: center; }

.sub-label { font-size: 12px; color: var(--brand); font-weight: 600; margin-top: 4px; }

/* ---------- línea de tiempo ---------- */
.timeline-box { margin: 16px 0 4px; }
.timeline { display: grid; grid-template-columns: repeat(5, 1fr); position: relative; }
.timeline::before { content: ''; position: absolute; top: 9px; left: 10%; right: 10%; height: 2px; background: var(--border); }
.step { position: relative; text-align: center; padding: 0 2px; font-size: 12px; }
.step .dot { display: block; width: 20px; height: 20px; border-radius: 50%; margin: 0 auto 6px; background: #fff; border: 2px solid var(--border); position: relative; z-index: 1; }
.step.hecho .dot { background: var(--brand); border-color: var(--brand); }
.step.actual .dot { background: #fff; border: 6px solid var(--brand); box-shadow: 0 0 0 4px #e8ebf6; }
.step.salteada .dot { background: var(--border); }
.step-label { font-weight: 600; color: var(--muted); line-height: 1.2; }
.step.hecho .step-label, .step.actual .step-label { color: var(--text); }
.step.actual .step-label { color: var(--brand); }
.step-date { color: var(--muted); font-size: 11px; margin-top: 2px; }
.step.has-sub { cursor: pointer; border-radius: 8px; }
.step.has-sub:hover, .step.has-sub:focus-visible { background: #f1f3fa; outline: none; }
.chev { display: block; color: var(--brand); font-size: 12px; }
.timeline .substeps { grid-column: 1 / -1; order: 10; position: relative; z-index: 1; }
.substeps { margin-top: 10px; background: #f6f7fc; border: 1px solid #e3e7f5; border-radius: 8px; padding: 10px 12px; display: grid; gap: 8px; }
.substep { display: grid; grid-template-columns: 16px 1fr auto; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.substep .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); background: #fff; }
.substep.hecho { color: var(--text); }
.substep.hecho .dot { background: var(--brand); border-color: var(--brand); }
.substep.actual { color: var(--brand); font-weight: 700; }
.substep.actual .dot { border: 4px solid var(--brand); }

@media (max-width: 640px) {
  #who-company { display: none; }
  .timeline { grid-template-columns: 1fr; gap: 0; }
  .timeline::before { top: 10px; bottom: 10px; left: 9px; right: auto; width: 2px; height: auto; }
  .step { display: grid; grid-template-columns: 20px 1fr auto; gap: 10px; text-align: left; align-items: center; padding: 6px 0; }
  .step .dot { margin: 0; }
  .timeline .substeps { order: 0; margin: 2px 0 6px 30px; }
  .step.has-sub { grid-template-columns: 20px 1fr auto auto; }
}

/* ---------- Inicio y bolsa de trabajo ---------- */
.bolsa-head h2 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.bolsa-head p { margin: 4px 0 12px; }
.bolsa-count { background: var(--urgent); color: #fff; border-radius: 999px; font-size: 13px; padding: 2px 9px; }
.bolsa-count.cero { background: var(--ok); }
.bolsa { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.bolsa-card { background: #fff; border: 1px solid #f5c9ad; border-left: 5px solid var(--urgent); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; box-shadow: 0 2px 10px rgba(194,65,12,.08); }
.bolsa-card.demorada { border-left-color: #b91c1c; background: #fffaf7; }
.bolsa-card h3 { margin: 0; font-size: 16px; }
.bolsa-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.bolsa-n { color: var(--muted); font-weight: 600; }
.bolsa-wait { color: var(--urgent); font-weight: 700; }
.bolsa-card.demorada .bolsa-wait { color: #b91c1c; }
.bolsa-pedido { background: #fff4ec; border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.bolsa-pedido span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--urgent); font-weight: 700; margin-bottom: 2px; }
.bolsa-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bolsa-reply { display: grid; gap: 8px; }
.btn.ghost-dark { background: #fff; color: var(--brand); border: 1px solid var(--border); }
.bolsa-vacia { grid-column: 1 / -1; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: var(--radius); padding: 18px; display: grid; gap: 4px; color: #166534; }

/* detalle: pedido destacado */
.alerta-pas { margin: 14px 0 4px; background: #fff4ec; border: 1px solid #f5c9ad; border-left: 5px solid var(--urgent); border-radius: 8px; padding: 10px 12px; display: grid; gap: 2px; font-size: 14px; }
.alerta-pas b { color: var(--urgent); }

@media (max-width: 640px) {
  .bolsa { grid-template-columns: 1fr; }
}
.bolsa-card .meta { color: var(--muted); font-size: 13px; }

/* ---------- columna izquierda: pendientes ---------- */
.container.layout { max-width: 1380px; display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 28px; align-items: start; }
.side { position: sticky; top: 20px; display: grid; gap: 10px; }
.pend-card { display: grid; gap: 4px; text-align: left; width: 100%; border: 0; border-radius: 14px; padding: 20px 18px; cursor: pointer; font: inherit;
  color: #fff; background: linear-gradient(150deg, #3449a8 0%, var(--brand) 55%, var(--brand-dark) 100%); box-shadow: 0 10px 28px rgba(37,56,135,.35); transition: transform .15s; }
.pend-card:hover { transform: translateY(-2px); }
.pend-card:focus-visible { outline: 3px solid #9aa6d6; outline-offset: 2px; }
.pend-num { font-size: 52px; font-weight: 800; line-height: 1; }
.pend-txt { font-size: 17px; font-weight: 700; line-height: 1.25; }
.pend-sub { font-size: 13px; opacity: .9; }
.pend-cta { margin-top: 10px; background: #fff; color: var(--brand); border-radius: 8px; padding: 9px 10px; font-weight: 700; font-size: 14px; text-align: center; }
.pend-card.cero { background: #f0fdf4; color: #166534; box-shadow: none; border: 1px solid #bbf7d0; cursor: default; }
.pend-card.cero:hover { transform: none; }
.pend-card.cero .pend-num { font-size: 32px; }
.pend-card.cero .pend-txt { font-size: 15px; }
#drawer-pend .bolsa { grid-template-columns: 1fr; margin-top: 12px; }

/* clip en las tarjetas del listado */
.card .right { position: relative; }
.clip { margin-top: 6px; border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 4px 8px; cursor: pointer; font-size: 14px; }
.clip:hover { border-color: var(--brand); }

/* ---------- adjuntos ---------- */
.file-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.file-pick { position: relative; display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 8px 12px; border: 1px dashed #9aa6d6; border-radius: 8px; color: var(--brand); font-weight: 600; cursor: pointer; background: #f6f7fc; }
.file-pick:hover { background: #eef1fb; }
.file-pick input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-pick:focus-within { outline: 2px solid var(--brand); }
.file-pick.big { padding: 14px 16px; font-size: 15px; }
.file-names { font-size: 13px; color: var(--muted); }
.file-err { color: var(--urgent) !important; font-weight: 600; }
.dropzone { border: 2px dashed var(--border); border-radius: 10px; padding: 16px; text-align: center; transition: background .15s; }
.dropzone.over { background: #eef1fb; border-color: var(--brand); }
.dropzone .muted { margin: 10px 0 0; font-size: 13px; }
.file-list { list-style: none; padding: 0; margin: 10px 0 0; text-align: left; font-size: 13px; display: grid; gap: 4px; }
.file-list li { background: var(--bg); border-radius: 6px; padding: 6px 10px; }
.btn.wide { width: 100%; margin-top: 16px; }
.adjuntos { display: grid; gap: 4px; margin-top: 6px; }
.adjuntos a { color: var(--brand); font-weight: 600; text-decoration: none; font-size: 13px; }
.adjuntos a:hover { text-decoration: underline; }

@media (max-width: 1100px) {
  .container.layout { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .side { position: static; grid-template-columns: minmax(0, 1fr); }
  .pend-card { grid-template-columns: auto minmax(0, 1fr); column-gap: 14px; align-items: center; padding: 14px 16px; }
  .pend-num { font-size: 36px; grid-row: span 2; }
  .pend-sub { grid-column: 2; }
  .pend-cta { grid-column: 1 / -1; margin-top: 6px; }
}


/* ---------- vista completa de la gestión ---------- */
.back-link { background: none; border: 0; color: var(--brand); font: inherit; font-weight: 700; cursor: pointer; padding: 6px 0; margin-bottom: 6px; }
.back-link:hover { text-decoration: underline; }
.det-n { font-size: 13px; color: var(--muted); font-weight: 600; }
.det-title { font-size: 24px; margin: 2px 0 8px; line-height: 1.25; }
#det-head .alerta-pas { margin-top: 14px; }
#det-head .alerta-pas .bolsa-actions { margin-top: 8px; }
.det-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "info aside" "conv aside"; gap: 16px; margin-top: 16px; align-items: start; }
.det-info { grid-area: info; display: grid; gap: 16px; min-width: 0; }
.det-aside { grid-area: aside; display: grid; gap: 16px; position: sticky; top: 20px; }
.det-conv { grid-area: conv; }
.det-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.det-card .timeline-box { margin: 0; }
.det-h { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.det-datos { display: grid; gap: 2px; margin: 0; }
.det-datos dt { font-size: 12px; color: var(--muted); margin-top: 8px; }
.det-datos dt:first-child { margin-top: 0; }
.det-datos dd { margin: 0; font-weight: 600; }
.doc-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.doc-list li { display: grid; gap: 1px; }
.doc-list a { color: var(--brand); font-weight: 600; text-decoration: none; word-break: break-word; }
.doc-list a:hover { text-decoration: underline; }
.doc-list small { color: var(--muted); font-size: 11px; }
#det-docs .muted { margin: 0 0 12px; }
.det-conv .msg-form { margin-top: 16px; }

@media (max-width: 900px) {
  .det-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "info" "aside" "conv"; }
  .det-aside { position: static; }
  .det-title { font-size: 20px; }
}

/* Pantallas táctiles: botones con tamaño cómodo para el dedo */
.clip { min-width: 36px; min-height: 34px; }
@media (pointer: coarse) {
  .clip { min-width: 44px; min-height: 44px; font-size: 18px; }
  .btn.small { min-height: 40px; }
  .back-link { min-height: 40px; }
}
@media (max-width: 640px) {
  .bell-panel { position: fixed; top: 60px; left: 12px; right: 12px; width: auto; max-width: none; }
}
/* En celular/tablet, la vista de una gestión usa toda la pantalla (la tarjeta vuelve en el listado) */
@media (max-width: 1100px) {
  body.en-detalle .side { display: none; }
}

/* ---------- nueva gestión (página completa) ---------- */
#sec-nueva { max-width: 860px; }
.nueva-form { display: grid; gap: 16px; margin-top: 14px; }
.nueva-form .grid label { margin-top: 0; }
.nueva-form .grid { row-gap: 12px; }
.area-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.area-opt { margin: 0; display: block; cursor: pointer; }
.area-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.area-opt span { display: grid; gap: 2px; border: 2px solid var(--border); border-radius: 10px; padding: 12px 14px; background: #fff; height: 100%; }
.area-opt b { font-size: 16px; color: var(--text); }
.area-opt small { font-weight: 400; color: var(--muted); font-size: 13px; }
.area-opt input:checked + span { border-color: var(--brand); background: #eef1fb; }
.area-opt input:checked + span b { color: var(--brand); }
.area-opt input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.nueva-actions { display: flex; gap: 12px; align-items: center; padding-bottom: 20px; }
.nueva-actions .btn.primary { padding: 12px 28px; font-size: 16px; }
@media (max-width: 640px) {
  .area-pick { grid-template-columns: 1fr; }
  .nueva-form .grid { grid-template-columns: minmax(0, 1fr); }
  .nueva-actions { flex-direction: column; align-items: stretch; }
}
.opc { font-weight: 400; color: var(--muted); font-size: 12px; }

/* ---------- analista y cierre ---------- */
.analista-mini { font-size: 12px; color: var(--muted); }
.det-pills { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.analista { display: inline-flex; align-items: center; gap: 10px; margin-top: 12px; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px 8px 10px; }
.analista-ico { width: 32px; height: 32px; border-radius: 50%; background: #eef1fb; display: grid; place-items: center; font-size: 16px; }
.analista small { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.analista b { color: var(--brand); }
.analista.sin b { color: var(--muted); font-weight: 600; }
.btn.danger { background: #b91c1c; color: #fff; }
.btn.danger:hover { background: #991b1b; }
.btn.danger-outline { background: #fff; color: #b91c1c; border: 1px solid #fca5a5; }
.btn.danger-outline:hover { background: #fef2f2; }
