/* BILLING-UI-001: operator views for sales and invoicing. Tokens and components of design-system/nexxxt-level-business-os/MASTER.md
   (Navy, Lime, Space Grotesk titles, Inter content); the rules are scoped to the billing views so the existing views keep their look. */
:root{--ok:#1d7a46;--ok-bg:#e6f4ec;--warn:#8a5a00;--warn-bg:#fff4d6;--danger:#b42318;--danger-bg:#fdecea;--danger-hover:#8f1c13;--info:#1f4f8f;--info-bg:#e8f0fb;--neutral:#506075;--neutral-bg:#eef2f5}

.billing-view{display:grid;grid-template-columns:minmax(0,1fr);gap:24px;align-content:start;font-size:15px;line-height:1.5}
.billing-view>*,.billing-view .pane,.billing-view .actions-stack{min-width:0}
.billing-view .pane,.billing-view .actions-stack{display:grid;grid-template-columns:minmax(0,1fr);gap:24px;align-content:start}
.billing-view .actions-stack>button{justify-self:start}
.billing-view h2,.billing-dialog h2{font-size:20px;line-height:1.3;margin:0 0 12px}
.billing-view h3,.billing-view h4{font-size:16px;line-height:1.4;margin:0 0 8px}
.billing-card h3{margin-top:16px}
.billing-view p{margin:0}
.billing-view .muted{color:var(--muted);font-size:14px}
/* Running text keeps a readable measure, also in a wide card with the menu closed. */
.billing-view p.muted,.billing-view .notice{max-width:75ch}
.billing-view :focus-visible,.billing-dialog :focus-visible{outline:3px solid var(--ink);outline-offset:2px;box-shadow:0 0 0 5px var(--lime)}
.billing-view .back-link{display:inline-flex;align-items:center;min-height:44px}
.sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}

.billing-card{padding:24px;background:var(--surface);border:1px solid var(--line);border-radius:12px;min-width:0}
.billing-card>*+*{margin-top:12px}
details.billing-card>summary{cursor:pointer;min-height:44px;display:flex;align-items:center;font:600 16px 'Space Grotesk',sans-serif}
details.billing-card[open]>summary{margin-bottom:12px}
.billing-view .toolbar,.billing-view .form-actions,.billing-dialog .form-actions{display:flex;flex-wrap:wrap;gap:12px;align-items:center}
.billing-view .toolbar{margin-bottom:16px}
.billing-view .form-actions{margin-top:16px}

/* Status badges: always text, the colour only repeats it */
.billing-view .badge{display:inline-block;margin:0;padding:2px 8px;border-radius:4px;font-size:13px;font-weight:600;line-height:1.5;white-space:nowrap;background:var(--neutral-bg);color:var(--neutral)}
.billing-view .badge-ok{background:var(--ok-bg);color:var(--ok)}
.billing-view .badge-warn{background:var(--warn-bg);color:var(--warn)}
.billing-view .badge-danger{background:var(--danger-bg);color:var(--danger)}
.billing-view .badge-info{background:var(--info-bg);color:var(--info)}
.billing-view .badge-neutral{background:var(--neutral-bg);color:var(--neutral)}
.billing-view .badges{display:flex;flex-wrap:wrap;gap:8px;margin:0 0 16px}

