/* Fakturata design system — modern, responsive, light/dark */
:root {
  color-scheme: light;
  --scrollbar-thumb: #b6bfce;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --surface-3: #e9ecf3;
  --text: #172033;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-100: #eef2ff;
  --primary-soft: rgba(79, 70, 229, 0.12);
  --success: #047857;
  --success-bg: #ecfdf5;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --warning: #92400e;
  --warning-bg: #fffbeb;
  --info: #1d4ed8;
  --info-bg: #eff6ff;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 16px 48px rgba(16, 24, 40, 0.16);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 264px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}
[data-theme="dark"] {
  color-scheme: dark;
  --scrollbar-thumb: #46546c;
  --bg: #0d1320;
  --surface: #151d2d;
  --surface-2: #1c273a;
  --surface-3: #233047;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #334155;
  --primary: #7c7cf8;
  --primary-600: #9292ff;
  --primary-100: #292a50;
  --primary-soft: rgba(124, 124, 248, 0.16);
  --success: #6ee7b7;
  --success-bg: #10352d;
  --danger: #fca5a5;
  --danger-bg: #3e222b;
  --warning: #fcd34d;
  --warning-bg: #382d17;
  --info: #93c5fd;
  --info-bg: #192f4d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
}
html,body,.sidebar,.sidebar nav,.main,.content,.table-wrap,.data-scroll,.palette-results,textarea,pre { scrollbar-color:var(--scrollbar-thumb) transparent;scrollbar-width:thin; }
*::-webkit-scrollbar { width:8px;height:8px; }
*::-webkit-scrollbar-track,*::-webkit-scrollbar-corner { background:transparent; }
*::-webkit-scrollbar-thumb { background:var(--scrollbar-thumb);border-radius:8px;border:2px solid transparent;background-clip:padding-box; }
@media(forced-colors:active){html,body,.sidebar,.sidebar nav,.main,.content,.table-wrap,textarea{scrollbar-color:auto;scrollbar-width:auto}}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 0.5rem; line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75rem; }
small { color: var(--muted); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86em; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 1.5rem; max-width: 1280px; width: 100%; margin: 0 auto; animation: fadeUp 0.25s ease; }
@keyframes fadeUp { from { transform: translateY(6px); } to { transform: none; } }
.skip-link { position: absolute; left: -9999px; top: 0; z-index: 400; background: var(--primary); color: #fff; padding: 0.6rem 1rem; border-radius: 0 0 10px 0; font-weight: 700; }
.skip-link:focus { left: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
.nav-group-label { padding: 0.7rem 0.85rem 0.2rem; font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 50;
}
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1rem 0.75rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 800; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800;
  background: linear-gradient(135deg, #6366f1, #8b5cf6 55%, #ec4899); box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}
.sidebar-nav { padding: 0.5rem 0.65rem; flex: 1; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.62rem 0.75rem; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 600; font-size: 0.92rem; margin-bottom: 2px; border: 0; background: none;
  width: 100%; cursor: pointer; text-align: left; font-family: inherit;
}
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-link svg { width: 20px; height: 20px; fill: currentColor; flex-shrink: 0; }
.nav-sep { height: 1px; background: var(--border); margin: 0.6rem 0.5rem; }
.sidebar-foot { padding: 0.65rem; border-top: 1px solid var(--border); }
.nav-logout { color: var(--danger); }
.nav-logout:hover { background: var(--danger-bg); color: var(--danger); }
.sidebar-backdrop { display: none; }
.sidebar .sidebar-close { display: none; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1.5rem; background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 1.15rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 38px; height: 38px;
  border-radius: 10px; display: grid; place-items: center; cursor: pointer; transition: 0.15s;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }
.topbar .icon-btn svg { fill: currentColor; }
.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
.lang-pill {
  border: 1px solid var(--border); border-radius: 999px; padding: 0.35rem 0.7rem; font-weight: 700; font-size: 0.8rem;
  color: var(--muted); background: var(--surface);
}
.lang-pill:hover { color: var(--primary); border-color: var(--primary); text-decoration: none; }
.user-chip { display: flex; align-items: center; gap: 0.5rem; padding-left: 0.5rem; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
}
.user-name { font-weight: 600; font-size: 0.9rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.card + .card { margin-top: 1rem; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.card-header h2, .card-header h3 { margin: 0; flex: 1; }
.card-body { padding: 1.25rem; }
.card-footer { padding: 0.85rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface-2); display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; }
.flex { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem; border: 1px solid transparent;
  background: var(--surface-3); color: var(--text); font-family: inherit; font-weight: 600; font-size: 0.9rem;
  padding: 0.55rem 1rem; border-radius: 10px; cursor: pointer; transition: 0.15s; text-decoration: none; line-height: 1.3;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; box-shadow: 0 6px 16px rgba(99, 102, 241, 0.3); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.82rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.18rem 0.6rem; border-radius: 999px; font-size: 0.76rem; font-weight: 700; white-space: nowrap; }
.badge-draft { background: var(--surface-3); color: var(--muted); }
.badge-issued { background: var(--info-bg); color: var(--info); }
.badge-sent { background: var(--primary-100); color: var(--primary); }
.badge-paid { background: var(--success-bg); color: var(--success); }
.badge-cancelled { background: var(--danger-bg); color: var(--danger); }
.badge-valid { background: var(--success-bg); color: var(--success); }
.badge-invalid { background: var(--danger-bg); color: var(--danger); }
.badge-warn { background: var(--warning-bg); color: var(--warning); }
.badge-refunded { background: var(--danger-bg); color: var(--danger); }
.badge-disputed { background: var(--warning-bg); color: var(--warning); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.field > label { font-weight: 600; font-size: 0.84rem; color: var(--muted); }
.field .req::after { content: " *"; color: var(--danger); }
input, select, textarea {
  font-family: inherit; font-size: 0.92rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.75rem; width: 100%; transition: 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[readonly], input:disabled, select:disabled { background: var(--surface-3); color: var(--muted); }
textarea { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 1rem; }
.form-grid .span-2 { grid-column: span 2; }
.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 0.88rem; cursor: pointer; }
.check input { width: auto; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th {
  text-align: left; padding: 0.7rem 0.85rem; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: linear-gradient(180deg, var(--primary), #8b5cf6); }
.stat-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.45rem; font-weight: 800; margin-top: 0.15rem; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 0.78rem; color: var(--muted); }

/* Flash & toasts */
.toast-stack { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(90vw, 400px); }
.toast {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.8rem 1rem; border-radius: 12px; box-shadow: var(--shadow-lg);
  background: var(--surface); border: 1px solid var(--border); animation: slideIn 0.25s ease; font-size: 0.9rem; font-weight: 600;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-close { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; }

/* Items editor */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; padding: 0.35rem 0.4rem; text-align: left; }
.items-table td { padding: 0.25rem 0.3rem; border: 0; }
.items-table input { padding: 0.5rem 0.55rem; }
.items-table .col-num { width: 90px; } .items-table .col-unit { width: 90px; } .items-table .col-vat { width: 90px; }
.items-table .col-total { width: 120px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.items-table .btn-remove { color: var(--danger); background: transparent; border: 0; cursor: pointer; font-size: 1.1rem; padding: 0.3rem; }
.totals-panel { max-width: 340px; margin-left: auto; }
.totals-row { display: flex; justify-content: space-between; padding: 0.35rem 0; font-size: 0.92rem; }
.totals-row.grand { font-weight: 800; font-size: 1.1rem; border-top: 2px solid var(--border); margin-top: 0.4rem; padding-top: 0.6rem; }

/* Invoice view */
.invoice-paper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; max-width: 900px; margin: 0 auto; box-shadow: var(--shadow); }
.invoice-paper .doc-title { color: var(--primary); letter-spacing: 0.02em; }
.invoice-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin: 1.25rem 0; }
.watermark { position: relative; }
.watermark .stamp {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg); font-size: 5rem; font-weight: 900;
  color: var(--primary); opacity: 0.07; pointer-events: none; letter-spacing: 0.1em;
}

/* Landing */
.public-nav {
  position: sticky; top: 0; z-index: 60; display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border);
}
.public-nav .brand { flex: 1; }
.hero { position: relative; overflow: hidden; padding: 5rem 1.5rem 4rem; text-align: center; }
.hero::before, .hero::after { content: ""; position: absolute; width: 480px; height: 480px; border-radius: 50%; filter: blur(90px); opacity: 0.35; z-index: -1; }
.hero::before { background: #6366f1; top: -180px; left: -120px; }
.hero::after { background: #ec4899; top: -120px; right: -140px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); max-width: 850px; margin: 0 auto 1rem; background: linear-gradient(120deg, var(--text), var(--primary)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.hero p { color: var(--muted); max-width: 720px; margin: 0 auto 1.75rem; font-size: 1.08rem; }
.hero-cta { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }
.hero-badges { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; margin-top: 1.5rem; }
.chip { background: var(--surface); border: 1px solid var(--border); padding: 0.3rem 0.75rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; color: var(--muted); box-shadow: var(--shadow-sm); }
.section { padding: 3.5rem 1.5rem; max-width: 1150px; margin: 0 auto; }
.section-title { text-align: center; margin-bottom: 2rem; }
.features-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.25rem; }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow-sm); transition: 0.2s; }
.feature-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--primary); }
.feature-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); margin-bottom: 0.8rem; font-size: 1.3rem; }
.public-footer { border-top: 1px solid var(--border); padding: 2rem 1.5rem; text-align: center; color: var(--muted); font-size: 0.85rem; }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; background: radial-gradient(1000px 500px at 10% -10%, var(--primary-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 430px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 2rem; box-shadow: var(--shadow-lg); }
.auth-card .brand { justify-content: center; margin-bottom: 1.25rem; }
.demo-box { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 12px; padding: 0.75rem 1rem; font-size: 0.85rem; margin-top: 1rem; }

/* Client search dropdown */
.client-search { position: relative; }
.client-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); max-height: 300px; overflow: auto;
}
.client-result {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 0.6rem 0.8rem;
  cursor: pointer; font-family: inherit; font-size: 0.9rem; color: var(--text); border-bottom: 1px solid var(--border);
}
.client-result:last-child { border-bottom: 0; }
.client-result:hover { background: var(--primary-soft); }

/* Alerts */
.alert { display: flex; align-items: center; gap: 0.75rem; padding: 0.85rem 1rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); flex-wrap: wrap; }
.alert-danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.alert-warn { background: var(--warning-bg); border-color: color-mix(in srgb, var(--warning) 35%, var(--border)); }
.alert .alert-body { flex: 1; min-width: 180px; }
.alert .alert-title { font-weight: 800; }

