/* Invoice list in the Agency module. Each status sets --inv and the rest follows. */
.inv-is-paid { --inv: var(--emerald); --inv-soft: var(--emerald-soft); --inv-border: var(--emerald-border); }
.inv-is-partial { --inv: var(--amber); --inv-soft: var(--amber-soft); --inv-border: var(--amber-border); }
.inv-is-unpaid,
.inv-is-overdue { --inv: var(--rose); --inv-soft: var(--rose-soft); --inv-border: var(--rose-border); }
.inv-is-none { --inv: var(--fg-4); --inv-soft: var(--surface-2); --inv-border: var(--border); }
.inv-is-invoiced { --inv: var(--indigo); --inv-soft: var(--indigo-soft); --inv-border: var(--indigo-border); }

/* ── Toolbar ── */
#invoicesViewToggle .view-toggle-btn { color: var(--fg-3); }
#invoicesViewToggle .view-toggle-btn.active { color: var(--indigo); }

.inv-search input { width: 100%; }
/* The table sorts from its headers, so the list is only for cards and phones. */
#agencyInvoicesPanel[data-view="table"] .inv-sort-select { display: none; }

@media (min-width: 861px) {
  #agencyInvoicesPanel .agency-panel-toolbar { flex-wrap: wrap; }
  #agencyInvoicesPanel .agency-panel-toolbar .select-input { flex: 0 1 165px; width: 165px; min-width: 0; }
  #agencyInvoicesPanel .inv-search { flex: 0 1 180px; min-width: 150px; }
  #invoicesViewToggle { margin-left: auto; }
}

/* ── Payments and repeating in the form ── */
.payment-rows { display: flex; flex-direction: column; gap: 8px; }
.payment-row { display: grid; grid-template-columns: 150px 150px minmax(0, 1fr) 32px; align-items: center; gap: 8px; }
.payment-empty { margin: 0; color: var(--fg-3); font-size: 13px; }
.payment-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.recurring-box { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
#invoiceRecurringFields { margin-top: 10px; }
#invoiceRecurringFields input { max-width: 200px; }

/* ── Monthly invoices due ── */
.inv-recurring-due { display: flex; flex-direction: column; gap: 8px; margin: 0 32px 16px; padding: 14px 18px; border: 1px solid var(--indigo-border); border-radius: 16px; background: var(--indigo-soft); }
.inv-recurring-due[hidden] { display: none; }
.inv-recurring-title { margin: 0; color: var(--indigo); font-size: 14px; font-weight: 650; }
.inv-recurring-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--surface); }
.inv-recurring-info { display: flex; flex: 1 1 auto; align-items: center; gap: 14px; min-width: 0; flex-wrap: wrap; }
.inv-recurring-meta { color: var(--fg-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.inv-recurring-badge { display: inline-block; margin-left: 7px; padding: 1px 7px; border-radius: 999px; background: var(--indigo-soft); color: var(--indigo); font-family: var(--font-sans); font-size: 10.5px; font-weight: 600; vertical-align: middle; }
.inv-last-payment { color: var(--emerald); }
.quote-invoiced { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; padding: 1px 8px; border-radius: 999px; background: var(--emerald-soft); color: var(--emerald); font-size: 11px; font-weight: 600; white-space: nowrap; }

/* ── Summary strip ── */
.inv-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0 32px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.inv-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 14px 20px;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  text-align: left;
}
.inv-tile + .inv-tile { border-left: 1px solid var(--border); }
.inv-tile-label { display: flex; align-items: center; gap: 7px; color: var(--fg-3); font-size: 12px; font-weight: 500; }
.inv-tile-label::before { content: ''; width: 8px; height: 8px; flex-shrink: 0; border-radius: 50%; background: var(--tile, var(--fg-4)); }
.inv-tile-value { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; overflow-wrap: break-word; }
.inv-tile-issued { --tile: var(--indigo); }
.inv-tile-paid { --tile: var(--emerald); }
.inv-tile-paid .inv-tile-value { color: var(--emerald); }
.inv-tile-outstanding { --tile: var(--amber); }
.inv-tile-outstanding .inv-tile-value { color: var(--amber); }
.inv-tile-overdue { --tile: var(--rose); cursor: pointer; transition: background 0.15s; }
.inv-tile-overdue:hover, .inv-tile-overdue:focus-visible { background: var(--surface-2); }
.inv-tile-overdue.has-overdue { background: var(--rose-soft); }
.inv-tile-overdue.has-overdue .inv-tile-value { color: var(--rose); }
.inv-tile-count { padding: 0 7px; border-radius: 999px; background: var(--rose); color: var(--surface); font-size: 11px; font-weight: 700; line-height: 17px; }

/* ── Shared pieces ── */
.inv-number { font-family: var(--font-mono); font-size: 13px; font-weight: 600; white-space: nowrap; }
.inv-client { display: flex; align-items: center; gap: 10px; min-width: 0; }
.inv-client .card-avatar { width: 32px; height: 32px; border-radius: 10px; font-size: 11.5px; }
.inv-client-name { min-width: 0; font-weight: 500; line-height: 1.3; overflow-wrap: break-word; }

.inv-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 11px 3px 4px;
  border: 1px solid var(--inv-border);
  border-radius: 999px;
  background: var(--inv-soft);
  color: var(--inv);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.inv-status-icon { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--inv); color: var(--surface); }
