/*
 * Invoice generator editor (the page around the document; the document
 * itself is styled by doc-base.css and friends inside the preview iframe).
 * Uses the site's variables from style2.css, so light and dark themes work.
 */
.inv-hero { padding-bottom: var(--sp-4, 1rem); }
.inv-app { max-width: 1440px; margin: 0 auto; padding: 0 var(--sp-4, 1rem) var(--sp-6, 2rem); }
.inv-noscript { padding: 1rem; border: 1px solid var(--color-warning); border-radius: var(--r-md); }
/* Author display rules (flex, grid) would otherwise beat the hidden attribute,
   showing other countries' fields */
.inv-app [hidden], .inv-content [hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Fields */
.inv-app label, .inv-app legend, .inv-label { font-size: var(--text-sm); color: var(--text-secondary); font-weight: 500; }
.inv-app input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]),
.inv-app select, .inv-app textarea {
	width: 100%; min-width: 0; padding: .5rem .625rem; font: inherit; font-size: var(--text-sm);
	color: var(--text-primary); background: var(--bg-input); border: 1px solid var(--border-color); border-radius: var(--r-sm);
}
.inv-app textarea { resize: vertical; line-height: 1.4; }
.inv-app input:focus-visible, .inv-app select:focus-visible, .inv-app textarea:focus-visible,
.inv-app button:focus-visible, .inv-app summary:focus-visible, .inv-app a:focus-visible,
.inv-styles input:focus-visible + label, .inv-accents input:focus-visible + label {
	outline: 2px solid var(--color-primary); outline-offset: 2px;
}
.inv-app [aria-invalid="true"] { border-color: var(--color-danger) !important; }
.inv-field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.inv-field-error { margin: 0; min-height: 0; font-size: var(--text-xs); color: var(--color-danger); }
.inv-field-error:empty { display: none; }
.inv-hint { font-size: var(--text-xs); color: var(--text-muted); font-weight: normal; margin: 0; }
.inv-check { display: flex; align-items: center; gap: .5rem; font-size: var(--text-sm); color: var(--text-primary); margin: .5rem 0; cursor: pointer; }
.inv-check input { width: 1rem; height: 1rem; accent-color: var(--color-primary); }
.inv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem 1rem; margin-bottom: .75rem; }
.inv-grid:empty { display: none; }
.inv-wide { grid-column: 1 / -1; }
.inv-inline { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; }
.inv-inline legend { width: 100%; margin-bottom: .2rem; padding: 0; }
.inv-inline .inv-check { margin: 0; }
.inv-inline-fields { display: flex; align-items: center; gap: .5rem; font-size: var(--text-sm); }
.inv-inline-fields[hidden] { display: none; }
.inv-inline-fields input[type=date] { width: auto !important; }
.inv-days { width: 5rem !important; }
.inv-pair { display: flex; gap: .4rem; }
.inv-pair select { width: 6.5rem !important; flex: none; }

/* Top bar */
.inv-topbar {
	display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end;
	padding: .85rem 1rem; margin: 0 0 1rem; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--r-lg);
}
.inv-topbar .inv-field { flex: 1 1 10rem; max-width: 16rem; }
.inv-topbar .inv-narrow { flex: 0 1 6.5rem; }
.inv-topbar .inv-country { flex: 1 1 15rem; max-width: 22rem; }
.inv-country-row { display: flex; align-items: center; gap: .5rem; }
.inv-badge { flex: none; font-size: var(--text-xs); font-weight: 600; padding: .15rem .5rem; border-radius: var(--r-full); background: var(--color-primary-subtle); color: var(--color-primary); }

