/* Invoices (invoices.js): the list, and the editor with the page in the
   middle and the ask box and fields beside it. The page itself is page.js. */

#view[data-r=invoices]:has(.iv) { max-width: none; padding-bottom: 20px; }

/* list */
.iv-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.iv-kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.iv-kpi span { font-size: 13px; font-weight: 600; color: var(--ink); }
.iv-kpi b { font: 700 24px/1.15 var(--sans); color: var(--ink); letter-spacing: -.01em; }
.iv-kpi small { font-size: 12.5px; font-weight: 500; color: var(--ink); }
.iv-kpi.bad b { color: var(--crit); }
.iv-tobill { padding: 16px 20px; margin-bottom: 16px; display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); gap: 18px; align-items: start; }
.iv-tobill h2 { font-size: 16px; margin: 0 0 4px; }
.iv-tobill p { margin: 0; font-size: 13.5px; line-height: 1.45; color: var(--ink); }
.iv-tobill ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.iv-tobill li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 13.5px; }
.iv-tobill li > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iv-tobill li > span:nth-child(2) { font-weight: 600; }
.iv-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.iv-search { height: 38px; min-width: 300px; flex: 0 1 380px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 12px; font: 500 14px var(--sans); color: var(--ink); background: #fff; }
.iv-search:focus { outline: 2px solid var(--brand); border-color: transparent; }
.iv-chips, .iv-sugg, .iv-quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.iv-quick > span { font-size: 12px; font-weight: 600; color: var(--ink); margin-right: 2px; }
.iv-chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: #fff; font: 600 12.5px var(--sans); color: var(--ink); cursor: pointer; transition: background .12s, border-color .12s; }
.iv-chip:hover { background: var(--brand-tint); border-color: var(--brand-line); }
.iv-chip b { font-size: 11px; background: var(--tile); border-radius: 999px; padding: 1px 7px; }
.iv-chip.on { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }
.iv-chip.on b { background: rgba(255,255,255,.2); }
.iv-table-wrap { padding: 0; overflow-x: auto; }
.iv-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.iv-table th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--ink); padding: 12px 14px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.iv-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.iv-table td small { display: block; font-size: 12px; font-weight: 500; color: var(--ink); margin-top: 1px; }
.iv-table .r { text-align: right; }
.iv-table .mono { font-family: var(--mono); font-size: 12.5px; }
.iv-table tbody tr { cursor: pointer; transition: background .1s; }
.iv-table tbody tr:hover, .iv-table tbody tr:focus-visible { background: var(--hover); outline: none; }
.iv-table tr:last-child td { border-bottom: 0; }
.iv-empty { padding: 44px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.iv-empty h3 { margin: 0; font-size: 17px; }
.iv-empty p { margin: 0; max-width: 460px; font-size: 14px; line-height: 1.5; color: var(--ink); }
.iv-pick { padding: 12px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.iv-pick[hidden] { display: none; }
.iv-pick-head { display: flex; gap: 8px; }
.iv-pick-head input { flex: 1; height: 38px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 12px; font: 500 14px var(--sans); }
.iv-pick ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px; }
.iv-pick li button { width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; font: 500 13px var(--sans); color: var(--ink); }
.iv-pick li button:hover { border-color: var(--brand-line); background: var(--brand-tint); }

/* status */
.iv-st { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; font: 700 12px var(--sans); white-space: nowrap; background: var(--tile); color: var(--ink); }
.iv-st.s-sent { background: var(--brand-tint); color: var(--brand-deep); }
.iv-st.s-part { background: var(--brand-soft); color: var(--brand-deep); }
.iv-st.s-overdue { background: var(--crit-bg); color: var(--crit); }
.iv-st.s-paid { background: var(--good-bg); color: var(--good); }
.iv-st.s-cancelled { background: var(--tile); color: var(--ink-3); text-decoration: line-through; }

/* editor */
.iv { display: flex; flex-direction: column; gap: 12px; height: calc(100vh - 64px - 28px - 20px); min-height: 600px; }
.iv-loading { padding: 4px; }
.iv-bar { display: flex; align-items: center; gap: 8px; }
.iv-back { flex: none; }
.iv-num { font: 700 17px var(--sans); border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; width: 170px; color: var(--ink); background: transparent; letter-spacing: .01em; }
.iv-num:hover { border-color: var(--line-2); }
.iv-num:focus { outline: 2px solid var(--brand); background: #fff; }
.iv-saved { font-size: 12.5px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.iv-saved.good { color: var(--good); }
.iv-saved.bad { color: var(--crit); }
.iv-ib { width: 34px; height: 34px; flex: none; display: inline-grid; place-items: center; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer; }
.iv-ib svg { width: 18px; height: 18px; }
/* an icon inside a button is the button's size, not the panel's */
.iv .btn svg, .iv-pick .btn svg { width: 15px; height: 15px; flex: none; }
.iv-ib:hover:not(:disabled) { background: var(--tile); }
.iv-ib:disabled { opacity: .38; cursor: default; }
.iv-more { position: relative; }
.iv-menu { position: absolute; right: 0; top: 40px; z-index: 30; min-width: 260px; background: #fff; border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 12px 32px rgba(17,19,24,.16); padding: 6px; display: flex; flex-direction: column; }
.iv-menu[hidden] { display: none; }
.iv-menu button { text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; font: 600 13.5px var(--sans); color: var(--ink); cursor: pointer; }
.iv-menu button:hover { background: var(--tile); }
.iv-menu button.bad { color: var(--crit); }
.iv-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 16px; }
.iv-canvas { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.iv-checks { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; }
.iv-check { height: 28px; padding: 0 11px; border-radius: 999px; border: 1px solid transparent; font: 600 12.5px var(--sans); cursor: pointer; background: var(--brand-tint); color: var(--brand-deep); }
.iv-check.warn { background: var(--crit-bg); color: var(--crit); }
.iv-check.good { background: var(--good-bg); color: var(--good); cursor: default; }
.iv-check:hover:not(.good) { border-color: currentColor; }
.iv-stage { flex: 1; min-height: 0; overflow: auto; background: var(--tile); border-radius: 16px; padding: 24px; }
.iv-fit { margin: 0 auto; position: relative; }
.iv-paper { position: absolute; left: 0; top: 0; width: 210mm; transform-origin: 0 0; background: #fff; box-shadow: 0 1px 2px rgba(17,19,24,.06), 0 12px 36px rgba(17,19,24,.12); border-radius: 2px; }
.iv-paper iframe { display: block; width: 210mm; height: 297mm; border: 0; background: #fff; }
.iv-zoom { display: flex; align-items: center; gap: 6px; }
.iv-zoom .iv-ib { width: 30px; height: 30px; }
.iv-zl { height: 30px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; font: 600 12.5px var(--sans); cursor: pointer; color: var(--ink); }
.iv-pages { font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.iv-pages.good { background: var(--good-bg); color: var(--good); }
.iv-pages.warn { background: var(--crit-bg); color: var(--crit); }

/* side panel */
.iv-side { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.iv-side .sx-tabs button { display: inline-flex; align-items: center; gap: 6px; }
.iv-side .sx-tabs svg { width: 13px; height: 13px; color: var(--brand); }
.iv-pane { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.iv-pane[hidden] { display: none; }
.iv-log { flex: 1; min-height: 140px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.iv-log b { font-weight: 700; }
.iv-link { border: 0; background: none; padding: 0; font: 600 13px var(--sans); color: var(--brand); text-decoration: underline; cursor: pointer; }
.iv-ask .sx-ask textarea { min-height: 76px; }
.iv-edit { gap: 0; padding-top: 4px; }
.iv-sec { border-bottom: 1px solid var(--line); border-radius: 8px; transition: background .4s; }
.iv-sec.flash { animation: ivflash 1.1s ease-out; }
@keyframes ivflash { 0% { background: var(--brand-tint); } 100% { background: transparent; } }
.iv-sec summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 4px; cursor: pointer; }
.iv-sec summary::-webkit-details-marker { display: none; }
.iv-sec summary::after { content: ''; width: 8px; height: 8px; border-right: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2); transform: rotate(45deg); margin: -4px 4px 0 auto; transition: transform .15s; flex: none; }
.iv-sec[open] summary::after { transform: rotate(-135deg); margin-top: 4px; }
.iv-sec summary b { font-size: 14px; flex: none; }
.iv-sec summary span { font-size: 12.5px; font-weight: 500; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: auto; }
.iv-sec-in { display: flex; flex-direction: column; gap: 10px; padding: 0 4px 16px; }
.iv-edit .field { display: flex; flex-direction: column; gap: 4px; margin: 0; min-width: 0; }
.iv-edit .field > span:first-child { font-size: 12px; font-weight: 600; color: var(--ink); }
.iv-edit input:not([type=checkbox]), .iv-edit select, .iv-edit textarea { height: 34px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 9px; font: 500 13px var(--sans); color: var(--ink); background: #fff; min-width: 0; width: 100%; }
.iv-edit textarea { height: auto; padding: 8px 10px; line-height: 1.45; resize: vertical; }
.iv-edit input:focus, .iv-edit select:focus, .iv-edit textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
.iv-edit .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.iv-row { display: flex; gap: 8px; }
.iv-row .grow { flex: 1; }
.iv-hon { width: 86px; flex: none; }
.iv-seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; height: 32px; align-self: flex-start; max-width: 100%; }
.iv-seg button { border: 0; background: #fff; padding: 0 12px; font: 600 12.5px var(--sans); color: var(--ink); cursor: pointer; white-space: nowrap; }
.iv-seg button + button { border-left: 1px solid var(--line-2); }
.iv-seg button.on { background: var(--brand-deep); color: #fff; }
.iv-switch { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink); cursor: pointer; min-height: 34px; }
.iv-switch input { width: 16px; height: 16px; accent-color: var(--brand); flex: none; }
.iv-fine { font-size: 12px; line-height: 1.45; margin: 0; color: var(--ink); }
.iv-inline { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 500; flex-wrap: wrap; }
.iv-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.iv-lines li { display: grid; grid-template-columns: 14px minmax(0, 1fr) 28px; gap: 6px; align-items: start; padding: 8px 6px 8px 4px; border: 1px solid var(--line); border-radius: 10px; background: #fff; position: relative; }
.iv-lines li.drag { opacity: .45; }
.iv-lines li.above::before, .iv-lines li.below::after { content: ''; position: absolute; left: 6px; right: 6px; height: 3px; border-radius: 3px; background: var(--brand); }
.iv-lines li.above::before { top: -6px; }
.iv-lines li.below::after { bottom: -6px; }
.iv-grip { color: var(--ink-3); cursor: grab; padding-top: 8px; touch-action: none; }
.iv-grip svg { width: 12px; height: 20px; display: block; }
.iv-line { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.iv-edit .iv-desc { font-weight: 600; }
.iv-nums { display: grid; grid-template-columns: 56px auto minmax(0, 1fr) auto; gap: 6px; align-items: center; font-size: 13px; }
.iv-nums b { font-size: 13px; text-align: right; min-width: 82px; white-space: nowrap; }
.iv-line-x { display: flex; align-items: center; gap: 8px; }
.iv-edit .iv-note { height: 30px; font-size: 12.5px; flex: 1; }
.iv-mini { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.iv-mini input { accent-color: var(--brand); }
.iv-x { width: 28px; height: 28px; border: 0; background: none; border-radius: 8px; display: grid; place-items: center; color: var(--ink-3); cursor: pointer; flex: none; }
.iv-x svg { width: 16px; height: 16px; }
.iv-x:hover { background: var(--crit-bg); color: var(--crit); }
.iv-paid { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--good-bg); color: var(--good); font-size: 12.5px; font-weight: 600; }
.iv-payform { display: grid; grid-template-columns: minmax(0, 1fr) 118px minmax(0, 1fr) auto; gap: 6px; align-items: center; }

@media (max-width: 1180px) {
  .iv { height: auto; min-height: 0; }
  .iv-body { grid-template-columns: 1fr; }
  .iv-stage { min-height: 70vh; }
  .iv-side { max-height: none; }
  .iv-pane { overflow: visible; }
}
@media (max-width: 760px) {
  .iv-bar { flex-wrap: wrap; }
  .iv-bar .grow { flex-basis: 100%; height: 0; }
  .iv-bar [data-iv=undo], .iv-bar [data-iv=redo] { display: none; }
  .iv-stage { padding: 10px; min-height: 0; }
  .iv-kpis { grid-template-columns: 1fr; }
  .iv-tobill { grid-template-columns: 1fr; }
  .iv-search { min-width: 0; flex: 1 1 100%; }
  .iv-payform { grid-template-columns: 1fr 1fr; }
}
.iv-chip.iv-chip-new { border-style: dashed; }
