@import url("https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@3.26.0/dist/tabler-icons.min.css");
:root {
  --bg: #f4f6fb;          /* fondo general (claro) */
  --surface: #ffffff;     /* tarjetas / paneles */
  --surface-2: #eef1f7;   /* hover / inputs */
  --line: #e1e6ef;        /* bordes */
  --text: #1b2433;
  --muted: #6c7689;
  --accent: #2F6FED;      /* azul corporativo */
  --accent-2: #2456c9;    /* azul oscuro para degradados */
  --accent-soft: rgba(47, 111, 237, 0.10);
  --danger: #E5392E;      /* rojo corporativo */
  --ok: #1FA463;          /* verde corporativo */
  --amber: #b8860b;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 2px 6px rgba(16,24,40,.05);
  --radius: 14px;
  --maxw: 560px;
  font-size: 16px;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
#app { max-width: var(--maxw); margin: 0 auto; min-height: 100vh; background: var(--bg); }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  background: rgba(255, 255, 255, 0.88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
}
.topbar .brand-logo { height: 30px; width: auto; display: block; }
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: 0.2px; }
.topbar .sub { font-size: 12px; color: var(--muted); margin-left: auto; }
.iconbtn { background: none; border: 0; color: var(--muted); font-size: 22px; padding: 4px; cursor: pointer; display: inline-flex; }
.iconbtn:hover { color: var(--text); }

