/* ==========================================================================
   polish.css  -  visual refinement layer
   Loaded AFTER dashboard.css. Presentation only: no markup, script or
   behaviour is changed by this file. Same brand colours, same layout
   structure; this unifies spacing, alignment, controls and tables.
   ========================================================================== */

/* ---------- 1. Tokens ------------------------------------------------------ */
:root {
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --ink-2: #475569;
    --ink-3: #64748b;
    --bg-subtle: #f8fafc;
    --radius: 10px;
    --radius-sm: 8px;
    --control-h: 40px;
    --control-h-sm: 34px;
    --ring: 0 0 0 3px rgba(37, 99, 235, 0.18);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 18px rgba(15, 23, 42, 0.05);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

/* ---------- 2. Base -------------------------------------------------------- */
html { -webkit-text-size-adjust: 100%; }

body {
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* scripts toggle [hidden]; component display rules must never defeat it */
[hidden] { display: none !important; }

h1, h2, h3, h4 { color: var(--text); letter-spacing: -0.01em; }

/* Site.css caps every input at 280px, which breaks grid alignment */
input, select, textarea { max-width: none; }

::placeholder { color: #94a3b8; opacity: 1; }

/* ---------- 3. Form controls (one system for every form) ------------------- */
.filter-field.filter-field input:not([type="checkbox"]):not([type="radio"]),
.filter-field.filter-field select,
.settings-field.settings-field input:not([type="checkbox"]):not([type="radio"]),
.settings-field.settings-field select,
.form-field.form-field input:not([type="checkbox"]):not([type="radio"]),
.form-field.form-field select,
.form-field.form-field textarea,
.purchase-capture-actions.purchase-capture-actions input,
.purchase-mapping-dialog.purchase-mapping-dialog input:not([type="checkbox"]):not([type="radio"]),
.purchase-mapping-dialog.purchase-mapping-dialog select,
.purchase-mapping-dialog.purchase-mapping-dialog textarea,
.user-details-panel.user-details-panel .form-field input:not([type="checkbox"]),
.login-form.login-form input {
    width: 100%;
    max-width: none;
    height: var(--control-h);
    min-height: var(--control-h);
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background-color: #ffffff;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    box-shadow: var(--shadow-sm);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.form-field.form-field textarea,
.purchase-mapping-dialog.purchase-mapping-dialog textarea {
    height: auto;
    min-height: 84px;
    padding: 10px 12px;
    resize: vertical;
}

/* custom chevron so every select looks identical across browsers */
.filter-field.filter-field select,
.settings-field.settings-field select,
.form-field.form-field select,
.purchase-mapping-dialog.purchase-mapping-dialog select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 34px;
    background-image: var(--chevron);
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
}

.filter-field.filter-field input:hover,
.filter-field.filter-field select:hover,
.settings-field.settings-field input:hover,
.settings-field.settings-field select:hover,
.form-field.form-field input:hover,
.form-field.form-field select:hover,
.form-field.form-field textarea:hover {
    border-color: #94a3b8;
}

.filter-field.filter-field input:focus,
.filter-field.filter-field select:focus,
.settings-field.settings-field input:focus,
.settings-field.settings-field select:focus,
.form-field.form-field input:focus,
.form-field.form-field select:focus,
.form-field.form-field textarea:focus,
.purchase-capture-actions.purchase-capture-actions input:focus,
.purchase-mapping-dialog.purchase-mapping-dialog input:focus,
.purchase-mapping-dialog.purchase-mapping-dialog select:focus,
.purchase-mapping-dialog.purchase-mapping-dialog textarea:focus,
.login-form.login-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}

.filter-field.filter-field input[readonly]:not([type="checkbox"]),
.settings-field.settings-field input[readonly]:not([type="checkbox"]),
.form-field.form-field input[readonly]:not([type="checkbox"]),
.purchase-mapping-dialog.purchase-mapping-dialog input[readonly] {
    background-color: var(--bg-subtle);
    color: var(--ink-3);
    box-shadow: none;
    cursor: default;
}

input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: .6; }

/* labels: sentence-case, quiet, consistent */
.filter-field label,
.settings-field label,
.form-field label,
.purchase-mapping-dialog .form-field label,
.user-details-panel .form-field label,
.purchase-capture-actions label {
    margin: 0;
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
}

.filter-field, .settings-field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.form-field { min-width: 0; }

/* checkboxes / radios */
input[type="checkbox"], input[type="radio"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
    vertical-align: middle;
}

.form-field input[type="checkbox"] { align-self: flex-start; width: 18px; height: 18px; margin-top: 4px; }
.role-checks label { font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer; }

/* validation */
.field-validation-error, .text-danger { display: block; margin-top: 2px; color: #b91c1c; font-size: 13px; font-weight: 500; }
input.input-validation-error { border-color: #dc2626; }

/* ---------- 4. Buttons ------------------------------------------------------ */
.primary-action,
.settings-save-button,
.secondary-action,
.icon-button,
.grid-action-button {
    font-family: inherit;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.primary-action,
.settings-save-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--control-h);
    padding: 0 20px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #ffffff;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}

.primary-action:hover,
.settings-save-button:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; text-decoration: none; }

.primary-action:focus,
.settings-save-button:focus,
.secondary-action:focus,
.icon-button:focus,
.grid-action-button:focus,
.page-link:focus,
.logout-button:focus { outline: none; box-shadow: var(--ring); }

.primary-action:active, .settings-save-button:active { transform: translateY(1px); }
.primary-action:disabled, .secondary-action:disabled, .icon-button:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.secondary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--control-h);
    padding: 0 16px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: var(--ink-2);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
}

