:root {
  --ground: #fbfaf8;
  --surface: #ffffff;
  --surface-2: #f5f2ec;
  --line: #e7e2d9;
  --line-soft: #f0ece5;
  --ink: #1b1d21;
  --dim: #6c7079;
  --muted: #9498a1;
  --accent: #d9600a;
  --accent-soft: #fff3e8;
  --accent-line: rgba(217, 96, 10, .35);
  --pos: #0e8a56;
  --neg: #c4392f;
  /* Paleta categórica validada contra fondo blanco */
  --s1: #d9600a;
  --s2: #2f6fd0;
  --s3: #0e9c6f;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 16px;
  --shadow: 0 1px 2px rgba(24, 20, 14, .04), 0 8px 24px rgba(24, 20, 14, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -.015em; margin: 0; }
h1 { font-size: 1.65rem; font-weight: 640; }
h2 { font-size: 1.2rem; font-weight: 620; }
h3 { font-size: .95rem; font-weight: 620; }
p { margin: 0 0 .8em; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px 80px; }

/* ---------- Cabecera ---------- */
.top {
  position: sticky; top: 0; z-index: 30;
  background: rgba(251, 250, 248, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1080px; margin: 0 auto; padding: 13px 24px; display: flex; align-items: center; gap: 16px; }
.brand { font-weight: 650; letter-spacing: -.02em; color: var(--ink); }
.brand span { color: var(--accent); }
.top nav { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: .875rem; }
.top nav a { color: var(--dim); }
.top nav a:hover { color: var(--ink); text-decoration: none; }

/* ---------- Pestañas ---------- */
.tabs {
  position: sticky; top: 53px; z-index: 20;
  background: rgba(251, 250, 248, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  margin: 0 -24px 0; padding: 10px 24px;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 1px solid transparent; background: transparent; color: var(--dim);
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: .875rem;
  cursor: pointer; white-space: nowrap;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); font-weight: 600; }

/* ---------- Día / semana ---------- */
.grain-row { display: flex; align-items: center; gap: 6px; margin-top: 16px; font-size: .8rem; color: var(--muted); }
.grain {
  border: 1px solid var(--line); background: var(--surface); color: var(--dim);
  border-radius: 999px; padding: 4px 12px; font-size: .8rem; cursor: pointer; box-shadow: none;
}
.grain[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); font-weight: 600; }

/* ---------- Calculadora ---------- */
.sim { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 14px; align-items: start; }
.sim-controls { position: sticky; top: 112px; }
.sim-field { margin-bottom: 20px; }
.sim-field label { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 9px; }
.sim-field label b { color: var(--ink); font-size: .95rem; font-weight: 640; font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 5px; padding: 0; border: 0; border-radius: 999px; background: var(--surface-2); cursor: pointer; }
input[type=range]:focus { box-shadow: none; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); border: 3px solid #fff; box-shadow: 0 1px 6px rgba(24, 20, 14, .28); cursor: grab;
  transition: transform .12s ease;
}
input[type=range]::-webkit-slider-thumb:active { transform: scale(1.15); cursor: grabbing; }
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--accent);
  border: 3px solid #fff; box-shadow: 0 1px 6px rgba(24, 20, 14, .28); cursor: grab;
}
.sim-big { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sim-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; box-shadow: var(--shadow); }
.sim-value { font-size: 2.1rem; font-weight: 660; letter-spacing: -.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.sim-delta { font-size: .82rem; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; min-height: 1.2em; }
.sim-delta.up { color: var(--pos); }
.sim-delta.down { color: var(--neg); }
.cmp { margin-top: 12px; display: grid; gap: 10px; }
.cmp-row { display: grid; grid-template-columns: 150px 1fr; gap: 12px; align-items: center; font-size: .82rem; color: var(--dim); }
.cmp-track { background: var(--surface-2); border-radius: 999px; height: 12px; overflow: hidden; }
.cmp-fill { height: 12px; border-radius: 999px; background: var(--s1); width: 0; transition: width .35s cubic-bezier(.4, 0, .2, 1); }
.cmp-fill.base { background: #c9c3b8; }

@media (max-width: 780px) {
  .sim { grid-template-columns: 1fr; }
  .sim-controls { position: static; }
  .sim-big { grid-template-columns: 1fr; }
  .cmp-row { grid-template-columns: 120px 1fr; }
}

/* ---------- Secciones ---------- */
.hero { padding: 34px 0 18px; }
.hero .eyebrow { color: var(--dim); font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; }
section { margin-top: 34px; }
.panel-section { display: none; }
.panel-section.on { display: block; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head p { color: var(--dim); font-size: .875rem; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-label { color: var(--accent); text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; font-weight: 650; }
.card-label.plain { color: var(--muted); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 15px 17px; box-shadow: var(--shadow); }
.kpi .k-label { color: var(--dim); font-size: .78rem; }
.kpi .k-value { font-size: 1.5rem; font-weight: 640; letter-spacing: -.025em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .k-delta { font-size: .76rem; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.k-delta.up { color: var(--pos); }
.k-delta.down { color: var(--neg); }

/* ---------- Objetivos ---------- */
.goals { display: grid; gap: 12px; }
.goal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; box-shadow: var(--shadow); }
.goal-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.goal-head .g-name { font-weight: 620; }
.goal-head .g-pct { margin-left: auto; font-size: 1.45rem; font-weight: 660; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.goal .g-nums { color: var(--dim); font-size: .84rem; font-variant-numeric: tabular-nums; }
.goal .g-nums b { color: var(--ink); font-weight: 620; }
.track { background: var(--surface-2); border-radius: 999px; height: 10px; margin-top: 12px; overflow: hidden; }
.track .fill { height: 10px; border-radius: 999px; background: var(--s1); transition: width .4s ease; }
.track .fill.done { background: var(--pos); }
.track .fill.low { background: var(--s2); }

/* ---------- Gráficos ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 14px; }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 18px 10px; box-shadow: var(--shadow); }
.chart-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.chart-head h3 { font-size: .9rem; }
.legend { display: flex; gap: 12px; margin-left: auto; font-size: .78rem; color: var(--dim); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend [data-series] { cursor: pointer; user-select: none; transition: opacity .15s; }
.legend [data-series]:hover { color: var(--ink); }
.legend [data-series].off { opacity: .38; text-decoration: line-through; }
.chart { position: relative; }
.chart-empty { height: 178px; display: grid; place-items: center; color: var(--muted); font-size: .82rem; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.tip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity .1s;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 11px; font-size: .78rem; white-space: nowrap; z-index: 5;
  box-shadow: 0 8px 28px rgba(24, 20, 14, .14);
}
.tip .t-date { color: var(--dim); margin-bottom: 3px; }
.tip .t-row { display: flex; gap: 14px; justify-content: space-between; font-variant-numeric: tabular-nums; }

/* ---------- Tablas ---------- */
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { text-align: left; color: var(--dim); font-weight: 500; font-size: .78rem; padding: 0 10px 8px 0; border-bottom: 1px solid var(--line); }
td { padding: 11px 10px 11px 0; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; padding-right: 0; }
.table-scroll { overflow-x: auto; }

.bar-track { background: var(--surface-2); border-radius: 4px; height: 8px; min-width: 60px; }
.bar-fill { background: var(--s1); height: 8px; border-radius: 4px; }

/* ---------- Plan y packs ---------- */
.plan { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.plan .step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.plan .step .mes { color: var(--accent); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 650; }
.plan .step .obj { margin-top: 6px; }
.plan .step .inv { margin-top: 12px; color: var(--dim); font-size: .82rem; border-top: 1px solid var(--line-soft); padding-top: 9px; }

.pill { display: inline-block; font-size: .72rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--dim); background: var(--surface-2); }
.pill.ok { color: var(--pos); border-color: rgba(14, 138, 86, .3); background: rgba(14, 138, 86, .07); }
.pill.err { color: var(--neg); border-color: rgba(196, 57, 47, .3); background: rgba(196, 57, 47, .06); }

.empty { color: var(--muted); font-size: .875rem; border: 1px dashed var(--line); border-radius: var(--r); padding: 22px; text-align: center; background: var(--surface); }

/* ---------- Formularios ---------- */
label { display: block; font-size: .8rem; color: var(--dim); margin-bottom: 5px; }
input, textarea, select {
  width: 100%; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
  font: inherit; font-size: .9rem;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 130px; resize: vertical; line-height: 1.55; }
.field { margin-bottom: 12px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

button, .btn {
  display: inline-block; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 9px 15px; font: inherit; font-size: .875rem; cursor: pointer;
  box-shadow: 0 1px 2px rgba(24, 20, 14, .04);
}
button:hover, .btn:hover { border-color: var(--accent-line); color: var(--accent); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { color: #fff; filter: brightness(1.06); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); box-shadow: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 14px; }

.aviso { background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: var(--r); padding: 13px 17px; margin: 18px 0; font-size: .875rem; }

.center { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { font-size: 1.2rem; display: block; margin-bottom: 4px; }
.login-card .sub { color: var(--dim); font-size: .85rem; margin-bottom: 22px; }
.error-text { color: var(--neg); font-size: .85rem; margin-bottom: 12px; }

.foot { margin-top: 60px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; }

/* ---------- Entrada de las tarjetas ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.panel-section.on .kpi,
.panel-section.on .chart-card,
.panel-section.on .goal,
.panel-section.on .card,
.panel-section.on .plan .step,
.panel-section.on .sim-card { animation: rise .38s cubic-bezier(.4, 0, .2, 1) both; }
.panel-section.on .kpi:nth-child(2), .panel-section.on .chart-card:nth-child(2), .panel-section.on .goal:nth-child(2) { animation-delay: .05s; }
.panel-section.on .kpi:nth-child(3), .panel-section.on .chart-card:nth-child(3), .panel-section.on .goal:nth-child(3) { animation-delay: .1s; }
.panel-section.on .kpi:nth-child(4), .panel-section.on .chart-card:nth-child(4), .panel-section.on .goal:nth-child(4) { animation-delay: .15s; }
.panel-section.on .kpi:nth-child(5), .panel-section.on .chart-card:nth-child(5) { animation-delay: .2s; }
.panel-section.on .kpi:nth-child(6), .panel-section.on .chart-card:nth-child(6) { animation-delay: .25s; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 640px) {
  .wrap, .top-in { padding-left: 16px; padding-right: 16px; }
  .tabs { margin: 0 -16px; padding: 10px 16px; }
  h1 { font-size: 1.4rem; }
}
