/* Oficinapp — presupuestos, banco de precios, facturas y portal del cliente. */

/* «hidden» manda sobre los display de estos componentes */
.cpick [hidden], .qtotals [hidden], .qdlg [hidden], [data-q-add] [hidden], [data-q-pane][hidden], [data-rect-lines][hidden], [data-q-lines] [hidden], .qtoast[hidden] { display: none !important; }

input[type=date], input[type=number], input[type=file] {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  font: inherit; font-size: 16px; color: var(--gray-900); background: #fff;
}
input[type=file] { padding: 7px 12px; }
@media (min-width: 768px) { input[type=date], input[type=number], input[type=file] { font-size: 14px; } }

.icon-btn--sm { width: 32px; height: 32px; border-radius: 8px; }
p.hint { font-size: 12px; color: var(--gray-500); }
.qdlg p.hint { margin: 12px 0 0; }
.kpi__value--money { font-size: 24px; white-space: nowrap; }
.kpi__icon--danger { background: var(--danger-50); color: var(--danger); }
a.kpi { color: inherit; text-decoration: none; }
a.kpi:hover { box-shadow: var(--shadow-elevated); }
.q-segmented { flex-wrap: wrap; }
.q-count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 2px; border-radius: 9px; background: rgba(11,31,58,.08); font-size: 11px; text-align: center; }
.q-pos { color: var(--success); }
.q-neg { color: var(--danger); }

