*,
*::before,
*::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

:root {
	--font: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
	--ink: #1a1a1f;
	--ink-muted: #5c5c66;
	--ink-placeholder: #9b9ba8;
	--border: #e4e4ea;
	--border-strong: #d0d0da;
	--surface: #f6f6f8;
	--paper: #ffffff;
	--accent: #2d4a6f;
	--accent-hover: #1e3550;
	--accent-soft: rgba(45, 74, 111, 0.1);
	--accent-ring: rgba(45, 74, 111, 0.22);
	--danger: #b33a3a;
	--radius: 6px;
	--radius-input: 5px;
	--shadow: 0 4px 24px rgba(26, 26, 31, 0.08);
	--input-transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

html {
	font-size: 16px;
}

body {
	font-family: var(--font);
	background: var(--surface);
	color: var(--ink);
	line-height: 1.5;
	min-height: 100vh;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	font-feature-settings: "kern" 1, "liga" 1;
}

/* Toolbar */
.toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 1rem 1.5rem;
	background: var(--paper);
	border-bottom: 1px solid var(--border);
	position: sticky;
	top: 0;
	z-index: 10;
}

.app-title {
	font-size: 1.125rem;
	font-weight: 700;
	color: var(--accent);
	letter-spacing: -0.02em;
}

.toolbar-actions {
	display: flex;
	gap: 0.5rem;
	flex-wrap: wrap;
}

.btn {
	font-family: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	padding: 0.5rem 1rem;
	border-radius: var(--radius);
	border: none;
	cursor: pointer;
	transition: background 0.15s, color 0.15s;
}

.btn-primary {
	background: var(--accent);
	color: #fff;
}

.btn-primary:hover {
	background: var(--accent-hover);
}

.btn-secondary {
	background: var(--paper);
	color: var(--accent);
	border: 1px solid var(--border);
}

.btn-secondary:hover {
	background: var(--surface);
}

.btn-label-short {
	display: none;
}

/* Page layout */
.page {
	max-width: 900px;
	margin: 2rem auto;
	padding: 0 1.5rem 3rem;
}

/* Facture document */
.facture {
	background: var(--paper);
	padding: 2.5rem 2.75rem;
	border-radius: 2px;
	box-shadow: var(--shadow);
}

/* Shared input styling */
.facture input,
.facture textarea {
	font-family: inherit;
	color: var(--ink);
	border: 1px solid transparent;
	border-radius: var(--radius-input);
	background-color: var(--accent-soft);
	transition: var(--input-transition);
}

.facture input::placeholder,
.facture textarea::placeholder {
	color: var(--ink-placeholder);
	opacity: 1;
}

.facture input:hover:not(:focus),
.facture textarea:hover:not(:focus) {
	border-color: var(--border-strong);
	background-color: rgba(45, 74, 111, 0.06);
}

.facture input:focus,
.facture textarea:focus,
.facture select:focus {
	outline: none;
	border-color: var(--accent);
	background-color: var(--paper);
	box-shadow: 0 0 0 3px var(--accent-ring);
}

.facture select {
	font-family: inherit;
	color: var(--ink);
	border: 1px solid transparent;
	border-radius: var(--radius-input);
	background-color: var(--accent-soft);
	transition: var(--input-transition);
	cursor: pointer;
}

.facture select:hover:not(:focus) {
	border-color: var(--border-strong);
	background-color: rgba(45, 74, 111, 0.06);
}

.facture-title-row {
	display: flex;
	align-items: center;
	flex-wrap: nowrap;
	gap: 0.2rem;
	width: 100%;
	margin-bottom: 0.35rem;
	font-size: 1.625rem;
	font-weight: 600;
	letter-spacing: -0.03em;
	line-height: 1;
	color: var(--ink);
}

.facture-title-display {
	display: none;
	font-size: 1.625rem;
	font-weight: 600;
	letter-spacing: -0.03em;
	line-height: 1.2;
	margin-bottom: 0.35rem;
}

.doc-type-select {
	font-family: inherit;
	font-size: inherit;
	font-weight: inherit;
	width: auto;
	min-width: 0;
	padding: 0.2rem 1.5rem 0.2rem 0;
	appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%232d4a6f' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.15rem center;
	background-size: 0.55rem;
}

.doc-type-select:focus {
	box-shadow: 0 0 0 3px var(--accent-ring), inset 0 -2px 0 var(--accent);
}

.title-number-prefix {
	display: inline-flex;
	align-items: center;
	line-height: 1;
	user-select: none;
	white-space: nowrap;
}

.title-number-prefix .prefix-deg {
	font-size: 0.72em;
	line-height: 1;
	position: relative;
	top: -0.05em;
}

.facture-number {
	font-family: inherit;
	font-size: inherit;
	font-weight: inherit;
	flex: 1;
	width: 100%;
	min-width: 10rem;
	max-width: none;
	padding: 0.2rem 0.35rem;
}

