/* ============================================================
   BODEGAS EMPRESARIALES 2 CAMINOS — CRM de ventas
   Sistema de diseño v3 · según especificación de diseño
   Móvil primero · modo oscuro automático · sin sombras
   ============================================================ */
:root {
  --bg: #EEF0ED;
  --card: #FFFFFF;
  --ink: #14212B;
  --muted: #5B6770;
  --line: #DADFDA;
  --chip: #E2E6E1;
  --dark: #14212B;
  --dark-ink: #C5D0D8;
  --ok: #1F8A5B;
  --ok-bg: #E4F2EA;
  --amber: #D9930D;
  --amber-bg: #FCEFD2;
  --amber-tx: #8A5A00;
  --blue: #4A6FA5;
  --blue-bg: #E7EDF6;
  --red: #C7352B;
  --red-bg: #FBE9E7;
  --radius: 16px;
  --font: "Archivo", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D151B;
    --card: #16222B;
    --ink: #E8EDF0;
    --muted: #93A0AA;
    --line: #263541;
    --chip: #1E2C37;
    --dark: #0A1117;
    --dark-ink: #C5D0D8;
    --red-bg: #3A1C19;
    --amber-bg: #3B2E10;
    --amber-tx: #F2C45E;
    --ok-bg: #143527;
    --blue-bg: #1B2A3F;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45;
  background: var(--bg); color: var(--ink);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 8px; }
a { color: var(--blue); }
button, input, select, textarea { font-family: var(--font); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------------- Estructura ---------------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 60;
  background: var(--dark); color: var(--dark-ink);
  display: flex; flex-direction: column; padding: 22px 14px;
}
.side-brand { font-weight: 800; font-size: 15px; color: #fff; line-height: 1.3; padding: 0 10px 18px; }
.brand-mascota { display: block; width: 60px; height: auto; margin-bottom: 8px; }
.side-brand span { display: block; font-weight: 500; font-size: 13px; color: var(--dark-ink); }
.side-nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.side-nav a {
  display: flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 10px 14px; border-radius: 10px;
  color: var(--dark-ink); text-decoration: none; font-size: 14px; font-weight: 600;
  transition: background .15s ease, color .15s ease;
}
.side-nav a svg { width: 20px; height: 20px; flex: none; }
.side-nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.side-nav a.active { background: #fff; color: var(--dark); }

.mobilebar { display: none; }

.side-user {
  margin-top: auto; padding: 14px 10px 0;
  border-top: 1px solid rgba(255,255,255,.15);
  display: flex; align-items: center; gap: 8px;
}
.side-mascota { padding: 10px 10px 12px; }
.side-mascota img { display: block; width: 52px; height: auto; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.28); }
.user-float {
  position: fixed; top: 18px; right: 32px; z-index: 55;
  display: flex; align-items: center; gap: 10px;
}
.user-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px 4px 4px; font-size: 13px; font-weight: 600;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--dark); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.content { margin-left: 250px; padding: 32px; max-width: 1264px; }
.grid6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
@media (max-width: 899px) {
  .grid6 { grid-template-columns: 1fr; }
  .grid6 > * { grid-column: span 1 !important; }
}
.no-nav .content { margin: 0 auto; max-width: 720px; }