.inv-is-overdue .inv-status { border-color: var(--rose); background: var(--rose); color: var(--surface); }
.inv-is-overdue .inv-status-icon { background: var(--surface); color: var(--rose); }

.inv-date { white-space: nowrap; }
.inv-date.is-overdue { color: var(--rose); font-weight: 600; }
.inv-date.is-soon { color: var(--amber); font-weight: 600; }
.inv-money-paid { color: var(--emerald); }
.inv-money-left { color: var(--rose); font-weight: 600; }
.inv-is-partial .inv-money-left { color: var(--amber); }
.inv-money-paid.zero, .inv-money-left.zero { color: var(--fg-4); font-weight: 400; }

.inv-actions { flex-shrink: 0; justify-content: flex-end; opacity: 1; }
.inv-action { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border-radius: 10px; color: var(--fg-2); }
.inv-action-pdf:hover { border-color: var(--indigo-border); background: var(--indigo-soft); color: var(--indigo); }
.inv-action-paid { color: var(--emerald); }
.inv-action-paid:hover { border-color: var(--emerald-border); background: var(--emerald-soft); color: var(--emerald); }

.inv-toast-undo {
  margin-left: 12px;
  padding: 2px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--indigo);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
/* The toast ignores clicks and stays in the page when hidden, so only a visible one may be clicked. */
.toast.show .inv-toast-undo { pointer-events: auto; }
.inv-toast-undo:hover, .inv-toast-undo:focus-visible { background: var(--indigo-soft); }

.inv-empty { padding: 40px 0; color: var(--fg-4); text-align: center; }

