/* Workflow patterns shared by invoices, quotes, expenses, banking, time and the admin pages.
   Built only on tokens.css; no new colours. */

/* ---------- Toolbar (search + filters) ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: center; margin-bottom: 1rem; }
.toolbar-search { position: relative; flex: 1 1 16rem; max-width: 26rem; }
.toolbar-search .bi, .toolbar-search .hx-icon { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.toolbar-search .form-control { padding-left: 2.5rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0; padding: 0; list-style: none; }
.chip {
    display: inline-flex; align-items: center; gap: .4rem; min-height: 2.25rem; padding: .25rem .85rem; border-radius: var(--radius-pill);
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: var(--text-sm); font-weight: 600; cursor: pointer;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.chip:hover { border-color: var(--brand-500); color: var(--text); }
.chip[aria-pressed="true"], .chip.active { background: var(--brand-100); border-color: var(--brand-500); color: var(--link); }
.chip .chip-count { font-weight: 500; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---------- Summary tiles ---------- */
.stat-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); margin-bottom: 1.25rem; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: .9rem 1.1rem; box-shadow: var(--shadow-1); min-width: 0; }
.stat-tile .stat-label { font-size: var(--text-sm); color: var(--text-3); }
.stat-tile .stat-value { font-family: var(--font-display); font-weight: 560; font-size: clamp(1.25rem, 1rem + 1vw, 1.65rem); font-variant-numeric: lining-nums tabular-nums; letter-spacing: -.02em; line-height: 1.25; overflow-wrap: anywhere; }
.stat-tile .stat-hint { font-size: var(--text-xs); color: var(--text-3); margin-top: .1rem; }
.stat-tile.tone-warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); background: var(--warn-bg); }
.stat-tile.tone-danger .stat-value { color: var(--danger); }
.stat-tile.tone-pos .stat-value { color: var(--pos); }

/* ---------- List rows (clickable table rows) ---------- */
.table-link { font-weight: 650; text-decoration: none; }
.table-link:hover { text-decoration: underline; }
.row-sub { display: block; font-size: var(--text-xs); color: var(--text-3); font-weight: 450; }
.row-actions { display: inline-flex; gap: .35rem; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Status steps ---------- */
.status-steps { display: flex; gap: .25rem; list-style: none; padding: 0; margin: 0 0 1.25rem; counter-reset: step; flex-wrap: wrap; }
.status-steps li { display: flex; align-items: center; gap: .5rem; color: var(--text-3); font-size: var(--text-sm); font-weight: 600; }
.status-steps li::before {
    counter-increment: step; content: counter(step); display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%;
    border: 2px solid var(--border-strong); font-size: var(--text-xs); background: var(--surface);
}
.status-steps li + li::after { content: none; }
.status-steps li:not(:last-child)::after { content: ""; width: 1.75rem; height: 2px; background: var(--border-strong); margin: 0 .25rem 0 .5rem; }
.status-steps li.done { color: var(--text-2); }
.status-steps li.done::before { content: "✓"; background: var(--pos); border-color: var(--pos); color: #fff; }
.status-steps li.done:not(:last-child)::after { background: var(--pos); }
.status-steps li.current { color: var(--text); }
.status-steps li.current::before { border-color: var(--brand-500); background: var(--brand-100); color: var(--link); }
.status-steps li.alt { color: var(--text-2); }
.status-steps li.alt::before { content: "!"; border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }

/* ---------- Document layout (detail pages) ---------- */
.doc-layout { display: grid; gap: 1rem; align-items: start; }
@media (min-width: 1100px) { .doc-layout { grid-template-columns: minmax(0, 1fr) 21rem; } .doc-aside { position: sticky; top: 1rem; } }
.doc-aside { display: grid; gap: 1rem; min-width: 0; }
.paper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); overflow: hidden; }
.paper-section { padding: 1.25rem 1.35rem; }
.paper-section + .paper-section { border-top: 1px solid var(--border); }
.paper .table { margin: 0; }
.paper .table > thead > tr > th { border-top: 0; }
.meta-grid { display: grid; gap: 1rem 1.5rem; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); margin: 0; }
.meta-grid dt { font-size: var(--text-xs); font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); margin-bottom: .15rem; }
.meta-grid dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.meta-grid .wide { grid-column: 1 / -1; }
.party-name { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 560; margin: 0 0 .15rem; }
.section-title { font-size: var(--text-xs); font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin: 0 0 .75rem; }