@media (max-width: 899px) {
  .sidebar { display: none; }
  .user-float { display: none; }
  .mobilebar { display: block; position: sticky; top: 0; z-index: 60; background: var(--bg); }
  .mobile-top {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px 8px;
  }
  .brand { font-weight: 800; font-size: 14px; }
  .brand span { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
  .mobile-nav {
    display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 12px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .mobile-nav::-webkit-scrollbar { display: none; }
  .mobile-nav a {
    flex: none; display: inline-flex; align-items: center; gap: 8px;
    min-height: 44px; padding: 10px 14px; border-radius: 12px;
    background: var(--card); border: 1px solid var(--line);
    color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 600;
  }
  .mobile-nav a svg { width: 20px; height: 20px; }
  .mobile-nav a.active { background: var(--dark); color: #fff; border-color: var(--dark); }
  .content { margin-left: 0; padding: 16px 16px 40px; max-width: none; }
}

/* ---------------- Encabezado de página ---------------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--muted); font-size: 13px; margin: 2px 0 14px; }

/* ---------------- Tarjetas ---------------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.card h3 { font-size: 16px; font-weight: 700; margin: 0 0 14px; }

/* Hero: tarjeta destacada (una por página) */
.hero {
  background: var(--dark); color: #fff;
  border-radius: 20px; padding: 22px; border: none;
}
.hero .hero-label { font-size: 13px; color: var(--dark-ink); margin-bottom: 6px; }
.hero .hero-value {
  font-size: clamp(27px, 4vw, 38px); font-weight: 700; letter-spacing: -.025em;
  line-height: 1.05; font-variant-numeric: tabular-nums; margin-bottom: 14px;
}
.hero-bar { display: flex; gap: 3px; height: 12px; margin-bottom: 10px; }
.hero-bar span { border-radius: 999px; min-width: 6px; }
.hero-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 15.5px; color: var(--dark-ink); }
.hero-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; font-style: normal; }

/* Alerta */
.alert-card {
  background: var(--red-bg); border: 1px solid var(--red);
  border-radius: var(--radius); padding: 18px;
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
}
.alert-card .alert-num { font-size: 30px; font-weight: 700; color: var(--red); font-variant-numeric: tabular-nums; }
.alert-card .alert-tx { flex: 1; min-width: 180px; }
.alert-card .alert-tx b { display: block; font-size: 15px; }
.alert-card .alert-tx span { font-size: 13px; color: var(--muted); }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin: 14px 0; }
.kpi-grid.k4 { grid-template-columns: repeat(4, 1fr); }
.kpi-grid.k3 { grid-template-columns: repeat(3, 1fr); }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 14px 14px 18px; position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--kpi-c, var(--muted)); }
.kpi .kpi-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .kpi-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
@media (max-width: 899px) {
  .kpi-grid, .kpi-grid.k4, .kpi-grid.k3 { grid-template-columns: 1fr 1fr; }
  .kpi-grid .kpi:first-child { grid-column: 1 / -1; }
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin: 14px 0; }
.card-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.card-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------- Botones ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: filter .15s ease, background .15s ease;
  white-space: nowrap;
}
.btn:hover { filter: brightness(.96); }
.btn-primary { background: var(--dark); border-color: var(--dark); color: #fff; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------------- Etiquetas de estado ---------------- */
.pill, .badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
  border: 1px solid transparent;
}
.pill-ok, .badge-ok { background: var(--ok-bg); color: var(--ok); }
.pill-pend, .badge-amarillo { background: var(--amber-bg); color: var(--amber-tx); }
.pill-bad, .badge-rojo, .badge-bad { background: var(--red-bg); color: var(--red); }
.pill-info { background: var(--blue-bg); color: var(--blue); }
.pill-mut, .badge-mut { background: var(--chip); color: var(--muted); }
.pill-warn, .badge-warn { background: var(--amber-bg); color: var(--amber-tx); }

/* ---------------- Tablas ---------------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 0 14px; text-align: left; border-bottom: 1px solid var(--line); }
thead th { height: 44px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
tbody td { min-height: 52px; padding-top: 10px; padding-bottom: 10px; vertical-align: middle; }
tbody tr:hover { background: var(--chip); }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { white-space: nowrap; text-align: right; }
@media (max-width: 899px) {
  .table-wrap { background: none; border: none; overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; padding: 6px 0; }
  .table-wrap td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    border: none; min-height: 0; padding: 7px 14px; text-align: right;
  }
  .table-wrap td::before {
    content: attr(data-label);
    flex: none; max-width: 44%;
    font-size: 12px; font-weight: 700; color: var(--muted); text-align: left;
  }
  .table-wrap td.num { text-align: right; }
  /* Celdas de acciones y celdas sin etiqueta: bloque simple, sin etiqueta */
  .table-wrap td.actions, .table-wrap td[data-label=""] { display: block; text-align: left; }
  .table-wrap td.actions::before, .table-wrap td[data-label=""]::before { content: none; }
  /* Celdas con texto largo (mensajes, notas, descripciones): etiqueta arriba */
  .table-wrap td.wide { display: block; text-align: left; }
  .table-wrap td.wide::before { display: block; max-width: none; margin-bottom: 3px; }
}
@media (max-width: 899px) {
  .page-head h1 { flex: 1 1 100%; font-size: 24px; }
}

