/* ============================================================
   Herramienta de presupuestos Somfy / BFT
   Paleta tomada de somfypro.es: azul petróleo + amarillo Somfy.
   Mobile-first: lo que está fuera de @media es el diseño de móvil.
   ============================================================ */
:root {
  --teal-900: #1e3a48;
  --teal-800: #25485a;
  --teal-700: #31596e;
  --teal-600: #4a6776;
  --teal-100: #e3ecf1;
  --teal-50: #f1f5f8;
  --yellow: #fab607;
  --yellow-600: #e5a400;
  --yellow-100: #fff3d0;
  --ink: #1b2a33;
  --muted: #5b6b76;
  --line: #d5dee4;
  --paper: #eef3f6;
  --white: #fff;
  --ok: #2f7d6b;
  --ok-bg: #e2f1ed;
  --warn: #9a6a00;
  --warn-bg: #fff3d0;
  --err: #b4413a;
  --err-bg: #fbe9e7;
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Nunito Sans", "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 2px rgba(30, 58, 72, .08), 0 6px 18px rgba(30, 58, 72, .07);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.45; color: var(--ink);
  background: var(--paper); min-height: 100vh; display: flex; flex-direction: column;
}
h1, h2, h3 { margin: 0; line-height: 1.2; color: var(--teal-800); }
h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 800; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0 0 .6rem; }
a { color: var(--teal-700); }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; border-radius: 6px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- barra superior ---------- */
.topbar { background: var(--teal-900); color: #fff; position: sticky; top: 0; z-index: 30; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: .55rem 1rem; display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; }
.brand img { height: 30px; width: auto; display: block; }
.brand span { color: #fff; font-weight: 700; font-size: .78rem; letter-spacing: .02em; border: 1px solid rgba(255,255,255,.35); border-radius: 5px; padding: 1px 6px; }
.tabs { display: flex; background: rgba(255,255,255,.1); border-radius: 999px; padding: 3px; margin-left: auto; }
.tabs a { color: #fff; text-decoration: none; font-weight: 700; font-size: .88rem; padding: .42rem .95rem; border-radius: 999px; white-space: nowrap; }
.tabs a[aria-current="page"] { background: #fff; color: var(--teal-800); }
.topbar .exit { color: #c9d8e0; font-size: .82rem; text-decoration: none; padding: .4rem .3rem; }
.topbar .exit:hover { color: #fff; }
.admin-bar { background: var(--yellow); color: var(--ink); font-size: .85rem; font-weight: 700; }
.admin-bar .topbar-inner { padding: .35rem 1rem; }
.admin-bar a { color: var(--ink); }

/* ---------- estructura ---------- */
.hero { background: var(--teal-800); color: #fff; }
.hero-inner { max-width: 1180px; margin: 0 auto; padding: 1.2rem 1rem 4.2rem; }
.hero h1 { color: #fff; }
.hero p { color: #c9d8e0; margin: .25rem 0 0; font-size: .95rem; }
main { flex: 1; width: 100%; max-width: 1180px; margin: -3.1rem auto 0; padding: 0 1rem 7rem; }
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card > h2 { margin-bottom: .75rem; }
.grid-2 { display: grid; gap: 1rem; }
footer.site { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 1rem 1.2rem; }
footer.site a { color: var(--muted); }

/* ---------- formularios ---------- */
label, .lbl { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: .25rem; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, input[type=file], textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); padding: .62rem .75rem; min-height: 46px; appearance: none; -webkit-appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%2325485a' stroke-width='2'%3E%3Cpath d='m1 1 5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .8rem center; padding-right: 2.2rem; }
input:focus, select:focus, textarea:focus { border-color: var(--teal-700); outline: 3px solid rgba(250,182,7,.55); outline-offset: 0; }
input[readonly] { background: var(--teal-50); color: var(--muted); }
input.invalid, select.invalid { border-color: var(--err); background: var(--err-bg); }
.field { margin-bottom: .85rem; }
.row { display: grid; gap: .85rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.error-text { font-size: .82rem; color: var(--err); font-weight: 700; margin-top: .3rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 46px; padding: .55rem 1.25rem;
  border-radius: 999px; border: 2px solid transparent; font: inherit; font-weight: 800; font-size: .95rem; cursor: pointer;
  text-decoration: none; background: var(--yellow); color: var(--ink); transition: background .12s, transform .05s;
}
.btn:hover { background: var(--yellow-600); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--teal-800); border-color: var(--teal-800); }
.btn.secondary:hover { background: var(--teal-50); }
.btn.ghost { background: transparent; color: var(--teal-700); border-color: transparent; padding-inline: .7rem; }
.btn.ghost:hover { background: var(--teal-50); }
.btn.danger { background: #fff; color: var(--err); border-color: var(--err); }
.btn.small { min-height: 38px; padding: .3rem .9rem; font-size: .85rem; }
.btn[disabled], .btn[aria-disabled=true] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex: none; }

/* ---------- selector tipo píldora (ASAP / fecha) ---------- */
.seg { display: inline-flex; background: var(--teal-100); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; font: inherit; font-weight: 700; font-size: .88rem; color: var(--teal-800); padding: .45rem 1rem; border-radius: 999px; cursor: pointer; min-height: 38px; }
.seg button[aria-pressed=true] { background: var(--teal-800); color: #fff; }

/* ---------- autocompletado ---------- */
.ac { position: relative; }
.ac-list { position: absolute; z-index: 25; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1.5px solid var(--teal-700);
  border-radius: var(--radius-sm); box-shadow: 0 10px 28px rgba(30,58,72,.22); max-height: 58vh; overflow-y: auto; margin: 0; padding: .25rem; list-style: none; }
.ac-list li { padding: .6rem .7rem; border-radius: 7px; cursor: pointer; min-height: 44px; }
.ac-list li[aria-selected=true], .ac-list li:hover { background: var(--yellow-100); }
.ac-list .t { font-weight: 700; display: block; }
.ac-list .s { font-size: .82rem; color: var(--muted); display: block; }
.ac-empty { padding: .8rem; color: var(--muted); font-size: .9rem; }
.ac-free { background: var(--teal-50); font-weight: 700; color: var(--teal-800); }

.search-big { position: relative; }
.search-big input { padding-left: 2.8rem; min-height: 52px; font-size: 1.02rem; border-color: var(--teal-700); }
.search-big svg { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; color: var(--teal-700); pointer-events: none; }

.chip-customer { display: flex; align-items: flex-start; gap: .6rem; background: var(--teal-50); border: 1.5px solid var(--teal-100); border-radius: var(--radius-sm); padding: .6rem .75rem; }
.chip-customer .name { font-weight: 800; color: var(--teal-800); }
.chip-customer .meta { font-size: .85rem; color: var(--muted); }
.chip-customer button { margin-left: auto; }
.badge { display: inline-block; font-size: .72rem; font-weight: 800; padding: .12rem .5rem; border-radius: 999px; background: var(--teal-100); color: var(--teal-800); white-space: nowrap; }
.badge.warn { background: var(--yellow-100); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }

/* ---------- líneas de presupuesto (tarjeta en móvil) ---------- */
.line { border: 1.5px solid var(--line); border-radius: var(--radius); padding: .8rem; margin-top: .75rem; background: #fff; position: relative; }
.line.has-error { border-color: var(--err); background: #fffafa; }
.line .title { padding-right: 2.6rem; }
.line .ref { font-weight: 800; color: var(--teal-800); }
.line .desc { color: var(--ink); }
.line .tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.line .del { position: absolute; top: .45rem; right: .45rem; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.line .del:hover { background: var(--err-bg); color: var(--err); }
.line .del svg { width: 20px; height: 20px; }
.cells { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem .7rem; margin-top: .7rem; }
.cell { min-width: 0; }
.cell .v { font-weight: 700; min-height: 46px; display: flex; align-items: center; }
.cell.span2 { grid-column: 1 / -1; }
.cell.total .v { font-size: 1.15rem; color: var(--teal-800); font-weight: 800; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.stepper { display: flex; align-items: stretch; }
.stepper input { text-align: center; border-radius: 0; border-left: 0; border-right: 0; min-width: 0; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper button { width: 46px; flex: none; border: 1.5px solid var(--line); background: var(--teal-50); font-size: 1.3rem; font-weight: 800; color: var(--teal-800); cursor: pointer; }
.stepper button:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.stepper button:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.stepper button:active { background: var(--yellow-100); }
.pct { position: relative; }
.pct input { padding-right: 1.9rem; text-align: right; }
.pct::after { content: "%"; position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; pointer-events: none; }
.line-error { margin-top: .6rem; background: var(--err-bg); color: var(--err); border-radius: var(--radius-sm); padding: .5rem .7rem; font-size: .88rem; font-weight: 700; }
.line-error button { margin-left: .4rem; }
.line.ab .top { display: grid; gap: .6rem; grid-template-columns: 1fr 1fr; padding-right: 2.6rem; }
.line.ab .top .ref-cell { grid-column: 1 / -1; }
.line.ab .top .del { top: .45rem; right: .45rem; }
.panels { display: grid; gap: .7rem; margin-top: .85rem; }
.panel { border: 1.5px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.panel-h { font-size: .78rem; font-weight: 800; padding: .35rem .7rem; }
.panel.bad .panel-h { background: var(--err); color: #fff; }
.panel.ok .panel-h { background: var(--yellow); color: var(--ink); }
.panel .cells { margin: 0; padding: .6rem .7rem .7rem; }
.empty { text-align: center; color: var(--muted); padding: 1.6rem .5rem; border: 2px dashed var(--line); border-radius: var(--radius); margin-top: .75rem; }

/* ---------- resumen ---------- */
.summary dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: .45rem .8rem; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.summary .sep { grid-column: 1 / -1; border-top: 1px solid var(--line); }
.summary .big dt { color: var(--teal-800); font-weight: 800; font-size: 1.05rem; }
.summary .big dd { font-size: 1.4rem; color: var(--teal-800); font-weight: 800; }
.summary .note { font-size: .8rem; color: var(--muted); font-weight: 400; display: block; }
.summary .actions { display: grid; gap: .6rem; margin-top: 1rem; }

/* barra fija inferior en móvil */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 28; background: var(--teal-900); color: #fff;
  padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: .7rem; box-shadow: 0 -6px 20px rgba(30,58,72,.25); }
.dock .tot { line-height: 1.15; }
.dock .tot small { display: block; color: #c9d8e0; font-size: .72rem; }
.dock .tot strong { font-size: 1.25rem; color: var(--yellow); font-variant-numeric: tabular-nums; }
.dock .btns { margin-left: auto; display: flex; gap: .5rem; }
.dock .btn { min-height: 44px; padding-inline: 1rem; }
.dock .btn.secondary { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }

/* ---------- avisos ---------- */
.alert { border-radius: var(--radius-sm); padding: .7rem .9rem; margin-bottom: 1rem; font-size: .92rem; font-weight: 600; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.error { background: var(--err-bg); color: var(--err); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--teal-100); color: var(--teal-800); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 88px; z-index: 60; background: var(--ink); color: #fff;
  padding: .7rem 1.1rem; border-radius: 999px; font-weight: 700; box-shadow: var(--shadow); max-width: 92vw; }
.toast.err { background: var(--err); }

/* ---------- login ---------- */
.login-page { background: var(--teal-800); }
.login-wrap { margin: auto; width: 100%; max-width: 400px; padding: 1.2rem; }
.login-card { background: #fff; border-radius: 20px; padding: 1.6rem 1.4rem; box-shadow: 0 20px 50px rgba(0,0,0,.28); }
.login-logo { display: block; background: var(--teal-800); border-radius: 14px; padding: 1.1rem; margin-bottom: 1.2rem; text-align: center; }
.login-logo img { height: 44px; }
.login-card h1 { font-size: 1.3rem; margin-bottom: .2rem; }
.login-card p.sub { color: var(--muted); margin-bottom: 1.1rem; }

/* ---------- administración ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
.kpi { background: var(--teal-50); border-radius: var(--radius-sm); padding: .8rem; }
.kpi .n { font-size: 1.7rem; font-weight: 800; color: var(--teal-800); line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: .8rem; color: var(--muted); font-weight: 700; }
.kpi .sub { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.status-grid { display: grid; gap: .8rem; }
.status-item { border: 1.5px solid var(--line); border-radius: var(--radius); padding: .9rem; display: flex; flex-direction: column; gap: .35rem; }
.status-item .n { font-size: 1.5rem; font-weight: 800; color: var(--teal-800); }
.status-item .btn { margin-top: .4rem; align-self: flex-start; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -.2rem; }
table.data { border-collapse: collapse; width: 100%; font-size: .88rem; }
table.data th { text-align: left; color: var(--muted); font-size: .76rem; font-weight: 800; padding: .45rem .55rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.data td { padding: .5rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data td.r, table.data th.r { text-align: right; font-variant-numeric: tabular-nums; }
.stats-list { display: grid; gap: .5rem; margin: 0 0 1rem; padding: 0; list-style: none; }
.stats-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem .75rem; border-radius: var(--radius-sm); background: var(--teal-50); }
.stats-list li strong { font-variant-numeric: tabular-nums; }
.stats-list li.ok { background: var(--ok-bg); } .stats-list li.warn { background: var(--warn-bg); } .stats-list li.muted { background: #f6f8f9; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--font); font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 1rem; font-size: .82rem; color: var(--muted); margin: .2rem 0 .6rem; flex-wrap: wrap; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.heat { display: grid; grid-template-columns: 34px repeat(24, 1fr); gap: 2px; font-size: .68rem; color: var(--muted); }
.heat .c { aspect-ratio: 1; border-radius: 3px; background: var(--teal-50); }
.heat .hl { text-align: center; align-self: end; }
.heat .wd { display: flex; align-items: center; }
.tabsel { display: inline-flex; gap: .3rem; margin-bottom: .6rem; }

/* ---------- escritorio ---------- */
@media (min-width: 720px) {
  h1 { font-size: 1.9rem; }
  .row.cols-2 { grid-template-columns: 1fr 1fr; }
  .row.cols-3 { grid-template-columns: 2fr 1fr 1fr; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .status-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 960px) {
  .card { padding: 1.25rem 1.4rem; }
  .grid-2.quote-layout { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
  .quote-layout .summary-card { position: sticky; top: 76px; }
  .dock { display: none; }
  main { padding-bottom: 2.5rem; }
  .toast { bottom: 24px; }

  /* Abono-Cargo */
  .line.ab .top { grid-template-columns: 170px 110px minmax(0, 1fr) 150px 34px; align-items: end; }
  .line.ab .top .ref-cell { grid-column: auto; }
  .line.ab .top .del { position: static; }
  .panels { grid-template-columns: 1fr 1fr; }
  .panel .cells { grid-template-columns: repeat(4, 1fr); }
  .panel .cell .v { justify-content: flex-end; }
}
@media (min-width: 720px) {
  .line.q .cells { grid-template-columns: repeat(4, 1fr); }
  .line.q .cell.span2 { grid-column: span 2; }
  .cell .v { white-space: nowrap; }
}
@media (min-width: 1200px) {
  .topbar-inner, .hero-inner, main { max-width: 1320px; }
  .grid-2.quote-layout { grid-template-columns: minmax(0, 1fr) 340px; }
  .line.q .grid { display: grid; grid-template-columns: 150px 96px 112px repeat(4, minmax(86px, 1fr)) 34px; gap: .5rem .8rem; align-items: end; }
  .line.q .title { grid-column: 1 / 8; padding-right: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .8rem; }
  .line.q .title .tags { margin-top: 0; }
  .line.q .cells { display: contents; }
  .line.q .cell.span2 { grid-column: auto; }
  .line.q .del { position: static; grid-column: 8; grid-row: 1; align-self: start; width: 34px; height: 34px; }
}
@media (min-width: 960px) and (max-width: 1100px) {
  .grid-2.quote-layout { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { .topbar, .dock, .btn, footer.site { display: none !important; } body { background: #fff; } main { margin: 0; } }
.login-page main { margin: auto; padding: 0; max-width: none; flex: 0 1 auto; }
