/* ============================================================
   MicroFil — Application CSS
   Design : utilitaire-élégant, typographie soignée, densité maîtrisée
   ============================================================ */

/* --- Reset & base --- */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root {
  /* Palette */
  --c-bg: #f6f7f9;
  --c-surface: #ffffff;
  --c-border: #dfe3e8;
  --c-border-light: #eef0f3;
  --c-text: #1e2a3a;
  --c-text-muted: #6b7a8d;
  --c-text-light: #9aa5b4;
  --c-primary: #2563eb;
  --c-primary-hover: #1d4ed8;
  --c-primary-light: #eff4ff;
  --c-danger: #dc2626;
  --c-danger-hover: #b91c1c;
  --c-danger-light: #fef2f2;
  --c-success: #16a34a;
  --c-success-light: #f0fdf4;
  --c-warning: #d97706;
  --c-warning-light: #fffbeb;
  --c-sidebar-bg: #1e2a3a;
  --c-sidebar-text: #c8d1dc;
  --c-sidebar-hover: #2a3a4e;
  --c-sidebar-active: #2563eb;

  /* Typography */
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;

  /* Layout */
  --sidebar-w: 240px;
  --header-h: 56px;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
  --transition: 150ms ease;
}

html { font-size: 16px; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Layout shell --- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--c-sidebar-bg);
  color: var(--c-sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform var(--transition);
}

.sidebar__brand {
  padding: var(--sp-5) var(--sp-5);
  font-size: var(--fs-lg);
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar__brand-link {
  display: flex;
  align-items: center;
  min-height: 32px;
  width: 100%;
  overflow: hidden;
  color: #fff;
  text-decoration: none;
}

.sidebar__brand-link:hover { text-decoration: none; }

.sidebar__brand-logo {
  display: none;
  width: 160px;
  height: 160px;
  max-width: 160px;
  max-height: 160px;
  object-fit: contain;
  object-position: left center;
  flex: 0 0 160px;
}

.sidebar__brand-logo.is-ready {
  display: block;
}

.sidebar__brand--with-image .sidebar__brand-text {
  display: none;
}

.sidebar__brand-link {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 28px;
  color: #fff;
  text-decoration: none;
  overflow: hidden;
}

.sidebar__brand-link:hover {
  text-decoration: none;
}

.sidebar__brand-text {
  display: inline-flex;
  align-items: center;
}

.sidebar__brand-logo {
  display: none;
  width: 160px;
  max-width: 160px;
  height: auto;
  max-height: 160px;
  object-fit: contain;
  object-position: left center;
}

.sidebar__brand--logo-ready .sidebar__brand-logo { display: block; }
.sidebar__brand--logo-ready .sidebar__brand-text { display: none; }

.sidebar__brand span { color: var(--c-primary); }

.sidebar__nav { flex: 1; padding: var(--sp-3) 0; }

.sidebar__section {
  padding: var(--sp-2) var(--sp-5) var(--sp-1);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
  margin-top: var(--sp-3);
}

.sidebar__link {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-5);
  color: var(--c-sidebar-text);
  font-size: var(--fs-sm);
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
}

.sidebar__link:hover { background: var(--c-sidebar-hover); color: #fff; text-decoration: none; }
.sidebar__link.active { background: var(--c-sidebar-active); color: #fff; font-weight: 500; }
.sidebar__link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .7; }
.sidebar__link.active svg { opacity: 1; }

.sidebar__footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: var(--fs-xs);
  color: rgba(255,255,255,.35);
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Header --- */
.header {
  height: var(--header-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-6);
  position: sticky; top: 0; z-index: 50;
}

.header__left { display: flex; align-items: center; gap: var(--sp-4); }
.header__title { font-size: var(--fs-lg); font-weight: 600; }

.header__breadcrumb {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm); color: var(--c-text-muted);
}

.header__breadcrumb a { color: var(--c-text-muted); }
.header__breadcrumb a:hover { color: var(--c-primary); }
.header__right { display: flex; align-items: center; gap: var(--sp-4); }

.header__user {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm); color: var(--c-text-muted); cursor: pointer;
  padding: var(--sp-1) var(--sp-2); border-radius: var(--radius);
}

.header__user:hover { background: var(--c-bg); }

.header__avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--c-primary-light); color: var(--c-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); font-weight: 600;
}

/* Mobile toggle */
.sidebar-toggle { display: none; background: none; border: none; color: var(--c-text); cursor: pointer; padding: var(--sp-2); }