/* ---------------- Embudo ---------------- */
.funnel { display: flex; flex-direction: column; gap: 7px; }
.funnel-row { display: grid; grid-template-columns: 96px 1fr 22px; align-items: center; gap: 10px; font-size: 14px; }
.funnel-row .fbar { height: 10px; background: var(--chip); border-radius: 999px; overflow: hidden; }
.funnel-row .fbar span { display: block; height: 100%; border-radius: 999px; min-width: 4px; }
.funnel-row .fnum { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------------- Cobros ---------------- */
.cobros { display: flex; flex-direction: column; }
.cobro-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.cobro-row:last-child { border-bottom: none; }
.cobro-row .c-label { font-size: 14px; color: var(--muted); }
.cobro-row .c-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------- Lista de acciones ---------------- */
.action-list { display: flex; flex-direction: column; }
.action-row { display: flex; gap: 14px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.action-row:last-child { border-bottom: none; }
.date-block {
  flex: none; width: 52px; text-align: center;
  background: var(--chip); border-radius: 12px; padding: 8px 0;
}
.date-block b { display: block; font-size: 20px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.date-block span { font-size: 12px; color: var(--muted); }
.action-row .a-title { font-size: 15px; font-weight: 700; }
.action-row .a-detail { font-size: 14px; color: var(--muted); margin-top: 2px; }

/* ---------------- Formularios ---------------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 2px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink); font-size: 15px; margin-top: 6px;
}
textarea { min-height: 0; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--amber); outline-offset: 1px; border-color: var(--amber); }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; margin-top: 0; accent-color: var(--dark); }
.field-error { color: var(--red); font-size: 13px; margin-top: 4px; }
.form-grid { display: grid; gap: 12px; max-width: 720px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 14px; background: var(--card); display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
legend { font-weight: 700; padding: 0 8px; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; align-items: center; margin: 8px 0 24px; flex-wrap: wrap; }
.link-plain { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; }
.inline-form { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form label { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.inline-form input, .inline-form select { width: auto; margin-top: 0; min-height: 40px; }

/* ---------------- Alertas y mensajes ---------------- */
.alert { padding: 12px 16px; border-radius: 12px; margin: 12px 0; font-size: 14px; border: 1px solid transparent; }
.alert-error { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.flash { background: var(--ok-bg); color: var(--ok); padding: 12px 16px; border-radius: 12px; margin: 12px 0; }
.muted { color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
@media (max-width: 899px) { .two-col { grid-template-columns: 1fr; } }

/* ---------------- Kanban ---------------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; }
.kcol { flex: 1 0 240px; background: var(--chip); border-radius: var(--radius); padding: 12px; min-height: 200px; }
.kcol h4 { font-size: 12px; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 0 0 10px; font-weight: 700; }
.kcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; font-size: 14px; }
.kcard b { display: block; font-size: 15px; }
.kcard .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.meta { color: var(--muted); font-size: 13px; }

/* ---------------- Bitácora ---------------- */
.cob-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.cob-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
details.card summary { cursor: pointer; font-weight: 700; }

/* ---------------- Login ---------------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 80vh; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 32px; width: 400px; max-width: 100%; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-mascota { display: block; width: 120px; height: auto; margin: 0 auto 12px; }
.login-has-oficial { position: relative; }
.login-oficial { position: absolute; top: 14px; right: 14px; width: 46px; height: auto; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.22); }
.login-card label { margin-bottom: 12px; display: block; }
.login-card .btn { width: 100%; margin-top: 8px; }

/* ---------------- Mascota 2Caminos ---------------- */
.mascota-band { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 16px; margin: 0 0 14px; }
.mascota-band img { width: 72px; height: auto; flex-shrink: 0; }
.mascota-band .mb-tx b { display: block; font-size: 1.02rem; }
.mascota-band.celebra { border-color: #1F8A5B; }

/* ---------------- Vistas específicas ---------------- */
.spec { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.spec > div { background: var(--chip); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.note { background: var(--amber-bg); border: 1px solid var(--amber); border-radius: 12px; padding: 12px 14px; color: var(--amber-tx); font-size: 14px; }
.terms { font-size: 13px; color: var(--muted); }
.foot { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.hdr { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.sec { margin-bottom: 20px; }
.tot { font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
.big { font-size: 18px; }
.folio { font-weight: 800; font-variant-numeric: tabular-nums; }
.ok { color: var(--ok); font-weight: 700; }
.warn { color: var(--amber-tx); font-weight: 700; }
.r { text-align: right; }
.page { background: var(--card); }
.sub { color: var(--muted); font-size: 13px; }
.cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