/* Cabecera de ficha */
.qhead { display: flex; gap: 16px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.qhead__main { min-width: 0; }
.qhead__top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 4px; }
.qhead__number { font-weight: 700; color: var(--gray-500); }
.qhead__title { margin: 0 0 4px; font-size: 22px; color: var(--navy-900); }
.qhead__meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 13px; align-items: center; }
.qhead__total { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.qhead__amount { font-size: 28px; font-weight: 800; color: var(--navy-900); line-height: 1.2; }

.qside { display: grid; gap: 16px; }
.qactions { display: grid; gap: 8px; }
.qactions form { display: contents; }
.qactions .btn { width: 100%; justify-content: flex-start; }
.qactions .list-row { padding: 10px 0; color: inherit; }
.list-row.is-current .list-row__title { color: var(--orange-600); }
a.list-row { color: inherit; text-decoration: none; }
.qinline { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.qinline input { flex: 1 1 90px; min-width: 0; }
.qinline select { flex: 1 1 120px; width: auto; min-width: 0; }
.qcopy { display: flex; gap: 8px; }
.qcopy input { flex: 1; min-width: 0; font-size: 13px; color: var(--gray-500); }
.qcode { background: var(--gray-50); border: 1px solid var(--gray-100); border-radius: var(--radius-sm); padding: 12px; font-size: 12px; overflow-x: auto; white-space: pre; }

/* Partidas */
.qlines td { vertical-align: top; }
.qlines td.num, .qlines td[data-label="IVA"], .qlines td[data-label="Unidad"] { white-space: nowrap; }
.qlines tbody tr { cursor: default; }
.qlines tbody tr:hover { background: transparent; }
.qlines__chapter td { background: var(--gray-50); font-weight: 700; color: var(--navy-900); padding: 10px 16px; }
.qlines__chapter .icon { vertical-align: -3px; color: var(--orange-500); }
.qlines--edit td { padding: 8px 4px; }
.qlines--edit th { padding-left: 4px; padding-right: 4px; }
.qlines--edit th:first-child { padding-left: 16px; }
.qlines--edit td:first-child { padding-left: 16px; }
.qlines--edit td:last-child { padding-right: 12px; }
.qlines .ql-input { height: 36px; padding: 0 8px; font-size: 14px; border-color: transparent; background: transparent; border-radius: 6px; }
.qlines .ql-input:hover { border-color: var(--gray-300); background: #fff; }
.qlines .ql-input:focus { border-color: var(--orange-500); background: #fff; }
.qlines textarea.ql-desc { min-height: 36px; height: 36px; padding: 8px; resize: none; line-height: 1.35; overflow: hidden; min-width: 170px; width: 100%; display: block; }
.qlines .ql-num { width: 78px; text-align: right; }
.qlines .ql-unit { width: 66px; padding-right: 0; }
.qlines .ql-vat { width: 70px; padding-right: 0; }
.qlines__chapter td.num { white-space: nowrap; }
.qlines--edit .ql-sub { padding-top: 16px; white-space: nowrap; }
.ql-code { display: block; font-size: 11px; color: var(--gray-500); padding-left: 8px; }
.qlines--edit .ql-actions { width: 40px; padding-top: 10px; }
.qlines__line.is-saving { opacity: .6; }
.qlines__line.is-error .ql-input { border-color: var(--danger); }
.qlines--edit [data-isub] { padding-top: 16px; white-space: nowrap; }

/* Totales */
.qtotals__row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.qtotals__row--strong { font-weight: 600; color: var(--navy-900); border-top: 1px solid var(--gray-100); padding-top: 8px; margin-top: 4px; }
.qtotals__total { display: flex; justify-content: space-between; margin: 10px 0 6px; padding: 12px 14px; background: var(--navy-900); color: #fff; border-radius: var(--radius-md); font-weight: 800; font-size: 18px; }
.qtotals__cost { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--gray-300); font-size: 13px; color: var(--gray-500); }
.qtotals__cost .icon { vertical-align: -2px; }

/* Banco de precios dentro del editor */
.qbank { display: grid; gap: 0; margin-top: 8px; max-height: 420px; overflow-y: auto; }
.qbank__item { display: flex; gap: 12px; align-items: center; padding: 10px 4px; border-top: 1px solid var(--gray-100); }
.qbank__item:first-child { border-top: 0; }
.qbank__main { flex: 1; min-width: 0; }
.qbank__desc { font-weight: 600; color: var(--navy-900); }
.qbank__sub { font-size: 12px; color: var(--gray-500); }
.qbank__qty { width: 80px !important; text-align: right; flex: none; }
.qbank__price { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Selector de cliente */
.cpick { position: relative; }
.cpick__selected { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius-sm); }
.cpick__name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cpick__name .muted { font-size: 12px; }
.cpick__search { width: 100%; }
.cpick__results { position: absolute; left: 0; right: 0; top: 44px; z-index: 30; padding: 4px; max-height: 300px; overflow-y: auto; box-shadow: var(--shadow-elevated); }
.cpick__results button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 8px 10px; border: 0; background: none; border-radius: 8px; font: inherit; text-align: left; cursor: pointer; }
.cpick__results button:hover, .cpick__results button.is-active { background: var(--orange-50); }
.cpick__results small { display: block; color: var(--gray-500); font-size: 12px; }
.cpick__empty { padding: 10px; color: var(--gray-500); font-size: 13px; }

/* Diálogos */
.qdlg { border: 0; border-radius: var(--radius-lg); padding: 20px; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: var(--shadow-elevated); color: var(--gray-900); overflow: visible; }
.qdlg--wide { width: min(860px, calc(100vw - 24px)); overflow-y: auto; }
.qdlg::backdrop { background: rgba(11,31,58,.45); }
.qdlg__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.qdlg__head h3 { margin: 0; }
.qdlg .form-actions { margin-top: 16px; }
.qradio { display: grid; gap: 8px; }
.qradio label { display: block; cursor: pointer; }
.qradio input { position: absolute; opacity: 0; pointer-events: none; }
.qradio span { display: grid; grid-template-columns: 24px 1fr; gap: 0 10px; padding: 10px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius-md); }
.qradio span .icon { grid-row: span 2; color: var(--gray-500); margin-top: 2px; }
.qradio small { color: var(--gray-500); font-size: 12px; }
.qradio input:checked + span { border-color: var(--orange-500); background: var(--orange-50); }
.qradio input:checked + span .icon { color: var(--orange-600); }
.qradio input:disabled + span { opacity: .5; cursor: not-allowed; }
.qradio input:focus-visible + span { box-shadow: 0 0 0 3px var(--orange-50); }

/* Verifactu */
.qvf { display: flex; gap: 14px; align-items: center; }
.qvf__qr { width: 96px; height: 96px; flex: none; background: #fff; }
.qvf__qr svg, .qvf__qr img { width: 100%; height: 100%; display: block; }
.qvf__hash { font-size: 11px; margin: 0 0 6px; word-break: break-all; }

/* Aviso flotante */
.qtoast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; background: var(--navy-900); color: #fff; padding: 10px 16px; border-radius: var(--radius-md); box-shadow: var(--shadow-elevated); font-weight: 500; max-width: calc(100vw - 32px); }
.qtoast--error { background: var(--danger); }

.q-issue { background: var(--navy-900); }
.q-issue:hover { background: var(--navy-700); }

@media (max-width: 1023px) {
  .qhead { flex-direction: column; align-items: flex-start; }
  .qhead__total { align-items: flex-start; }
}

/* Móvil: la tabla de partidas se convierte en tarjetas */
@media (max-width: 767px) {
  .table-card .table.qlines { display: block; }
  .qlines thead { display: none; }
  .qlines tbody { display: block; }
  .qlines tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 12px; padding: 12px 16px; border-bottom: 1px solid var(--gray-100); }
  .qlines td { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 !important; border: 0 !important; }
  .qlines td[data-label]::before { content: attr(data-label); font-size: 12px; color: var(--gray-500); font-weight: 500; }
  .qlines td[data-label="Descripción"] { grid-column: 1 / -1; display: block; }
  .qlines td[data-label="Descripción"]::before { display: none; }
  .qlines td[data-label="Importe"] { grid-column: 1 / -1; border-top: 1px dashed var(--gray-100) !important; padding-top: 6px !important; }
  .qlines tr.qlines__chapter { display: flex; justify-content: space-between; background: var(--gray-50); }
  .qlines tr.qlines__chapter td { background: none; }
  .qlines tr.qlines__chapter td:empty { display: none; }
  .ql-actions { position: absolute; right: 8px; }
  .qlines--edit tr { position: relative; padding-right: 48px; }
  .qlines--edit td.ql-actions { position: absolute; top: 12px; right: 8px; width: auto; }
  .qlines textarea.ql-desc { min-width: 0; width: 100%; }
  .qlines .ql-input { border-color: var(--gray-300); background: #fff; }
  .qlines .ql-num, .qlines .ql-unit, .qlines .ql-vat { width: 100%; max-width: 110px; min-width: 0; }
  .qlines td { min-width: 0; }
  .qcopy { flex-direction: column; }
  .qhead__amount { font-size: 24px; }
  .qbank__item { flex-wrap: wrap; }
  .kpi__value--money { font-size: 18px; }
}

/* ---------- Portal del cliente ---------- */
body.portal { background: var(--gray-50); min-height: 100dvh; display: flex; flex-direction: column; }
.portal .btn--primary { background: var(--brand, var(--orange-500)); }
.portal .btn--primary:hover { filter: brightness(.93); background: var(--brand, var(--orange-600)); }
.portal__wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }
.portal__bar { background: #fff; border-top: 4px solid var(--brand, var(--orange-500)); box-shadow: var(--shadow-card); }
.portal__brand { display: flex; align-items: center; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.portal__logo { max-height: 44px; max-width: 150px; object-fit: contain; }
.portal__mark { width: 44px; height: 44px; border-radius: 12px; background: var(--navy-900); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; }
.portal__company { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.portal__company strong { color: var(--navy-900); font-size: 16px; }
.portal__company span { font-size: 12px; color: var(--gray-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.portal__call { width: 44px; height: 44px; border-radius: 50%; background: var(--orange-50); color: var(--brand, var(--orange-600)); display: flex; align-items: center; justify-content: center; flex: none; }
.portal__main { flex: 1; padding-top: 16px; padding-bottom: 24px; display: grid; gap: 12px; align-content: start; }
.portal__main > .alert { margin-bottom: 0; }
.portal__foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; padding-top: 8px; padding-bottom: 24px; font-size: 12px; color: var(--gray-500); }
.portal__foot a { color: var(--gray-500); text-decoration: underline; }
.pcard { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: 20px; }
.pcard--flush { padding: 20px 0 8px; }
.pcard--flush .pcard__title { padding: 0 20px; }
.pcard__title { font-size: 17px; margin: 0 0 12px; color: var(--navy-900); display: flex; align-items: center; gap: 8px; }
.ptext { white-space: pre-line; margin: 0; }
.phero__top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.phero__label { font-size: 13px; font-weight: 600; color: var(--gray-500); }
.phero__title { font-size: 24px; margin: 8px 0 4px; color: var(--navy-900); line-height: 1.25; }
.phero__meta { margin: 0; color: var(--gray-500); font-size: 14px; }
.phero__total { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; padding: 14px 16px; background: var(--navy-900); color: #fff; border-radius: var(--radius-md); }
.phero__total strong { font-size: 24px; }
.phero__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.phero__actions form { display: contents; }
.pchapter__head { display: flex; justify-content: space-between; gap: 12px; padding: 10px 20px; background: var(--gray-50); font-weight: 700; color: var(--navy-900); border-bottom: 2px solid var(--brand, var(--orange-500)); }
.pline { padding: 12px 20px; border-bottom: 1px solid var(--gray-100); }
.pcard:not(.pcard--flush) .pline { padding-left: 0; padding-right: 0; }
.pline__desc { white-space: normal; }
.pline__nums { display: flex; justify-content: space-between; gap: 12px; margin-top: 4px; font-size: 13px; }
.pline__nums strong { color: var(--navy-900); font-size: 14px; }
.ptotals { padding: 12px 20px; display: grid; gap: 4px; }
.ptotals > div { display: flex; justify-content: space-between; gap: 12px; }
.ptotals__total { font-weight: 800; font-size: 18px; color: var(--navy-900); border-top: 1px solid var(--gray-300); padding-top: 8px; margin-top: 4px; }
.pbank { display: grid; gap: 8px; margin-bottom: 8px; }
.pbank > div { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 10px 12px; background: var(--gray-50); border-radius: var(--radius-sm); }
.pbank span { font-size: 12px; color: var(--gray-500); width: 100%; }
.pbank strong { flex: 1; color: var(--navy-900); }
.pbank .btn { height: 32px; padding: 0 10px; }
.psign { position: relative; border: 2px dashed var(--gray-300); border-radius: var(--radius-md); background: #fff; height: 200px; touch-action: none; }
.psign canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.psign__hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--gray-300); font-size: 15px; pointer-events: none; }
.psign.is-signed { border-style: solid; border-color: var(--brand, var(--orange-500)); }
.psign.is-signed .psign__hint { display: none; }
.psign__clear { position: absolute; top: 8px; right: 8px; display: inline-flex; gap: 4px; align-items: center; border: 1px solid var(--gray-300); background: #fff; border-radius: 8px; padding: 4px 8px; font: inherit; font-size: 12px; cursor: pointer; color: var(--gray-500); }
.pcheck { display: flex; gap: 10px; align-items: flex-start; margin: 16px 0; cursor: pointer; }
.pcheck input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--brand, var(--orange-500)); flex: none; }
.preject { margin-top: 20px; border-top: 1px solid var(--gray-100); padding-top: 12px; }
.preject summary { cursor: pointer; color: var(--gray-500); font-size: 14px; }
.preject form { margin-top: 12px; }
.pdeposit { border: 2px solid var(--brand, var(--orange-500)); }
.pvf { display: flex; align-items: center; gap: 16px; }
@media (max-width: 767px) {
  .phero__actions .btn { flex: 1 1 100%; height: 48px; }
  .phero__title { font-size: 21px; }
}