/* --- Content area --- */
.content { flex: 1; padding: var(--sp-6); max-width: 1400px; }
.content--narrow { max-width: 800px; }
.content--full { max-width: none; padding: 0; }

/* --- Page header --- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-6); flex-wrap: wrap; gap: var(--sp-4);
}

.page-header__title { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.01em; }
.page-header__actions { display: flex; gap: var(--sp-3); align-items: center; }

/* --- Cards --- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card__header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--c-border-light);
  display: flex; align-items: center; justify-content: space-between;
}

.card__title { font-size: var(--fs-md); font-weight: 600; }
.card__body { padding: var(--sp-5); }

.card__footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--c-border-light);
  display: flex; justify-content: flex-end; gap: var(--sp-3);
}

/* --- Stats row (dashboard) --- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-6); }

.stat-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-lg); padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}

.stat-card__label { font-size: var(--fs-xs); color: var(--c-text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: var(--sp-1); }
.stat-card__value { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; }
.stat-card__sub { font-size: var(--fs-xs); color: var(--c-text-muted); margin-top: var(--sp-1); }
.stat-card--primary .stat-card__value { color: var(--c-primary); }
.stat-card--success .stat-card__value { color: var(--c-success); }
.stat-card--warning .stat-card__value { color: var(--c-warning); }
.stat-card--danger .stat-card__value { color: var(--c-danger); }

/* --- Tables --- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }

thead th {
  text-align: left; padding: var(--sp-3) var(--sp-4);
  font-weight: 600; font-size: var(--fs-xs); text-transform: uppercase;
  letter-spacing: .04em; color: var(--c-text-muted);
  border-bottom: 2px solid var(--c-border);
  white-space: nowrap;
}

tbody td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-border-light);
  vertical-align: middle;
}

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--c-bg); }
tbody tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: var(--fs-xs); }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm); font-weight: 500; font-family: var(--font-sans);
  border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; transition: all var(--transition);
  white-space: nowrap; line-height: 1.4;
}

.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--c-primary); color: #fff; }
.btn--primary:hover { background: var(--c-primary-hover); }
.btn--secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border); }
.btn--secondary:hover { background: var(--c-bg); }
.btn--danger { background: var(--c-danger); color: #fff; }
.btn--danger:hover { background: var(--c-danger-hover); }
.btn--ghost { background: transparent; color: var(--c-text-muted); }
.btn--ghost:hover { background: var(--c-bg); color: var(--c-text); }
.btn--sm { padding: var(--sp-1) var(--sp-3); font-size: var(--fs-xs); }
.btn--lg { padding: var(--sp-3) var(--sp-6); font-size: var(--fs-md); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Forms --- */
.form-group { margin-bottom: var(--sp-4); }
.form-label { display: block; font-size: var(--fs-sm); font-weight: 500; margin-bottom: var(--sp-1); color: var(--c-text); }
.form-hint { font-size: var(--fs-xs); color: var(--c-text-muted); margin-top: var(--sp-1); }

.form-input, .form-select, .form-textarea {
  width: 100%; padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-base); font-family: var(--font-sans);
  border: 1px solid var(--c-border); border-radius: var(--radius);
  background: var(--c-surface); color: var(--c-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-light);
}

.form-input.error { border-color: var(--c-danger); }
.form-error { font-size: var(--fs-xs); color: var(--c-danger); margin-top: var(--sp-1); }
.form-textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.form-row--3 { grid-template-columns: 1fr 1fr 1fr; }

/* --- Badges / Status --- */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px var(--sp-2); border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 500;
  white-space: nowrap;
}

.badge--neutral { background: var(--c-bg); color: var(--c-text-muted); }
.badge--primary { background: var(--c-primary-light); color: var(--c-primary); }
.badge--success { background: var(--c-success-light); color: var(--c-success); }
.badge--warning { background: var(--c-warning-light); color: var(--c-warning); }
.badge--danger { background: var(--c-danger-light); color: var(--c-danger); }

/* --- Toolbar / Filters --- */
.toolbar {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-bottom: var(--sp-4); flex-wrap: wrap;
}

.toolbar__search {
  flex: 1; min-width: 200px; max-width: 320px;
  position: relative;
}

.toolbar__search input {
  width: 100%; padding: var(--sp-2) var(--sp-3) var(--sp-2) 36px;
  font-size: var(--fs-sm); border: 1px solid var(--c-border);
  border-radius: var(--radius); background: var(--c-surface);
}

.toolbar__search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--c-text-light); }

/* --- Pagination --- */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) 0; font-size: var(--fs-sm); color: var(--c-text-muted);
}