/* Notices and messages */
.billing-view .notice{margin:0;padding:12px 16px;border-left:4px solid var(--ink);border-radius:8px}
/* A notice in a card keeps the rhythm of the card: 12 px from what stands above it. */
.billing-view .billing-card>*+.notice{margin-top:12px}
.billing-view .notice p,.billing-view .notice li{color:var(--ink)}
.billing-view .notice-info{background:var(--info-bg);border-left-color:var(--info)}
.billing-view .notice-warn{background:var(--warn-bg);border-left-color:var(--warn)}
.billing-view .notice-danger{background:var(--danger-bg);border-left-color:var(--danger)}
.billing-view .notice h2{margin-bottom:8px}
.billing-view .notice ul{margin:8px 0;padding-left:20px}
.billing-view .message{padding:12px 16px;border-left:4px solid var(--ok);background:var(--ok-bg);border-radius:8px;margin:0 0 16px}
/* An empty live region takes no room but stays in the accessibility tree (never display:none), so what is written into it is announced. */
.billing-view .message:empty,.billing-view .form-message:empty{position:absolute;width:1px;height:1px;margin:0;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
.billing-view .cancel-blocked ul{list-style:none;margin:8px 0 0;padding:0;display:grid;gap:12px}
.billing-view .cancel-blocked li{display:grid;gap:4px;justify-items:start}
.billing-view .cancel-blocked h3{margin:0}
/* Links that are the way out of a block (a blocker, a hint on the overview) get the 44-px target of a button. */
.billing-view .cancel-blocked li a,.billing-view #invoice-blockers a,.billing-view #series-auto-notice a,.billing-overview .attention a{display:inline-flex;align-items:center;min-height:44px}
.billing-view .check-field .help,.billing-view .gate-state{display:block}
.billing-view .gate-state{margin-top:4px;font-weight:600;color:var(--ink)}
.billing-view .message-error{border-left-color:var(--danger);background:var(--danger-bg)}
.billing-view .empty-state{margin:0;padding:24px;border:1px dashed var(--line);border-radius:12px;background:var(--surface)}
.billing-view .empty-state p{color:var(--muted)}

/* Übersicht */
.billing-overview{padding:0;margin:32px 0 0}
.billing-overview .tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,150px),1fr));gap:16px;margin-bottom:16px}
.billing-overview .tile{display:grid;gap:4px;padding:16px 24px;background:var(--surface);border:1px solid var(--line);border-radius:12px;text-decoration:none;color:inherit;min-height:44px}
.billing-overview .tile:hover{border-color:var(--ink)}
.billing-overview .tile-label{font-size:14px;font-weight:600}
.billing-overview .tile-count{font:600 32px/1.2 'Space Grotesk',sans-serif;font-variant-numeric:tabular-nums}
.billing-overview .tile-detail{font-size:14px;color:var(--muted)}
.billing-overview .attention{margin:0 0 16px;padding-left:20px}
.billing-overview .billing-card{margin-bottom:16px}
.billing-overview .limit{display:grid;gap:4px;margin:16px 0}
.billing-overview progress{width:100%;height:12px;accent-color:var(--ink)}
.billing-overview .limit-warn{font-weight:600;color:var(--warn)}
.billing-overview .revenue-received{font-size:20px;font-weight:600;font-variant-numeric:tabular-nums}

/* Tables */
.table-scroll{overflow:auto;max-width:100%;max-height:min(70vh,640px);border:1px solid var(--line);border-radius:12px;background:var(--surface)}
.data-table{width:100%;border-collapse:separate;border-spacing:0;font-size:14px}
/* 12 px between the columns (6 px on each side) and at the edges, rows of at least 44 px. With the menu open, eight or nine columns have about
   900 px at 1280 px: numbers, dates and amounts keep their line (nowrap), names and free text wrap, so no table scrolls sideways there. */