.facture-number:focus {
	box-shadow: 0 0 0 3px var(--accent-ring), inset 0 -2px 0 var(--accent);
}

.facture-number::placeholder {
	font-weight: 400;
	opacity: 0.55;
}

.facture-date {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 0.35rem;
	font-size: 0.9375rem;
	color: var(--ink-muted);
	margin-bottom: 0.85rem;
}

.facture-date .label {
	margin-right: 0;
}

.date-input {
	font-size: inherit;
	color: var(--ink);
	width: auto;
	min-width: 7.5rem;
	padding: 0.3rem 0.5rem;
}

.separator {
	border: none;
	border-top: 1px solid var(--ink);
	margin: 0 0 1rem;
}

.facture-header-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 2rem;
	margin-bottom: 0.75rem;
	align-items: start;
}

.col-emitter {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
}

.col-client {
	display: flex;
	flex-direction: column;
	gap: 0;
}

.col-client .field-label {
	line-height: 1.2;
}

.col-client .field-textarea {
	margin-top: 0.05rem;
	padding-top: 0.1rem;
	min-height: 2rem;
}

.col-emitter .field + .field {
	margin-top: 0;
}

@media (max-width: 640px) {
	.toolbar {
		flex-wrap: wrap;
		align-items: center;
		gap: 0.65rem;
		padding: 0.75rem 1rem;
	}

	.app-title {
		font-size: 1rem;
		flex: 1 1 auto;
		min-width: 0;
	}

	.toolbar-actions {
		flex: 1 1 100%;
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: 0.5rem;
	}

	.toolbar-actions .btn {
		width: 100%;
		padding: 0.55rem 0.5rem;
		font-size: 0.8125rem;
		white-space: nowrap;
	}

	.btn-label-full {
		display: none;
	}

	.btn-label-short {
		display: inline;
	}

	.page {
		margin-top: 1rem;
		padding: 0 0.75rem 2rem;
	}

	.facture {
		padding: 1.25rem 1rem;
	}

	.facture-header-grid {
		grid-template-columns: 1fr;
		gap: 1.25rem;
	}

	.facture-title-row {
		flex-wrap: wrap;
	}

	.facture-number {
		min-width: 0;
		flex: 1 1 100%;
	}
}

.col-emitter .field,
.col-client .field {
	display: block;
	width: 100%;
}

.field-label {
	display: block;
	font-size: 0.75rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--ink-muted);
	margin-bottom: 0;
}

.field {
	font-size: 0.9375rem;
	padding: 0.45rem 0;
	width: 100%;
}

.facture .field,
.facture .field-compact,
.facture .date-input,
.facture-subject-block .field {
	padding-left: 0;
	padding-right: 0;
}

.field-textarea {
	resize: vertical;
	min-height: 2.5rem;
	line-height: 1.35;
}

.field-compact {
	padding: 0.3rem 0;
}

.field-subject {
	font-weight: 600;
	font-size: 1rem;
}

.facture-subject-block {
	margin-top: 4.5rem;
	margin-bottom: 1rem;
}

/* Table */
.table-wrap {
	overflow-x: auto;
	margin-bottom: 1.5rem;
}

.lines-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.875rem;
}

.lines-table thead th {
	text-align: left;
	font-size: 0.6875rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--ink-muted);
	padding: 0 0.5rem 0.65rem;
	border-bottom: 1px solid var(--ink);
	white-space: nowrap;
	line-height: 1.2;
}

.lines-table .col-qty,
.lines-table .col-tva {
	width: 4.5rem;
	min-width: 4.5rem;
	text-align: right;
}

.lines-table .col-total {
	width: 6.5rem;
	min-width: 6.5rem;
	text-align: right;
}

.lines-table .col-price {
	width: 6.75rem;
	min-width: 6.75rem;
	text-align: right;
}

.lines-table thead .col-qty,
.lines-table thead .col-price,
.lines-table thead .col-tva,
.lines-table thead .col-total {
	text-align: right;
}

.lines-table .col-actions {
	width: 2rem;
}

.line-row td {
	padding: 0.65rem 0.5rem;
	vertical-align: top;
	border-bottom: 1px solid var(--border);
	transition: background-color 0.2s ease;
}

.line-row:focus-within td {
	background-color: rgba(45, 74, 111, 0.03);
}

.col-details .line-title,
.col-details .line-desc {
	display: block;
	width: 100%;
	font-size: 0.875rem;
	padding: 0.35rem 0.45rem;
}

.col-details .line-title {
	font-weight: 600;
	color: var(--ink);
}

.col-details .line-desc {
	font-size: 0.8125rem;
	color: var(--ink);
	margin-top: 0.35rem;
}

.col-details .line-desc::placeholder {
	color: var(--ink-muted);
}

