/* A2D2 · zona privada de felipelovera.com (CRM + proyectos)
   Misma identidad que el sitio: Raleway, casi negro, azul y verde lima. */
:root {
  --ink: #15181B; --ink-2: #262B30; --blue: #4A9ACA; --blue-d: #377397;
  --lime: #B6C833; --lime-d: #6D781E; --lime-l: #DCE596;
  --bg: #EEF3F8; --panel: #FFFFFF; --fg: #1F2328; --muted: #5C6670; --line: #D9DEE4;
  --tint: #E6EEF6; --track: #E3EAF2; --ok: #2E7D32; --warn: #9A5B00; --bad: #B3261E;
  --label: #5E6A10; --chip-bg: #EEF4C9;
  --font: "Raleway", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 12px;
}
:root[data-tema="oscuro"] {
  --bg: #0F1215; --panel: #181C20; --fg: #E9EDF1; --muted: #A2ACB6; --line: #2B3238;
  --tint: #20262C; --track: #262D34; --ok: #7BC67E; --warn: #F2B35B; --bad: #FF8A80;
  --label: #DCE596; --chip-bg: #2B3112; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) {
    --bg: #0F1215; --panel: #181C20; --fg: #E9EDF1; --muted: #A2ACB6; --line: #2B3238;
    --tint: #20262C; --track: #262D34; --ok: #7BC67E; --warn: #F2B35B; --bad: #FF8A80;
    --label: #DCE596; --chip-bg: #2B3112; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--fg); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Encabezado */
.top { background: var(--ink); color: #fff; }
.top-in, .wrap { max-width: 1240px; margin: 0 auto; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px)); }
.top-in { display: flex; flex-direction: column; gap: 14px; padding-block: 16px 0; }
.top-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.logo { height: 28px; width: auto; display: block; }
.top-tools { display: flex; align-items: center; gap: 10px; font-size: .82rem; color: #C3CCD5; flex-wrap: wrap; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid rgba(255,255,255,.22); background: transparent; color: #C3CCD5; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.icon-btn:hover { color: #fff; border-color: rgba(255,255,255,.5); }
.link-btn { background: none; border: 0; color: #C3CCD5; cursor: pointer; font-weight: 600; padding: 6px 4px; }
.link-btn:hover { color: #fff; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; overflow-x: auto; }
.nav a, .nav button { color: #C3CCD5; text-decoration: none; font-weight: 600; font-size: .92rem; padding: 12px 14px; border: 0; border-bottom: 3px solid transparent; background: none; cursor: pointer; white-space: nowrap; }
.nav a[aria-current="page"], .nav button[aria-selected="true"] { color: #fff; font-weight: 700; border-bottom-color: var(--lime); }
.stripe { height: 5px; display: flex; } .stripe i { display: block; }

/* Contenido */
.wrap { padding-block: 24px 48px; display: flex; flex-direction: column; gap: 22px; width: 100%; }
/* Una hoja dentro de la página (p. ej. las pestañas del CRM) ocupa todo el ancho de la página:
   sin esto, los márgenes automáticos la encogen al ancho de su contenido en pantallas grandes. */
.wrap .wrap { max-width: none; margin: 0; padding-left: 0; padding-right: 0; align-self: stretch; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.eyebrow { margin: 0; font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--label); }
h1 { margin: 4px 0 0; font-size: clamp(1.6rem, 3vw, 2.1rem); font-weight: 800; line-height: 1.1; text-wrap: balance; }
h2 { margin: 0; font-size: 1.08rem; font-weight: 800; }
.note { margin: 0; font-size: .82rem; color: var(--muted); max-width: 78ch; }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.filters label { display: flex; gap: 6px; align-items: center; }
select, input[type=text], input[type=email], input[type=number], input[type=date], input[type=url], textarea {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); min-height: 38px; }
textarea { resize: vertical; }

.xf { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 40px; padding: 8px 12px; border-radius: 10px; background: var(--tint); font-size: .85rem; }
.xf > b { color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; background: var(--ink); color: #fff; font-size: .76rem; font-weight: 700; padding: 5px 10px 5px 12px; cursor: pointer; }
:root[data-tema="oscuro"] .chip { background: var(--blue-d); }
.clear { border: 0; background: none; color: var(--blue); font-weight: 700; cursor: pointer; padding: 4px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-top: 4px solid var(--c, var(--ink)); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.tile .lbl { font-size: .68rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--label); }
.tile .num { font-size: 1.65rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .sub { font-size: .8rem; color: var(--muted); }
.tile .sub b { color: var(--fg); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .76rem; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.rows { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; flex-direction: column; gap: 6px; text-align: left; border: 0; background: transparent; padding: 6px 8px; margin: 0 -8px; border-radius: 8px; color: var(--fg); width: calc(100% + 16px); }
button.row { cursor: pointer; }
button.row:hover { background: var(--tint); }
.row[aria-pressed="true"] { background: color-mix(in srgb, var(--blue) 14%, var(--panel)); box-shadow: inset 3px 0 0 var(--blue); }
.row.dim { opacity: .42; }
.row-top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; font-size: .9rem; }
.row-top b { font-weight: 700; }
.row-top small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.val { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.val b { color: var(--fg); }
.track { position: relative; display: block; height: 12px; border-radius: 4px; background: var(--track); overflow: hidden; }
.seg { position: absolute; top: 0; bottom: 0; }
.ref { position: absolute; top: 0; bottom: 0; border-left: 2px dashed var(--fg); }
.pill { display: inline-block; font-size: .7rem; font-weight: 700; padding: 1px 9px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; line-height: 1.7; }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); } .pill.mute { color: var(--muted); }
.tag { font-size: .7rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--chip-bg); color: var(--label); white-space: nowrap; }

.acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--fg); font-weight: 700; font-size: .8rem; padding: 8px 12px; border-radius: 8px; cursor: pointer; min-height: 36px; }
.btn:hover { border-color: var(--blue); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
:root[data-tema="oscuro"] .btn.primary { background: var(--blue-d); border-color: var(--blue-d); }
.btn.win { border-color: var(--lime-d); color: var(--label); }
.btn.lose { color: var(--muted); }
.btn.conf { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }

.curso { display: flex; flex-direction: column; gap: 8px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.log { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; }
.log div { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.prox { margin-left: auto; font-size: .78rem; color: var(--muted); }

.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: .78rem; font-weight: 700; color: var(--muted); }
.form .wide { grid-column: 1 / -1; }
.msg { font-size: .82rem; color: var(--muted); }
.msg.ok { color: var(--ok); } .msg.err { color: var(--bad); }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: top; }
thead th { background: var(--ink); color: #fff; font-weight: 700; position: sticky; top: 0; }
td.r, th.r { text-align: right; }
td.wrap-txt { white-space: normal; min-width: 220px; }

.det { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kv { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; background: var(--tint); }
.kv span { font-size: .66rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.kv b { font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--fg); padding: 22px; width: min(640px, 92vw); }
dialog::backdrop { background: rgba(10, 12, 14, .55); }

.foot { background: var(--ink); color: #C3CCD5; font-size: .78rem; }
.foot .wrap { padding-block: 14px; flex-direction: row; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.foot img { height: 20px; width: auto; }

/* Acceso */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--ink); }
.gate-card { width: min(420px, 100%); background: #FFFFFF; color: #1F2328; border-radius: 16px; padding: 30px 28px; display: flex; flex-direction: column; gap: 16px; color-scheme: light;
  --panel: #FFFFFF; --fg: #1F2328; --muted: #5C6670; --line: #D9DEE4; --label: #5E6A10; --bad: #B3261E; }
.gate-card .logo-dark { height: 30px; width: auto; align-self: flex-start; }
.sso { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); font-weight: 700; cursor: pointer; }
.sso:hover { border-color: var(--blue); }
.sso.apple { background: #000; color: #fff; border-color: #000; }
.skeleton { color: transparent !important; background: var(--track); border-radius: 6px; }
@media (prefers-reduced-motion: no-preference) { .fade { animation: fade .25s ease-out; } @keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } } }

/* botón Columnas ▾ de las tablas (tablas.js y el Inicio) */
.colsel { position: relative; }
.colsel > summary { list-style: none; }
.colsel > summary::-webkit-details-marker { display: none; }
.colsel-l { position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 2px; min-width: 190px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.colsel-l label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: .85rem; }
.colsel-l label:hover { background: var(--tint); }
.colbar { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.colsel > summary.btn { min-height: 32px; padding: 6px 12px; font-size: .8rem; }
.colsel-todas { margin-top: 4px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--blue); font-weight: 700; padding: 8px; cursor: pointer; text-align: left; }

/* secciones plegables (secciones.js): flecha junto al título */
.plg-h { cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 8px; }
.plg-h:hover { color: var(--blue); }
.plg-car { color: var(--muted); font-size: .85em; width: 12px; display: inline-block; }
.card.plegada > :not(:first-child) { display: none !important; }

/* el botón de columnas va dentro del encabezado de la tabla */
th.con-colsel { text-align: right; }
.colsel.en-th { display: inline-block; vertical-align: middle; margin-left: 6px; }
.colsel-btn { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 24px; border-radius: 6px; border: 1px solid rgba(255,255,255,.35); color: #fff; cursor: pointer; font-size: .9rem; line-height: 1; }
.colsel-btn:hover, .colsel[open] > .colsel-btn { background: rgba(255,255,255,.15); }
.colsel.en-th .colsel-l { color: var(--fg); font-weight: 500; text-align: left; white-space: nowrap; text-transform: none; letter-spacing: 0; }
.colsel.en-th .colsel-l { position: fixed; right: auto; top: 0; left: 0; z-index: 50; }

/* tablas.js: ordenar, mover y cambiar el ancho de columnas (antes solo en crm.html y proyectos.html) */
table thead th[draggable="true"] { user-select: none; }
table thead th[draggable="true"]:hover { color: var(--fg); }
.ord-ic { font-size: .7em; color: var(--blue); }
.ord-hint { font-size: .7em; color: var(--muted); opacity: .55; }
th:hover .ord-hint { opacity: 1; }
.col-asa { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 2; }
th:last-child > .col-asa { right: 0; }
.col-asa:hover { background: color-mix(in srgb, var(--blue) 45%, transparent); }
table[data-fijo] th, table[data-fijo] td { white-space: normal !important; overflow-wrap: break-word; word-break: normal; overflow: hidden; }
table[data-fijo] .btn, table[data-fijo] .clear, table[data-fijo] .pill, table[data-fijo] .tag { white-space: nowrap; }
table[data-fijo] td.r, table[data-fijo] th.r { white-space: nowrap !important; text-overflow: ellipsis; }
table[data-fijo] th.con-colsel { overflow: visible; }

/* ===================== CELULAR (≤ 700 px) =====================
   Tablas → tarjetas (tablas.js pone data-label y marca .tc-extra en los campos secundarios),
   ventanas a pantalla completa, tarjetas de indicadores de 2 en 2, pestañas que se deslizan,
   filtros de la cabecera detrás de un botón (secciones.js). */
.tc-mas, .filtros-btn { display: none; }
@media (max-width: 700px) {
  .top-in, .wrap { padding-left: 16px !important; padding-right: 16px !important; }
  .wrap { padding-block: 16px 40px; gap: 16px; }
  .top-tools > span { display: none; }               /* el correo: no cabe */
  .nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; margin-inline: -16px; padding-inline: 16px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a, .nav button { padding: 12px 12px; flex: 0 0 auto; }
  h1 { font-size: 1.5rem; }
  .head { align-items: stretch; }
  .card { padding: 14px; border-radius: 14px; }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 10px 12px; border-top-width: 3px; }
  .tile .num { font-size: 1.2rem; overflow-wrap: anywhere; }
  .tile .sub { font-size: .74rem; }
  .btn, .clear, select, input[type=text], input[type=email], input[type=number], input[type=date], input[type=url], textarea { min-height: 44px; font-size: 16px; }
  .btn { padding: 8px 14px; }

  /* filtros de la cabecera: detrás de "Filtros" */
  .filtros-btn { display: inline-flex; align-items: center; gap: 6px; }
  .head > .filters.plegable:not(.abiertos) > :not(.filtros-btn):not(.siempre) { display: none !important; }
  .head > .filters.plegable { width: 100%; }
  .head > .filters.plegable.abiertos { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; flex-direction: column; align-items: stretch; }

  /* ventanas: pantalla completa, título y cierre siempre visibles */
  dialog, dialog[open] { width: 100vw !important; max-width: 100vw !important; height: 100dvh !important; max-height: 100dvh !important; margin: 0 !important; border-radius: 0 !important; border: 0 !important; padding: 16px 16px 32px !important; box-sizing: border-box; overflow-y: auto; inset: 0; }
  dialog .form, dialog .fi-form, dialog form { grid-template-columns: minmax(0, 1fr) !important; }
  dialog .acts { position: sticky; bottom: -32px; background: var(--panel); padding-block: 10px; z-index: 2; }
  .ficha { height: 100dvh !important; }
  .fi-head { position: sticky; top: 0; z-index: 3; background: var(--panel); }

  /* tablas → tarjetas */
  .tablewrap { overflow: visible; }
  table.tc, table.tc[data-fijo] { display: block; width: 100% !important; table-layout: auto !important; font-size: .88rem; }
  table.tc thead { display: none; }
  table.tc tbody, table.tc tfoot { display: flex; flex-direction: column; gap: 10px; }
  table.tc tfoot { margin-top: 10px; }
  table.tc tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
  table.tc tr.clic:hover td { background: transparent; }
  table.tc td { display: block; border: 0 !important; padding: 0 !important; white-space: normal !important; width: auto !important; min-width: 0 !important; max-width: none !important; text-align: left !important; position: static !important; box-shadow: none !important; background: transparent !important; overflow: visible !important; }
  table.tc td[data-label]::before { content: attr(data-label); display: block; font-size: .64rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
  table.tc td.tc-titulo { grid-column: 1 / -1; font-size: 1rem; }
  table.tc td.tc-titulo::before { display: none; }
  table.tc td.tc-acc, table.tc td[colspan] { grid-column: 1 / -1; }
  table.tc td.tc-acc::before { display: none; }
  table.tc tr:not(.tc-abierta) td.tc-extra { display: none !important; }
  table.tc .tc-mas { display: flex; width: fit-content; margin-top: 6px; border: 0; background: none; color: var(--blue); font: inherit; font-weight: 700; font-size: .84rem; padding: 4px 0; cursor: pointer; min-height: 32px; align-items: center; }
  table.tc .col-asa, table.tc .ord-hint { display: none; }
}
