/* SP E-Invoice Viewer — rendered inside a Shadow DOM ( theme-isolated ).
 *
 * Layout: rectangular ( "eckig" ), inspired by the original ZUGFeRD QUBA viewer — square cards with a
 * coloured header tab ( dark = the section carries data, light = empty section ) and label / value rows.
 *
 * Colours follow the invoicePress logo: teal-blue ( "invoice" #5f8fa8 ) as the primary colour and
 * orange ( "Press" #f28c1b ) as the accent.
 *
 * Theme independence:
 *   :host { all: initial } neutralises every inherited property that would otherwise leak through the
 *   shadow boundary. All sizes are stated in px ( NOT rem — rem would resolve against the outer document
 *   root and re-introduce theme coupling ).
 */

:host {
	all: initial;
	display: block;
	contain: layout style;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	color: #1f2a30;
	text-align: left;
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

/* design tokens ( logo palette ) */
:host {
	--spev-primary:        #5f8fa8;   /* logo "invoice" teal-blue */
	--spev-primary-dark:   #456b80;
	--spev-primary-darker: #385666;
	--spev-primary-soft:   #dde8ee;   /* light header tab ( empty sections ) */
	--spev-primary-tint:   #eef4f7;   /* field value background */
	--spev-accent:         #f28c1b;   /* logo "Press" orange */
	--spev-accent-dark:    #d6790c;
	--spev-accent-soft:    #fff3e3;
	--spev-surface:        #ffffff;
	--spev-muted-surface:  #f4f8fa;
	--spev-border:         #cddbe3;
	--spev-border-strong:  #a9c0cc;
	--spev-text:           #1f2a30;
	--spev-text-muted:     #5d6b73;
	--spev-radius:         0;         /* eckig */
}

.spev-viewer,
.spev-viewer *,
.spev-viewer *::before,
.spev-viewer *::after {
	box-sizing: border-box;
}

.spev-viewer {
	max-width: 1040px;
	margin: 0 auto;
	color: var( --spev-text );
}

/* ---------------------------------------------------------------- uploader */

.spev-dropzone {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 150px;
	padding: 28px;
	border: 2px dashed var( --spev-border-strong );
	border-radius: var( --spev-radius );
	background: var( --spev-muted-surface );
	text-align: center;
	cursor: pointer;
	transition: border-color .15s ease, background .15s ease;
}

.spev-dropzone:hover,
.spev-dropzone:focus {
	border-color: var( --spev-primary );
	background: var( --spev-primary-tint );
	outline: none;
}

.spev-dropzone.spev-dragover {
	border-color: var( --spev-accent );
	background: var( --spev-accent-soft );
}

.spev-dropzone.spev-busy {
	opacity: .6;
	pointer-events: none;
}

.spev-dropzone-inner {
	display: flex;
	flex-direction: column;
	gap: 5px;
}

.spev-dropzone-text {
	font-weight: 600;
	font-size: 16px;
}

.spev-dropzone-hint {
	font-size: 13px;
	color: var( --spev-text-muted );
}

.spev-dropzone.spev-busy::after {
	content: "";
	position: absolute;
	width: 26px;
	height: 26px;
	border: 3px solid var( --spev-primary-soft );
	border-top-color: var( --spev-accent );
	border-radius: 50%;
	animation: spev-spin .8s linear infinite;
}

@keyframes spev-spin {
	to { transform: rotate( 360deg ); }
}

.spev-message {
	margin: 12px 0;
	font-size: 14px;
}

.spev-message.spev-error { color: #b91c1c; }
.spev-message.spev-info  { color: var( --spev-text-muted ); }

.spev-result { margin-top: 16px; }

.spev-bt-toggle-wrap {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	margin: 4px 0 14px;
	font-size: 14px;
	color: var( --spev-text-muted );
	cursor: pointer;
	user-select: none;
}

.spev-bt-toggle-wrap input { margin: 0; }

/* ---------------------------------------------------------- invoice canvas */

.spev-invoice {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

/* hero / document head */

.spev-hero {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	justify-content: space-between;
	gap: 18px;
	padding: 20px 22px;
	border-radius: var( --spev-radius );
	background: linear-gradient( 135deg, var( --spev-primary-dark ) 0%, var( --spev-primary ) 100% );
	color: #ffffff;
	border-bottom: 3px solid var( --spev-accent );
}

.spev-hero-main { min-width: 0; }

.spev-hero-type {
	font-size: 13px;
	font-weight: 600;
	letter-spacing: .06em;
	text-transform: uppercase;
	color: #e6eef2;
}

.spev-hero-no {
	margin-top: 2px;
	font-size: 26px;
	font-weight: 700;
	line-height: 1.2;
	word-break: break-word;
}

.spev-hero-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 6px 22px;
	margin-top: 12px;
	font-size: 13px;
	color: #e6eef2;
}

.spev-hero-meta b {
	display: block;
	font-weight: 600;
	color: #ffffff;
	font-size: 14px;
}

.spev-hero-amount {
	flex: 0 0 auto;
	text-align: right;
	padding: 12px 18px;
	border-radius: var( --spev-radius );
	background: var( --spev-accent );
	color: #ffffff;
}

.spev-hero-amount > span {
	display: block;
	font-size: 12px;
	letter-spacing: .04em;
	text-transform: uppercase;
	color: #fff0df;
}

.spev-hero-amount b {
	font-size: 22px;
	font-weight: 700;
	white-space: nowrap;
}

/* disclaimer note */

.spev-disclaimer {
	padding: 9px 14px;
	border: 1px solid #f3d39a;
	background: var( --spev-accent-soft );
	border-radius: var( --spev-radius );
	font-size: 13px;
	color: #8a5a12;
	text-align: center;
}

/* card grid */

.spev-grid {
	display: grid;
	grid-template-columns: repeat( 2, minmax( 0, 1fr ) );
	gap: 16px;
	align-items: start;
}

.spev-grid > .spev-span-2 { grid-column: 1 / -1; }

@media ( max-width: 720px ) {
	.spev-grid { grid-template-columns: minmax( 0, 1fr ); }
}

/* position group */

.spev-pos {
	border: 1px solid var( --spev-border );
	border-left: 4px solid var( --spev-primary );
	background: var( --spev-muted-surface );
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.spev-pos-head {
	font-size: 15px;
	font-weight: 700;
	color: var( --spev-primary-dark );
}

/* card */

.spev-card {
	background: var( --spev-surface );
	border: 1px solid var( --spev-border );
	border-radius: var( --spev-radius );
}

/* the header tab : only as wide as its text, sitting at the top-left ( QUBA style ) */

.spev-card-head {
	display: inline-block;
	max-width: 100%;
	padding: 7px 16px;
	font-size: 14px;
	font-weight: 700;
	line-height: 1.3;
	color: #ffffff;
	background: var( --spev-primary-dark );
	word-break: break-word;
}

/* empty section → light tab with dark text */

.spev-card--empty .spev-card-head {
	background: var( --spev-primary-soft );
	color: var( --spev-primary-dark );
}

.spev-card-body { padding: 12px 16px 16px; }
.spev-card-body--flush { padding: 0; }

/* field rows ( label + value box ) — always rendered, even when empty */

.spev-fields {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.spev-field {
	display: grid;
	grid-template-columns: 42% 1fr;
	gap: 12px;
	align-items: start;
}

.spev-field-label {
	font-size: 13px;
	color: var( --spev-text-muted );
	padding-top: 7px;
	word-break: break-word;
}

.spev-field-value {
	display: block;
	min-height: 32px;
	padding: 6px 10px;
	font-size: 14px;
	color: var( --spev-text );
	background: var( --spev-primary-tint );
	border-radius: var( --spev-radius );
	word-break: break-word;
	white-space: pre-wrap;
}

.spev-field-value.spev-empty {
	color: #9aacb5;
}

a.spev-field-value.spev-link {
	color: var( --spev-accent-dark );
	text-decoration: underline;
	cursor: pointer;
}

/* sub-heading inside a card */

.spev-subhead {
	margin-top: 6px;
	font-size: 13.5px;
	font-weight: 700;
	color: var( --spev-text );
}

/* span-2 cards lay their fields out in two columns ( sub-headings span the full width ) */

.spev-card.spev-span-2 .spev-fields {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px 28px;
	align-items: start;
}

.spev-card.spev-span-2 .spev-subhead {
	grid-column: 1 / -1;
}

@media ( max-width: 720px ) {
	.spev-card.spev-span-2 .spev-fields { grid-template-columns: 1fr; }
}

/* tables ( vat / charges ) */

.spev-table-wrap { overflow-x: auto; }

.spev-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13.5px;
}

.spev-table th {
	text-align: left;
	background: var( --spev-muted-surface );
	color: var( --spev-text-muted );
	font-weight: 600;
	padding: 9px 12px;
	border-bottom: 1px solid var( --spev-border );
	white-space: nowrap;
}

.spev-table td {
	padding: 9px 12px;
	border-bottom: 1px solid var( --spev-border );
	vertical-align: top;
}

.spev-table tbody tr:last-child td { border-bottom: 0; }

.spev-num { text-align: right; white-space: nowrap; }

/* totals */

.spev-totals-list {
	display: flex;
	flex-direction: column;
}

.spev-totals-row {
	display: flex;
	justify-content: space-between;
	gap: 16px;
	padding: 9px 16px;
	font-size: 14px;
}

.spev-totals-row:not( :last-child ) {
	border-bottom: 1px solid var( --spev-border );
}

.spev-totals-row span { color: var( --spev-text-muted ); }
.spev-totals-row b    { font-weight: 600; white-space: nowrap; }

.spev-totals-row.spev-grand {
	background: var( --spev-primary-tint );
	font-size: 16px;
}

.spev-totals-row.spev-grand span,
.spev-totals-row.spev-grand b { color: var( --spev-primary-dark ); font-weight: 700; }

.spev-totals-row.spev-due {
	background: var( --spev-accent-soft );
}

.spev-totals-row.spev-due span,
.spev-totals-row.spev-due b { color: var( --spev-accent-dark ); font-weight: 700; }

/* ---- BT ( Business Term ) badges : hidden unless toggled on ---- */

.spev-bt {
	display: none;
	margin-left: 6px;
	padding: 1px 6px;
	font-size: 11px;
	font-weight: 600;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	color: var( --spev-primary-dark );
	background: var( --spev-primary-soft );
	border-radius: var( --spev-radius );
	vertical-align: middle;
	white-space: nowrap;
}

/* badges sitting on a dark surface */
.spev-hero .spev-bt,
.spev-card-head .spev-bt {
	color: #ffffff;
	background: rgba( 255, 255, 255, .25 );
}

.spev-card--empty .spev-card-head .spev-bt {
	color: var( --spev-primary-dark );
	background: rgba( 56, 86, 102, .14 );
}

.spev-result.spev-show-bt .spev-bt {
	display: inline-block;
}