/* ── Table ── */
#invoicesTableWrap[hidden], #invoicesCards[hidden] { display: none; }
#invoicesTableWrap { margin-top: 0; padding-top: 0; }
#invoicesTable td { vertical-align: middle; }
.inv-sort-btn { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
.inv-sort-btn:hover, .inv-sort-btn:focus-visible { color: var(--fg); }
#invoicesTable th[aria-sort] .inv-sort-btn { color: var(--indigo); }
.inv-sort-arrow { display: inline-block; width: 10px; }
th[aria-sort="ascending"] .inv-sort-arrow::after { content: '↑'; }
th[aria-sort="descending"] .inv-sort-arrow::after { content: '↓'; }
.inv-row { cursor: pointer; }
.inv-row:focus-visible { outline: 2px solid var(--indigo); outline-offset: -2px; }
#invoicesTable tbody td:first-child { box-shadow: inset 3px 0 0 var(--inv, transparent); }
#invoicesTable tbody tr.inv-is-overdue td { background: color-mix(in srgb, var(--rose) 4%, transparent); }
#invoicesTable tbody tr.inv-is-overdue:hover td { background: color-mix(in srgb, var(--rose) 8%, transparent); }
#invoicesTable .inv-money { font-variant-numeric: tabular-nums; white-space: nowrap; }

@media (min-width: 861px) {
  #invoicesTable .inv-money, #invoicesTable th:nth-child(n+5):nth-child(-n+7) { text-align: right; }
  #invoicesTable .inv-client { min-width: 170px; }
}

/* Too narrow for every column: the cards still show all of them. */
@media (min-width: 861px) and (max-width: 1440px) {
  #invoicesTable th:nth-child(6), #invoicesTable td:nth-child(6) { display: none; }
}
@media (min-width: 861px) and (max-width: 1360px) {
  #invoicesTable th:nth-child(3), #invoicesTable td:nth-child(3) { display: none; }
}
@media (min-width: 861px) and (max-width: 1200px) {
  #invoicesTable th, #invoicesTable td { padding-left: 8px; padding-right: 8px; }
  #invoicesTable .inv-client { min-width: 130px; }
  #invoicesTable .inv-action { width: 32px; height: 32px; }
}
@media (min-width: 861px) and (max-width: 1100px) {
  #invoicesTable th:nth-child(5), #invoicesTable td:nth-child(5) { display: none; }
  #invoicesTable th, #invoicesTable td { padding-left: 6px; padding-right: 6px; }
  #invoicesTable .inv-action { width: 30px; }
}

/* ── Cards ── */
.inv-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; padding: 0 32px 32px; }
.inv-cards .inv-empty { grid-column: 1 / -1; }
.inv-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-top: 3px solid var(--inv);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}
.inv-card:hover { box-shadow: var(--shadow-sm, var(--shadow-xs)); transform: translateY(-2px); }
.inv-card:focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; }
.inv-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.inv-card .inv-client { min-height: 36px; }
.inv-card .inv-client-name { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.inv-card-amount { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.inv-progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.inv-progress span { display: block; height: 100%; border-radius: inherit; background: var(--inv); }
.inv-card-figures { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0; }
.inv-card-figures dt { margin-bottom: 2px; color: var(--fg-3); font-size: 11.5px; }
.inv-card-figures dd { margin: 0; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.inv-card-bottom { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.inv-card-dates { display: flex; flex-direction: column; gap: 3px; min-width: 0; color: var(--fg-3); font-size: 11.5px; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .inv-card { transition: none; }
  .inv-card:hover { transform: none; }
}

@media (max-width: 860px) {
  .inv-recurring-due { margin: 0 16px 12px; }
  .inv-recurring-row { flex-wrap: wrap; }
  .inv-recurring-info { flex: 1 1 100%; }
  .payment-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 32px; }
  .payment-row input[type="text"] { grid-column: 1 / -1; grid-row: 2; }
  .inv-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0 16px 12px; }
  .inv-tile { padding: 12px 14px; }
  .inv-tile-value { font-size: 15px; }
  .inv-tile:nth-child(3) { border-left: 0; }
  .inv-tile:nth-child(n+3) { border-top: 1px solid var(--border); }
  .inv-cards { grid-template-columns: minmax(0, 1fr); padding: 0 16px 24px; }
  #agencyInvoicesPanel .agency-panel-toolbar { flex-wrap: wrap; }
  #agencyInvoicesPanel .inv-search { flex: 1 1 100%; }
  #agencyInvoicesPanel[data-view="table"] .inv-sort-select { display: block; }
  #invoicesViewToggle { flex: 0 0 auto; width: auto; }
  #invoicesViewToggle .view-toggle-btn { flex: 0 0 44px; }
  #invoicesTable .inv-actions { justify-content: flex-end; }
  #invoicesTable tbody td:first-child { box-shadow: none; }
  #invoicesTable tbody tr { box-shadow: inset 3px 0 0 var(--inv, transparent); }
}

/* ── Same look for hours, projects and quotes ── */
#hoursTable td, #projectsTable td, #quotesTable td { vertical-align: middle; }
#hoursTable tbody td:first-child, #projectsTable tbody td:first-child { box-shadow: inset 3px 0 0 var(--inv, transparent); }
#hoursTable .inv-money, #projectsTable .inv-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
#hoursTable .inv-money-left, #projectsTable .inv-money-left { color: var(--amber); }
#hoursTable .inv-is-unpaid .inv-money-left { color: var(--rose); }
#hoursTable .inv-money-left.zero, #projectsTable .inv-money-left.zero { color: var(--fg-4); font-weight: 400; }
#projectsTable tr.row-done td:nth-child(2) { text-decoration: none; }
#hoursTable .empty-row td, #projectsTable .empty-row td, #quotesTable .empty-row td, #invoicesTable .empty-row td { box-shadow: none; padding: 44px 16px; }
#hoursTable .empty-row:hover td, #projectsTable .empty-row:hover td, #quotesTable .empty-row:hover td, #invoicesTable .empty-row:hover td { background: none; }
.quote-title { font-weight: 550; }

@media (min-width: 861px) {
  #hoursTable .inv-money, #hoursTable th:nth-child(n+4):nth-child(-n+7) { text-align: right; }
  #projectsTable .inv-money, #projectsTable th:nth-child(n+5):nth-child(-n+7) { text-align: right; }
  #hoursTable .inv-client { min-width: 140px; }
  #projectsTable .inv-client { min-width: 130px; }
  #agencyQuotesPanel .agency-panel-toolbar .select-input { flex: 0 1 240px; width: 240px; min-width: 0; }
  #addQuoteBtn { margin-left: auto; }
}

@media (max-width: 860px) {
  #hoursTable tbody td:first-child, #projectsTable tbody td:first-child { box-shadow: none; }
  #hoursTable tbody tr, #projectsTable tbody tr { box-shadow: inset 3px 0 0 var(--inv, transparent); }
  #hoursTable .empty-row, #projectsTable .empty-row, #quotesTable .empty-row, #invoicesTable .empty-row { box-shadow: none; }
}

/* Too narrow for every column. */
@media (min-width: 861px) and (max-width: 1440px) {
  #hoursTable th:nth-child(6), #hoursTable td:nth-child(6), #projectsTable th:nth-child(6), #projectsTable td:nth-child(6) { display: none; }
}
@media (min-width: 861px) and (max-width: 1280px) {
  #projectsTable th:nth-child(4), #projectsTable td:nth-child(4), #projectsTable th:nth-child(9), #projectsTable td:nth-child(9) { display: none; }
}
@media (min-width: 861px) and (max-width: 1100px) {
  #hoursTable th:nth-child(5), #hoursTable td:nth-child(5), #projectsTable th:nth-child(5), #projectsTable td:nth-child(5) { display: none; }
  #hoursTable th, #hoursTable td, #projectsTable th, #projectsTable td { padding-left: 8px; padding-right: 8px; }
}

/* ── Invoice popup: the PDF look ── */
.inv-look-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.inv-look-head label { margin: 0; }
.q-thumbs.inv-thumbs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.q-thumb-page .invoice-doc { zoom: 0.14; }
.inv-look-colors { margin-top: 12px; }
.inv-look-sub { display: block; margin-bottom: 6px; color: var(--text2); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.inv-look-colors .q-color-inputs { max-width: 360px; }

.inv-preview-dialog { position: fixed; inset: 0; width: min(880px, 96vw); max-width: none; max-height: 94vh; margin: auto; padding: 0; border: 0; border-radius: 14px; background: var(--surface); color: var(--fg); box-shadow: 0 24px 60px rgb(0 0 0 / 0.35); overflow: hidden; }
.inv-preview-dialog::backdrop { background: rgb(10 10 20 / 0.55); }
.inv-preview-dialog[open] { display: flex; flex-direction: column; }
.inv-preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.inv-preview-bar h2 { margin: 0; font-size: 16px; }
.inv-preview-scroll { flex: 1; min-height: 0; padding: 20px; overflow: auto; background: #6b6b74; }
.inv-preview-page { width: fit-content; margin: 0 auto; box-shadow: 0 6px 24px rgb(0 0 0 / 0.28); }

@media (max-width: 860px) {
  .q-thumbs.inv-thumbs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inv-thumbs .q-thumb-page { width: 111px; }
  .inv-preview-scroll { padding: 12px; }
  .inv-preview-page .invoice-doc { zoom: 0.44; }
}

/* ── Invoice popup: reading an earlier invoice with AI ── */
.inv-import { margin-bottom: 18px; }
.inv-import[hidden] { display: none !important; }
.inv-import.is-busy .file-pick { opacity: 0.6; pointer-events: none; }
.inv-import-status { margin-top: 10px; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface-2); font-size: 12.5px; line-height: 1.5; }
.inv-import-status[hidden] { display: none; }
.inv-import-status.is-busy { color: var(--fg-2); }
.inv-import-status.is-error { background: var(--rose-soft); color: var(--rose); }
.inv-import-title { margin: 0 0 6px; font-weight: 650; }
.inv-import-notes { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.inv-import-note { position: relative; padding-left: 18px; }
.inv-import-note::before { content: ''; position: absolute; left: 2px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--tone); }
.inv-import-note.is-ok { --tone: var(--emerald); }
.inv-import-note.is-warn { --tone: var(--amber); }
.inv-import-note.is-bad { --tone: var(--rose); color: var(--rose); font-weight: 600; }
.inv-import-paid { margin-top: 10px; }
.inv-import-check { margin: 8px 0 0; color: var(--fg-3); }