/* Design popover (style and accent), opened from the preview bar */
.inv-preview-wrap { position: relative; }
.inv-bar-actions { display: flex; align-items: center; gap: .5rem; }
.inv-design-toggle {
	display: inline-flex; align-items: center; gap: .5rem; padding: .35rem .7rem; font: inherit; font-size: var(--text-sm);
	color: var(--text-primary); background: var(--bg-elevated); border: 1px solid var(--border-color); border-radius: var(--r-full); cursor: pointer;
}
.inv-design-toggle:hover { border-color: var(--color-primary); }
.inv-design-toggle .fa-chevron-down { font-size: .7em; color: var(--text-muted); transition: transform .15s; }
.inv-design-toggle[aria-expanded="true"] .fa-chevron-down { transform: rotate(180deg); }
.inv-design-dot { width: .85rem; height: .85rem; border-radius: 50%; box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 3px var(--border-color); }
.inv-design {
	position: absolute; z-index: 5; top: 2.9rem; right: .75rem; width: min(22rem, calc(100% - 1.5rem));
	display: grid; gap: 1rem; padding: 1rem; background: var(--bg-surface); border: 1px solid var(--border-color);
	border-radius: var(--r-lg); box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
}
.inv-styles, .inv-accents { border: 0; padding: 0; margin: 0; min-width: 0; }
.inv-styles legend, .inv-accents legend { padding: 0; margin-bottom: .5rem; }
.inv-style-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; }
.inv-accent-list { display: grid; grid-template-columns: repeat(auto-fill, 2rem); gap: .5rem; }
.inv-styles input, .inv-accents input[type=radio] { position: absolute; opacity: 0; pointer-events: none; }
.inv-style { display: flex; flex-direction: column; align-items: center; gap: .3rem; cursor: pointer; font-size: var(--text-xs) !important; }
.inv-style img { width: 100%; height: auto; aspect-ratio: 3 / 4; border: 2px solid var(--border-color); border-radius: var(--r-sm); background: #fff; object-fit: cover; transition: border-color .15s; }
.inv-style:hover img { border-color: var(--text-muted); }
.inv-styles input:checked + .inv-style img { border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-subtle); }
.inv-styles input:checked + .inv-style { color: var(--text-primary); font-weight: 600; }
.inv-swatch { width: 2rem; height: 2rem; border-radius: 50%; background: var(--swatch); cursor: pointer; border: 3px solid var(--bg-surface); box-shadow: 0 0 0 1px var(--border-color); }
.inv-accents input:checked + .inv-swatch { box-shadow: 0 0 0 2px var(--text-primary); }
.inv-swatch-custom { position: relative; width: 2rem; height: 2rem; border-radius: 50%; overflow: hidden; box-shadow: 0 0 0 1px var(--border-color);
	background: conic-gradient(#ef4444, #f59e0b, #22c55e, #06b6d4, #6366f1, #d946ef, #ef4444); }
#accentCustom { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.inv-swatch-custom:focus-within { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Split view */
.inv-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 1.25rem; align-items: start; }
.inv-form { min-width: 0; }
.inv-section { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--r-lg); padding: 0 1.1rem; margin-bottom: .6rem; }
.inv-section[open] { padding-bottom: 1rem; }
.inv-section[open] > summary { margin-bottom: .25rem; }
.inv-section > summary {
	display: flex; align-items: center; gap: .65rem; cursor: pointer; padding: .8rem 0; font-weight: 600; color: var(--text-primary); list-style: none;
}
.inv-section > summary::-webkit-details-marker { display: none; }
.inv-section > summary::after {
	content: ""; flex: none; width: .5rem; height: .5rem; margin: 0 .25rem 0 auto; border: solid var(--text-muted);
	border-width: 0 2px 2px 0; transform: rotate(45deg) translateY(-2px); transition: transform .15s;
}
.inv-section[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.inv-section > summary:hover::after { border-color: var(--text-primary); }
.inv-sec-icon { flex: none; width: 1.9rem; height: 1.9rem; display: inline-grid; place-items: center; border-radius: var(--r-md);
	background: var(--color-primary-subtle); color: var(--color-primary); font-size: .85rem; }
.inv-sec-title { flex: none; }
.inv-sum { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 400; font-size: var(--text-sm); color: var(--text-secondary); }
.inv-sum.is-empty { color: var(--text-muted); }
.inv-section[open] .inv-sum { display: none; }
.inv-sub { margin: .5rem 0; }
.inv-sub > summary { cursor: pointer; font-size: var(--text-sm); color: var(--text-secondary); padding: .25rem 0; }
.inv-image input[type=file] { font-size: var(--text-sm); color: var(--text-secondary); }
.inv-image-preview { display: flex; align-items: center; gap: .75rem; margin-top: .4rem; }
.inv-image-preview[hidden] { display: none; }
.inv-image-preview img { max-height: 48px; max-width: 160px; background: #fff; padding: 4px; border-radius: var(--r-xs); border: 1px solid var(--border-color); }
.inv-form-actions { display: flex; gap: .5rem; justify-content: flex-end; }

/* Items */
.inv-items-wrap { overflow-x: auto; margin: .5rem 0; }
.inv-items { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.inv-items th { text-align: left; font-weight: 500; color: var(--text-secondary); font-size: var(--text-xs); padding: .3rem .25rem; white-space: nowrap; }
.inv-items td { padding: .25rem; vertical-align: top; }
.inv-items .c-num { text-align: right; }
.inv-items .c-num input { width: 5.5rem !important; text-align: right; }
.inv-items .c-desc { min-width: 12rem; width: 40%; }
.inv-items .c-desc textarea { min-height: 2.25rem; overflow: hidden; resize: none; }
.inv-items select { width: auto !important; max-width: 9rem; }
.inv-items .c-amount { padding-top: .75rem; white-space: nowrap; color: var(--text-secondary); }
.inv-items .c-move { white-space: nowrap; padding-top: .5rem; }
.inv-items .c-wh { text-align: center; }
.inv-items tr.is-dragging { opacity: .4; }
.inv-grip { cursor: grab; color: var(--text-muted); padding: 0 .15rem; user-select: none; }
.inv-icon { background: none; border: 0; color: var(--text-secondary); cursor: pointer; padding: .1rem .3rem; border-radius: var(--r-xs); font-size: 1rem; line-height: 1; }
.inv-icon:hover:not(:disabled) { color: var(--text-primary); background: var(--bg-elevated); }
.inv-icon:disabled { opacity: .3; cursor: default; }
.inv-del:hover { color: var(--color-danger) !important; }

/* Tax */
.inv-custom-rates { margin-bottom: .75rem; }
.inv-custom-rates[hidden] { display: none; }
.inv-rate-row { display: flex; align-items: center; gap: .5rem; margin: .35rem 0; }
.inv-rate-row input { max-width: 14rem; }
.inv-rate-row .inv-rate { max-width: 6rem; text-align: right; }

/* Notes */
.inv-phrases { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
.inv-phrase { font-size: var(--text-xs); padding: .3rem .6rem; border-radius: var(--r-full); border: 1px dashed var(--border-color); background: none; color: var(--text-secondary); cursor: pointer; text-align: left; }
.inv-phrase:hover { color: var(--text-primary); border-color: var(--color-primary); }
.inv-phrase[hidden] { display: none; }

/* Preview and checklist */
.inv-side { position: sticky; top: calc(var(--header-h, 64px) + .75rem); min-width: 0; }
.inv-preview-wrap { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--r-lg); overflow: hidden; }
.inv-preview-bar { display: flex; justify-content: space-between; align-items: center; padding: .5rem .75rem; border-bottom: 1px solid var(--border-color); min-height: 2.5rem; }
.inv-total { font-weight: 600; color: var(--text-primary); font-size: var(--text-sm); }
.inv-preview { position: relative; height: calc(100vh - var(--header-h, 64px) - 15rem); min-height: 28rem; background: #e9eaed; }
.inv-preview iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; visibility: hidden; }
.inv-preview iframe.is-shown { visibility: visible; }
.inv-checklist { margin-top: .75rem; padding: .75rem 1rem; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--r-lg); }
.inv-checklist-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.inv-checklist h2 { font-size: var(--text-base); margin: 0; }
.inv-progress { font-size: var(--text-xs); font-weight: 600; padding: .15rem .55rem; border-radius: var(--r-full); }
.inv-progress:empty { display: none; }
.inv-progress.is-todo { color: var(--color-danger); background: var(--color-danger-dim, rgba(220, 38, 38, .1)); }
.inv-progress.is-ok { color: var(--color-success); background: var(--color-success-dim); }
.inv-checklist ul { list-style: none; margin: 0; padding: 0; max-height: 11rem; overflow: auto; }
.inv-all-done { font-size: var(--text-sm); color: var(--text-secondary); padding: .25rem; }
.inv-done { margin-top: .25rem; }
.inv-done > summary { cursor: pointer; font-size: var(--text-xs); color: var(--text-muted); padding: .25rem; }
.inv-done > summary:hover { color: var(--text-secondary); }
.inv-checklist li { margin: 0; }
.inv-check-item { display: flex; gap: .5rem; align-items: baseline; width: 100%; background: none; border: 0; padding: .25rem .25rem; color: var(--text-primary); font: inherit; font-size: var(--text-sm); text-align: left; cursor: pointer; border-radius: var(--r-xs); }
.inv-check-item:hover { background: var(--bg-elevated); }
.inv-mark { flex: none; width: 1rem; text-align: center; font-weight: 700; }
.inv-checklist .is-ok .inv-mark { color: var(--color-success); }
.inv-checklist .is-ok .inv-check-item { color: var(--text-secondary); }
.inv-checklist .is-missing .inv-mark { color: var(--color-danger); }
.inv-checklist .is-advice .inv-mark { color: var(--color-warning); }
.inv-checklist .is-info .inv-mark { color: var(--color-info); }
.inv-checklist .is-error { color: var(--color-danger); font-size: var(--text-sm); }
.inv-rules-date { font-size: var(--text-xs); color: var(--text-muted); margin: .5rem 0 0; }

/* Actions */
.inv-actions {
	position: sticky; bottom: 0; z-index: 20; display: flex; gap: .5rem; justify-content: flex-end; align-items: center;
	padding: .75rem 0; margin-top: .75rem; background: var(--bg-page); border-top: 1px solid var(--border-subtle);
}
.inv-actions button[disabled] { opacity: .6; cursor: progress; }
.inv-status { font-size: var(--text-sm); color: var(--text-secondary); min-height: 1.25rem; text-align: right; }
.inv-status.is-error { color: var(--color-danger); }
.inv-after { margin: .75rem 0; padding: 1rem; border: 1px solid var(--color-success); border-radius: var(--r-lg); background: var(--color-success-dim); }
.inv-after p { margin: 0 0 .5rem; }
.inv-after-links { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.inv-privacy { font-size: var(--text-xs); color: var(--text-muted); max-width: 60rem; margin: 1rem 0 0; }
.inv-mobile-preview, .inv-close-preview { display: none; }

/* Content below the tool */
.inv-content { max-width: 52rem; padding-top: 2rem; padding-bottom: 3rem; }
.inv-content h2 { font-size: var(--text-xl); margin: 2rem 0 .75rem; }
.inv-content p, .inv-content li { color: var(--text-secondary); line-height: 1.6; }
.inv-country-grid { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .5rem; }
.inv-country-grid a { display: block; padding: .6rem .8rem; border: 1px solid var(--border-color); border-radius: var(--r-md); color: var(--text-primary); text-decoration: none; background: var(--bg-surface); }
.inv-country-grid a:hover { border-color: var(--color-primary); }
.inv-rates { border-collapse: collapse; }
.inv-rates th, .inv-rates td { text-align: left; padding: .35rem 1rem .35rem 0; border-bottom: 1px solid var(--border-subtle); font-weight: normal; color: var(--text-secondary); }
.inv-faqs details { border-bottom: 1px solid var(--border-subtle); padding: .6rem 0; }
.inv-faqs summary { cursor: pointer; font-weight: 600; color: var(--text-primary); }
.inv-faqs p { margin: .5rem 0 0; }
.inv-sources a { word-break: break-all; }

/* Mobile: one column, sticky Preview + Download, preview as a full-screen sheet */
@media (max-width: 960px) {
	.inv-split { grid-template-columns: 1fr; }
	.inv-side { display: none; position: static; }
	.inv-mobile-preview { display: inline-flex; }
	#previewPdf { display: none; }
	.inv-actions { justify-content: stretch; }
	.inv-actions .btn { flex: 1; justify-content: center; }
	body.inv-preview-open { overflow: hidden; }
	body.inv-preview-open .inv-side { display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 1000; background: var(--bg-page); padding: .5rem; overflow: auto; }
	body.inv-preview-open .inv-close-preview { display: inline-flex; }
	body.inv-preview-open .inv-preview { height: 75vh; }
	.inv-grid { grid-template-columns: 1fr; }
}