/* Onboarding checklist */
.checklist { display: grid; gap: 0.5rem; }
.checklist-item { display: flex; gap: 0.75rem; align-items: center; padding: 0.65rem 0.8rem; border: 1px solid var(--border); border-radius: 12px; color: var(--text); }
.checklist-item:hover { border-color: var(--primary); text-decoration: none; }
.checklist-item .step { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-weight: 800; font-size: 0.8rem; flex-shrink: 0; }
.checklist-item.done { opacity: 0.65; }
.checklist-item.done .step { background: var(--success-bg); color: var(--success); }
.checklist-item .ci-title { font-weight: 700; font-size: 0.92rem; }
.checklist-item .ci-sub { color: var(--muted); font-size: 0.8rem; }

/* Status timeline */
.timeline { display: flex; gap: 0.15rem; align-items: center; flex-wrap: wrap; }
.timeline-step { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.timeline-step .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--border); }
.timeline-step.done .dot { background: var(--success); }
.timeline-step.current .dot { background: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.timeline-step.done, .timeline-step.current { color: var(--text); }
.timeline-sep { width: 26px; height: 2px; background: var(--border); margin: 0 0.3rem; }
.timeline-sep.done { background: var(--success); }

/* Command palette */
.palette-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 300; display: none; padding: 8vh 1rem 1rem; }
.palette-backdrop.open { display: block; }
.palette { max-width: 620px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden; animation: fadeUp 0.15s ease; }
.palette input { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 1rem 1.1rem; font-size: 1.05rem; }
.palette input:focus { box-shadow: none; }
.palette-results { max-height: 56vh; overflow: auto; }
.palette-group { padding: 0.5rem 0.9rem 0.2rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 800; }
.palette-item { display: flex; align-items: center; gap: 0.7rem; width: 100%; border: 0; background: none; padding: 0.6rem 0.9rem; cursor: pointer; font-family: inherit; font-size: 0.92rem; color: var(--text); text-align: left; }
.palette-item .pi-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); font-size: 0.9rem; flex-shrink: 0; }
.palette-item.active, .palette-item:hover { background: var(--primary-soft); }
.palette-item .pi-sub { color: var(--muted); font-size: 0.78rem; }
.palette-foot { border-top: 1px solid var(--border); padding: 0.5rem 0.9rem; color: var(--muted); font-size: 0.75rem; display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.kbd { border: 1px solid var(--border); background: var(--surface-2); border-radius: 6px; padding: 0.05rem 0.35rem; font-size: 0.72rem; font-family: ui-monospace, monospace; }
.palette-trigger { display: flex; align-items: center; gap: 0.5rem; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 10px; padding: 0.45rem 0.7rem; cursor: pointer; font-family: inherit; font-size: 0.85rem; font-weight: 600; }
.palette-trigger:hover { border-color: var(--primary); color: var(--primary); }
.palette-trigger svg { width: 16px; height: 16px; fill: currentColor; }

/* Bottom navigation (mobile) */
.bottom-nav { display: none; }
@media (max-width: 760px) {
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px);
    border-top: 1px solid var(--border); padding: 0.35rem 0.35rem calc(0.35rem + env(safe-area-inset-bottom));
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0.35rem 0.2rem; border: 0; background: none;
    color: var(--muted); font-size: 0.66rem; font-weight: 700; font-family: inherit; border-radius: 10px; text-decoration: none;
  }
  .bottom-nav a.active { color: var(--primary); background: var(--primary-soft); }
  .bottom-nav svg { width: 22px; height: 22px; fill: currentColor; }
  .bottom-nav .fab { margin-top: -20px; }
  .bottom-nav .fab .fab-circle { width: 46px; height: 46px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; display: grid; place-items: center; box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4); }
  .content { padding-bottom: 5.75rem; }
  .card-footer.sticky-actions { position: sticky; bottom: 4.75rem; z-index: 30; background: var(--surface); border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -6px 18px rgba(16, 24, 40, 0.08); }
}
@media (min-width: 761px) {
  .palette-trigger .kbd { display: inline-block; }
}
tr.row-overdue td { background: color-mix(in srgb, var(--danger-bg) 65%, transparent); }

/* Invoice form layout */
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 1rem; align-items: start; }
.summary-card { position: sticky; top: 84px; }
.invoice-side .card + .card { margin-top: 1rem; }
.item-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.item-chip { border: 1px dashed var(--border); background: var(--surface); border-radius: 999px; padding: 0.25rem 0.7rem; font-size: 0.8rem; cursor: pointer; font-family: inherit; color: var(--muted); }
.item-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.form-alerts { display: grid; gap: 0.4rem; }
.form-alert { display: flex; gap: 0.55rem; align-items: flex-start; padding: 0.55rem 0.75rem; border-radius: 10px; font-size: 0.86rem; border: 1px solid var(--border); }
.form-alert.error { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.form-alert.warning { background: var(--warning-bg); border-color: color-mix(in srgb, var(--warning) 35%, var(--border)); }
.form-alert.info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 30%, var(--border)); }
.form-alert .fa-actions { margin-left: auto; flex-shrink: 0; }
.dirty-indicator { display: none; color: var(--warning); font-weight: 700; font-size: 0.78rem; vertical-align: middle; margin-left: 0.4rem; }
.dirty-indicator.show { display: inline; }
@media (max-width: 1080px) {
  .invoice-layout { grid-template-columns: 1fr; }
  .summary-card { position: static; }
}

@media (max-width: 1024px) {
  input, select, textarea { font-size: 16px; }
  .btn { padding: 0.65rem 1rem; }
  .btn-sm { padding: 0.5rem 0.7rem; }
  .items-table thead { display: none; }
  .items-table, .items-table tbody { display: block; width: 100%; }
  .items-table tr.item-row { display: block; border: 1px solid var(--border); border-radius: 14px; padding: 0.6rem 0.7rem 0.3rem; margin-bottom: 0.7rem; position: relative; background: var(--surface); }
  .items-table tr.item-row td { display: block; padding: 0; border: 0; margin-bottom: 0.45rem; }
  .items-table tr.item-row td[data-label]::before { content: attr(data-label); display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 800; margin-bottom: 0.1rem; }
  .items-table tr.item-row td.it-qty,
  .items-table tr.item-row td.it-unit,
  .items-table tr.item-row td.it-price,
  .items-table tr.item-row td.it-disc { display: inline-block; width: 48%; vertical-align: top; margin-right: 2%; }
  .items-table tr.item-row td.it-unit,
  .items-table tr.item-row td.it-disc { margin-right: 0; }
  .items-table tr.item-row td.col-total { text-align: left; font-size: 1.05rem; }
  .items-table tr.item-row td:last-child { position: absolute; top: 0.3rem; right: 0.4rem; margin: 0; width: auto; }
  .items-table tr.item-row .btn-remove { font-size: 1.15rem; padding: 0.4rem; }
  .row-actions .btn-sm { min-height: 38px; }
}

/* Tag editor */
.tag-editor { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; border: 1px solid var(--border); border-radius: 10px; padding: 0.4rem 0.5rem; background: var(--surface); }
.tag-editor input { border: 0; flex: 1; min-width: 110px; padding: 0.35rem; box-shadow: none; }
.tag-editor input:focus { box-shadow: none; }
.tag-chip { display: inline-flex; align-items: center; gap: 0.3rem; background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 0.15rem 0.6rem; font-size: 0.8rem; font-weight: 700; }
.tag-chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 0.9rem; padding: 0 0 0 0.1rem; }
.tag-chip .tag-ai { font-size: 0.7rem; opacity: 0.8; }
.ai-panel { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1rem; background: var(--surface-2); }
.ai-panel.open { border-color: var(--primary); background: var(--primary-soft); }