.pagination__pages { display: flex; gap: var(--sp-1); }

.pagination__page {
  padding: var(--sp-1) var(--sp-3); border-radius: var(--radius);
  border: 1px solid var(--c-border); background: var(--c-surface);
  cursor: pointer; font-size: var(--fs-sm);
}

.pagination__page:hover { background: var(--c-bg); }
.pagination__page.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--c-surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 90%; max-width: 600px;
  max-height: 85vh; overflow-y: auto;
  transform: translateY(10px); transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal__header {
  padding: var(--sp-5); border-bottom: 1px solid var(--c-border-light);
  display: flex; align-items: center; justify-content: space-between;
}

.modal__title { font-size: var(--fs-md); font-weight: 600; }
.modal__close { background: none; border: none; cursor: pointer; color: var(--c-text-muted); padding: var(--sp-1); }
.modal__body { padding: var(--sp-5); }
.modal__footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--c-border-light); display: flex; justify-content: flex-end; gap: var(--sp-3); }

/* --- Tabs --- */
.tabs { display: flex; border-bottom: 2px solid var(--c-border); margin-bottom: var(--sp-5); }

.tab {
  padding: var(--sp-3) var(--sp-5); font-size: var(--fs-sm); font-weight: 500;
  color: var(--c-text-muted); cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all var(--transition);
}

.tab:hover { color: var(--c-text); }
.tab.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }

/* --- Toast / Alert --- */
.toast-container { position: fixed; top: var(--sp-4); right: var(--sp-4); z-index: 2000; display: flex; flex-direction: column; gap: var(--sp-2); }

.toast {
  padding: var(--sp-3) var(--sp-5); border-radius: var(--radius);
  font-size: var(--fs-sm); box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: var(--sp-3);
  animation: toast-in .3s ease;
  max-width: 400px;
}

.toast--success { background: var(--c-success); color: #fff; }
.toast--error { background: var(--c-danger); color: #fff; }
.toast--warning { background: var(--c-warning); color: #fff; }
.toast--info { background: var(--c-primary); color: #fff; }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.alert {
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
  font-size: var(--fs-sm); margin-bottom: var(--sp-4);
  border: 1px solid;
}

.alert--info { background: var(--c-primary-light); border-color: var(--c-primary); color: var(--c-primary); }
.alert--success { background: var(--c-success-light); border-color: var(--c-success); color: var(--c-success); }
.alert--warning { background: var(--c-warning-light); border-color: var(--c-warning); color: var(--c-warning); }
.alert--danger { background: var(--c-danger-light); border-color: var(--c-danger); color: var(--c-danger); }

/* --- Empty state --- */
.empty-state {
  text-align: center; padding: var(--sp-12) var(--sp-6);
  color: var(--c-text-muted);
}

.empty-state__icon { font-size: 3rem; margin-bottom: var(--sp-4); opacity: .3; }
.empty-state__title { font-size: var(--fs-md); font-weight: 600; margin-bottom: var(--sp-2); color: var(--c-text); }
.empty-state__text { font-size: var(--fs-sm); margin-bottom: var(--sp-4); }

/* --- Loading --- */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--c-border); border-top-color: var(--c-primary); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

/* --- Login page --- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e2a3a 0%, #2a3a4e 100%);
}

.login-card {
  background: var(--c-surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; padding: var(--sp-8);
}

.login-card__logo { text-align: center; margin-bottom: var(--sp-6); }
.login-card__logo h1 { font-size: var(--fs-xl); font-weight: 700; color: var(--c-text); }
.login-card__logo h1 span { color: var(--c-primary); }
.login-card__logo p { font-size: var(--fs-sm); color: var(--c-text-muted); margin-top: var(--sp-1); }

/* --- Detail layout --- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.detail-item__label { font-size: var(--fs-xs); color: var(--c-text-muted); text-transform: uppercase; letter-spacing: .03em; }
.detail-item__value { font-size: var(--fs-base); font-weight: 500; margin-top: 2px; }

/* --- Line items (invoice/quote) --- */
.line-items { margin: var(--sp-4) 0; }
.line-items__row { display: grid; grid-template-columns: 3fr 1fr 1fr 1fr 1fr auto; gap: var(--sp-3); align-items: start; padding: var(--sp-2) 0; border-bottom: 1px solid var(--c-border-light); }
.line-items__header { font-size: var(--fs-xs); font-weight: 600; color: var(--c-text-muted); text-transform: uppercase; }
.line-items__total { display: flex; justify-content: flex-end; gap: var(--sp-8); padding: var(--sp-4) 0; font-weight: 600; }
.line-items__total dt { color: var(--c-text-muted); }
.line-items__total dd { font-family: var(--font-mono); font-size: var(--fs-base); }

/* --- Purchase invoice workspace --- */
.purchase-invoice-page { display: flex; flex-direction: column; gap: var(--sp-6); }

.purchase-invoice-page--workspace {
  gap: 0;
  min-height: 100vh;
  background: var(--c-bg);
}

.purchase-invoice-workspace__topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
}

.purchase-invoice-workspace__eyebrow,.purchase-invoice-preview__eyebrow {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--c-text-muted);
  margin-bottom: var(--sp-1);
}