/* ---------- Totals ---------- */
.totals { margin: 0; display: grid; gap: .35rem; }
.totals > div { display: flex; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }
.totals dt { font-weight: 450; color: var(--text-2); }
.totals dd { margin: 0; font-weight: 550; white-space: nowrap; }
.totals .grand { margin-top: .35rem; padding-top: .65rem; border-top: 1px solid var(--border-strong); align-items: baseline; }
.totals .grand dt { font-weight: 650; color: var(--text); }
.totals .grand dd { font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; letter-spacing: -.02em; }
.totals .due dt { font-weight: 650; color: var(--text); }
.totals .due dd { font-weight: 700; color: var(--link); }
.totals .due.settled dd { color: var(--pos); }
.pay-bar { height: .5rem; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; margin: .85rem 0 .25rem; }
.pay-bar > span { display: block; height: 100%; background: var(--pos); border-radius: inherit; }
.pay-bar-label { font-size: var(--text-xs); color: var(--text-3); margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: .85rem; }
.timeline li { display: grid; grid-template-columns: 1.1rem 1fr auto; gap: .6rem; align-items: baseline; font-size: var(--text-sm); }
.timeline li::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; background: var(--pos); margin-top: .3rem; }
.timeline .tl-sub { display: block; color: var(--text-3); font-size: var(--text-xs); }

/* ---------- Action bar ---------- */
.action-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1.25rem; }
.action-note { color: var(--text-3); font-size: var(--text-sm); margin: -.5rem 0 1.25rem; }
.panel-form { border-left: 4px solid var(--brand-500); }
.panel-form.danger { border-left-color: var(--danger); }