.line-row input[type="number"] {
	width: 100%;
	font-size: 0.875rem;
	text-align: right;
	padding: 0.35rem 0.4rem;
	-moz-appearance: textfield;
}

.line-row input[type="number"]:focus {
	box-shadow: 0 0 0 2px var(--accent-ring);
}

.line-row input[type="number"]::-webkit-outer-spin-button,
.line-row input[type="number"]::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

.line-total-ht {
	display: block;
	text-align: right;
	font-variant-numeric: tabular-nums;
	font-feature-settings: "tnum" 1;
	font-weight: 600;
	padding-top: 0.15rem;
	white-space: nowrap;
}

.btn-remove {
	font-size: 1.25rem;
	line-height: 1;
	color: var(--ink-muted);
	background: none;
	border: none;
	cursor: pointer;
	padding: 0.1rem 0.25rem;
	opacity: 0.5;
}

.btn-remove:hover {
	color: var(--danger);
	opacity: 1;
}

/* Totals */
.totals-block {
	display: grid;
	grid-template-columns: auto auto;
	column-gap: 2rem;
	row-gap: 0.35rem;
	margin-left: auto;
	margin-right: 0;
	width: max-content;
	max-width: 100%;
}

.totals-row {
	display: contents;
	font-size: 0.9375rem;
	color: var(--ink-muted);
}

.totals-row span:first-child {
	text-align: left;
	justify-self: start;
}

.totals-row span:last-child {
	font-variant-numeric: tabular-nums;
	font-feature-settings: "tnum" 1;
	color: var(--ink);
	font-weight: 600;
	white-space: nowrap;
	text-align: right;
	justify-self: end;
	min-width: 6.5rem;
}

.totals-divider {
	grid-column: 1 / -1;
	border: none;
	border-top: 1px solid var(--ink);
	margin: 0.35rem 0 0;
	height: 0;
	width: 100%;
}

.totals-row-grand span:first-child,
.totals-row-grand span:last-child {
	padding-top: 0.5rem;
	font-size: 1rem;
	font-weight: 600;
	color: var(--ink);
}

.totals-row-grand span:last-child {
	font-weight: 700;
}

.legal-note {
	margin-top: 2rem;
	font-size: 0.75rem;
	color: var(--ink-muted);
	font-style: italic;
}

/* PDF export */
body.exporting-pdf .toolbar,
body.exporting-pdf .col-actions,
body.exporting-pdf .btn-remove {
	display: none !important;
}

body.exporting-pdf .page {
	margin: 0;
	padding: 0;
	max-width: none;
}

body.exporting-pdf .facture {
	box-shadow: none;
	padding: 0;
}

body.exporting-pdf .facture-title-row {
	display: none !important;
}

body.exporting-pdf .facture-title-display {
	display: block;
}

body.exporting-pdf .facture-date {
	margin-bottom: 0.5rem;
}

body.exporting-pdf .separator {
	margin-bottom: 0.65rem;
}

body.exporting-pdf .facture-header-grid {
	gap: 1.5rem;
	margin-bottom: 0.5rem;
}

body.exporting-pdf .col-emitter {
	gap: 0.05rem;
}

body.exporting-pdf .col-client {
	gap: 0;
}

body.exporting-pdf .col-client .field-textarea {
	margin-top: 0;
	padding-top: 0 !important;
}

body.exporting-pdf .field-compact {
	padding: 0.1rem 0 !important;
	line-height: 1.35;
}

body.exporting-pdf .field-textarea {
	min-height: 0 !important;
	padding: 0.1rem 0 !important;
	resize: none;
	overflow: hidden;
}

body.exporting-pdf .facture-subject-block {
	margin-top: 3rem;
	margin-bottom: 0.65rem;
	padding-left: 0;
}

body.exporting-pdf .field-subject {
	padding-left: 0 !important;
}

body.exporting-pdf .facture-subject-block.is-empty {
	display: none !important;
}

body.exporting-pdf .totals-block {
	margin-left: auto;
	margin-right: 0;
}

body.exporting-pdf .facture input,
body.exporting-pdf .facture textarea,
body.exporting-pdf .facture select {
	border: none !important;
	background: transparent !important;
	box-shadow: none !important;
	appearance: none;
}

body.exporting-pdf .line-desc.is-empty {
	display: none !important;
}

body.exporting-pdf .col-details .line-title,
body.exporting-pdf .col-details .line-desc {
	padding: 0.1rem 0 !important;
}

body.exporting-pdf .col-details .line-desc {
	margin-top: 0 !important;
}

body.exporting-pdf .line-row td {
	background: transparent !important;
}

body.exporting-pdf .line-row input[type="number"]::-webkit-inner-spin-button {
	display: none;
}

@media print {
	.toolbar,
	.col-actions {
		display: none !important;
	}

	.page {
		margin: 0;
		padding: 0;
		max-width: none;
	}

	.facture {
		box-shadow: none;
	}
}