.data-table th,.data-table td{padding:12px 6px;text-align:left;vertical-align:middle;border-bottom:1px solid var(--line);overflow-wrap:break-word}
.data-table th:first-child,.data-table td:first-child{padding-left:12px}
.data-table th:last-child,.data-table td:last-child{padding-right:12px}
.data-table .nowrap{white-space:nowrap}
.data-table thead th{position:sticky;top:0;z-index:1;background:var(--surface);font-weight:600}
.data-table tbody tr:last-child>*{border-bottom:0}
/* A link that opens the row has the 44-px target of a button; it reaches into the cell padding, so the row keeps its height. */
.data-table td a{display:inline-flex;align-items:center;min-height:44px;margin-block:-10px}
.data-table .amount{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
.data-table tfoot td{font-weight:600;background:var(--canvas);border-bottom:0;border-top:1px solid var(--line)}
.data-table td.actions .button,.data-table td.actions button{margin:2px 4px 2px 0}
.data-table .sort{min-height:44px;min-width:44px;padding:0;border:0;background:none;font:inherit;font-weight:600;gap:6px}
.data-table .sort:hover{background:none;text-decoration:underline}
.data-table [aria-sort=ascending] .sort::after,.data-table [aria-sort=descending] .sort::after{content:'';border:5px solid transparent;border-top-color:currentColor;margin-top:5px}
.data-table [aria-sort=ascending] .sort::after{border-top-color:transparent;border-bottom-color:currentColor;margin-top:-5px}
.data-table code{font-size:13px}
.data-table .badge{white-space:normal}
.data-table .nowrap .badge{white-space:nowrap}

/* Forms: one column on small screens, a twelve-column grid from 761 px (fields say how many columns they take) */
.billing-form{display:grid;gap:16px}
.billing-form .form-grid,.billing-view .line-row,.billing-view .allocation-row{display:grid;grid-template-columns:minmax(0,1fr);gap:12px 16px;align-items:start}
.billing-view .line-row,.billing-view .allocation-row{align-items:end}
.billing-form fieldset,.lines-editor{min-width:0;margin:0;padding:16px;border:1px solid var(--line);border-radius:12px}
.billing-form legend{padding:0 8px;font-weight:600}
.billing-view .form-field label{font-weight:600}
.billing-view .required{color:var(--danger)}
.billing-view .help{color:var(--muted);font-size:14px}
.billing-view textarea{display:block;width:100%;min-height:44px;padding:10px 12px;border:1px solid var(--control-line);border-radius:6px;background:var(--surface);color:var(--ink);font:400 16px Inter,Arial,sans-serif;resize:vertical}
.billing-view .field-error{margin:6px 0 0;color:var(--danger);font-size:14px}
.billing-view [aria-invalid=true]{border-color:var(--danger);box-shadow:inset 0 0 0 1px var(--danger)}
.billing-view .error-summary,.billing-dialog .error-summary{padding:12px 16px;border:1px solid var(--danger);border-left-width:4px;border-radius:8px;background:var(--danger-bg)}
.billing-view .error-summary ul{margin:8px 0 0;padding-left:20px}
.billing-view .error-summary a{color:var(--danger);font-weight:600}
.billing-view .check-row{display:flex;align-items:center;gap:12px;min-height:44px}
.billing-view .check-row input{width:20px;height:20px;flex-shrink:0;accent-color:var(--ink)}
.billing-view .check-row label{display:flex;align-items:center;min-height:44px;font-weight:600}
.billing-view .lines{display:grid;gap:16px}
.lines-editor>.form-field{margin-bottom:12px}
.billing-view .line-row,.billing-view .allocation-row{padding-bottom:16px;border-bottom:1px solid var(--line)}
.billing-view .line-row .line-sum{align-self:center}
.billing-view .lines-total{margin-top:12px;font-weight:600;font-variant-numeric:tabular-nums}
.billing-view .line-amount{font-weight:600;font-variant-numeric:tabular-nums}
@media(min-width:761px){
  .billing-form .form-grid,.billing-view .line-row,.billing-view .allocation-row{grid-template-columns:repeat(12,minmax(0,1fr))}
  .billing-form .form-grid>*,.billing-view .line-row>*,.billing-view .allocation-row>*{grid-column:span 6}
  .billing-form .span-2{grid-column:span 2}.billing-form .span-3{grid-column:span 3}.billing-form .span-4{grid-column:span 4}.billing-form .span-5{grid-column:span 5}
  .billing-form .span-6{grid-column:span 6}.billing-form .span-8{grid-column:span 8}.billing-form .span-9{grid-column:span 9}.billing-form .span-12{grid-column:1/-1}
  .billing-view .line-row .remove-line{justify-self:end}
}

/* Recurring invoices: a failure at its row, the tag on an invoice from a series, the interval rows of the settings, the filter in one line */
.billing-view[data-view="wiederkehrende-rechnungen"] .empty-state>*+*{margin-top:12px}
.billing-view .series-sort-select{display:none}
#series-auto-notice>*+*{margin-top:4px}
#series-auto-notice p{max-width:none}
#series-list th a{display:inline;min-height:0;margin-block:0}
#series-list th,#series-list th small{overflow-wrap:normal}
/* The warning of a failed run is a row of its own across the table, directly under its series; the series row loses the line between them. */
.data-table .row-note>td{padding:0 12px 12px;white-space:normal}
.data-table tr:has(+ .row-note)>*{border-bottom:0}
.data-table .series-failure{max-width:none;margin:0;white-space:normal}
/* Notices get their space like the others: below a hint in a field, above a table in the preview. */
#series-form .form-field>.notice{margin-top:8px}
#series-preview>*+*{margin-top:12px}
/* In the form the preview is a section with a heading like the field groups, not a card in a card; in the detail it stays a card. */
#series-form #series-preview-card{padding:0;border:0;background:none}
#series-form #series-preview-card h2{font-size:16px;margin-bottom:8px}
.data-table a.series-tag{display:inline-flex;align-items:center;min-height:24px;margin-block:0;text-decoration:none}
.data-table .series-marks{display:flex;flex-wrap:wrap;gap:4px;margin-top:4px;white-space:normal}
.billing-view :is(#series-preview,#series-auto-warning) .notice{max-width:none}
/* The actions and the inner cells of the series list are compact: at 1280 px with the menu open the table fits its card without sideways scrolling. */
#series-list td.actions .button,#series-list td.actions button{padding-inline:10px;margin-right:4px}
#series-list .data-table th:not(:first-child):not(:last-child),#series-list .data-table td:not(:first-child):not(:last-child){padding-inline:4px}
.billing-view #invoice-series a{display:inline-flex;align-items:center;min-height:44px}
/* An interval has a line of its own with fields wide enough for their content: name, unit, number, and the way to remove it. */
.billing-form .form-grid>.interval-row{grid-column:1/-1}
.billing-view .interval-row{align-items:start}
.billing-view .interval-row .remove-interval{justify-self:start}
@media(min-width:761px){
  .billing-form .interval-row .remove-interval{grid-column:span 2;justify-self:end;margin-top:26px}
  #series-filter{display:flex;flex-wrap:wrap;align-items:flex-end;gap:16px}
  #series-filter .form-grid{flex:0 1 600px}
  #series-filter .form-actions{margin:0}
  #series-filter .error-summary{flex:1 0 100%}
}
/* The tables of the series never cut off their last row; the preview and the history may be as tall as they are. */
:is(#series-list,#series-preview,#series-runs,#series-lines) .table-scroll{max-height:none}

/* Details, previews, totals */
.billing-view .facts{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,220px),1fr));gap:16px;margin:16px 0}
.billing-view .facts dd{margin:4px 0 0;white-space:normal}
.billing-view .totals{display:grid;gap:4px;margin:16px 0 0;max-width:520px;margin-left:auto}
.billing-view .totals>div{display:flex;justify-content:space-between;gap:16px}
.billing-view .totals dd{margin:0;font-variant-numeric:tabular-nums}
.billing-view .totals .total{padding-top:8px;border-top:1px solid var(--ink);font-weight:600}
.billing-view .plans{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,260px),1fr));gap:16px;margin:16px 0}
.billing-view .plan,.billing-view .order,.billing-view .bank-row{padding:16px;border:1px solid var(--line);border-radius:12px;display:grid;gap:8px;align-content:start;min-width:0}
.billing-view .order{margin-bottom:16px}
#bank-suggestions{display:grid;gap:16px}
.billing-view .suggestion{padding:12px 16px;background:var(--canvas);border-radius:8px;display:grid;gap:8px;justify-items:start}
.billing-view .files{list-style:none;margin:16px 0 0;padding:0;display:grid;gap:12px}
.billing-view .payment-balance{font-size:18px;font-weight:600;font-variant-numeric:tabular-nums}
.billing-view .pdf-block{margin-top:16px;display:grid;gap:12px;justify-items:start}