/* ---------- Line editor ---------- */
.lines-head { display: none; }
.line-row { display: grid; gap: .75rem; grid-template-columns: 1fr 1fr; padding: 1rem 1.1rem; border-bottom: 1px solid var(--border); }
.line-row:last-of-type { border-bottom: 0; }
.line-row .line-desc, .line-row .line-vat, .line-row .line-extra, .line-row .line-foot { grid-column: 1 / -1; }
.line-foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.line-amount { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.line-amount small { display: block; font-weight: 450; color: var(--text-3); font-size: var(--text-xs); }
@media (min-width: 768px) {
    .lines-head, .line-row { grid-template-columns: minmax(0, 1fr) 5.5rem 7.5rem 11rem 8rem 2.75rem; align-items: start; padding: .75rem 1.1rem; }
    .lines-head { display: grid; gap: .75rem; font-size: var(--text-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--border); }
    .lines-head .num { text-align: right; }
    .line-row .line-desc, .line-row .line-vat { grid-column: auto; }
    .line-row .line-extra { grid-column: 1 / -1; }
    .line-row .line-foot { display: contents; }
    .line-row .form-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .line-amount { padding-top: .65rem; }
}
.line-row .btn-icon { min-width: 2.75rem; padding-left: 0; padding-right: 0; }
.lines-add { padding: .75rem 1.1rem; border-top: 1px solid var(--border); background: var(--surface-2); }
.totals-card { max-width: 24rem; margin-left: auto !important; width: 100%; }

.form-stack { display: grid; gap: 1rem; max-width: 62rem; margin: 0; }
.form-stack > :not(.totals-card) { margin: 0 !important; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
@media (max-width: 991.98px) {
    /* Save bar docks flush above the bottom tab bar (below it while the on-screen keyboard is open). */
    .form-actions.sticky-mobile {
        position: sticky; bottom: var(--tabbar-height); z-index: 5; flex-wrap: nowrap; align-items: stretch;
        margin: 0 -1rem !important; padding: .65rem 1rem; border-top: 1px solid var(--border);
        background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(10px);
        box-shadow: 0 -8px 18px rgba(0, 0, 0, .06);
    }
    .form-actions.sticky-mobile .btn { min-height: var(--tap); }
    .form-actions.sticky-mobile .btn-primary { flex: 1 1 auto; }
    .form-actions.sticky-mobile .btn:not(.btn-primary) { flex: 0 0 auto; }
    html { scroll-padding-top: calc(var(--topbar-height) + 1rem); scroll-padding-bottom: calc(var(--tabbar-height) + 6rem); }
    .app-main:has(.form-actions.sticky-mobile) { padding-bottom: 0; }
    html.kb-open .tabbar { display: none; }
    html.kb-open .form-actions.sticky-mobile { bottom: var(--kb-inset, 0px); }
    html.kb-open .app-main { padding-bottom: 1rem; }
}

/* ---------- Form sections (customers, suppliers, settings) ---------- */
.form-section { border: 0; padding: 0; margin: 0 0 1.75rem; min-width: 0; }
.form-section:last-of-type { margin-bottom: 0; }
.form-section > legend {
    float: none; width: auto; padding: 0; margin: 0 0 .75rem; font-size: var(--text-xs); font-weight: 650;
    text-transform: uppercase; letter-spacing: .08em; color: var(--text-3);
}
form.card-soft { display: block; }
.form-stack .card-soft + .card-soft { margin-top: 0; }

.section-nav { display: flex; gap: .4rem; margin: 0 0 1rem; padding: 0 0 .25rem; overflow-x: auto; scrollbar-width: none; }
.section-nav::-webkit-scrollbar { display: none; }
.section-nav a {
    flex: 0 0 auto; display: inline-flex; align-items: center; min-height: 2.25rem; padding: 0 .9rem; border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill); background: var(--surface); color: var(--text-2); text-decoration: none; font-size: var(--text-sm); font-weight: 560;
}
.section-nav a:hover { border-color: var(--brand-500); color: var(--text); }
.card-soft[id], [id$="-card"] { scroll-margin-top: calc(var(--topbar-height) + 1rem); }

/* Collapsible panel (e.g. void an expense): one tap target, closed by default */
details.collapsible > summary {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: var(--tap); cursor: pointer;
    font-size: 1.125rem; font-weight: 650; list-style: none;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::after { content: ""; width: .6rem; height: .6rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform var(--dur) var(--ease); }
details.collapsible[open] > summary::after { transform: rotate(-135deg); }
details.collapsible[open] > summary { margin-bottom: .5rem; }
details.collapsible > summary:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; border-radius: var(--radius-sm, .375rem); }

/* Read-only line list: description on its own row, three amounts beneath on phones */
@media (max-width: 767.98px) {
    .table-lines tbody { gap: 0 !important; }
    .table-lines tr { display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .15rem .75rem; border-radius: 0 !important; box-shadow: none !important; border-width: 0 0 1px !important; padding: .75rem 1rem !important; }
    .table-lines tr:last-child { border-bottom: 0 !important; }
    .table-lines td { display: block !important; text-align: left !important; padding: 0 !important; }
    .table-lines td::before { display: block; font-size: var(--text-xs); }
    .table-lines td.line-desc-cell { grid-column: 1 / -1; font-weight: 600; }
    .table-lines td.line-desc-cell::before { display: none; }
    .table-lines td.num { text-align: left !important; font-variant-numeric: tabular-nums; }
    .table-lines td:last-child { font-weight: 650; }
}

/* ---------- Drop zone (file input with Faroese text) ---------- */
.dropzone { position: relative; display: grid; place-items: center; gap: .35rem; text-align: center; padding: 1.5rem 1rem; border: 2px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-2); cursor: pointer; transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease); }
.dropzone:hover, .dropzone:focus-within { border-color: var(--brand-500); background: var(--brand-50); }
.dropzone input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone .dz-icon { font-size: 1.75rem; color: var(--link); }
.dropzone .dz-title { font-weight: 650; }
.dropzone .dz-hint { font-size: var(--text-sm); color: var(--text-3); }
.dropzone:focus-within { outline: 2px solid var(--brand-500); outline-offset: 2px; }