/* UX polish */
a.stat { color: inherit; text-decoration: none; display: block; }
a.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; }
.item-chip.active { border-style: solid; border-color: var(--primary); color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.row-new { animation: rowIn 0.9s ease; }
@keyframes rowIn { from { background: var(--primary-soft); } to { background: transparent; } }
.card[id^="sec-"] { scroll-margin-top: 130px; }
#settingsNav { position: sticky; top: 62px; z-index: 25; }
@media (max-width: 1024px) { #settingsNav { position: static; } }

/* Splash / PWA */
.splash { display: none; position: fixed; inset: 0; z-index: 500; background: linear-gradient(160deg, #eef2ff, #f5f6fb); place-items: center; text-align: center; }
.splash.show { display: grid; }
.splash.hide { opacity: 0; transition: opacity 0.4s ease; }
.splash-logo { width: 96px; height: 96px; border-radius: 22px; box-shadow: 0 18px 44px rgba(79, 70, 229, 0.35); animation: splashPulse 1.4s ease infinite alternate; }
.splash-name { font-size: 1.5rem; font-weight: 800; margin-top: 1rem; color: #111827; }
.splash-domain { color: #6b7280; font-size: 0.9rem; margin-top: 0.15rem; }
.splash-bar { width: 140px; height: 4px; border-radius: 999px; background: #e5e7eb; margin: 1.2rem auto 0; overflow: hidden; }
.splash-bar span { display: block; height: 100%; width: 40%; border-radius: 999px; background: linear-gradient(90deg, #4f46e5, #8b5cf6); animation: splashBar 1.1s ease-in-out infinite; }
@keyframes splashPulse { from { transform: scale(0.97); } to { transform: scale(1.03); } }
@keyframes splashBar { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }
[data-theme="dark"] .splash { background: linear-gradient(160deg, #0b1020, #131a2e); }
[data-theme="dark"] .splash-name { color: #e5e9f5; }
.brand-logo { width: 36px; height: 36px; border-radius: 10px; box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35); flex-shrink: 0; }
.app-legal { text-align: center; color: var(--muted); font-size: 0.78rem; padding: 1.5rem 1rem 0.5rem; }
.app-legal a { color: var(--muted); }
.app-legal a:hover { color: var(--primary); }
.installAppBtn[hidden] { display: none; }

/* Landing (design 2026) */
.lp-nav-links { display: flex; gap: 1.25rem; align-items: center; }
.lp-nav-links a { color: var(--muted); font-weight: 600; font-size: 0.92rem; }
.lp-nav-links a:hover { color: var(--primary); text-decoration: none; }
.lp-hero { position: relative; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); gap: 2.5rem; align-items: center; max-width: 1150px; margin: 0 auto; padding: 4rem 1.5rem 3rem; }
.lp-hero::before, .lp-hero::after { content: ""; position: absolute; width: 460px; height: 460px; border-radius: 50%; filter: blur(100px); opacity: 0.33; z-index: -1; }
.lp-hero::before { background: #6366f1; top: -200px; left: -140px; }
.lp-hero::after { background: #ec4899; top: -160px; right: -160px; }
.lp-hero-title { font-size: clamp(2.1rem, 4.6vw, 3.4rem); line-height: 1.08; letter-spacing: -0.02em; margin: 0 0 1rem; }
.lp-hero-subtitle { color: var(--muted); font-size: 1.08rem; max-width: 560px; margin: 0 0 1.6rem; }
.lp-hero-buttons { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.lp-chips { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.lp-chip { background: var(--surface); border: 1px solid var(--border); color: var(--muted); border-radius: 999px; padding: 0.28rem 0.75rem; font-size: 0.8rem; font-weight: 600; box-shadow: var(--shadow-sm); }
.lp-hero-right { position: relative; }
.lp-invoice-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 24px 60px rgba(16, 24, 40, 0.14); padding: 1.1rem 1.2rem; max-width: 460px; margin-left: auto; }
.lp-inv-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--border); padding-bottom: 0.6rem; margin-bottom: 0.6rem; }
.lp-inv-title { font-weight: 800; color: var(--primary); font-size: 1.05rem; }
.lp-inv-num { color: var(--muted); font-size: 0.85rem; }
.lp-inv-badge { background: var(--primary-soft); color: var(--primary); font-size: 0.7rem; font-weight: 800; border-radius: 8px; padding: 0.15rem 0.5rem; }
.lp-inv-row { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 0.6rem; }
.lp-inv-label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
.lp-inv-value { font-size: 0.86rem; font-weight: 600; }
.lp-inv-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; margin-bottom: 0.6rem; }
.lp-inv-table td { padding: 0.4rem 0.25rem; border-bottom: 1px dashed var(--border); color: var(--text); }
.lp-inv-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.lp-inv-totals { background: var(--surface-2); border-radius: 12px; padding: 0.7rem 0.8rem; }
.lp-inv-total-row { display: flex; justify-content: space-between; font-size: 0.86rem; padding: 0.15rem 0; color: var(--muted); }
.lp-inv-total-row.grand { font-weight: 800; color: var(--text); font-size: 1.02rem; padding-top: 0.35rem; }
.lp-inv-note { color: var(--success); font-size: 0.76rem; font-weight: 700; margin-top: 0.35rem; }
.lp-ai-chip { position: absolute; left: -10px; bottom: -14px; background: var(--surface); }
.lp-section-head { margin-bottom: 1.6rem; }
.lp-section-head h2 { font-size: clamp(1.5rem, 3vw, 2.1rem); margin: 0; }
.lp-how { padding-top: 1.5rem; }
.lp-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.lp-step { display: flex; gap: 0.9rem; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow-sm); }
.lp-step-circle { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; display: grid; place-items: center; font-weight: 800; flex-shrink: 0; }
.lp-step h3 { margin: 0 0 0.2rem; font-size: 1rem; }
.lp-step p { margin: 0; font-size: 0.88rem; }
.lp-features { padding-top: 1.5rem; }
.lp-cta-band { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; border-radius: 18px; padding: 1.4rem 1.6rem; margin-top: 2rem; box-shadow: 0 18px 44px rgba(99, 102, 241, 0.35); }
.lp-cta-band .muted { color: rgba(255, 255, 255, 0.85); }
.lp-cta-band .btn-primary { background: #fff; color: var(--primary-600); box-shadow: none; }
@media (max-width: 1024px) {
  .lp-hero { grid-template-columns: 1fr; padding-top: 2.5rem; }
  .lp-invoice-card { margin: 0 auto; }
  .lp-steps { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .lp-nav-links { display: none; }
  .lp-hero { padding: 1.5rem 1rem 2rem; }
}

/* Misc */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .big { font-size: 2.5rem; margin-bottom: 0.5rem; }
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.progress { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), #8b5cf6); }
.scan-drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2.5rem 1rem; text-align: center; color: var(--muted); cursor: pointer; transition: 0.2s; }
.scan-drop:hover, .scan-drop.dragover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.scan-result { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-top: 1rem; max-height: 320px; overflow: auto; }
.ai-answer { white-space: pre-wrap; background: var(--surface-2); border-left: 4px solid var(--primary); border-radius: 10px; padding: 1rem; margin-top: 1rem; }
.loader { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.pagination { display: flex; gap: 0.35rem; justify-content: center; margin-top: 1rem; }

/* Responsive */
@media (min-width: 1024px) {
  #sidebarOpen { display: none; }
}
@media (max-width: 1080px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1023px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-105%); transition: transform 0.25s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 45; }
  .sidebar .sidebar-close { display: grid; }
  .content { padding: 1rem; }
  .topbar { padding: 0.65rem 1rem; }
}
@media (max-width: 520px) {
  .public-nav { gap: 0.4rem; padding: 0.7rem 0.9rem; }
  .public-nav .btn-sm { padding: 0.4rem 0.55rem; font-size: 0.78rem; }
  .public-nav .brand-text { display: none; }
}
@media (max-width: 760px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .hide-sm { display: none !important; }
  .invoice-paper { padding: 1.1rem; }
  .invoice-meta { grid-template-columns: 1fr; gap: 1rem; }
  .stat-value { font-size: 1.25rem; }
  .table th, .table td { padding: 0.6rem 0.55rem; }
}
@media print {
  .sidebar, .topbar, .toast-stack, .no-print, .public-nav { display: none !important; }
  .content { padding: 0; max-width: none; }
  .invoice-paper { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; }
}

/* Voice and AI search (design review) */

/* Voice and AI search */
.voice-toggle { min-height: 56px; font-size: 1rem; }
.voice-example { cursor: default; }
.voice-example:hover {
  border-color: var(--border);
  background: var(--surface);
  color: var(--muted);
}
.voice-log {
  min-height: 120px;
  max-height: 320px;
  overflow: auto;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
}
.voice-tool-log {
  max-height: 260px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}
.voice-log-line + .voice-log-line { margin-top: 0.6rem; }
.voice-log-error, .search-error { color: var(--danger); }
.search-controls { display: flex; gap: 0.6rem; }
.search-controls input { min-width: 0; }
.search-controls .btn { flex-shrink: 0; }
.search-summary-chip { cursor: default; }
.search-table { min-width: 720px; }
.search-reasons { min-width: 150px; }
.search-reasons .tag-chip { margin: 0.1rem 0.2rem 0.1rem 0; }

.scan-drop:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
  border-color: var(--primary);
}
.scan-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

@media (max-width: 760px) {
  .search-controls { flex-direction: column; }
  .search-controls .btn, .scan-actions .btn { width: 100%; }
  .scan-actions { flex-direction: column; }
}

.voice-layout { align-items: start; }
@media (max-width: 760px) {
  .voice-toggle { width: 100%; }
}

/* UI redesign (receivables/offers/cashflow/projects/stock/contracts/fx) */
/* Shared workspace layout: receivables, offers, cashflow, projects, stock, contracts, FX */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.page-head h2 { font-size: clamp(1.35rem, 2.5vw, 1.8rem); margin-bottom: 0.2rem; }
.page-head p:last-child { margin-bottom: 0; }
.page-metric {
  display: grid;
  gap: 0.1rem;
  min-width: 190px;
  padding: 0.8rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.page-metric strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.heading-with-status { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem; }
.heading-with-status h2 { margin: 0; }
.heading-with-status + p { margin-top: 0.45rem; }
.stacked-form { display: grid; gap: 1rem; }
.stacked-form .card + .card { margin-top: 0; }
.stacked-form .field:last-child { margin-bottom: 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; }
.action-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem; }
.action-bar form, .row-actions form, .card-footer form { margin: 0; }
.action-destructive { margin-left: auto !important; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }

.data-scroll { min-width: 0; }
.card--dropdown { overflow: visible; }
.flex > select, .flex > input, .flex > textarea { min-width: 0; }
.mobile-scroll-hint { display: none; }
.wide-table { min-width: 760px; }
.stock-table { min-width: 1050px; }
.wide-table td, .stock-table td { overflow-wrap: anywhere; }
.wide-table td:first-child a, .stock-table td:first-child strong { font-weight: 700; }
.cell-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; min-width: 170px; max-width: 320px; }
.cell-tags .tag-chip { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }

.receivable-editor[hidden] { display: none; }
.receivable-editor > td { padding: 0 !important; }
.editor-panel {
  padding: 1.25rem;
  background: var(--surface-2);
  border-block: 1px solid var(--border);
}
.editor-panel h3 { margin: 0; }
.editor-panel .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.editor-panel .field { min-width: 0; }
.editor-panel .form-actions { margin-top: 0.3rem; }

.metric-strip { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1rem; }
.metric-strip-item {
  display: grid;
  gap: 0.1rem;
  min-width: 160px;
  flex: 1;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.metric-strip-item strong { font-size: 1.12rem; font-variant-numeric: tabular-nums; }
.standalone-metrics { margin-top: 0; }
.standalone-metrics .metric-strip-item { background: var(--surface); box-shadow: var(--shadow-sm); }
.cash-in { color: var(--success); }
.cash-out { color: var(--danger); }
.control-form { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 0.75rem; }
.control-form .field { flex: 1 1 180px; max-width: 280px; margin: 0; }

.entry-list, .activity-list { list-style: none; padding: 0; margin: 0; }
.entry-list { min-width: 235px; }
.entry-list li + li { margin-top: 0.4rem; }
.activity-list li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--border);
}
.activity-list li:first-child { padding-top: 0; }
.activity-list li:last-child { padding-bottom: 0; border-bottom: 0; }

.offer-totals {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.4rem 1.5rem;
  max-width: 360px;
  margin: 0 0 0 auto;
}
.offer-totals dt, .offer-totals dd { margin: 0; }
.offer-totals dt { color: var(--muted); }
.offer-totals dd { text-align: right; font-variant-numeric: tabular-nums; }
.offer-totals dt:nth-last-of-type(1),
.offer-totals dd:nth-last-of-type(1) {
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  color: var(--text);
}

.table-control { display: flex; align-items: flex-end; gap: 0.5rem; }
.table-control .field { margin: 0; min-width: 95px; }
.table-control .field > label { font-size: 0.75rem; }
.table-control .btn { white-space: nowrap; }
.stock-adjust-form .field:nth-of-type(2) { min-width: 155px; flex: 1; }
.stock-table td:nth-child(3) { min-width: 245px; }
.stock-table td:nth-child(4) { min-width: 405px; }
.stock-table td:first-child { min-width: 170px; }
.stock-table td:first-child .badge { margin-top: 0.3rem; }
.currency-input { text-transform: uppercase; }
.rate-chips .item-chip { cursor: default; }
.rate-chips .item-chip:hover {
  border-color: var(--border);
  background: var(--surface);
  color: var(--muted);
}

@media (max-width: 760px) {
  .page-head { align-items: stretch; }
  .page-head > .btn { width: 100%; }
  .page-metric { width: 100%; }
  .mobile-scroll-hint {
    display: block;
    margin: 0;
    padding: 0.6rem 0.85rem;
    color: var(--muted);
    background: var(--surface-2);
    font-size: 0.8rem;
  }
  .filter-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.35rem; }
  .filter-chips .item-chip { flex: 0 0 auto; }
  .editor-panel .form-grid { grid-template-columns: 1fr; }
  .action-bar > form:not(.action-destructive),
  .action-bar > a,
  .action-bar > form:not(.action-destructive) .btn,
  .action-bar > a.btn { width: 100%; }
  .action-destructive { margin-left: 0 !important; }
  .control-form .field { max-width: none; flex-basis: 100%; }
  .control-form .btn { width: 100%; }
  .metric-strip-item { min-width: 130px; }
}

.alert-info { background: var(--primary-soft, #eef2ff); border: 1px solid var(--primary, #4f46e5); color: var(--text, inherit); border-radius: 0.7rem; padding: 0.7rem 0.9rem; display: flex; gap: 0.5rem; }

/* Sidebar: favorites & reorder */
.nav-item { display: flex; align-items: center; gap: 0.15rem; border-radius: 0.6rem; }
.nav-item .nav-link { flex: 1; min-width: 0; }
.nav-review-badge { margin-left: auto; padding: 0.12rem 0.42rem; border-radius: 99px; background: var(--primary-soft); color: var(--primary); font-size: 0.68rem; font-weight: 700; line-height: 1.3; }
.ai-workspace-nav { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.32rem; width: fit-content; max-width: 100%; border: 1px solid var(--border); border-radius: 0.75rem; background: var(--surface-2); }
.ai-workspace-nav a { padding: 0.55rem 0.85rem; border-radius: 0.5rem; color: var(--muted); font-size: 0.84rem; font-weight: 650; text-decoration: none; }
.ai-workspace-nav a:hover { color: var(--primary); }
.ai-workspace-nav a.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.nav-tools { display: flex; align-items: center; gap: 0.1rem; }
.nav-star, .nav-move-btn { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 0.85rem; line-height: 1; padding: 0.3rem; border-radius: 0.4rem; }
.nav-star { opacity: 0.4; }
.nav-star:hover, .nav-star[aria-pressed="true"] { opacity: 1; color: #f59e0b; }
.nav-move { display: none; }
.sidebar-nav.nav-edit-mode .nav-move { display: inline-flex; flex-direction: column; }
.sidebar-nav.nav-edit-mode .nav-item { outline: 1px dashed var(--border); margin-bottom: 0.15rem; }
.nav-empty-hint { font-size: 0.75rem; color: var(--muted); padding: 0 0.6rem 0.4rem; display: none; }
.sidebar-nav.nav-edit-mode .nav-empty-hint { display: block; }

/* iPad/tablet layout fixes: no overlapping fields or cramped cards */
.grid-2 > *, .grid-3 > *, .form-grid > *, .stats-grid > *, .invoice-layout > * { min-width: 0; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { min-width: 0; min-inline-size: 0; }
.field > * { min-width: 0; max-width: 100%; }
.kv dd { min-width: 0; overflow-wrap: anywhere; }
.topbar-title { min-width: 0; }
.topbar-actions { flex-shrink: 0; }
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { gap: 0.5rem; }
  .topbar-actions { gap: 0.35rem; }
}
@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1024px) {
  .toast-stack { top: 74px; }
  .mobile-scroll-hint {
    display: block;
    margin: 0;
    padding: 0.6rem 0.85rem;
    color: var(--muted);
    background: var(--surface-2);
    font-size: 0.8rem;
  }
  .editor-panel .form-grid { grid-template-columns: 1fr; }
}
.auth-page { padding: 2rem 1rem; }

/* Filter bars must never overlap: wrapping flex instead of grid for GET forms.
   iOS Safari date/month inputs have an intrinsic width that ignores min-width:0
   inside grid tracks and paints over the next field — flex + wrap + appearance fix it. */
form.form-grid[method="get"] {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem 1rem;
}
form.form-grid[method="get"] .field {
  flex: 1 1 200px;
  min-width: 0;
  max-width: 340px;
  margin-bottom: 0;
}
form.form-grid[method="get"] .field > * { min-width: 0; width: 100%; }
form.form-grid[method="get"] .field.span-2 { flex-basis: 100%; max-width: none; }
@supports (-webkit-touch-callout: none) {
  /* iOS/iPadOS only: let date controls shrink without collapsing their height */
  input[type="date"], input[type="month"], input[type="datetime-local"], input[type="time"] {
    -webkit-appearance: none;
    appearance: none;
    min-width: 0;
    width: 100%;
    min-height: 2.6rem;
    height: auto;
    line-height: 1.4;
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    color: var(--text);
    text-align: left;
    display: inline-flex;
    align-items: center;
  }
}

/* Receivables iPad fix */
.ar-chips {
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
}

.ar-shell,
.ar-list,
.ar-item,
.ar-heading,
.ar-heading-main,
.ar-amount,
.ar-facts,
.ar-fact,
.ar-tags,
.ar-actions,
.ar-editor,
.ar-fields {
  min-width: 0;
}

.ar-list {
  display: grid;
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ar-item {
  box-sizing: border-box;
  padding: 1rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 0.75rem;
}

.ar-heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem 1.5rem;
}

.ar-heading-main,
.ar-amount {
  overflow-wrap: anywhere;
}

.ar-label,
.ar-fact dt {
  display: block;
  color: var(--muted, #666);
  font-size: 0.85rem;
}

.ar-invoice {
  margin: 0.15rem 0 0;
  font-size: 1.1rem;
}

.ar-amount strong {
  display: block;
  font-variant-numeric: tabular-nums;
}

.ar-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 1.25rem;
  margin: 1rem 0;
}

.ar-fact dd {
  min-width: 0;
  margin: 0.2rem 0 0;
  overflow-wrap: anywhere;
}

.ar-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.ar-tags .tag-chip {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.ar-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.ar-actions form,
.ar-actions button {
  min-width: 0;
  width: 100%;
}

.ar-actions button,
.ar-close,
.ar-form-actions .btn {
  box-sizing: border-box;
  min-height: 44px;
  white-space: normal;
}

.ar-editor[hidden] {
  display: none;
}

.ar-editor {
  box-sizing: border-box;
  max-width: 100%;
  margin-top: 1rem;
}

.ar-editor-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.ar-editor-head h3 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.ar-editor .ar-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ar-editor .ar-fields .field,
.ar-editor .ar-fields input {
  min-width: 0;
  max-width: 100%;
}

.ar-editor .ar-fields input {
  box-sizing: border-box;
  width: 100%;
}

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

@media (max-width: 1024px) {
  .ar-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ar-editor .ar-fields {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 560px) {
  .ar-facts,
  .ar-actions {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* iPhone portrait: keep the open sidebar above the fixed bottom navigation
   and leave room for the home indicator so the last items/logout stay visible */
@media (max-width: 760px) {
  .sidebar { z-index: 80; }
  .sidebar.open { z-index: 80; }
  .sidebar-backdrop.show { z-index: 75; }
  .sidebar-nav { padding-bottom: 1rem; }
  .sidebar-foot { padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px)); }
}

/* iPhone: off-canvas sidebar must fit the visible viewport (100dvh), scroll
   internally without chaining to the page, and lock background scroll via JS */
body.nav-locked { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
@media (max-width: 1023px) {
  .sidebar {
    height: 100vh;
    height: 100dvh;
    bottom: auto;
    box-sizing: border-box;
    overflow: hidden;
  }
  .sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .sidebar-foot { flex: none; padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px)); }
}

/* Invoice form mobile redesign (gpt-6.1-sol) */
/* Load after the existing application CSS.
 * If the shell has fixed bottom navigation, set --inv-bottom-offset to its height.
 */
.inv-form {
  --inv-bottom-offset: 0px;
  --inv-action-height: 148px;
  padding-bottom: calc(var(--inv-action-height) + var(--inv-bottom-offset) + 24px);
  color: var(--text);
}

.inv-form,
.inv-form *,
.inv-page-head,
.inv-page-head * {
  box-sizing: border-box;
}

.inv-page-head {
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
}

.inv-page-head h2 {
  min-width: 0;
  margin: 0;
  font-size: clamp(1.25rem, 3.5vw, 1.65rem);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.inv-page-head .dirty-indicator {
  font-size: 0.75rem;
}

.inv-page-head .btn,
.inv-form .btn,
.inv-form .btn-remove,
.inv-form button.item-chip {
  min-height: 48px;
  touch-action: manipulation;
}

.inv-form .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: normal;
  line-height: 1.3;
}

.inv-form :where(input, select, textarea, button, a, summary, [tabindex]):focus-visible,
.inv-page-head a:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}

.inv-form :where(input, select, textarea) {
  max-width: 100%;
  font-family: inherit;
  font-size: 16px;
}

.inv-form input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.inv-form select {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 11px 12px;
  border-radius: 10px;
}

.inv-form textarea {
  width: 100%;
  min-width: 0;
  min-height: 104px;
  padding: 12px;
  border-radius: 10px;
  line-height: 1.5;
  resize: vertical;
}

.inv-form :where(input, select, textarea, button, a, summary) {
  scroll-margin-block: 100px calc(var(--inv-action-height) + var(--inv-bottom-offset) + 24px);
}

.inv-form .field {
  min-width: 0;
  gap: 6px;
  margin-bottom: 16px;
}

.inv-form .field > label {
  font-size: 0.875rem;
  line-height: 1.4;
}

.inv-form .form-grid {
  grid-template-columns: minmax(0, 1fr);
  gap: 0 16px;
}

.inv-form .form-grid .span-2 {
  grid-column: 1 / -1;
}

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

.inv-main,
.inv-side {
  min-width: 0;
}

.inv-card {
  border-radius: 16px;
}

.inv-card .card-header {
  gap: 12px;
  padding: 16px;
}

.inv-card .card-header h3 {
  font-size: 1.05rem;
  line-height: 1.4;
}

.inv-card .card-body {
  padding: 16px;
}

.inv-card .card-footer {
  padding: 12px 16px;
}

.inv-summary-card {
  position: static;
  overflow: visible;
}

.inv-status,
.inv-help,
.inv-issued-note {
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.inv-status,
.inv-help {
  font-size: 0.875rem;
}

.inv-issued-note {
  font-size: 0.8rem;
}

.inv-ai-controls {
  align-items: stretch;
  flex-direction: column;
  gap: 12px;
}

.inv-ai-field {
  flex: 1;
  margin-bottom: 0 !important;
}

.inv-ai-buttons {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.inv-preview-wrap {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.inv-preview-wrap .table {
  min-width: 460px;
}

.inv-preview-wrap .num {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.inv-client-card {
  overflow: visible;
}

.inv-client-card .client-results {
  max-width: 100%;
  max-height: min(320px, 45vh);
  overflow-y: auto;
  overflow-wrap: anywhere;
  z-index: 40;
}

.inv-client-card .client-results :where(button, a) {
  min-height: 48px;
}

.inv-client-controls {
  align-items: stretch;
  flex-direction: column;
  gap: 12px;
}

.inv-client-select {
  flex: 1;
  margin-bottom: 0 !important;
}

.inv-new-client {
  margin-top: 16px;
}

.inv-new-client-card {
  box-shadow: none;
  border-style: dashed;
  background: var(--surface-2, var(--surface));
}

.inv-new-client-head {
  gap: 12px;
}

.inv-new-client-head strong {
  min-width: 0;
}

.inv-quick-actions {
  align-items: stretch;
  flex-direction: column;
  gap: 10px;
}

.inv-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  cursor: pointer;
  line-height: 1.4;
}

.inv-check input[type="checkbox"] {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--primary);
}

.inv-details {
  overflow: visible;
}

.inv-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  cursor: pointer;
  list-style: none;
  font-weight: 650;
}

.inv-summary::-webkit-details-marker {
  display: none;
}

.inv-summary::marker {
  content: "";
}

.inv-summary h3,
.inv-summary > span:first-child {
  flex: 1;
  min-width: 0;
}

.inv-details:not([open]) > .card-header {
  border-bottom: 0;
}

.inv-chevron {
  flex: 0 0 auto;
  display: inline-block;
  font-size: 1.3rem;
  line-height: 1;
  transition: transform 150ms ease;
}

.inv-details[open] > .inv-summary .inv-chevron {
  transform: rotate(180deg);
}

.inv-advanced {
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2, var(--surface));
}

.inv-advanced > .inv-summary {
  padding: 12px;
  font-size: 0.9rem;
}

.inv-advanced-body {
  padding: 4px 12px 12px;
}

.inv-advanced-body .field:last-child,
.inv-details > .card-body > .field:last-child {
  margin-bottom: 0;
}

.inv-tax-notice {
  margin-bottom: 16px;
}

.inv-item-hint {
  font-size: 0.8rem;
}

.inv-chip-caption {
  width: 100%;
  align-self: center;
  font-size: 0.8rem;
}

.inv-items-card .item-chips {
  gap: 8px;
  margin-bottom: 16px;
}

.inv-items-card .item-chip {
  max-width: 100%;
  padding: 10px 14px;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.inv-items-wrap {
  overflow: visible;
}

.inv-items-card .items-table,
.inv-items-card .items-table tbody {
  display: block;
  width: 100%;
}

.inv-items-card .items-table thead {
  display: none;
}

.inv-items-card .items-table tr.item-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  position: relative;
  margin: 0 0 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2, var(--surface));
}

.inv-items-card .items-table tr.item-row td {
  display: block;
  position: static;
  width: auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.inv-items-card .items-table tr.item-row td[data-label]::before {
  content: attr(data-label);
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: normal;
}

.inv-items-card .items-table tr.item-row td:first-child {
  grid-column: 1 / -1;
  padding-right: 52px;
}

.inv-items-card .items-table tr.item-row td:last-child {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 48px;
  margin: 0;
}

.inv-items-card .items-table tr.item-row td.it-qty,
.inv-items-card .items-table tr.item-row td.it-unit,
.inv-items-card .items-table tr.item-row td.it-price,
.inv-items-card .items-table tr.item-row td.it-disc,
.inv-items-card .items-table tr.item-row td.it-vat {
  display: block;
  width: auto;
  margin: 0;
}

.inv-items-card .items-table :where(input, select),
.inv-items-card .items-table .col-num,
.inv-items-card .items-table .col-unit,
.inv-items-card .items-table .col-vat {
  width: 100%;
  min-width: 0;
  min-height: 48px;
}

.inv-items-card .items-table :where(.item-qty, .item-price, .item-disc, .item-vat) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.inv-items-card .items-table tr.item-row td.col-total {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-top: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  text-align: right;
  font-size: 1.125rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.inv-items-card .items-table tr.item-row td.col-total::before {
  margin: 0;
  text-align: left;
  font-size: 0.875rem;
}

.inv-items-card .items-table .btn-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1.15rem;
}

.inv-add-item {
  width: 100%;
  border-style: dashed;
}

.inv-totals {
  max-width: none;
  margin-left: 0;
}

.inv-totals .totals-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding-block: 8px;
  line-height: 1.4;
}

.inv-totals .totals-row > :last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.inv-totals .totals-row.grand {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 1.2rem;
  font-weight: 750;
}

.inv-total-value {
  display: inline-flex;
  justify-content: flex-end;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

.inv-currency {
  font-size: 0.8em;
  font-weight: 600;
}

.inv-form .card-footer.sticky-actions.inv-action-bar {
  position: fixed;
  inset: auto 0 var(--inv-bottom-offset);
  z-index: 60;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  box-shadow: 0 -6px 24px rgba(16, 24, 40, 0.12);
}

.inv-action-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.inv-action-caption {
  color: var(--muted);
  font-size: 0.85rem;
}

.inv-action-total strong {
  min-width: 0;
  text-align: right;
  font-size: 1.125rem;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.inv-submit-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  min-width: 0;
}

.inv-submit-actions .btn {
  min-width: 0;
  min-height: 48px;
  padding: 12px 16px;
}

.inv-draft-action {
  flex: 1 1 100px;
}

.inv-primary-action {
  flex: 2 1 140px;
  font-weight: 700;
}

.inv-secondary-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-radius: 0 0 16px 16px;
}

.inv-secondary-actions .btn-danger {
  margin-left: auto;
}

.inv-num {
  text-align: right !important;
}

.inv-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (min-width: 600px) {
  .inv-form .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inv-client-controls {
    flex-direction: row;
    align-items: flex-end;
  }

  .inv-client-controls > .btn {
    flex: 0 0 auto;
  }

  .inv-quick-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .inv-ai-controls {
    flex-direction: row;
    align-items: flex-start;
  }

  .inv-ai-buttons {
    flex: 0 0 auto;
  }

  .inv-form .card-footer.sticky-actions.inv-action-bar {
    grid-template-columns: minmax(140px, 1fr) minmax(280px, 1.4fr);
    align-items: center;
    gap: 20px;
  }

  .inv-action-total {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .inv-action-total strong {
    text-align: left;
  }
}

@media (min-width: 1100px) {
  .inv-form {
    --inv-action-height: 0px;
    padding-bottom: 24px;
  }

  .inv-layout {
    grid-template-columns: minmax(0, 1fr) 350px;
    gap: 24px;
  }

  .inv-summary-card {
    position: sticky;
    top: 84px;
  }

  .inv-side .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .inv-side .inv-document-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inv-card .card-header,
  .inv-card .card-body {
    padding: 20px;
  }

  .inv-form .card-footer.sticky-actions.inv-action-bar {
    position: static;
    inset: auto;
    display: block;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    box-shadow: none;
    background: var(--surface-2, var(--surface));
  }

  .inv-action-total {
    display: none;
  }

  .inv-submit-actions {
    gap: 8px;
  }

  .inv-secondary-actions {
    padding-inline: 20px !important;
  }

  .inv-add-item {
    width: auto;
    min-width: 220px;
  }

  .inv-chip-caption {
    width: auto;
  }
}

@media (min-width: 1280px) {
  .inv-items-wrap {
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .inv-items-card .items-table {
    display: table;
    min-width: 760px;
    table-layout: auto;
    border-collapse: separate;
    border-spacing: 0 8px;
  }

  .inv-items-card .items-table thead {
    display: table-header-group;
  }

  .inv-items-card .items-table tbody {
    display: table-row-group;
  }

  .inv-items-card .items-table th {
    padding: 6px;
    font-size: 0.72rem;
    line-height: 1.4;
  }

  .inv-items-card .items-table tr.item-row {
    display: table-row;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .inv-items-card .items-table tr.item-row td,
  .inv-items-card .items-table tr.item-row td.it-qty,
  .inv-items-card .items-table tr.item-row td.it-unit,
  .inv-items-card .items-table tr.item-row td.it-price,
  .inv-items-card .items-table tr.item-row td.it-disc,
  .inv-items-card .items-table tr.item-row td.it-vat,
  .inv-items-card .items-table tr.item-row td.col-total,
  .inv-items-card .items-table tr.item-row td:last-child {
    display: table-cell;
    position: static;
    width: auto;
    padding: 4px;
    margin: 0;
    border: 0;
    vertical-align: middle;
  }

  .inv-items-card .items-table tr.item-row td[data-label]::before {
    display: none;
  }

  .inv-items-card .items-table tr.item-row td:first-child {
    min-width: 170px;
    padding-right: 4px;
  }

  .inv-items-card .items-table .col-num,
  .inv-items-card .items-table .col-unit,
  .inv-items-card .items-table .col-vat {
    width: 80px;
  }

  .inv-items-card .items-table tr.item-row td.col-total {
    min-width: 96px;
    font-size: 0.95rem;
    white-space: nowrap;
    text-align: right;
  }

  .inv-items-card .items-table tr.item-row td:last-child {
    width: 56px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .inv-chevron {
    transition: none;
  }

  .inv-form .btn:hover {
    transform: none;
  }
}

/* Invoice form FINAL redesign (gpt-6.1-sol, high effort) */
/*
 * Append this COMPLETE block at the END of app.css, after existing invoice
 * rules and media queries. Do not replace shared design-system rules.
 *
 * These scoped overrides supersede the previous .inv-* presentation rules,
 * .items-table mobile/table layouts, .summary-card positioning and
 * .card-footer.sticky-actions positioning only within .inv-form.
 *
 * Optional shell contract:
 * --inv-shell-bottom: actual occupied bottom-navigation height.
 * Without it, the view detects conventional fixed bottom navigation.
 */

.inv-form {
  --inv-accent: #2459cf;
  --inv-accent-hover: #1d48ae;
  --inv-on-accent: #fff;
  --inv-focus: #507ee8;
  --inv-action-height: 150px;
  --inv-bottom-offset: 0px;
  --inv-action-left: 0px;
  --inv-action-width: 100%;
  --inv-safe-bottom: env(safe-area-inset-bottom, 0px);
  color: var(--text, #172033);
  padding-bottom: calc(var(--inv-action-height) + var(--inv-bottom-offset) + 24px);
}

.inv-form,
.inv-form *,
.inv-page-head,
.inv-page-head * {
  box-sizing: border-box;
}

.inv-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 20px;
}

.inv-page-title {
  min-width: 0;
}

.inv-page-head h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  margin: 0;
  font-size: clamp(1.35rem, 2.5vw, 1.8rem);
  line-height: 1.25;
  color: var(--text, #172033);
}

.inv-document-number {
  font-size: 0.75em;
  font-weight: 500;
  color: var(--muted, #536174);
  overflow-wrap: anywhere;
}

.inv-page-head .dirty-indicator {
  display: none;
  margin: 7px 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted, #536174);
}

.inv-page-head .dirty-indicator.show {
  display: inline-block;
}

.inv-page-head .btn,
.inv-form .btn,
.inv-form .btn-remove {
  min-height: 48px;
  min-width: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.inv-page-head .btn,
.inv-form .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 15px;
  border-radius: 10px;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.25;
  font-weight: 650;
  text-align: center;
  white-space: normal;
  text-decoration: none;
}

.inv-page-head > .btn {
  flex: 0 0 auto;
}

.inv-form .btn-primary {
  color: var(--inv-on-accent);
  background: var(--inv-accent);
  border: 1px solid var(--inv-accent);
}

.inv-form .btn-outline {
  color: var(--text, #172033);
  background: var(--surface, #fff);
  border: 1px solid var(--border, #d5dae3);
}

.inv-form .btn-ghost {
  color: var(--text, #172033);
}

.inv-form :where(input, select, textarea, button, a, summary, [tabindex]):focus-visible,
.inv-page-head a:focus-visible {
  outline: 3px solid var(--inv-focus, #507ee8);
  outline-offset: 3px;
}

.inv-form :where(input, select, textarea) {
  min-width: 0;
  max-width: 100%;
  color: var(--text, #172033);
  background: var(--surface, #fff);
  border: 1px solid var(--border, #d5dae3);
  border-radius: 9px;
  font: inherit;
  font-size: 16px; /* Prevents iPhone focus zoom. */
  line-height: 1.35;
}

.inv-form input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
.inv-form select {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 11px;
}

.inv-form input[type="date"] {
  min-width: 0;
  text-align: left;
}

.inv-form input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
}

.inv-form select {
  padding-right: 30px;
}

.inv-form textarea {
  display: block;
  width: 100%;
  min-height: 104px;
  padding: 11px;
  resize: vertical;
}

.inv-form :where(input, textarea)::placeholder {
  color: var(--muted, #536174);
  opacity: 1;
}

.inv-form :where(input, select, textarea):focus {
  border-color: var(--inv-focus);
}

.inv-form :where(input, select, textarea):disabled,
.inv-form .btn:disabled,
.inv-form .btn-remove:disabled {
  color: var(--muted, #536174);
  -webkit-text-fill-color: var(--muted, #536174);
  background: var(--surface-2, #f4f6fa);
  border-color: var(--border, #d5dae3);
  opacity: 1;
  cursor: not-allowed;
  box-shadow: none;
}

.inv-form :where(input, textarea):-webkit-autofill,
.inv-form :where(input, textarea):-webkit-autofill:hover,
.inv-form :where(input, textarea):-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text, #172033);
  -webkit-box-shadow: 0 0 0 1000px var(--surface, #fff) inset;
  caret-color: var(--text, #172033);
}

.inv-form :where(input, textarea):autofill {
  color: var(--text, #172033);
  background: var(--surface, #fff);
}

.inv-form :where(input, select, textarea):user-invalid {
  border-color: var(--danger, #b42318);
}

.inv-form :where(input, select, textarea, button, a, summary),
.inv-form .item-row {
  scroll-margin-block: 100px calc(var(--inv-action-height) + var(--inv-bottom-offset) + 24px);
}

.inv-form .field {
  min-width: 0;
  margin: 0 0 16px;
}

.inv-form .field > label {
  display: block;
  margin: 0 0 6px;
  color: var(--text, #172033);
  font-size: 0.85rem;
  line-height: 1.4;
  font-weight: 600;
}

.inv-form .form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0 16px;
}

.inv-form .form-grid .span-2 {
  grid-column: 1 / -1;
}

.inv-form .inv-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "main" "side" "terms";
  align-items: start;
  gap: 16px;
}

.inv-form .inv-main {
  grid-area: main;
  display: grid;
  gap: 16px;
  min-width: 0;
}

.inv-form .inv-side {
  grid-area: side;
  display: block;
  min-width: 0;
}

.inv-form .inv-terms-card {
  grid-area: terms;
}

.inv-form .inv-card {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--border, #d5dae3);
  border-radius: 14px;
  background: var(--surface, #fff);
  box-shadow: none;
}

.inv-form .inv-card > .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 64px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, #d5dae3);
  background: transparent;
}

.inv-form .inv-card .card-header h3,
.inv-form .inv-summary h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.35;
  font-weight: 700;
  color: var(--text, #172033);
}

.inv-form .inv-card > .card-body {
  padding: 16px;
}

.inv-form .inv-summary-card {
  position: static;
  top: auto;
}

.inv-form .inv-help,
.inv-form .inv-status,
.inv-form .inv-issued-note,
.inv-form .inv-freq-hint,
.inv-form .inv-price-hint {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--muted, #536174);
  overflow-wrap: anywhere;
}

.inv-form .inv-help {
  display: block;
  margin: 6px 0 16px;
}

.inv-form .inv-status:empty {
  display: none;
}

.inv-form .inv-status {
  margin: 12px 0;
}

.inv-form .inv-issued-note {
  margin: 16px 0 0;
}

.inv-form .inv-freq-hint {
  margin: 0 0 6px;
}

.inv-form .inv-price-hint {
  margin: 0 0 16px;
}

.inv-form .inv-client-card {
  overflow: visible;
}

.inv-form .client-search {
  position: relative;
  z-index: 5;
}

.inv-form .inv-client-card .client-results {
  position: absolute;
  inset: calc(100% + 6px) 0 auto;
  z-index: 60;
  max-height: min(320px, 45vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--text, #172033);
  background: var(--surface, #fff);
  border: 1px solid var(--border, #d5dae3);
  border-radius: 10px;
  box-shadow: 0 10px 26px rgb(0 0 0 / 16%);
}

.inv-form .inv-client-card .client-results > *,
.inv-form .inv-client-card .client-results :where(button, a) {
  min-height: 48px;
}

.inv-form .inv-client-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.inv-form .inv-client-select {
  flex: 1 1 240px;
  margin-bottom: 0;
}

.inv-form .inv-client-controls > .btn {
  flex: 1 1 180px;
}

.inv-form .inv-new-client {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--border, #d5dae3);
  border-radius: 12px;
  background: var(--surface-2, #f4f6fa);
}

.inv-form .inv-new-client-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.inv-form .inv-new-client-head h4 {
  margin: 0;
  font-size: 0.95rem;
}

.inv-form .inv-new-client-head .btn {
  flex: 0 0 48px;
  padding: 0;
}

.inv-form .inv-quick-actions,
.inv-form .inv-ai-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.inv-form .inv-quick-actions .btn,
.inv-form .inv-ai-buttons .btn {
  flex: 1 1 180px;
}

.inv-form .inv-details {
  min-width: 0;
}

.inv-form .inv-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  list-style: none;
  cursor: pointer;
  color: var(--text, #172033);
  font-size: 0.9rem;
  line-height: 1.4;
  font-weight: 600;
}

.inv-form .inv-summary::-webkit-details-marker {
  display: none;
}

.inv-form .inv-summary::marker {
  content: "";
}

.inv-form .inv-details:not([open]) > .card-header {
  border-bottom-color: transparent;
}

.inv-form .inv-chevron {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  margin-right: 3px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 160ms ease;
}

.inv-form .inv-details[open] > .inv-summary .inv-chevron {
  transform: rotate(225deg) translate(-1px, -1px);
}

.inv-form .inv-assist,
.inv-form .inv-advanced {
  margin-top: 16px;
  border-top: 1px solid var(--border, #d5dae3);
}

.inv-form .inv-assist > .inv-summary,
.inv-form .inv-advanced > .inv-summary {
  padding: 12px 0;
}

.inv-form .inv-disclosure-body {
  padding: 4px 0 0;
}

.inv-form .inv-disclosure-body > .field:last-child {
  margin-bottom: 4px;
}

.inv-form .inv-preview-wrap {
  max-width: 100%;
  margin: 12px 0;
  overflow-x: auto;
}

.inv-form .inv-preview-wrap .table {
  min-width: 500px;
}

.inv-form .inv-preview-wrap .num {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.inv-form #aiCmdChips {
  margin-top: 12px;
}

.inv-form #aiCmdChips .item-chip {
  cursor: default;
  border-style: solid;
  color: var(--text, #172033);
  background: var(--surface-2, #f4f6fa);
}

/* Cards at every viewport: no cramped desktop table in the two-column form. */
.inv-form .inv-items-wrap {
  position: relative;
  overflow: visible;
  margin-top: 16px;
}

.inv-form .inv-items-card .items-table,
.inv-form .inv-items-card .items-table tbody {
  display: block;
  width: 100%;
  border-collapse: separate;
}

.inv-form .inv-items-card .items-table thead {
  display: block;
}

.inv-form .inv-items-card .items-table tr.item-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: end;
  gap: 12px 10px;
  width: 100%;
  margin: 0 0 12px;
  padding: 14px;
  color: var(--text, #172033);
  background: var(--surface, #fff);
  border: 1px solid var(--border, #d5dae3);
  border-radius: 12px;
  transition: border-color 160ms ease;
}

.inv-form .inv-items-card .items-table tr.item-row:focus-within {
  border-color: var(--inv-focus);
}

.inv-form .inv-items-card .items-table tr.item-row td,
.inv-form .inv-items-card .items-table tr.item-row td.it-qty,
.inv-form .inv-items-card .items-table tr.item-row td.it-unit,
.inv-form .inv-items-card .items-table tr.item-row td.it-price,
.inv-form .inv-items-card .items-table tr.item-row td.it-disc,
.inv-form .inv-items-card .items-table tr.item-row td.it-vat {
  display: block;
  position: static;
  width: auto;
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
  vertical-align: initial;
}

.inv-form .inv-items-card .items-table tr.item-row td[data-label]::before {
  content: none;
  display: none;
}

.inv-form .inv-items-card .items-table tr.item-row td:first-child {
  grid-column: 1 / -1;
  padding-right: 48px;
}

.inv-form .inv-items-card .items-table tr.item-row td.it-qty,
.inv-form .inv-items-card .items-table tr.item-row td.it-unit {
  grid-column: span 3;
}

.inv-form .inv-items-card .items-table tr.item-row td.it-price,
.inv-form .inv-items-card .items-table tr.item-row td.it-disc,
.inv-form .inv-items-card .items-table tr.item-row td.it-vat {
  grid-column: span 2;
}

.inv-form .inv-items-card .inv-row-label {
  display: block;
  position: static;
  width: auto;
  height: auto;
  margin: 0 0 6px;
  padding: 0;
  overflow: visible;
  clip: auto;
  clip-path: none;
  white-space: normal;
  font-size: 0.76rem;
  line-height: 1.3;
  font-weight: 600;
  color: var(--text, #172033);
}

.inv-form .inv-items-card .items-table :where(input, select),
.inv-form .inv-items-card .items-table .col-num,
.inv-form .inv-items-card .items-table .col-unit,
.inv-form .inv-items-card .items-table .col-vat {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 10px 9px;
}

.inv-form .inv-items-card .items-table :where(.item-qty, .item-price, .item-disc, .item-vat) {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.inv-form .inv-items-card .items-table tr.item-row td.col-total {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: auto;
  margin: 2px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--border, #d5dae3);
  color: var(--text, #172033);
  text-align: right;
  font-size: 1rem;
  line-height: 1.3;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.inv-form .inv-items-card .items-table tr.item-row td.col-total::before {
  content: attr(data-label);
  display: block;
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  color: var(--muted, #536174);
  text-align: left;
}

.inv-form .inv-items-card .items-table tr.item-row td:last-child {
  position: absolute;
  inset: 6px 6px auto auto;
  width: 48px;
  margin: 0;
}

.inv-form .inv-items-card .items-table .btn-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  color: var(--danger, #b42318);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}

.inv-form .inv-items-card .items-table .btn-remove:disabled {
  background: transparent;
  border-color: transparent;
}

.inv-form .inv-items-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.inv-form .inv-add-item {
  flex: 1 1 100%;
  width: 100%;
}

.inv-form .inv-item-hint {
  display: none;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted, #536174);
}

.inv-form .inv-tax-notice {
  margin-bottom: 16px;
}

.inv-form .inv-totals {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid var(--border, #d5dae3);
  border-radius: 12px;
  background: var(--surface-2, #f4f6fa);
}

.inv-form .inv-totals .totals-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  padding: 5px 0;
  color: var(--text, #172033);
  font-size: 0.9rem;
  line-height: 1.5;
}

.inv-form .inv-totals .totals-row > :last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.inv-form .inv-totals .totals-row.grand {
  margin-top: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border, #d5dae3);
  color: var(--text, #172033);
  font-size: 1.05rem;
  font-weight: 750;
}

.inv-form .inv-total-value {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 3px 6px;
}

.inv-form .inv-currency {
  font-size: 0.75em;
  font-weight: 600;
  white-space: nowrap;
}

.inv-form .inv-delivery {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border, #d5dae3);
}

.inv-form .inv-check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 48px;
  padding: 10px 0;
  margin-bottom: 8px;
  color: var(--text, #172033);
  font-size: 0.9rem;
  line-height: 1.5;
  cursor: pointer;
}

.inv-form .inv-check input[type="checkbox"] {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  min-height: 22px;
  margin: 0;
  accent-color: var(--inv-accent);
}

.inv-form .inv-delivery .field:last-child {
  margin-bottom: 0;
}

.inv-form .inv-alerts-card {
  margin-bottom: 16px;
  border-left: 4px solid var(--danger, #b42318);
}

.inv-form .form-alert {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border, #d5dae3);
  border-radius: 10px;
  background: var(--surface-2, #f4f6fa);
  color: var(--text, #172033);
  font-size: 0.85rem;
  line-height: 1.5;
}

.inv-form .form-alert + .form-alert {
  margin-top: 10px;
}

.inv-form .form-alert > span:nth-child(2) {
  flex: 1 1 180px;
}

.inv-form .form-alert.error {
  border-left: 4px solid var(--danger, #b42318);
}

.inv-form .form-alert.warning {
  border-left: 4px solid var(--warning, #b7791f);
}

.inv-form .form-alert.info {
  border-left: 4px solid var(--inv-focus);
}

.inv-form .form-alert .fa-actions {
  flex: 1 1 100%;
}

.inv-form .form-alert .fa-actions .btn {
  width: 100%;
}

.inv-form .inv-secondary-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.inv-form .inv-secondary-actions .btn-danger {
  margin-left: auto;
}

/* Explicitly override the shared sticky footer. */
.inv-form .card-footer.sticky-actions.inv-action-bar {
  position: fixed;
  inset: auto auto var(--inv-bottom-offset) var(--inv-action-left);
  z-index: 40;
  display: block;
  width: var(--inv-action-width);
  max-width: 100%;
  margin: 0;
  padding: 12px max(16px, env(safe-area-inset-right, 0px))
    calc(12px + var(--inv-safe-bottom))
    max(16px, env(safe-area-inset-left, 0px));
  border: 0;
  border-top: 1px solid var(--border, #d5dae3);
  border-radius: 0;
  background: var(--surface, #fff);
  color: var(--text, #172033);
  box-shadow: 0 -8px 24px rgb(0 0 0 / 9%);
}

.inv-form .inv-action-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

.inv-form .inv-action-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.inv-form .inv-action-caption {
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--muted, #536174);
}

.inv-form .inv-action-total strong {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  font-size: 1.25rem;
  line-height: 1.2;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.inv-form .inv-submit-actions {
  display: flex;
  gap: 10px;
  min-width: 0;
}

.inv-form .inv-submit-actions .btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  margin: 0;
}

.inv-form .inv-submit-actions .inv-primary-action {
  flex-grow: 1.15;
}

.inv-form .inv-issue-help {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--text, #172033);
  font-size: 0.76rem;
  line-height: 1.4;
}

.inv-form .inv-issue-help[hidden],
.inv-form #aiCmdPreview[hidden] {
  display: none;
}

.inv-form.inv-submitting .inv-submit-actions .btn {
  pointer-events: none;
  cursor: progress;
}

.inv-form.inv-submitting .inv-primary-action {
  background: var(--inv-accent-hover);
}

.inv-form .inv-items-card .items-table tr.item-row.row-new {
  animation: inv-row-in 650ms ease-out both;
}

@keyframes inv-row-in {
  from {
    opacity: 0.45;
    transform: translateY(8px);
    border-color: var(--inv-focus);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    border-color: var(--border, #d5dae3);
  }
}

.inv-sr-only,
.inv-form .inv-sr-only,
.inv-form .items-table thead.inv-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (hover: hover) {
  .inv-form .btn-primary:hover:not(:disabled) {
    color: var(--inv-on-accent);
    background: var(--inv-accent-hover);
    border-color: var(--inv-accent-hover);
  }

  .inv-form .btn-outline:hover:not(:disabled),
  .inv-form .btn-ghost:hover:not(:disabled),
  .inv-page-head .btn:hover {
    color: var(--text, #172033);
    background: var(--surface-2, #f4f6fa);
    border-color: var(--muted, #536174);
  }

  .inv-form .inv-items-card .items-table .btn-remove:hover:not(:disabled) {
    background: var(--surface-2, #f4f6fa);
    border-color: var(--danger, #b42318);
  }

  .inv-form .inv-summary:hover {
    color: var(--text, #172033);
    background: var(--surface-2, #f4f6fa);
  }
}

@media (max-width: 359px) {
  .inv-page-head {
    gap: 8px;
  }

  .inv-page-head > .btn {
    padding-inline: 10px;
  }

  .inv-form .inv-items-card .items-table tr.item-row td.it-price {
    grid-column: 1 / -1;
  }

  .inv-form .inv-items-card .items-table tr.item-row td.it-disc,
  .inv-form .inv-items-card .items-table tr.item-row td.it-vat {
    grid-column: span 3;
  }

  .inv-form .inv-submit-actions .btn {
    padding-inline: 8px;
    font-size: 0.84rem;
  }
}

@media (min-width: 600px) {
  .inv-form .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inv-form .inv-client-controls {
    flex-wrap: nowrap;
  }

  .inv-form .inv-client-controls > .btn {
    flex: 0 0 auto;
  }

  .inv-form .inv-items-card .items-table tr.item-row {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 12px;
  }

  .inv-form .inv-items-card .items-table tr.item-row td.it-qty,
  .inv-form .inv-items-card .items-table tr.item-row td.it-unit,
  .inv-form .inv-items-card .items-table tr.item-row td.it-disc,
  .inv-form .inv-items-card .items-table tr.item-row td.it-vat {
    grid-column: span 2;
  }

  .inv-form .inv-items-card .items-table tr.item-row td.it-price {
    grid-column: span 4;
  }

  .inv-form .inv-add-item {
    flex: 0 0 auto;
    width: auto;
  }

  .inv-form .inv-item-hint {
    display: inline;
  }

  .inv-form .inv-action-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px 24px;
  }

  .inv-form .inv-action-total {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .inv-form .inv-action-total strong {
    justify-content: flex-start;
  }

  .inv-form .inv-submit-actions {
    min-width: 320px;
  }

  .inv-form .form-alert .fa-actions {
    flex: 0 0 auto;
  }
}

@media (min-width: 760px) and (max-width: 1099px) {
  .inv-form .inv-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: "main main" "side terms";
  }

  .inv-form .inv-terms-card .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (min-width: 1100px) {
  .inv-form .inv-layout {
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-areas: "main side" "terms side";
    gap: 20px;
  }

  .inv-form .inv-side {
    align-self: stretch;
  }

  .inv-form .inv-summary-card {
    position: sticky;
    top: var(--inv-summary-top, 84px);
  }

  .inv-form .inv-card > .card-header,
  .inv-form .inv-card > .card-body {
    padding-inline: 20px;
  }

  .inv-form .card-footer.sticky-actions.inv-action-bar {
    border: 1px solid var(--border, #d5dae3);
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .inv-form .inv-chevron,
  .inv-form .inv-items-card .items-table tr.item-row {
    transition: none;
  }

  .inv-form .inv-items-card .items-table tr.item-row.row-new {
    animation: none;
  }
}

@media (forced-colors: active) {
  .inv-form .btn,
  .inv-form .inv-items-card .items-table .btn-remove {
    border: 1px solid ButtonText;
  }

  .inv-form :where(input, select, textarea, button, a, summary):focus-visible {
    outline-color: Highlight;
  }
}

@media print {
  .inv-page-head > .btn,
  .inv-form .inv-action-bar,
  .inv-form .inv-secondary-actions,
  .inv-form .inv-assist,
  .inv-form #scanBtn,
  .inv-form .inv-items-footer,
  .inv-form .btn-remove {
    display: none !important;
  }

  .inv-form {
    padding-bottom: 0;
  }

  .inv-form .inv-summary-card {
    position: static;
  }
}

/* Onboarding wizard (gpt-6.1-sol) */
/* Scoped additions; reuse the existing .card/.btn/.field design system. */
.wiz-shell {
  --wiz-text: var(--text-color, #eef2f8);
  --wiz-muted: var(--muted-color, #aab5c7);
  --wiz-border: var(--border-color, #39465b);
  --wiz-surface: var(--surface-color, #182231);
  --wiz-accent: var(--accent-color, #9dbaff);
  --wiz-danger: var(--danger-color, #ffadb6);

  width: min(100%, 54rem);
  margin-inline: auto;
  padding: 1rem;
  color: var(--wiz-text);
  color-scheme: dark;
}

.wiz-shell *,
.wiz-shell *::before,
.wiz-shell *::after {
  box-sizing: border-box;
}

.wiz-shell [hidden] {
  display: none !important;
}

.wiz-header {
  margin-bottom: 1.25rem;
}

.wiz-header h1 {
  margin-block: .75rem .5rem;
  font-size: clamp(1.6rem, 5vw, 2.25rem);
  line-height: 1.2;
}

.wiz-muted {
  color: var(--wiz-muted);
  line-height: 1.55;
}

.wiz-card {
  padding: 1rem;
  overflow-wrap: anywhere;
}

.wiz-progress {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
}

.wiz-progress-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem;
  border: 1px solid var(--wiz-border);
  border-radius: .7rem;
  color: var(--wiz-muted);
  min-width: 0;
  font-size: .9rem;
}

.wiz-progress-item.is-current {
  color: var(--wiz-text);
  border-color: var(--wiz-accent);
  box-shadow: inset 0 0 0 1px var(--wiz-accent);
  font-weight: 700;
}

.wiz-step-number {
  display: inline-grid;
  place-items: center;
  flex: 0 0 1.8rem;
  height: 1.8rem;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.wiz-panel {
  padding-block: .25rem 1rem;
}

.wiz-panel + .wiz-panel {
  border-top: 1px solid var(--wiz-border);
  padding-top: 1.5rem;
}

.wiz-enhanced .wiz-panel {
  border-top: 0;
  padding-top: .25rem;
}

.wiz-panel h2 {
  margin-block: 0 .6rem;
  font-size: 1.3rem;
}

.wiz-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

.wiz-card .field {
  min-width: 0;
  margin-bottom: 1rem;
}

.wiz-card .field label {
  display: block;
  margin-bottom: .4rem;
  font-weight: 600;
}

.wiz-card input:not([type="checkbox"]):not([type="hidden"]),
.wiz-card textarea,
.wiz-card select {
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  padding: .7rem .8rem;
  font: inherit;
  color: var(--wiz-text);
  background: var(--wiz-surface);
  border: 1px solid var(--wiz-border);
  border-radius: .5rem;
}

.wiz-card textarea {
  resize: vertical;
}

.wiz-card .field small {
  display: block;
  margin-top: .4rem;
}

.wiz-card [aria-invalid="true"] {
  border-color: var(--wiz-danger) !important;
}

.wiz-card :is(input, textarea, select, button, a):focus-visible,
.wiz-panel h2:focus,
.wiz-error-summary:focus {
  outline: 3px solid var(--wiz-accent);
  outline-offset: 3px;
}

.wiz-inline {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: .65rem;
}

.wiz-check {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-block: .75rem;
}

.wiz-check input[type="checkbox"] {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--wiz-accent);
}

.wiz-check label {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  cursor: pointer;
}

.wiz-method {
  min-width: 0;
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid var(--wiz-border);
  border-radius: .75rem;
}

.wiz-method legend {
  padding-inline: .4rem;
  font-weight: 700;
}

.wiz-method-list {
  display: grid;
  gap: .75rem;
}

.wiz-provider + .wiz-provider {
  border-top: 1px solid var(--wiz-border);
  padding-top: .5rem;
}

.wiz-provider-details {
  padding-top: .25rem;
}

.wiz-status {
  min-height: 1.5em;
  margin-block: .65rem;
  font-size: .95rem;
}

.wiz-field-error,
.wiz-error-summary,
.wiz-error-summary a {
  color: var(--wiz-danger);
}

.wiz-error-summary {
  margin-block: 1rem;
  padding: 1rem;
  border: 1px solid var(--wiz-danger);
  border-radius: .6rem;
}

.wiz-summary-title {
  margin: 0 0 .5rem;
  font-size: 1rem;
}

.wiz-error-summary ul {
  margin-bottom: 0;
  padding-left: 1.2rem;
}

.wiz-error-summary li + li {
  margin-top: .4rem;
}

.wiz-notice {
  margin-bottom: 1rem;
}

.wiz-review {
  margin-block: 1.25rem;
}

.wiz-review > div {
  padding-block: .85rem;
  border-bottom: 1px solid var(--wiz-border);
}

.wiz-review dt {
  color: var(--wiz-muted);
  margin-bottom: .35rem;
}

.wiz-review dd {
  margin: 0;
  white-space: pre-wrap;
}

.wiz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  padding-top: 1rem;
  border-top: 1px solid var(--wiz-border);
}

.wiz-actions .btn,
.wiz-inline .btn {
  min-height: 2.75rem;
  white-space: normal;
}

.wiz-actions .btn {
  flex: 1 1 8rem;
}

.wiz-primary {
  font-weight: 700;
  border-color: var(--wiz-accent);
}

.wiz-footer-help {
  margin-bottom: 0;
  font-size: .9rem;
}

/* Progressive enhancement: without JS show all fields and one final submit. */
.wiz-js-only {
  display: none;
}

.wiz-enhanced .wiz-js-only {
  display: inline-flex;
}

.wiz-enhanced .wiz-review {
  display: block;
}

.wiz-card:not(.wiz-enhanced) .wiz-review {
  display: none;
}

@media (min-width: 40rem) {
  .wiz-shell {
    padding: 2rem 1rem;
  }

  .wiz-card {
    padding: 1.75rem;
  }

  .wiz-progress {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .wiz-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .wiz-inline {
    flex-direction: row;
    align-items: flex-start;
  }

  .wiz-inline input {
    flex: 1 1 auto;
  }

  .wiz-inline .btn {
    flex: 0 0 auto;
  }

  .wiz-actions .btn {
    flex: 0 1 auto;
  }

  .wiz-actions .wiz-primary {
    margin-inline-start: auto;
  }

  .wiz-review > div {
    display: grid;
    grid-template-columns: 12rem minmax(0, 1fr);
    gap: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wiz-shell *,
  .wiz-shell *::before,
  .wiz-shell *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
.cookie-preferences-link{text-align:center;padding:10px 16px 20px}.cookie-banner{position:fixed;z-index:900;left:16px;right:16px;bottom:18px;max-width:1040px;margin:auto;border:1px solid var(--border);border-radius:16px;background:var(--surface);color:var(--text);padding:22px;box-shadow:0 12px 48px #0003}.cookie-banner[hidden]{display:none}.cookie-banner h2,.cookie-dialog h2{font-size:1.15rem;margin:0 0 10px}.cookie-banner p,.cookie-dialog p{font-size:.87rem;line-height:1.6;margin-bottom:14px}.cookie-actions{display:flex;gap:10px;flex-wrap:wrap}.cookie-dialog{width:min(600px,calc(100% - 32px));max-height:calc(100dvh - 48px);border:1px solid var(--border);border-radius:16px;background:var(--surface);color:var(--text);padding:24px;overflow:auto}.cookie-dialog::backdrop{background:#0008}.registration-terms .check{align-items:flex-start;gap:10px}.registration-terms input{margin-top:5px;flex-shrink:0}.registration-terms small{display:block;margin-top:8px}@media(max-width:600px){.cookie-banner{bottom:76px;padding:16px;max-height:65dvh;overflow:auto}.cookie-actions .btn{white-space:normal;flex:1 1 150px}.cookie-preferences-link{padding-bottom:90px}}@media print{.cookie-banner,.cookie-dialog,.cookie-preferences-link{display:none!important}}
.topbar-preferences{display:flex;align-items:center;gap:10px}.topbar-more{display:none}.ux-pagination{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin:18px 0}.ux-pagination>div{display:flex;gap:8px}.ux-tabs{display:flex;gap:8px;flex-wrap:wrap;margin:16px 0}.ux-tabs .is-active{background:var(--primary);color:#fff}[data-ux-panel][hidden]{display:none!important}.ux-save-bar{position:sticky;bottom:16px;z-index:25;display:flex;justify-content:space-between;align-items:center;gap:12px;padding:12px 16px;background:var(--surface);border:1px solid var(--border);border-radius:12px;box-shadow:var(--shadow)}.ux-save-bar[hidden]{display:none}@media(max-width:767px){.topbar-more{display:inline-flex}.topbar-preferences{display:none;position:absolute;right:16px;top:62px;padding:12px;background:var(--surface);border:1px solid var(--border);border-radius:12px;box-shadow:var(--shadow-lg);z-index:500}.topbar-preferences.is-open{display:flex}.topbar-title{white-space:normal;font-size:15px;line-height:1.25;max-height:2.5em;overflow:hidden}.topbar-actions{gap:7px}.topbar .icon-btn{width:38px;min-width:38px}.ux-save-bar{bottom:76px}.invoice-detail .btn,.invoice-detail summary.btn{min-height:42px}.ux-tabs .btn{min-height:42px}}
.bulk-result{display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:14px;margin:10px 0;border:1px solid var(--border);border-radius:12px}.bulk-result strong{overflow-wrap:anywhere;flex:1 1 180px}.purchase-review-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.2fr);gap:20px;align-items:start}.purchase-original{position:sticky;top:80px;background:var(--surface);border:1px solid var(--border);border-radius:12px;padding:16px}.purchase-original img,.purchase-original iframe{width:100%;height:70dvh;object-fit:contain;border:0}.purchase-review-tabs{display:none}@media(max-width:767px){.purchase-review-grid{display:block}.purchase-review-tabs{display:flex;gap:10px;margin-bottom:14px}.purchase-review-grid[data-view="data"] .purchase-original{display:none}.purchase-review-grid[data-view="original"] #purchaseForm{display:none}.purchase-original{position:static}}
.reference-rate[hidden]{display:none!important}.all-reference-rates{margin-top:16px}.all-reference-rates>.field{margin-top:14px}

/* Keep the mobile app chrome compact and leave the legal footer scrollable above it. */
.topbar-title-mobile { display: none; }
@media (max-width: 760px) {
  .topbar { min-height: 64px; box-sizing: border-box; }
  .topbar-title { white-space: nowrap; max-height: none; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
  .topbar-title.has-mobile-title .topbar-title-full { display: none; }
  .topbar-title-mobile { display: inline; }
  .bottom-nav {
    min-height: calc(70px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    align-items: start;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav a, .bottom-nav button {
    min-width: 0;
    min-height: 58px;
    justify-content: center;
    gap: 4px;
    padding: 4px 2px;
    font-size: 10px;
    line-height: 1.1;
  }
  .bottom-nav > a > span:last-child, .bottom-nav > button > span:last-child {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .bottom-nav .fab { margin-top: 0; }
  .bottom-nav .fab .fab-circle {
    width: 27px;
    height: 27px;
    border-radius: 9px;
    box-shadow: none;
  }
  .bottom-nav .fab .fab-circle svg { width: 19px; height: 19px; }
  .content { padding-bottom: 24px; }
}
@media (max-width: 360px) {
  .topbar .user-chip { display: none; }
}

/* One footer and one reserve for the fixed navigation. */
html { scroll-padding-top: 84px; }
.app-shell { min-height: 100dvh; }
.app-footer { margin-top: auto; padding: 22px 24px 26px; text-align: center; border-top: 1px solid var(--border); }
.app-footer .app-legal { padding: 0; font-size: .75rem; line-height: 1.65; }
.app-footer .app-legal p { margin: 0 0 8px; }
.app-footer .app-legal nav { display: flex; justify-content: center; gap: 6px 16px; flex-wrap: wrap; }
.app-footer > button { margin-top: 10px; min-height: 40px; color: var(--muted); }
.content:has(.inv-form) + .app-footer { padding-bottom: 100px; }
@media (max-width: 760px) {
  .app-shell { min-height: 0; }
  .app-footer { margin-top: 8px; padding: 18px 20px calc(90px + env(safe-area-inset-bottom, 0px)); }
  .app-footer .app-legal { font-size: .73rem; }
  .content:has(.inv-form) + .app-footer { padding-bottom: calc(160px + env(safe-area-inset-bottom, 0px)); }
  .content .card-footer.sticky-actions:not(.inv-action-bar) { position: static; box-shadow: none; }
  .inv-form { padding-bottom: 24px; }
}
@media print { .app-footer { display: none; } }