.secondary-action:hover { background: var(--bg-subtle); border-color: #94a3b8; color: var(--text); text-decoration: none; }
.secondary-action:disabled:hover { background: #fff; border-color: var(--line-strong); color: var(--ink-2); }

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: var(--control-h);
    height: var(--control-h);
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: var(--ink-2);
    font-size: 19px;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}
.icon-button:hover { background: var(--bg-subtle); color: var(--text); border-color: #94a3b8; }

.settings-save-button { padding: 0 28px; }
.login-form .primary-action, .registration-submit { width: 100%; min-height: 44px; }

.grid-action-button {
    min-height: var(--control-h-sm);
    padding: 0 12px;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

/* compact buttons that live inside tables and pagination */
.data-table .secondary-action,
.data-grid .secondary-action,
.pagination-actions .secondary-action {
    min-height: var(--control-h-sm);
    padding: 0 10px;
}

/* ---------- 5. App shell: sidebar ------------------------------------------ */
.sidebar { width: 260px; padding: 20px 14px 14px; box-shadow: 1px 0 0 rgba(255, 255, 255, 0.04) inset; }

.sidebar-brand { gap: 10px; padding: 2px 6px 18px; margin-bottom: 14px; }
.sidebar-logo { width: 40px; height: 40px; }

.sidebar-nav { gap: 2px; padding-right: 2px; }

.app-shell .nav-item { min-height: 40px; padding: 8px 10px; gap: 12px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; transition: background-color .15s ease, color .15s ease; }
.nav-item:hover, .nav-item:focus { outline: none; }
.nav-item-active { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }

.nav-icon { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 7px; background: rgba(255, 255, 255, 0.08); }
.nav-item-active .nav-icon, .nav-expander[open] > summary .nav-icon { background: rgba(255, 255, 255, 0.16); }

.nav-expander { gap: 2px; }
.nav-expander[open] > summary { color: #ffffff; }

/* chevron replaces the +/- glyph */
.nav-expander summary::after,
.nav-expander[open] summary::after {
    content: "";
    width: 7px;
    height: 7px;
    margin: 0 4px 2px auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    background: none;
    color: #8fa0c4;
    font-size: 0;
    transform: rotate(45deg);
    transition: transform .2s ease;
}
.nav-expander[open] summary::after { transform: rotate(-135deg); margin-bottom: -2px; }

/* submenu sits under the parent label with a thin guide line */
.nav-submenu { gap: 2px; margin: 2px 0 6px 22px; padding: 0 0 0 14px; border-left: 1px solid rgba(255, 255, 255, 0.12); }
.app-shell .nav-subitem { min-height: 34px; padding: 6px 10px; gap: 10px; border-radius: 7px; font-size: 13.5px; transition: background-color .15s ease, color .15s ease; }
.nav-subitem.nav-item-active { background: rgba(37, 99, 235, 0.35); box-shadow: none; }
.nav-subicon { width: 16px; height: 16px; flex: 0 0 16px; opacity: .85; }
.nav-subicon svg { width: 15px; height: 15px; }

.sidebar-footer { padding: 14px 10px 4px; font-size: 13px; color: #94a3b8; }

/* ---------- 6. App shell: topbar & content --------------------------------- */
.topbar { min-height: 68px; padding: 12px 32px; background: #ffffff; box-shadow: var(--shadow-sm); }
.topbar h1 { margin: 2px 0 0; font-size: 21px; font-weight: 700; line-height: 1.25; }
.app-shell .topbar h1 { font-size: 21px; }
.app-shell .page-label { font-size: 12px; font-weight: 600; letter-spacing: 0.1em; color: var(--ink-3); }
.topbar-actions { gap: 12px; }
.topbar-actions .primary-action { min-height: 38px; padding: 0 16px; }
.app-shell .topbar-chip { display: inline-flex; align-items: center; min-height: 34px; padding: 0 14px; font-size: 13px; font-weight: 600; }
.logout-button { width: 38px; height: 38px; box-shadow: 0 1px 2px rgba(220, 38, 38, 0.3); }

.content-area { padding: 24px 32px 40px; max-width: 1680px; }

.eyebrow, .app-shell .eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.1em; color: var(--ink-3); }

/* ---------- 7. Cards & panels ---------------------------------------------- */
.panel, .stat-card, .settings-card, .hero-panel, .connect-card, .login-card {
    border-color: var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.panel { padding: 22px 24px; }
.grid-panel { max-width: none; }
.token-panel, .response-panel { max-width: 860px; }

.panel-heading { margin-bottom: 18px; gap: 16px; align-items: center; }
.panel-heading h3, .app-shell .panel-heading h3 { margin: 2px 0 0; font-size: 17px; font-weight: 700; }
.panel-copy { margin: 0 0 18px; font-size: 15px; }

/* alerts */
.alert-box {
    display: block;
    margin: 0 0 16px;
    padding: 11px 14px;
    border-width: 1px;
    border-left-width: 4px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    line-height: 1.5;
    box-shadow: none;
}

/* ---------- 8. Dashboard ---------------------------------------------------- */
.dashboard-grid { gap: 16px; margin-bottom: 16px; }
.quick-stats-grid { margin-bottom: 16px; }

.stat-card { padding: 18px 20px; }
.quick-stats-grid .stat-card { border-radius: var(--radius); border-bottom-width: 3px; }
.quick-stats-grid .stat-card.stat-card-invoice  { border-bottom-color: #2563eb; }
.quick-stats-grid .stat-card.stat-card-credit   { border-bottom-color: #16a34a; }
.quick-stats-grid .stat-card.stat-card-purchase { border-bottom-color: #7c3aed; }
.quick-stats-grid .stat-card.stat-card-debit    { border-bottom-color: #db2777; }
.stat-card span { font-size: 13px; font-weight: 600; color: var(--ink-3); }
.stat-card strong { margin-top: 8px; font-size: 29px; font-weight: 700; letter-spacing: -0.02em; }

.dashboard-company-action { margin: 0 0 16px; padding: 14px 20px; border-radius: var(--radius); background: #fff; box-shadow: var(--shadow-md); }
.dashboard-company-action strong { margin-top: 4px; font-size: 15px; font-weight: 700; }
.dashboard-company-action form { margin: 0; }
.dashboard-company-action .secondary-action { min-height: 36px; }

.dashboard-panels { gap: 16px; align-items: start; }

.flow-steps { gap: 12px; }
.flow-step { align-items: flex-start; gap: 14px; padding: 14px 16px; border-radius: var(--radius-sm); border-color: var(--line); background: var(--bg-subtle); }
.flow-step > span { width: 28px; height: 28px; font-size: 14px; }
.flow-step strong { font-size: 14px; font-weight: 700; }
.flow-step p { margin: 2px 0 0; font-size: 14px; line-height: 1.5; }

.health-list { gap: 10px; }
.health-item { align-items: center; padding: 12px 14px; border-radius: var(--radius-sm); border-color: var(--line); }
.health-item span { font-size: 14px; }
.health-item strong { font-size: 14px; font-weight: 700; }

/* ---------- 9. Filters (list pages) ---------------------------------------- */
.grid-filter-form.grid-filter-form,
.invoice-grid-panel .grid-filter-form.grid-filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    align-self: stretch;
    gap: 14px 16px;
    width: 100%;
    margin: 0 0 18px;
    padding: 0;
    border: 0;
    background: transparent;
}

.grid-filter-form > .filter-field { flex: 1 1 170px; max-width: 260px; }
.grid-filter-form > .filter-field:first-child { flex: 2 1 280px; max-width: 420px; }

/* ---------- 10. Summary cards (Invoices / Credit Notes) -------------------- */
.invoice-summary-cards { gap: 16px; margin: 0 0 18px; }

.invoice-summary-card {
    min-height: 78px;
    padding: 14px 18px 13px;
    border: 1px solid var(--line);
    border-bottom-width: 3px;
    border-radius: var(--radius);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
    justify-content: space-between;
    transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
.invoice-summary-card:hover, .invoice-summary-card:focus { transform: translateY(-1px); box-shadow: var(--shadow-md); outline: none; }
.invoice-summary-card span { font-size: 13px; font-weight: 600; color: var(--ink-3); }
.invoice-summary-card strong { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; }
.invoice-summary-card.total-card   { border-bottom-color: #2563eb; }
.invoice-summary-card.pending-card { border-bottom-color: #f59e0b; }
.invoice-summary-card.success-card { border-bottom-color: #16a34a; }
.invoice-summary-card.fail-card    { border-bottom-color: #dc2626; }
.summary-card-active { border-color: var(--accent); box-shadow: var(--ring); }

/* ---------- 11. Data tables (one look for every grid) ---------------------- */
.data-grid-wrap,
.purchase-table-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #ffffff;
}

/* a scroller nested inside a dialog needs no second frame on the dialog itself */
.data-grid, .data-table, .purchase-table-scroll .data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }

.data-grid th, .data-table th,
.purchase-table-scroll .data-table th {
    height: 40px;
    padding: 0 12px;
    border-bottom: 0;
    background: #2563eb;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
    vertical-align: middle;
}

.data-grid td, .data-table td,
.purchase-table-scroll .data-table td {
    height: 42px;
    padding: 8px 12px;
    border-bottom: 1px solid #eef2f7;
    color: var(--text);
    font-size: 14px;
    text-align: left;
    white-space: nowrap;
    vertical-align: middle;
}

.data-grid tr, .data-table tr { height: auto; }
.data-grid tbody tr:last-child td, .data-table tbody tr:last-child td { border-bottom: 0; }
.data-grid tbody tr:hover td, .data-table tbody tr:hover td { background: #f8fafc; }

.data-grid td.empty-cell, .data-table td.empty-cell { padding: 36px 14px; color: var(--ink-3); text-align: center; }
.data-table td[colspan] { padding: 36px 14px; color: var(--ink-3); text-align: center; }

.uuid-column { width: 150px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }

/* --- column alignment: text left, numbers right, status/actions centred --- */

/* reset the legacy positional rules, then re-apply them to the RIGHT columns */
.invoice-grid th, .invoice-grid td,
.manual-grid th, .manual-grid td,
.invoice-grid th:nth-child(n), .invoice-grid td:nth-child(n),
.manual-grid th:nth-child(n), .manual-grid td:nth-child(n) { text-align: left; }

/* Sales invoice / credit note:  6 Amt incl · 7 VAT · 8 Amt excl · 5 Currency · 9 Status */
.invoice-grid:not(.bill-grid) th:nth-child(6), .invoice-grid:not(.bill-grid) td:nth-child(6),
.invoice-grid:not(.bill-grid) th:nth-child(7), .invoice-grid:not(.bill-grid) td:nth-child(7),
.invoice-grid:not(.bill-grid) th:nth-child(8), .invoice-grid:not(.bill-grid) td:nth-child(8) { text-align: right; font-variant-numeric: tabular-nums; }
.invoice-grid:not(.bill-grid) th:nth-child(5), .invoice-grid:not(.bill-grid) td:nth-child(5),
.invoice-grid:not(.bill-grid) th:nth-child(9), .invoice-grid:not(.bill-grid) td:nth-child(9) { text-align: center; }

/* Manual send:  1 Select · 6 Currency · 7 Amt incl · 8 VAT · 9 Amt excl · 10 Status */
.manual-grid th:nth-child(7), .manual-grid td:nth-child(7),
.manual-grid th:nth-child(8), .manual-grid td:nth-child(8),
.manual-grid th:nth-child(9), .manual-grid td:nth-child(9) { text-align: right; font-variant-numeric: tabular-nums; }
.manual-grid th:nth-child(1), .manual-grid td:nth-child(1),
.manual-grid th:nth-child(6), .manual-grid td:nth-child(6),
.manual-grid th:nth-child(10), .manual-grid td:nth-child(10) { text-align: center; }
.manual-grid th:nth-child(1), .manual-grid td:nth-child(1) { width: 56px; }
.manual-grid .uuid-column { width: 120px; max-width: 120px; }
.manual-grid th, .manual-grid td { padding-left: 10px; padding-right: 10px; }

/* Purchase bills: 4 Currency · 5 Amount · 7 action */
.bill-grid th:nth-child(4), .bill-grid td:nth-child(4),
.bill-grid th:nth-child(7), .bill-grid td:nth-child(7) { text-align: center; }
.bill-grid th:nth-child(5), .bill-grid td:nth-child(5) { text-align: right; font-variant-numeric: tabular-nums; }

/* Tracking report: 6 Status · 7 Response centred */
.tracking-report-grid th:nth-child(6), .tracking-report-grid td:nth-child(6),
.tracking-report-grid th:nth-child(7), .tracking-report-grid td:nth-child(7) { text-align: center; }

/* Captured purchases: 5 Currency · 6 Total · 7 VAT · 8 actions */
#purchaseInbox > .purchase-table-scroll .data-table th:nth-child(5), #purchaseInbox > .purchase-table-scroll .data-table td:nth-child(5),
#purchaseInbox > .purchase-table-scroll .data-table th:nth-child(8) { text-align: center; }
#purchaseInbox > .purchase-table-scroll .data-table th:nth-child(6), #purchaseInbox > .purchase-table-scroll .data-table td:nth-child(6),
#purchaseInbox > .purchase-table-scroll .data-table th:nth-child(7), #purchaseInbox > .purchase-table-scroll .data-table td:nth-child(7) { text-align: right; font-variant-numeric: tabular-nums; }
#purchaseInbox > .purchase-table-scroll .data-table td:last-child { text-align: center; }
#purchaseInbox td[colspan] { text-align: center; }

/* Purchase mapping (dialog): 3 Rate · 4 Amount · 5 VAT right, 2 Qty centre */
.purchase-mapping-table th:nth-child(3), .purchase-mapping-table td:nth-child(3),
.purchase-mapping-table th:nth-child(4), .purchase-mapping-table td:nth-child(4),
.purchase-mapping-table th:nth-child(5), .purchase-mapping-table td:nth-child(5) { text-align: right; font-variant-numeric: tabular-nums; }
.purchase-mapping-table th:nth-child(2), .purchase-mapping-table td:nth-child(2) { text-align: center; }
.purchase-mapping-table td { white-space: normal; }
.purchase-mapping-table td select { width: 100%; min-width: 190px; }
.purchase-mapping-table th:last-child, .purchase-mapping-table td:last-child { text-align: left; }
.purchase-mapping-table { min-width: 960px; }

/* row action cells */
.grid-action-cell { width: 72px; text-align: center; white-space: nowrap; }
.purchase-table-scroll td:last-child .secondary-action { width: 32px; min-width: 32px; height: var(--control-h-sm); min-height: var(--control-h-sm); padding: 0; }
.create-bill-icon { width: 18px; height: 18px; color: var(--accent); }
.create-bill-icon path { fill: currentColor; }
.purchase-table-scroll td:last-child { min-width: 132px; }
.data-grid td:last-child .status-badge { vertical-align: middle; }

/* users & roles table: fixed proportional columns */
.users-list-panel .data-table { table-layout: fixed; }
.users-list-panel .data-table th, .users-list-panel .data-table td { padding: 0 14px; height: 42px; overflow: hidden; text-overflow: ellipsis; }
.users-list-panel .data-table th:nth-child(5), .users-list-panel .data-table td:nth-child(5) { text-align: center; }

/* download menu (per-row) */
.download-menu summary { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: var(--control-h-sm); border-radius: var(--radius-sm); color: var(--accent); transition: background-color .15s ease; }
.download-menu summary:hover { background: #eff6ff; }
.download-menu-items { top: 100%; margin-top: 4px; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14); }
.download-menu-items a { padding: 7px 12px; border-radius: 6px; font-weight: 500; }
.tracking-message-button { padding: 4px 8px; border-radius: 6px; font-size: 13px; font-weight: 600; text-decoration: none; }
.tracking-message-button:hover { background: #eff6ff; }

/* status pills */
.status-badge, .app-shell .status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}

/* ---------- 12. Pagination -------------------------------------------------- */
.pagination-bar { margin-top: 16px; gap: 12px; font-size: 13px; font-weight: 600; color: var(--ink-3); }
.page-link, .app-shell .page-link {
    min-width: var(--control-h-sm);
    min-height: var(--control-h-sm);
    padding: 0 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.page-link:hover { background: var(--bg-subtle); color: var(--accent); text-decoration: none; }
.page-link-active, .page-link-active:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-link-disabled { opacity: .45; }

/* ---------- 13. Manual send bar --------------------------------------------- */
.manual-progress { margin: 0 0 16px; padding: 12px 16px; border-radius: var(--radius-sm); border-color: var(--line); background: var(--bg-subtle); }
.manual-progress-row { margin-bottom: 10px; }
.manual-progress-status { font-size: 14px; font-weight: 600; }
.manual-progress-count { font-size: 13px; }
.manual-send-actions { margin-top: 18px; }
.manual-grid input[type="checkbox"] { vertical-align: middle; }

/* ---------- 14. Purchase capture toolbar ------------------------------------ */
.purchase-capture-actions { align-items: flex-end; gap: 12px; }
.purchase-capture-actions label { display: grid; gap: 6px; }
.purchase-capture-actions > .primary-action,
.purchase-capture-actions > .secondary-action { margin-top: 0; }
.purchase-capture-actions .primary-action,
.purchase-capture-actions .secondary-action { min-height: var(--control-h); padding: 0 18px; }
.purchase-capture-actions input { width: 160px; }
#purchaseProgress { display: block; width: 100%; height: 6px; margin: 0 0 16px; border: 0; border-radius: 999px; overflow: hidden; }
#purchaseInbox #purchaseStatus:empty { display: none; }
#purchaseInbox #purchaseStatus { border-left-color: var(--line-strong); }
.purchase-pagination { margin-top: 16px; }
.empty-state-panel { padding: 28px; border-radius: var(--radius-sm); border-color: var(--line-strong); }

/* ---------- 15. Dialogs / modals -------------------------------------------- */
.modal-backdrop { background: rgba(15, 23, 42, 0.5); }
.modal-card { border: 1px solid var(--line); border-radius: 12px; padding: 24px; box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28); }

.modal-heading { align-items: center; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.modal-heading h3 { margin: 2px 0 0; font-size: 19px; font-weight: 700; }
.modal-heading .icon-button { width: 34px; height: 34px; font-size: 21px; line-height: 1; }

.modal-actions { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); gap: 10px; }

.purchase-mapping-dialog, .tracking-message-dialog {
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28);
}
.purchase-mapping-dialog::backdrop, .tracking-message-dialog::backdrop { background: rgba(15, 23, 42, 0.5); }
.purchase-mapping-dialog h3 { margin: 0 0 16px; font-size: 19px; font-weight: 700; }
.purchase-modal-title { margin-bottom: 18px; padding: 0 0 16px; border-bottom: 1px solid var(--line); align-items: center; }
.purchase-modal-title h3 { margin: 0; font-size: 19px; }
.purchase-section-title { margin: 22px 0 10px; padding: 0; border-bottom: 0; font-size: 14px; font-weight: 700; letter-spacing: 0; color: var(--text); }
.purchase-mapping-dialog p { color: var(--ink-3); }
.purchase-inline-field { gap: 8px; }
.purchase-inline-field .icon-button { width: var(--control-h); }
#purchaseMappingStatus, #purchaseMasterStatus { margin-top: 12px; font-size: 13px; color: var(--ink-3); }
.tracking-message-dialog .modal-heading { margin-bottom: 14px; }
.tracking-message-content { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-subtle); font-size: 14px; line-height: 1.6; }

/* ---------- 16. Settings ---------------------------------------------------- */
.einvoice-settings-page { gap: 18px; }
.einvoice-settings-form { gap: 18px; }
.settings-card { padding: 22px 24px; }
.settings-card h3 { margin: 0 0 18px; padding-bottom: 14px; font-size: 16px; font-weight: 700; }
.settings-card h4 { margin: 24px 0 12px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; }
.settings-field-grid { gap: 16px 18px; }
.settings-card-grid { gap: 18px; }
.settings-save-row { padding-top: 2px; }

/* generic two-column form grid used by dialogs, user form, purchase form */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field-wide { grid-column: 1 / -1; }

/* ---------- 17. Users & roles ----------------------------------------------- */
.users-roles-grid { gap: 18px; }
.page-toolbar { margin-bottom: 16px; }
.users-list-panel .panel-heading { min-height: 0; padding: 0; margin-bottom: 14px; }
.users-list-panel .panel-heading .secondary-action { min-height: 36px; }
.user-details-panel { padding: 22px 24px; }
.user-details-panel h3 { margin: 0 0 18px; font-size: 17px; font-weight: 700; }
.role-checks { gap: 10px 22px; padding-top: 6px; }
.role-checks label { display: inline-flex; align-items: center; gap: 8px; }

/* ---------- 18. Registration ------------------------------------------------- */
.registration-panel { margin: 40px auto; }
.registration-card { border-radius: 12px; }
.registration-title { padding: 26px 32px 6px; }
.registration-title h3 { font-size: 21px; font-weight: 700; }
.registration-form { padding: 18px 32px 28px; }
.registration-layout { grid-template-columns: 220px minmax(0, 1fr); gap: 32px; }
.registration-steps { padding: 6px 20px 6px 0; gap: 4px; }
.registration-step { min-height: 44px; padding: 8px 10px; border-radius: var(--radius-sm); grid-template-columns: 26px minmax(0, 1fr); gap: 12px; transition: background-color .15s ease, color .15s ease; }
.registration-step:hover { background: var(--bg-subtle); }
.registration-step span { width: 24px; height: 24px; font-size: 13px; font-weight: 700; }
.registration-step strong { font-size: 14px; font-weight: 600; }
.registration-step-active { background: #eff6ff; color: var(--accent-dark); }
.registration-main { gap: 24px; }
.registration-section { padding-bottom: 24px; }
.registration-section:last-of-type { border-bottom: 0; padding-bottom: 0; }
.registration-section-heading { align-items: center; margin-bottom: 16px; gap: 12px; }
.registration-section-heading > span { width: 26px; height: 26px; font-size: 13px; font-weight: 700; }
.registration-section-heading h4 { margin: 0; font-size: 16px; font-weight: 700; }
.registration-grid { gap: 16px 18px; }
.username-suggestion-row { gap: 10px; }
.username-suggestion-button { min-height: var(--control-h); }
.username-suggestion { margin-top: 2px; font-size: 13px; font-weight: 500; color: var(--ink-3); }
.registration-submit { margin-top: 4px; }
.registration-login-link, .login-register-link { margin: 20px 0 0; padding-top: 18px; border-top: 1px solid var(--line); font-size: 14px; font-weight: 500; }
.registration-panel .registration-login-link { padding-bottom: 22px; }
.registration-login-link a, .login-register-link a { font-weight: 600; }

/* ---------- 19. Login -------------------------------------------------------- */
.login-card { width: min(100%, 420px); padding: 36px 34px 28px; border-radius: 14px; box-shadow: 0 20px 48px rgba(15, 23, 42, 0.12); }
.login-brand { margin-bottom: 20px; }
.login-card .eyebrow { display: block; text-align: center; }
.login-card h1 { margin: 6px 0 6px; text-align: center; font-size: 27px; font-weight: 700; }
.login-card > p { margin: 0 0 24px; text-align: center; font-size: 15px; }
.login-form { gap: 8px; }
.login-form label { margin: 8px 0 0; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.login-form label:first-of-type { margin-top: 0; }
.login-form.login-form input { height: 44px; min-height: 44px; padding: 0 44px 0 42px; background-color: var(--bg-subtle); font-size: 15px; }
.login-form.login-form input:focus { background-color: #fff; }
.clear-input { top: 50%; right: 8px; transform: translateY(-50%); }
.login-form .primary-action { margin-top: 14px; }

/* ---------- 20. Small screens (keep existing breakpoints) ------------------- */
@media (max-width: 980px) {
    .sidebar { width: 86px; padding-inline: 12px; }
    .nav-expander summary::after, .nav-expander[open] summary::after { display: none; }
    .content-area { padding: 20px; }
    .topbar { padding: 12px 20px; }
    .registration-layout { grid-template-columns: 180px minmax(0, 1fr); gap: 22px; }
    .settings-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
    .content-area { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .topbar-actions { width: 100%; }
    .topbar-actions .connect-form { flex: 1 1 auto; }
    .grid-filter-form > .filter-field, .grid-filter-form > .filter-field:first-child { flex: 1 1 100%; max-width: none; }
    .settings-grid { grid-template-columns: 1fr; }
    .registration-form { padding: 14px 16px 22px; }
    .registration-layout { gap: 14px; }
    .registration-step { padding: 6px; grid-template-columns: 22px minmax(0, 1fr); gap: 6px; }
    .registration-panel { margin: 16px auto; }
    .purchase-capture-actions { width: 100%; }
    .purchase-capture-actions input { width: 100%; }
    .modal-card, .purchase-mapping-dialog, .tracking-message-dialog { padding: 18px; }
    .login-card { padding: 28px 22px 22px; }
}

/* ==========================================================================
   21. Dialogs sit inside the content area (never over the sidebar)
   The sidebar is 260px (86px when collapsed, 0 when it becomes a top strip),
   the content area has 32px / 20px / 16px side padding. The dialog is centred
   in that area and, for the mapping dialog, spans the same width as the grid.
   ========================================================================== */
.purchase-mapping-dialog.purchase-mapping-dialog,
.tracking-message-dialog.tracking-message-dialog {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 260px;
    right: 0;
    margin: auto;
    max-width: none;
    height: fit-content;
    max-height: calc(100vh - 48px);
    overflow: auto;
}

.purchase-mapping-dialog.purchase-mapping-dialog { width: calc(100vw - 260px - 64px); }
.purchase-mapping-dialog.purchase-master-dialog  { width: min(640px, calc(100vw - 260px - 64px)); }
.tracking-message-dialog.tracking-message-dialog { width: min(680px, calc(100vw - 260px - 64px)); }

/* dim only the content area so the sidebar stays visible and untouched */
.purchase-mapping-dialog::backdrop,
.tracking-message-dialog::backdrop { clip-path: inset(0 0 0 260px); }

@media (max-width: 980px) {
    .purchase-mapping-dialog.purchase-mapping-dialog,
    .tracking-message-dialog.tracking-message-dialog { left: 86px; }
    .purchase-mapping-dialog.purchase-mapping-dialog { width: calc(100vw - 86px - 40px); }
    .purchase-mapping-dialog.purchase-master-dialog  { width: min(640px, calc(100vw - 86px - 40px)); }
    .tracking-message-dialog.tracking-message-dialog { width: min(680px, calc(100vw - 86px - 40px)); }
    .purchase-mapping-dialog::backdrop, .tracking-message-dialog::backdrop { clip-path: inset(0 0 0 86px); }
}

@media (max-width: 640px) {
    .purchase-mapping-dialog.purchase-mapping-dialog,
    .tracking-message-dialog.tracking-message-dialog { left: 0; }
    .purchase-mapping-dialog.purchase-mapping-dialog,
    .purchase-mapping-dialog.purchase-master-dialog,
    .tracking-message-dialog.tracking-message-dialog { width: calc(100vw - 32px); }
    .purchase-mapping-dialog::backdrop, .tracking-message-dialog::backdrop { clip-path: none; }
}

/* ==========================================================================
   22. Mapping table: item dropdown + "+" button, and the VAT-code column
   The "+" button is a sibling of the select inside the same cell, so the cell
   is laid out inline: [ select ......... ][+]  and never spills into VAT code.
   ========================================================================== */
.purchase-mapping-table { table-layout: auto; min-width: 900px; }

.purchase-mapping-table th:nth-child(1) { width: 20%; }
.purchase-mapping-table th:nth-child(6) { width: 38%; }
.purchase-mapping-table th:nth-child(7) { width: 20%; }

.purchase-mapping-table td:nth-child(6) { white-space: nowrap; padding-right: 8px; }
.purchase-mapping-table td:nth-child(6) select {
    display: inline-block;
    width: calc(100% - 50px);
    min-width: 160px;
    vertical-align: middle;
}
.purchase-mapping-table td:nth-child(6) .icon-button {
    display: inline-flex;
    margin-left: 8px;
    vertical-align: middle;
}

.purchase-mapping-table td:nth-child(7) { padding-left: 8px; }
.purchase-mapping-table td:nth-child(7) select { display: block; width: 100%; min-width: 150px; }
.purchase-mapping-table th:nth-child(6), .purchase-mapping-table th:nth-child(7) { text-align: left; }