/* Content */
.content { padding: 16px 16px 96px; }
.label { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.section-title {
  font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--muted); margin: 20px 0 10px;
}

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card.tap { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.card.tap:hover { border-color: #c2d2f6; box-shadow: 0 2px 6px rgba(47,111,237,.10), 0 6px 16px rgba(47,111,237,.08); }
.card.tap:active { background: var(--surface-2); }
.row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.row + .row { margin-top: 6px; }
.strong { font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }
.big { font-size: 22px; font-weight: 650; }
.pill {
  display: inline-block; font-size: 12px; padding: 2px 10px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent);
}
.pill.gray  { background: var(--surface-2); color: var(--muted); }
.pill.amber { background: rgba(184, 134, 11, .12); color: var(--amber); }
.pill.green { background: rgba(31, 164, 99, .12); color: var(--ok); }
.pill.red   { background: rgba(229, 57, 46, .12); color: var(--danger); }

/* Forms */
.field { margin-bottom: 14px; }
label.fl { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font-size: 16px; font-family: inherit; color: var(--text);
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; outline: none;
}
input::placeholder, textarea::placeholder { color: #aab1c0; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 64px; }
.inline { display: flex; gap: 8px; }
.inline > * { flex: 1; }

/* Buttons */
.btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 16px; font-weight: 500; padding: 13px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; transition: border-color .15s, filter .15s; box-shadow: var(--shadow);
}
.btn:hover { border-color: #c2d2f6; }
.btn:active { transform: scale(0.99); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0; color: #fff; font-weight: 600;
  box-shadow: 0 6px 18px rgba(47, 111, 237, 0.28);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: none; box-shadow: none; }
.btn.danger { color: var(--danger); border-color: rgba(229, 57, 46, .35); }
.btn + .btn { margin-top: 10px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* Líneas editor */
.linea { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); }
.linea .del { color: var(--danger); font-size: 13px; background: none; border: 0; padding: 0; cursor: pointer; }
.adder { border: 1px dashed #b9c4d8; color: var(--muted); background: none; box-shadow: none; }
.adder:hover { color: var(--accent); border-color: var(--accent); }

/* Totals */
.totals {
  background: linear-gradient(135deg, rgba(47,111,237,.08), rgba(31,164,99,.06));
  border: 1px solid rgba(47, 111, 237, .22);
  border-radius: 12px; padding: 12px 14px; margin: 14px 0;
}
.totals .row { color: #33405a; }
.totals .big { color: var(--accent); }

/* Tareas rápidas (chips) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--accent); cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip:active { background: var(--accent-soft); }

/* Bottom nav (móvil) */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  max-width: var(--maxw); margin: 0 auto;
  display: flex; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; text-align: center; padding: 8px 0 7px; color: var(--muted);
  text-decoration: none; font-size: 11px;
}
.nav a.active { color: var(--accent); }
.nav a i { font-size: 22px; display: block; line-height: 1.1; }
.nav .desk-only { display: none; }
.nav .side-logo { display: none; }
.nav.only-desk { display: none; }

/* Login */
.login { padding: 0 22px; display: flex; flex-direction: column; justify-content: center; min-height: 100vh; }
.brand { text-align: center; margin-bottom: 28px; }
.brand .brand-logo-img { width: 200px; max-width: 70%; height: auto; display: inline-block; }
.brand h2 { font-size: 20px; margin: 16px 0 2px; color: var(--text); }
.brand p { color: var(--muted); margin: 0; font-size: 14px; }
.error { color: var(--danger); font-size: 14px; margin: 4px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.spin { text-align: center; color: var(--muted); padding: 30px; }

/* ============ Escritorio: menú lateral ============ */
@media (min-width: 820px) {
  #app { max-width: none; margin: 0; }

  .nav {
    top: 0; bottom: 0; left: 0; right: auto;
    width: 240px; max-width: none; margin: 0;
    flex-direction: column; align-items: stretch; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line);
    background: #ffffff;
    padding: 18px 12px;
  }
  .nav .side-logo {
    display: block; height: 52px; width: auto; max-width: calc(100% - 20px);
    object-fit: contain; margin: 8px auto 22px;
  }
  .nav a {
    flex: none; display: flex; flex-direction: row; align-items: center; gap: 12px;
    text-align: left; font-size: 14.5px; padding: 11px 12px; border-radius: 10px;
    transition: background .15s, color .15s;
  }
  .nav a.desk-only { display: flex; }
  .nav a i { display: inline-block; font-size: 20px; line-height: 1; }
  .nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .nav a.active i { color: var(--accent); }
  .nav a:not(.active):hover { background: var(--surface-2); color: var(--text); }
  .nav.only-desk { display: flex; }

  .topbar { padding: 16px 40px; }
  .topbar .brand-logo { display: none; }
  .content { padding: 26px 40px 64px; max-width: 1500px; }
  /* dejar hueco al menú lateral SOLO en las páginas que lo muestran */
  div:has(> .nav) > .topbar,
  div:has(> .nav) > .content { margin-left: 240px; }

  .login { max-width: 400px; margin: 0 auto; }
}

/* ---------- Rendimientos: KPIs + barras ---------- */
.kpis {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi .k-label { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.kpi .k-value { font-size: 20px; font-weight: 650; color: var(--text); }
.bar-row {
  display: grid; grid-template-columns: 92px 1fr auto; align-items: center;
  gap: 10px; padding: 7px 0;
}
.bar-row + .bar-row { border-top: 1px solid var(--line); }
.bar-row .lbl { color: var(--muted); font-size: 13px; }
.bar-row .track {
  height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden;
}
.bar-row .fill {
  display: block; height: 100%; border-radius: 999px; min-width: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.bar-row .fill.neg { background: linear-gradient(90deg, var(--danger), #b6453f); }
.bar-row .val { font-size: 13.5px; font-weight: 600; color: var(--text); white-space: nowrap; }
@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Menú de usuario (topbar) ---------- */
.usermenu { position: relative; margin-left: auto; }
.userbtn {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 4px 6px; border-radius: 8px;
}
.userbtn:hover { color: var(--text); background: var(--surface-2); }
.userbtn .sub { margin-left: 0; }
.userbtn i { font-size: 15px; }
.usermenu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; min-width: 175px; box-shadow: 0 12px 30px rgba(16, 24, 40, 0.15);
}
.um-rol {
  font-size: 11px; color: var(--muted); text-transform: capitalize;
  padding: 6px 8px 8px; border-bottom: 1px solid var(--line); margin-bottom: 6px;
}
.um-logout {
  width: 100%; display: flex; align-items: center; gap: 8px;
  background: none; border: 0; color: var(--danger); cursor: pointer;
  font-size: 14px; padding: 8px; border-radius: 8px; text-align: left;
}
.um-logout:hover { background: var(--surface-2); }

/* Beneficio neto (Rendimientos) */
.neto-card { margin-bottom: 14px; }
.neto-card .neto-value { font-size: 28px; font-weight: 700; color: var(--ok); margin: 4px 0; }
.neto-card .neto-value.neg { color: var(--danger); }

/* "Más" solo en móvil */
@media (min-width: 820px) {
  .nav a.mobile-only { display: none; }
}

/* Bloqueo del parte cuando la obra está finalizada */
.lock-fs { border: 0; padding: 0; margin: 0; min-width: 0; }
.lock-fs:disabled { opacity: 0.6; }

/* ---------- Escritorio ancho: listas a 2 columnas ---------- */
@media (min-width: 1100px) {
  .content.list {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 10px; align-content: start;
  }
  .content.list > .btn,
  .content.list > .spin,
  .content.list > .empty,
  .content.list > .section-title { grid-column: 1 / -1; }
  .content.list > .card { margin-bottom: 0; }
}