/* Destructive actions (Storno, Löschen, Zahlung stornieren) in danger red: the button that starts one outlined, the button that confirms it filled. */
.billing-view .danger{color:var(--danger);border-color:var(--danger);background:var(--surface)}
.billing-view .danger:hover{background:var(--danger-bg)}
.billing-dialog .danger{color:#fff;border-color:var(--danger);background:var(--danger)}
.billing-dialog .danger:hover{border-color:var(--danger-hover);background:var(--danger-hover)}

/* Confirmation dialog */
.billing-dialog{width:min(560px,calc(100vw - 32px));padding:24px;border:2px solid var(--ink);border-radius:12px;background:var(--surface);color:var(--ink)}
/* What a bank suggestion is about: the booking next to the invoice, each fact on its own line. */
.billing-dialog .match-compare{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,200px),1fr));gap:16px 24px;margin:0 0 16px;padding:16px;background:var(--canvas);border-radius:8px}
.billing-dialog .match-side h3{font-size:14px;line-height:1.4;margin:0 0 8px}
.billing-dialog .match-side .facts{grid-template-columns:minmax(0,1fr);gap:8px;margin:0}
.billing-dialog .match-side dd{margin:2px 0 0;white-space:normal;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}
.billing-dialog .notice-warn{margin:0 0 16px;padding:12px 16px;border:0;border-left:4px solid var(--warn);border-radius:8px;background:var(--warn-bg);color:var(--ink)}
.billing-dialog::backdrop{background:#101d3199}
.billing-dialog .effect{margin:0 0 16px;font-size:16px}
.billing-dialog textarea{width:100%;padding:10px 12px;border:1px solid var(--control-line);border-radius:6px;font:400 16px Inter,Arial,sans-serif}
.billing-dialog .field-error{color:var(--danger);margin:6px 0 0}
.billing-dialog label{display:block;font-weight:600;margin-bottom:6px}
.billing-dialog [aria-invalid=true]{border-color:var(--danger)}

@media(max-width:760px){
  .billing-card{padding:16px}
  .billing-form fieldset,.lines-editor{padding:12px}
  .billing-view .totals{max-width:none}
  .billing-overview .tile{padding:16px}
}
/* Below 761 px the rows of the series tables stand one under the other: the series or date first, the status right after it, every value with its
   column name; nothing scrolls sideways and nothing is cut off. */
@media(max-width:760px){
  :is(#series-list,#series-preview,#series-runs,#series-lines) .data-table,:is(#series-list,#series-preview,#series-runs,#series-lines) .data-table tbody,:is(#series-list,#series-preview,#series-runs,#series-lines) .data-table tr{display:block}
  /* The header row is hidden completely; the sorting of the list is chosen in the field "Sortieren nach" above it. */
  :is(#series-list,#series-preview,#series-runs,#series-lines) .data-table thead{display:none}
  .billing-view .series-sort-select{display:block;margin-bottom:12px}
  #series-list .data-table tr:has(+ .row-note){padding-bottom:0;border-bottom:0}
  #series-list .data-table .row-note{padding-top:8px}
  #series-list .data-table .row-note>td{padding:0}
  :is(#series-list,#series-preview,#series-runs,#series-lines) .data-table tfoot{display:block}
  :is(#series-list,#series-preview,#series-runs,#series-lines) .data-table td:empty{display:none}
  :is(#series-list,#series-preview,#series-runs,#series-lines) .data-table tr{padding:12px;border-bottom:1px solid var(--line)}
  :is(#series-list,#series-preview,#series-runs,#series-lines) .data-table tbody tr:last-child{border-bottom:0}
  :is(#series-list,#series-preview,#series-runs,#series-lines) .data-table td,:is(#series-list,#series-preview,#series-runs,#series-lines) .data-table th{display:block;padding:4px 0;border:0;text-align:left;white-space:normal}
  :is(#series-list,#series-preview,#series-runs,#series-lines) .data-table td[data-label]::before{content:attr(data-label);display:block;font-size:12px;color:var(--muted)}
  :is(#series-list,#series-preview,#series-runs,#series-lines) .data-table td a{margin-block:0}
}
@media(prefers-reduced-motion:reduce){.billing-view *{transition:none!important;animation:none!important}}
