:root {
  --blue: #0B53A4; --blue-soft: #e7f0fb; --navy: #0F2A4A; --orange: #FF8200; --orange-soft: #fff1e3;
  --bg: #F4F7FB; --card: #ffffff; --line: #dfe6ef; --text: #0F2A4A; --muted: #5d6d82;
  --hot: #d92d20; --hot-bg: #fdecea; --warm: #b54708; --warm-bg: #fef3e2; --cold: #3a6ea5; --cold-bg: #e8f0fa;
  --ok: #127a3a; --ok-bg: #e5f6ec; --shadow: 0 6px 24px rgba(15, 42, 74, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue: #5b9be6; --blue-soft: #16304f; --navy: #e6edf6; --orange: #ff9a33; --orange-soft: #3a2611;
    --bg: #0b1626; --card: #122135; --line: #23364f; --text: #e6edf6; --muted: #9db0c6;
    --hot: #ff7a6e; --hot-bg: #3b1714; --warm: #f5b35c; --warm-bg: #3a2610; --cold: #8db8ec; --cold-bg: #142a45;
    --ok: #59d08b; --ok-bg: #0f3020; --shadow: 0 6px 24px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --blue: #5b9be6; --blue-soft: #16304f; --navy: #e6edf6; --orange: #ff9a33; --orange-soft: #3a2611;
  --bg: #0b1626; --card: #122135; --line: #23364f; --text: #e6edf6; --muted: #9db0c6;
  --hot: #ff7a6e; --hot-bg: #3b1714; --warm: #f5b35c; --warm-bg: #3a2610; --cold: #8db8ec; --cold-bg: #142a45;
  --ok: #59d08b; --ok-bg: #0f3020; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, sans-serif; }
a { color: var(--blue); }
h1, h2, h3 { font-family: Poppins, Inter, sans-serif; margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: .98rem; }
.muted { color: var(--muted); } .err { color: var(--hot); min-height: 1.2em; } .small { font-size: 12px; }
[hidden] { display: none !important; }

.brand { display: flex; align-items: center; gap: 10px; font: 700 17px Poppins, sans-serif; color: var(--blue); }
.logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--blue), var(--orange)); flex: none; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--blue); }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--hot); border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; }
label.inline { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.inline input { width: auto; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.top nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.top nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.top nav a.on { background: var(--blue-soft); color: var(--blue); }
.view { padding: 20px; max-width: 1400px; margin: 0 auto; outline: none; }

.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.bar .grow { flex: 1 1 220px; }
.bar select { width: auto; }
.spacer { flex: 1; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.row { display: grid; grid-template-columns: minmax(180px, 2fr) minmax(150px, 1.4fr) 130px 130px 54px 160px; gap: 12px; align-items: center; padding: 11px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--blue-soft); }
.row.head { cursor: default; background: transparent; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--blue-soft); color: var(--blue); white-space: nowrap; }
.chip.caliente { background: var(--hot-bg); color: var(--hot); }
.chip.tibio { background: var(--warm-bg); color: var(--warm); }
.chip.frio { background: var(--cold-bg); color: var(--cold); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.gray { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.src { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.src i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.late { color: var(--hot); font-weight: 600; }

.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; min-height: 200px; }
.col.drop { outline: 2px dashed var(--blue); }
.col-h { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 4px 10px; }
.col-h b { font-family: Poppins, sans-serif; }
.cardl { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; cursor: grab; }
.cardl:hover { border-color: var(--blue); }
.cardl .t { font-weight: 600; margin-bottom: 4px; }
.cardl .m { display: flex; justify-content: space-between; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.kpi .v { font: 700 1.6rem Poppins, sans-serif; margin-top: 2px; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.hbar { display: grid; grid-template-columns: 130px 1fr 44px; gap: 10px; align-items: center; margin: 8px 0; font-size: 13px; }
.hbar .track { height: 12px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 6px; background: var(--blue); }
.hbar .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
table.t th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }

.sources { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.source-card { display: grid; gap: 10px; align-content: start; }
.source-card .h { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.steps { margin: 0; padding-left: 18px; color: var(--muted); }
.steps li { margin: 3px 0; }
pre.code { margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all; max-height: 220px; overflow: auto; }
.copy-row { display: flex; gap: 6px; } .copy-row input { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.qr { width: 160px; height: 160px; background: #fff; padding: 8px; border-radius: 8px; }
.qr img, .qr canvas { width: 100% !important; height: 100% !important; }

.drawer { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.drawer-bg { position: absolute; inset: 0; background: rgba(8, 20, 36, .45); opacity: 0; transition: opacity .2s; }
.drawer-panel { position: absolute; top: 0; right: 0; height: 100%; width: min(640px, 100%); background: var(--card); box-shadow: -10px 0 30px rgba(0, 0, 0, .2); transform: translateX(100%); transition: transform .22s ease; overflow-y: auto; padding: 20px 22px 40px; }
.drawer.open { pointer-events: auto; } .drawer.open .drawer-bg { opacity: 1; } .drawer.open .drawer-panel { transform: none; }
.d-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields .full { grid-column: 1 / -1; }
.section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 16px; }
dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 28px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.timeline .ic { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--blue-soft); font-size: 13px; }
.timeline .when { color: var(--muted); font-size: 12px; }
.timeline .txt { white-space: pre-wrap; word-break: break-word; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--card); color: var(--text); width: min(440px, calc(100% - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(8, 20, 36, .5); }
#dlgForm { padding: 18px; display: grid; gap: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(120%); background: var(--navy); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; transition: transform .2s; z-index: 80; max-width: calc(100% - 32px); }
.toast.show { transform: translateX(-50%); }
.progress { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; } .progress > div { height: 100%; background: var(--orange); width: 0; transition: width .2s; }
.stage-list { display: grid; gap: 6px; } .stage-list .copy-row { align-items: center; }
.swatch { width: 38px !important; height: 34px; padding: 2px; flex: none; cursor: pointer; }

/* ---------- Estilo Bitrix24 con la marca de AO ---------- */
.nav-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: var(--hot); color: #fff; font-size: 11px; font-weight: 700; vertical-align: 1px; }

/* Vistas rápidas */
.presets { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: thin; }
.preset { font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--muted); padding: 6px 12px; border-radius: 999px; display: inline-flex; gap: 6px; align-items: center; }
.preset b { font-variant-numeric: tabular-nums; color: var(--text); background: var(--bg); border-radius: 999px; padding: 0 7px; font-size: 12px; }
.preset:hover { border-color: var(--blue); }
.preset.on { background: var(--blue); border-color: var(--blue); color: #fff; } .preset.on b { background: rgba(255, 255, 255, .22); color: #fff; }
.preset.warn b { background: var(--hot-bg); color: var(--hot); } .preset.warn.on b { background: rgba(255, 255, 255, .22); color: #fff; }

/* Lista: barra de progreso de etapa por fila */
.sprog { display: flex; gap: 2px; height: 7px; margin: 3px 0 2px; }
.sprog i { flex: 1; background: var(--line); border-radius: 2px; }
.row { border-left: 3px solid transparent; }
.row:hover { border-left-color: var(--sc, var(--blue)); }
.due { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.due.today { color: var(--warm); } .due.late { color: var(--hot); }
.nextcol { min-width: 0; }

/* Kanban: cabeceras en flecha (chevron) con el color de la etapa */
.board { grid-auto-columns: minmax(260px, 1fr); gap: 10px; }
.col { background: transparent; border: 0; padding: 0; min-height: 300px; border-radius: 0; }
.col.drop { outline: 2px dashed var(--sc, var(--blue)); outline-offset: 2px; border-radius: 12px; }
.chev { display: flex; justify-content: space-between; align-items: center; gap: 8px; height: 34px; padding: 0 22px 0 12px; background: var(--sc); color: #fff;
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 0 100%); border-radius: 8px 0 0 8px; font-size: 13px; }
.chev b { font: 600 12.5px Poppins, sans-serif; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev .cnt { font-weight: 700; font-variant-numeric: tabular-nums; background: rgba(255, 255, 255, .22); border-radius: 999px; padding: 1px 8px; font-size: 12px; }
.col-sum { text-align: center; font: 700 15px Poppins, sans-serif; margin: 8px 0 6px; padding: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.col-add { width: 100%; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: 8px; padding: 6px; margin-bottom: 8px; cursor: pointer; }
.col-add:hover { color: var(--blue); border-color: var(--blue); }
.cardl { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--sc); border-radius: 10px; padding: 10px 12px; box-shadow: 0 1px 3px rgba(15, 42, 74, .06); transition: box-shadow .15s, transform .15s; }
.cardl:hover { box-shadow: var(--shadow); transform: translateY(-1px); border-color: var(--line); border-left-color: var(--sc); }
.cardl .amt { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.cardl .due { margin-top: 6px; }
.cardl .qa { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.cardl .qa a { text-decoration: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); font-size: 13px; }
.cardl .qa a:hover { border-color: var(--blue); background: var(--blue-soft); }
.cardl .foot { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.cardl .foot .muted { margin-left: auto; }
.linkbtn { font: inherit; font-size: 12.5px; font-weight: 600; background: none; border: 0; color: var(--blue); cursor: pointer; padding: 0; }
.linkbtn:hover { text-decoration: underline; }
.avatar { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--navy); color: var(--bg); font-size: 10.5px; font-weight: 700; flex: none; }

/* Ficha: barra de etapas clicable */
.drawer-panel { width: min(1060px, 100%); }
.stagebar { display: flex; gap: 8px; align-items: center; margin: 4px 0 14px; flex-wrap: wrap; }
.chevrons { display: flex; flex: 1 1 420px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.seg { --seg: var(--line); font: 600 12px Poppins, Inter, sans-serif; text-transform: uppercase; letter-spacing: .02em; flex: 1 0 auto; min-width: 96px; height: 34px; border: 0; cursor: pointer;
  background: var(--seg); color: #fff; padding: 0 18px 0 22px; margin-right: -10px; white-space: nowrap;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%, 12px 50%); transition: filter .15s; }
.seg:first-child { clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%); border-radius: 8px 0 0 8px; padding-left: 14px; }
.seg[style=""], .seg:not([style*="--seg"]) { color: var(--muted); }
.seg:hover { filter: brightness(1.08); } .seg.cur { box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18); }
.seg:focus-visible { outline: 2px solid var(--navy); outline-offset: -4px; }
.close-btns { display: flex; gap: 6px; }
.btn.won { color: #1F9D55; border-color: #1F9D55; } .btn.won.on, .btn.won:hover { background: #1F9D55; color: #fff; }
.btn.lost { color: var(--hot); border-color: var(--hot); } .btn.lost.on, .btn.lost:hover { background: var(--hot); color: #fff; }

/* Ficha en dos columnas: información a la izquierda, actividad a la derecha */
.d-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 20px; align-items: start; }
.d-left { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.d-left .section { margin-top: 14px; }
.blk { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 10px; }
.composer { padding: 0; overflow: hidden; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; padding: 0 6px; }
.tab { font: inherit; font-size: 13px; font-weight: 600; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 10px 10px 8px; cursor: pointer; white-space: nowrap; }
.tab.on { color: var(--blue); border-bottom-color: var(--blue); }
.cform { display: grid; gap: 10px; padding: 12px; }
.todo { margin: 14px 0; padding: 12px 14px; border-radius: 12px; background: var(--orange-soft); border: 1px solid color-mix(in srgb, var(--orange) 35%, transparent); }
.todo.empty-todo { background: var(--warm-bg); }
.todo-h { font: 600 13px Poppins, sans-serif; display: flex; gap: 8px; align-items: center; }
.todo-h b { background: var(--orange); color: #fff; border-radius: 999px; padding: 0 8px; font-size: 12px; }
.tasks { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.task { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.task label { font-weight: 500; font-size: 13.5px; min-width: 0; } .task label span { overflow-wrap: anywhere; }
.task.done label span { text-decoration: line-through; color: var(--muted); }
.timeline { position: relative; }
.timeline li { border-bottom: 0; padding: 6px 0; }
.timeline .evc { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.timeline .ev-etapa .evc .txt { font-weight: 600; } .timeline .arrow { color: var(--muted); }
.timeline .ev-tarea_hecha .evc { background: var(--ok-bg); }

@media (max-width: 900px) { .d-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) {
  .drawer-panel { padding: 16px 14px 40px; }
  .d-head { flex-wrap: wrap; } .d-head .actions { width: 100%; }
  .d-left { padding: 12px; } .fields { grid-template-columns: minmax(0, 1fr); }
  .chevrons { flex-basis: 100%; } .seg { min-width: 86px; font-size: 11px; }
}

@media (max-width: 860px) {
  .row { grid-template-columns: 1fr auto; }
  .row > :nth-child(n+2):not(.score) { display: none; }
  .row.head { display: none; }
}
@media (max-width: 640px) {
  .top { flex-wrap: wrap; padding: 10px 16px; gap: 8px; } .top nav { order: 3; flex-basis: 100%; }
  .view { padding: 14px 16px; } .fields { grid-template-columns: 1fr; } dl.kv { grid-template-columns: 110px 1fr; }
  .hbar { grid-template-columns: 96px 1fr 36px; } .grid2, .sources { grid-template-columns: 1fr; }
}