/* ---------- Timer ---------- */
.timer-card { background: linear-gradient(135deg, var(--brand-700), var(--brand-600)); color: #fff; border-radius: var(--radius-xl); padding: 1.5rem; box-shadow: var(--shadow-2); }
[data-bs-theme="dark"] .timer-card { background: linear-gradient(135deg, var(--brand-50), var(--brand-100)); color: var(--text); border: 1px solid var(--border); }
.timer-clock { font-family: var(--font-display); font-weight: 520; font-size: clamp(2.75rem, 2rem + 4vw, 4.25rem); font-variant-numeric: lining-nums tabular-nums; letter-spacing: -.03em; line-height: 1; }
.timer-card .form-label { color: inherit; opacity: .85; }
.timer-card .text-muted { color: inherit !important; opacity: .8; }
.timer-live { display: inline-flex; align-items: center; gap: .5rem; font-size: var(--text-sm); font-weight: 600; }
.timer-live::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }
@media (prefers-reduced-motion: reduce) { .timer-live::before { animation: none; } }

/* ---------- Bank transaction state ---------- */
.state-dot { display: inline-flex; align-items: center; gap: .4rem; font-size: var(--text-sm); font-weight: 600; }
.state-dot::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; background: var(--text-3); }
.state-dot.matched::before { background: var(--pos); }
.state-dot.unmatched::before { background: var(--warn); }
.state-dot.ignored::before { background: var(--border-strong); }
.bank-row.is-unmatched { box-shadow: inset 3px 0 0 var(--warn); }
.bank-row.is-matched { box-shadow: inset 3px 0 0 var(--pos); }
.explain { display: flex; gap: .65rem; padding: .85rem 1rem; border-radius: var(--radius-md); background: var(--info-bg); font-size: var(--text-sm); }
.explain .bi, .explain .hx-icon { flex: none; color: var(--info); margin-top: .1rem; }

/* ---------- Settings / admin ---------- */
.settings-nav { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.section-card { margin-bottom: 1rem; }
.section-card > h2:first-child, .card-soft > h2:first-child, .card-soft > .h5:first-child { margin-bottom: .75rem; }
.kv { display: grid; gap: .25rem 1rem; grid-template-columns: max-content 1fr; margin: 0; }
.kv dt { color: var(--text-3); font-weight: 450; }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }

.grid-gap { display: grid; gap: 1rem; min-width: 0; }
.receipt-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); }
.receipt { display: grid; gap: .25rem; min-width: 0; }
.receipt-thumb { display: grid; place-items: center; aspect-ratio: 4 / 3; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); overflow: hidden; }
.receipt-thumb img { width: 100%; height: 100%; object-fit: cover; }
.receipt-pdf { font-size: 2.5rem; color: var(--danger); }
.receipt-name { font-size: var(--text-sm); font-weight: 600; overflow-wrap: anywhere; }

.how-steps { padding-left: 1.25rem; color: var(--text-2); font-size: var(--text-sm); display: grid; gap: .25rem; margin-bottom: 1rem; }
.how-steps li::marker { color: var(--link); font-weight: 700; }

.btn-accent { --bs-btn-bg: var(--accent); --bs-btn-border-color: var(--accent); --bs-btn-color: #2b1d00; --bs-btn-hover-bg: var(--accent); --bs-btn-hover-border-color: var(--accent); --bs-btn-hover-color: #2b1d00; --bs-btn-active-bg: var(--accent); --bs-btn-active-color: #2b1d00; min-height: 3rem; font-weight: 700; }
.btn-accent:hover { filter: brightness(1.05); }

/* Havit ships `form { display:flex; flex-direction:column; gap }`, which breaks Bootstrap grid forms. */
form.row { flex-direction: row; gap: 0; }

.auth-card h1 { margin-bottom: 1.25rem; }
.auth-card h1:focus { outline: none; }
.auth-card form { gap: 0; }

/* Small action buttons in rows must still be comfortable touch targets on phones */
@media (pointer: coarse) {
    .bank-row .btn-sm { min-height: var(--tap); padding-left: 1rem; padding-right: 1rem; }
}
.form-stack + .card-soft { margin-top: 1rem; }