.purchase-invoice-workspace__title,.purchase-invoice-preview__title {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.purchase-invoice-workspace__subtitle {
  margin-top: var(--sp-1);
  color: var(--c-text-muted);
}

.purchase-invoice-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-6);
  align-items: start;
}

.purchase-invoice-editor--with-preview {
  grid-template-columns: minmax(0, 1.35fr) minmax(520px, 1fr);
  gap: 0;
  flex: 1;
  min-height: calc(100vh - 89px);
}

.purchase-invoice-preview,.purchase-invoice-form-shell {
  overflow: hidden;
  min-width: 0;
}

.purchase-invoice-page--workspace .purchase-invoice-preview,.purchase-invoice-page--workspace .purchase-invoice-form-shell {
  border-radius: 0;
  box-shadow: none;
  border-top: none;
  border-bottom: none;
}

.purchase-invoice-page--workspace .purchase-invoice-form-shell {
  border-left: none;
}

.purchase-invoice-preview {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  background: #eef2f7;
}

.purchase-invoice-preview__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--c-border-light);
  background: var(--c-surface);
}

.purchase-invoice-preview__frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: var(--c-surface);
  min-height: calc(100vh - 150px);
}

.purchase-invoice-form {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.purchase-invoice-form__body {
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.purchase-invoice-form__footer {
  margin-top: auto;
  background: var(--c-surface);
}

.purchase-invoice-document-note { margin-bottom: 0; }

.purchase-invoice-lines {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.purchase-invoice-lines__toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
}

.purchase-invoice-lines__table {
  overflow-x: auto;
  padding-bottom: var(--sp-1);
}

.purchase-invoice-lines__canvas {
  min-width: 940px;
}

.purchase-invoice-lines__rows {
  display: flex;
  flex-direction: column;
}

.purchase-invoice-lines__header,.purchase-invoice-line {
  display: grid;
  grid-template-columns: minmax(140px, 2fr) minmax(180px, 2.2fr) minmax(56px, .8fr) minmax(72px, .9fr) minmax(88px, 1fr) minmax(120px, 1.2fr) minmax(92px, 1fr) 34px;
  gap: var(--sp-2);
  align-items: start;
}

.purchase-invoice-lines__header {
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--c-border-light);
  color: var(--c-text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.purchase-invoice-line {
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--c-border-light);
}

.purchase-invoice-line__total {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 38px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--c-text);
}

.purchase-invoice-summary {
  margin-left: auto;
  width: 100%;
  max-width: 320px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  background: var(--c-bg);
  padding: var(--sp-4);
}

.purchase-invoice-summary__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  font-size: var(--fs-sm);
}

.purchase-invoice-summary__row + .purchase-invoice-summary__row {
  margin-top: var(--sp-2);
}

.purchase-invoice-summary__row strong {
  font-family: var(--font-mono);
}

.purchase-invoice-summary__row--grand {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--c-border);
  font-size: var(--fs-base);
}

/* --- Responsive --- */
@media (max-width: 900px) {
  .purchase-invoice-editor--with-preview {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .purchase-invoice-page--workspace .purchase-invoice-form-shell {
    border-left: 1px solid var(--c-border);
  }

  .purchase-invoice-preview__frame {
    min-height: 55vh;
  }
}

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .main { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .line-items__row { grid-template-columns: 1fr; gap: var(--sp-1); }
  .purchase-invoice-lines__toolbar { flex-direction: column; align-items: stretch; }
}

@media (max-width: 640px) {
  .content { padding: var(--sp-4); }
  .stats-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .purchase-invoice-workspace__topbar { padding: var(--sp-4); align-items: flex-start; flex-direction: column; }
  .purchase-invoice-form__body { padding: var(--sp-4); }
  .purchase-invoice-lines__canvas { min-width: 820px; }
}
