@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@400;500;600;700&display=swap');

:root {
    --swedishred: #9c2b27;
    --leafgreen: #4a6b2c;
    --leafgreen-light: #719352;
    --creamwhite: #e9d7ab;
    --text-dark: #333;
    --leafgreendark: #3b5623;
    --fas-green: var(--leafgreen);
    --fas-green-dark: var(--leafgreendark);
    --fas-gold: var(--creamwhite);
    --fas-gold-dark: #b99f63;
    --text: var(--text-dark);
    --muted: #666;
    --line: #ded1ac;
    --bg: #f7f3e8;
    --white: #fff;
    --danger: #b42318;
}

* { box-sizing: border-box; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    margin: 0;
}

a { color: var(--fas-green); }

h1,
h2,
h3,
h4 {
    color: var(--leafgreen);
    font-family: 'Oswald', Arial, Helvetica, sans-serif;
    font-weight: 600;
    letter-spacing: 0;
}

.app-header,
.app-footer {
    align-items: center;
    display: flex;
    justify-content: space-between;
    min-height: 58px;
    padding: 12px 22px;
}

.app-header {
    background: var(--creamwhite);
    color: var(--leafgreen);
}

.app-footer {
    background: var(--leafgreendark);
    color: var(--creamwhite);
    font-size: 13px;
    min-height: 44px;
}

.brand,
.header-link {
    align-items: center;
    color: var(--leafgreen);
    display: inline-flex;
    gap: 10px;
    text-decoration: none;
}

.brand-mark {
    border: 1px solid var(--leafgreen);
    border-radius: 4px;
    font-weight: 700;
    padding: 4px 7px;
}

.brand-logo {
    display: block;
    max-height: 42px;
    max-width: 168px;
    object-fit: contain;
}

.header-user {
    align-items: center;
    display: flex;
    gap: 14px;
}

.app-shell {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    min-height: calc(100vh - 102px);
}

.sidebar {
    background: var(--leafgreen);
    border-right: 1px solid var(--leafgreendark);
    color: var(--creamwhite);
    padding: 14px 12px;
}

.nav-section {
    border-bottom: 1px solid rgba(233, 215, 171, 0.22);
    padding: 4px 0;
}

.nav-section + .nav-section { margin-top: 4px; }

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

.nav-section-title {
    align-items: center;
    border-radius: 6px;
    color: var(--creamwhite);
    cursor: pointer;
    display: grid;
    font-family: 'Oswald', Arial, Helvetica, sans-serif;
    font-size: 14px;
    gap: 9px;
    grid-template-columns: 22px minmax(0, 1fr) 18px;
    letter-spacing: 0;
    list-style: none;
    padding: 9px 10px;
    text-transform: uppercase;
}

.nav-section-title:hover {
    background: rgba(113, 147, 82, 0.48);
}

.nav-section[open] .nav-chevron {
    transform: rotate(180deg);
}

.nav-submenu {
    display: grid;
    gap: 3px;
    padding: 3px 0 8px 0;
}

.nav-link {
    border-radius: 6px;
    color: var(--creamwhite);
    display: grid;
    gap: 9px;
    grid-template-columns: 22px minmax(0, 1fr);
    padding: 8px 10px;
    text-decoration: none;
}

.nav-link:hover,
.nav-link.active {
    background: var(--leafgreen-light);
    color: var(--creamwhite);
}

.nav-icon {
    display: inline-flex;
    font-weight: 700;
    justify-content: center;
    line-height: 1;
}

.nav-chevron {
    display: inline-flex;
    justify-content: center;
    transition: transform 0.16s ease;
}

.language-switcher {
    margin-top: 10px;
    padding: 0 10px 8px;
}

.language-switcher label {
    color: var(--creamwhite);
    display: block;
    font-size: 12px;
    margin-bottom: 5px;
}

.language-select {
    align-items: center;
    display: flex;
    gap: 7px;
}

.language-select img {
    display: block;
    flex: 0 0 15px;
    height: 10px;
    object-fit: cover;
    width: 15px;
}

.language-select select {
    background: var(--creamwhite);
    border-color: var(--leafgreen-light);
    color: var(--text-dark);
    min-width: 78px;
    padding: 6px 8px;
}

.content {
    background: var(--white);
    color: var(--text);
    border: 1px solid #eadfbe;
    margin: 18px;
    padding: 22px;
}

h1 {
    font-size: 26px;
    margin: 0 0 18px;
}

h2 {
    font-size: 19px;
    margin: 0 0 14px;
}

.toolbar,
.form-actions,
.table-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.toolbar {
    justify-content: space-between;
    margin-bottom: 14px;
}

.card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 6px;
    margin-bottom: 18px;
    padding: 18px;
}

.report-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.report-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 210px;
}

.report-card h2 {
    margin-bottom: 8px;
}

.report-card p {
    margin: 0 0 16px;
}

.report-status {
    color: var(--leafgreendark);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.btn,
button,
input[type="submit"] {
    background: #ececec;
    border: 1px solid #c9c9c9;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    display: inline-block;
    font: inherit;
    padding: 8px 12px;
    text-decoration: none;
}

.btn-primary,
button.btn-primary,
input.btn-primary {
    background: var(--fas-green);
    border-color: var(--fas-green-dark);
    color: #fff;
}

.btn-gold {
    background: var(--fas-gold);
    border-color: var(--fas-gold-dark);
    color: #161300;
}

.btn-danger {
    background: var(--danger);
    border-color: #8f1c13;
    color: #fff;
}

.btn-small { padding: 5px 8px; }

.tabs {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 14px;
}

.tab-link {
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: 6px 6px 0 0;
    color: var(--text);
    padding: 8px 12px;
    text-decoration: none;
}

.tab-link.active {
    background: #f8f0da;
    border-color: var(--line);
    color: var(--leafgreendark);
    font-weight: 700;
}

.invoice-reminder {
    background: #fff4db;
    border-color: #d38a18;
    color: #8a4c00;
    font-weight: 700;
}

.invoice-reminder-2 {
    background: #ffe8e5;
    border-color: var(--danger);
    color: var(--danger);
    font-weight: 700;
}

.invoice-status {
    border-radius: 999px;
    display: inline-block;
    padding: 3px 8px;
}

.invoice-status-warning {
    background: #fff4db;
    color: #8a4c00;
    font-weight: 700;
}

.invoice-status-danger {
    background: #ffe8e5;
    color: var(--danger);
    font-weight: 700;
}

.btn-icon {
    align-items: center;
    display: inline-flex;
    font-size: 14px;
    height: 28px;
    justify-content: center;
    line-height: 1;
    padding: 0;
    width: 28px;
}

.invoice-pdf-button {
    background: #fff;
    flex: 0 0 28px;
    height: 28px;
    overflow: hidden;
    padding: 0;
    width: 28px;
}

.invoice-pdf-button img {
    display: block;
    flex: 0 0 20px;
    height: 20px;
    max-height: 20px;
    max-width: 20px;
    object-fit: contain;
    width: 20px;
}

.form-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.form-grid > .full { grid-column: 1 / -1; }

.form-row {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

label { font-weight: 700; }

input,
select,
textarea {
    background: #fff;
    border: 1px solid #bdbdbd;
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    padding: 8px 10px;
    width: 100%;
}

textarea { min-height: 96px; resize: vertical; }

.table-wrap { overflow-x: auto; }

table {
    border-collapse: collapse;
    width: 100%;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 9px 10px;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f8f0da;
    color: #111;
}

.alert {
    border-radius: 6px;
    margin-bottom: 16px;
    padding: 10px 12px;
}

.alert-success { background: #e9f5e6; border: 1px solid #9ec28f; }
.alert-error { background: #fff0ed; border: 1px solid #d79a91; }
.hint { color: var(--muted); font-size: 13px; }
.status-inactive { color: var(--danger); font-weight: 700; }

.stats-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.stat {
    background: #fbfaf5;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
}

.stat span {
    color: var(--muted);
    display: block;
    font-size: 13px;
}

.stat strong {
    color: var(--leafgreen);
    display: block;
    font-size: 24px;
    line-height: 1.2;
}

.badge {
    border-radius: 999px;
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    padding: 6px 8px;
}

.badge-ok { background: #e9f5e6; color: #315f2f; }
.badge-warning { background: #fff4d8; color: #7a4b00; }
.badge-error { background: #fbe6e2; color: var(--danger); }
.distance-route { color: var(--leafgreen); font-weight: 700; }
.distance-direct { color: var(--swedishred); font-weight: 700; }

.readonly-box {
    background: #f8f0da;
    border: 1px solid var(--line);
    border-radius: 6px;
    min-height: 40px;
    padding: 8px 10px;
}

.relation-proposal {
    border-color: var(--fas-gold-dark);
    background: #fffaf0;
}

.inline-form {
    display: inline-block;
    margin: 0;
}

.inline-form select,
.inline-form input {
    min-width: 120px;
}

.history-popover {
    display: inline-block;
    position: relative;
}

.history-popover summary {
    list-style: none;
}

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

.history-panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
    min-width: 280px;
    padding: 10px 12px;
    position: absolute;
    right: 0;
    top: 34px;
    z-index: 5;
}

.history-panel p {
    margin: 0 0 10px;
}

.invoice-dialog {
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
    max-height: 88vh;
    max-width: 1180px;
    padding: 0;
    width: min(1180px, calc(100vw - 36px));
}

.invoice-dialog::backdrop {
    background: rgba(33, 42, 28, 0.42);
}

.invoice-dialog-header {
    align-items: flex-start;
    background: #f8f0da;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 16px;
    justify-content: space-between;
    padding: 16px 132px 16px 18px;
    position: relative;
}

.invoice-dialog-header h2,
.invoice-dialog-section h3 {
    margin-bottom: 4px;
}

.invoice-dialog-close {
    margin: 0;
    position: absolute;
    right: 18px;
    top: 16px;
}

.invoice-dialog-meta {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
    padding: 16px 18px 0;
}

.invoice-dialog-section,
.invoice-lines-form {
    padding: 16px 18px 0;
}

.invoice-dialog-section:last-child {
    padding-bottom: 18px;
}

.invoice-lines-table input,
.invoice-lines-table select {
    min-width: 98px;
}

.invoice-lines-table td:nth-child(3) input {
    min-width: 240px;
}

.check-label {
    align-items: center;
    display: inline-flex;
    font-weight: 400;
    gap: 6px;
    white-space: nowrap;
}

.check-label input {
    width: auto;
}

.invoice-status-actions {
    display: block;
}

.status-action-form {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 14px;
}

.status-action-form textarea {
    min-height: 74px;
}

.status-action-form .form-grid {
    grid-template-columns: minmax(220px, 0.7fr) minmax(280px, 1.3fr);
}

.compact-line {
    margin: 0 0 5px;
}

.invoice-history {
    border-top: 1px solid var(--line);
    margin-top: 16px;
}

.invoice-history p {
    border-bottom: 1px solid #eee2bf;
    margin: 0;
    padding: 9px 0;
}

.attachment-list {
    margin: 12px 0 0;
    padding-left: 18px;
}

.attachment-list li {
    margin-bottom: 6px;
}

.invoice-dialog-row > td {
    border-bottom: 0;
    height: 0;
    padding: 0;
}

.filter-dropdown {
    position: relative;
}

.filter-dropdown summary {
    background: #fff;
    border: 1px solid #bdbdbd;
    border-radius: 6px;
    cursor: pointer;
    min-height: 40px;
    padding: 8px 10px;
}

.filter-options {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
    display: grid;
    gap: 6px;
    margin-top: 6px;
    min-width: 220px;
    padding: 10px;
    position: absolute;
    z-index: 5;
}

.checkbox-row {
    align-items: center;
    display: flex;
    gap: 8px;
    font-weight: 500;
}

.checkbox-row input {
    flex: 0 0 auto;
    width: auto;
}

.assignment-update-form {
    margin: 0;
}

.assignment-mini-grid {
    display: grid;
    gap: 6px;
    grid-template-columns: minmax(130px, 1fr) repeat(3, minmax(92px, 0.7fr)) minmax(150px, 1.2fr) auto;
}

.assignment-mini-grid input,
.assignment-mini-grid select {
    min-width: 0;
}

.planning-update-form {
    margin: 0;
}

.planning-mini-grid {
    display: grid;
    gap: 6px;
    grid-template-columns: minmax(132px, 0.8fr) minmax(170px, 1fr) auto;
}

.planning-mini-grid input,
.planning-mini-grid select {
    min-width: 0;
}

.status-pill {
    border-radius: 999px;
    display: inline-flex;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    padding: 6px 9px;
    white-space: nowrap;
}

.status-new { background: #f8f0da; color: #3b5623; }
.status-planned { background: #e7f0fb; color: #24506f; }
.status-in_progress { background: #fff4d8; color: #7a4b00; }
.status-completed { background: #e9f5e6; color: #315f2f; }

.login-page {
    align-items: center;
    background:
        linear-gradient(135deg, rgba(233, 215, 171, 0.94), rgba(255, 255, 255, 0.82)),
        var(--bg);
    display: flex;
    min-height: 100vh;
    justify-content: center;
    padding: 22px;
}

@supports (min-height: 100svh) {
    .login-page {
        min-height: 100svh;
    }
}

.login-card {
    background: #fff;
    border: 1px solid #d5c18b;
    border-radius: 8px;
    box-shadow: 0 18px 44px rgba(59, 86, 35, 0.18);
    max-width: 440px;
    padding: 30px;
    width: calc(100vw - 32px);
}

.login-logo {
    align-items: center;
    background: var(--creamwhite);
    display: flex;
    justify-content: center;
    margin: -30px -30px 24px;
    min-height: 92px;
    padding: 18px;
}

.login-logo img {
    display: block;
    max-height: 64px;
    max-width: 210px;
    object-fit: contain;
}

.login-logo-fallback {
    color: var(--leafgreen);
    font-family: 'Oswald', Arial, Helvetica, sans-serif;
    font-size: 30px;
    font-weight: 600;
}

.login-actions {
    justify-content: space-between;
}

.login-forgot {
    font-size: 14px;
}

.profile-card h2 + .form-grid {
    margin-bottom: 22px;
}

.mobile-page {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.mobile-header {
    align-items: center;
    background: var(--creamwhite);
    border-bottom: 1px solid rgba(74, 107, 44, 0.18);
    box-shadow: 0 8px 22px rgba(47, 63, 37, 0.08);
    color: var(--leafgreen);
    display: flex;
    justify-content: space-between;
    min-height: 74px;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-brand {
    align-items: center;
    color: var(--leafgreen);
    display: inline-flex;
    font-size: 18px;
    font-weight: 800;
    gap: 10px;
    letter-spacing: 0;
    min-width: 0;
    text-decoration: none;
}

.mobile-brand img {
    display: block;
    height: 42px;
    max-width: 132px;
    object-fit: contain;
}

.mobile-brand span {
    white-space: nowrap;
}

.mobile-header-actions {
    background: var(--creamwhite);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 40px rgba(47, 63, 37, 0.18);
    display: none;
    gap: 8px;
    min-width: 230px;
    padding: 10px;
    position: absolute;
    right: 14px;
    top: calc(100% + 8px);
    z-index: 60;
}

.mobile-header-actions.is-open {
    display: grid;
}

.mobile-header a {
    color: var(--leafgreen);
}

.mobile-header-actions a,
.mobile-header-actions button {
    align-items: center;
    background: transparent;
    border-radius: 6px;
    border: 0;
    color: var(--leafgreen);
    display: flex;
    font-size: 16px;
    font-weight: 700;
    min-height: 44px;
    padding: 10px 12px;
    text-align: left;
    text-decoration: none;
}

.mobile-header-actions a:hover,
.mobile-header-actions button:hover {
    background: rgba(74, 107, 44, 0.08);
}

.mobile-menu-button {
    align-items: center;
    background: transparent;
    border: 3px solid var(--leafgreen);
    border-radius: 11px;
    box-shadow: none;
    color: var(--leafgreen);
    display: inline-grid;
    gap: 4px;
    height: 44px;
    justify-items: center;
    padding: 0;
    width: 44px;
}

.mobile-menu-button span {
    background: var(--leafgreen);
    border-radius: 99px;
    display: block;
    height: 3px;
    width: 19px;
}

.mobile-document-scanner {
    background: rgba(74, 107, 44, .045);
    border: 1px solid rgba(74, 107, 44, .24);
    border-radius: 10px;
    margin: 18px 0;
    padding: 16px;
}
.mobile-document-scanner h2, .mobile-document-scanner h3 { margin-top: 0; }
.scanner-source-actions, .scanner-options { display: flex; flex-wrap: wrap; gap: 10px; }
.scanner-file-button { cursor: pointer; display: inline-flex; }
.scanner-file-button input { height: 1px; opacity: 0; position: absolute; width: 1px; }
.scanner-editor, .scanner-result { margin-top: 16px; }
.scanner-editor-header { align-items: center; display: flex; justify-content: space-between; }
.scanner-live { margin-top: 16px; }
.scanner-live-header { align-items: center; display: flex; justify-content: space-between; }
.scanner-live-close { background: transparent; border: 0; color: var(--leafgreendark); font-size: 30px; height: 42px; line-height: 1; padding: 0; width: 42px; }
.scanner-live-view { background: #111; border-radius: 10px; line-height: 0; max-height: 70vh; overflow: hidden; position: relative; }
.scanner-live-view video { display: block; max-height: 70vh; object-fit: contain; width: 100%; }
.scanner-live-view canvas { height: 100%; inset: 0; pointer-events: none; position: absolute; width: 100%; }
.scanner-live-guide { background: rgba(0,0,0,.56); bottom: 8px; color: #fff; font-size: 12px; left: 50%; line-height: 1.2; padding: 6px 9px; position: absolute; transform: translateX(-50%); white-space: nowrap; }
.scanner-live-status { background: rgba(74,107,44,.1); border-radius: 7px; font-weight: 700; margin: 10px 0; padding: 10px; }
.scanner-canvas-wrap { background: #263020; border-radius: 8px; line-height: 0; overflow: hidden; position: relative; touch-action: none; }
.scanner-canvas-wrap canvas { display: block; height: auto; max-height: 68vh; object-fit: contain; width: 100%; }
#scanner-overlay-canvas { inset: 0; position: absolute; }
.scanner-instruction { font-size: 14px; font-weight: 700; margin: 10px 0; }
.scanner-options label { align-items: center; display: flex; gap: 6px; }
.scanner-result canvas { background: #fff; border: 1px solid var(--line); border-radius: 8px; display: block; height: auto; max-height: 65vh; object-fit: contain; width: 100%; }
.scanner-quality { border-radius: 7px; font-weight: 700; margin-top: 10px; padding: 10px; }
.scanner-quality.success { background: rgba(74,107,44,.12); color: var(--leafgreendark); }
.scanner-quality.warning { background: #fff3cd; color: #664d03; }
.scanner-fallback { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 16px; }
.scanner-details, .scanner-fallback { margin-bottom: 10px; }
.scanner-details summary, .scanner-fallback summary { color: var(--leafgreendark); cursor: pointer; font-weight: 700; padding: 8px 0; }
.scanner-upload-progress { margin: 10px 0; }
.scanner-upload-track { background: rgba(74,107,44,.14); border-radius: 99px; height: 10px; overflow: hidden; }
.scanner-upload-track span { background: var(--leafgreen); border-radius: inherit; display: block; height: 100%; transition: width .2s ease; width: 0; }
.scanner-upload-track span.is-error { background: #a4382f; }
.scanner-upload-meta { display: flex; font-size: 12px; justify-content: space-between; margin-top: 5px; }
.ocr-mapping-panel { background: rgba(74,107,44,.045); border: 1px solid rgba(74,107,44,.22); border-radius: 8px; margin: 14px 0; padding: 14px; }
.ocr-mapping-panel h3 { margin: 0 0 5px; }
.ocr-mapping-table td { min-width: 180px; vertical-align: top; }
.ocr-mapping-table td:first-child { min-width: 260px; white-space: normal; }
.ocr-mapping-table input, .ocr-mapping-table select { min-width: 170px; width: 100%; }
.ocr-raw-text { margin-top: 14px; }
.ocr-raw-text summary { color: var(--leafgreendark); cursor: pointer; font-weight: 700; }
.ocr-raw-text pre { background: #fff; border: 1px solid var(--line); border-radius: 6px; max-height: 360px; overflow: auto; padding: 12px; white-space: pre-wrap; }
.purchase-overview-head { align-items: end; }
.purchase-overview-head h2 { margin-bottom: 4px; }
.purchase-search { display: grid; gap: 4px; min-width: min(360px, 100%); }
.purchase-search label { font-size: 13px; font-weight: 700; }
.purchase-dialog { background: transparent; border: 0; height: min(92vh, 980px); max-height: 92vh; max-width: min(1180px, 94vw); padding: 0; width: 100%; }
.purchase-dialog::backdrop { background: rgba(28,37,22,.66); backdrop-filter: blur(2px); }
.purchase-dialog-card { box-sizing: border-box; height: 100%; margin: 0; overflow: auto; padding: 20px; }
.purchase-dialog-actions { align-items: center; margin: 0; }
.account-picker-field { align-items: stretch; display: grid; gap: 6px; grid-template-columns: minmax(90px,1fr) auto; }
.account-picker-field .btn { min-height: 40px; padding: 7px 10px; }
.ledger-picker-dialog { background: transparent; border: 0; max-height: 82vh; max-width: min(680px, 94vw); padding: 0; width: 100%; }
.ledger-picker-dialog::backdrop { background: rgba(28,37,22,.66); }
.ledger-picker-dialog .card { margin: 0; max-height: 82vh; overflow: auto; }
.ledger-picker-list { display: grid; gap: 6px; max-height: 52vh; overflow: auto; }
.ledger-picker-list button { align-items: baseline; background: #fff; border: 1px solid var(--line); border-radius: 6px; color: var(--text); cursor: pointer; display: grid; gap: 4px; grid-template-columns: 70px 1fr; padding: 10px; text-align: left; }
.ledger-picker-list button:hover { background: rgba(74,107,44,.08); border-color: var(--leafgreen); }
body:has(.purchase-dialog[open]) { overflow: hidden; }
@media (max-width: 700px) {
    .purchase-overview-head { align-items: stretch; display: grid; }
    .purchase-search { min-width: 0; width: 100%; }
    .purchase-dialog { height: 100dvh; max-height: 100dvh; max-width: 100vw; width: 100vw; }
    .purchase-dialog-card { border-radius: 0; padding: 12px; }
}

/* Fullscreen mobile document camera. Kept outside media queries so iOS cannot render it inline. */
body.mobile-page.scanner-camera-open { height: 100dvh !important; overflow: hidden !important; position: fixed; width: 100%; }
body.mobile-page .scanner-live:not([hidden]) {
    background: #000;
    display: block;
    height: 100dvh;
    inset: 0;
    margin: 0;
    overflow: hidden;
    padding: 0;
    position: fixed;
    width: 100vw;
    z-index: 10000;
}
body.mobile-page .scanner-live-header { height: 0; position: static; }
body.mobile-page .scanner-live-header strong { display: none; }
body.mobile-page .scanner-live-close {
    align-items: center;
    background: rgba(20,20,20,.72);
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 50%;
    color: #fff;
    display: flex;
    font-size: 34px;
    height: 52px;
    justify-content: center;
    left: max(16px, env(safe-area-inset-left));
    position: absolute;
    top: max(18px, env(safe-area-inset-top));
    width: 52px;
    z-index: 4;
}
body.mobile-page .scanner-live-view {
    border-radius: 0;
    height: 100%;
    inset: 0;
    max-height: none;
    max-width: none;
    position: absolute;
    width: 100%;
}
body.mobile-page .scanner-live-view video { height: 100%; max-height: none; object-fit: cover; width: 100%; }
body.mobile-page .scanner-live-view canvas { height: 100%; inset: 0; position: absolute; width: 100%; }
body.mobile-page .scanner-live-guide { display: none; }
body.mobile-page .scanner-live-status {
    background: rgba(0,0,0,.58);
    border-radius: 18px;
    bottom: calc(118px + env(safe-area-inset-bottom));
    color: #fff;
    font-size: 13px;
    left: 50%;
    margin: 0;
    max-width: calc(100vw - 40px);
    padding: 7px 13px;
    position: absolute;
    text-align: center;
    transform: translateX(-50%);
    white-space: nowrap;
    z-index: 4;
}
body.mobile-page .scanner-live > .form-actions { bottom: calc(20px + env(safe-area-inset-bottom)); height: 82px; left: 0; margin: 0; position: absolute; width: 100%; z-index: 4; }
body.mobile-page .scanner-shutter {
    background: #fff;
    border: 7px solid rgba(30,30,30,.78);
    border-radius: 50%;
    box-shadow: 0 0 0 3px #fff;
    display: block;
    height: 72px;
    left: 50%;
    padding: 0;
    position: absolute;
    transform: translateX(-50%);
    width: 72px;
}
body.mobile-page .scanner-shutter span { clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; }
body.mobile-page #scanner-camera-stop { display: none; }

@media (max-width: 600px) {
    .mobile-header { min-height: 56px; padding: 7px 10px; }
    .mobile-brand { font-size: 16px; gap: 7px; }
    .mobile-brand img { height: 30px; max-width: 88px; }
    .mobile-brand span { font-size: 16px; }
    .mobile-menu-button { height: 42px; width: 42px; }
    .mobile-menu-button span { height: 3px; width: 18px; }
    .mobile-content { min-height: calc(100vh - 102px); padding: 10px 8px 18px; }
    .mobile-content > .toolbar { margin-bottom: 8px; }
    .mobile-content > .toolbar h1 { font-size: 20px; line-height: 1.15; margin: 0; }
    #mobile-scan-form.card { padding: 10px; }
    #mobile-scan-form .form-row { margin-bottom: 8px; }
    #mobile-scan-form input, #mobile-scan-form textarea { min-height: 40px; padding: 8px 9px; }
    .mobile-document-scanner { margin: 8px 0 10px; padding: 10px; }
    .mobile-document-scanner h2 { font-size: 18px; margin-bottom: 3px; }
    .mobile-document-scanner h3 { font-size: 16px; margin-bottom: 5px; }
    .mobile-document-scanner .hint { font-size: 12px; margin: 3px 0 8px; }
    .scanner-source-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
    .scanner-source-actions .btn, .scanner-source-actions .btn-primary { font-size: 13px; justify-content: center; min-height: 42px; padding: 7px 8px; }
    body.scanner-camera-open, body.scanner-editor-open, body.scanner-result-open { height: 100svh; overflow: hidden; position: fixed; width: 100%; }
    .scanner-live:not([hidden]) {
        background: var(--creamwhite);
        box-sizing: border-box;
        display: grid;
        grid-template-rows: 42px minmax(0, 1fr) auto auto;
        height: 100svh;
        inset: 0;
        margin: 0;
        overflow: hidden;
        padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
        position: fixed;
        width: 100vw;
        z-index: 1000;
    }
    .scanner-live-header { height: 42px; }
    .scanner-live-header strong { font-size: 17px; }
    .scanner-live-view {
        align-self: center;
        aspect-ratio: 3 / 4;
        border-radius: 8px;
        justify-self: center;
        max-height: calc(100svh - 150px);
        max-width: min(100%, calc((100svh - 150px) * .75));
        width: 100%;
    }
    .scanner-live-view video { height: 100%; max-height: none; object-fit: contain; width: 100%; }
    .scanner-live-view canvas { height: 100%; width: 100%; }
    .scanner-live-guide { bottom: 6px; font-size: 11px; max-width: 90%; overflow: hidden; text-overflow: ellipsis; }
    .scanner-editor:not([hidden]), .scanner-result:not([hidden]) {
        background: var(--creamwhite);
        box-sizing: border-box;
        display: grid;
        grid-template-rows: 42px minmax(0, 1fr) auto auto;
        height: 100svh;
        inset: 0;
        margin: 0;
        overflow: hidden;
        padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
        position: fixed;
        width: 100vw;
        z-index: 1001;
    }
    .scanner-editor-header { height: 42px; }
    .scanner-editor-header strong, .scanner-result h3 { font-size: 17px; margin: 0; }
    .scanner-canvas-wrap {
        align-self: center;
        aspect-ratio: var(--scan-aspect, 3 / 4);
        justify-self: center;
        max-height: calc(100svh - 174px);
        max-width: 100%;
        width: min(100%, calc((100svh - 174px) * var(--scan-ratio, .75)));
    }
    .scanner-canvas-wrap canvas { height: 100%; max-height: none; object-fit: fill; width: 100%; }
    .scanner-result canvas { align-self: center; height: auto; justify-self: center; max-height: calc(100svh - 174px); max-width: 100%; width: auto; }
    .scanner-live, .scanner-editor, .scanner-result { margin-top: 9px; }
    .scanner-live-status, .scanner-quality { font-size: 12px; margin: 6px 0; padding: 7px; }
    .scanner-instruction { font-size: 12px; margin: 6px 0; }
    .scanner-options { font-size: 12px; gap: 7px; }
    .scanner-editor .form-actions, .scanner-result .form-actions, .scanner-live .form-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 7px; }
    .scanner-editor .form-actions button, .scanner-result .form-actions button, .scanner-live .form-actions button { font-size: 13px; min-height: 42px; padding: 7px; }
    .scanner-canvas-wrap canvas { max-height: 52svh; }
    .scanner-result canvas { max-height: 48svh; }
    .scanner-fallback { margin-top: 8px; padding-top: 6px; }
    #scanner-upload-status { font-size: 12px; margin: 5px 0; }
    #scanner-submit { min-height: 44px; width: 100%; }
}

.mobile-menu-button[aria-expanded="true"] {
    background: rgba(74, 107, 44, 0.08);
}

.mobile-menu-button[aria-expanded="true"] span {
    background: var(--leafgreen);
}

.mobile-location-button {
    width: 100%;
}

.mobile-location-button[aria-pressed="true"] {
    background: var(--leafgreen);
    border-color: var(--leafgreen);
    color: var(--creamwhite);
}

.mobile-content {
    margin: 0 auto;
    max-width: 760px;
    min-height: calc(100vh - 126px);
    padding: 18px 14px 28px;
}

.mobile-footer {
    background: var(--leafgreen);
    color: var(--creamwhite);
    font-size: 13px;
    font-weight: 700;
    padding: 18px 14px max(24px, env(safe-area-inset-bottom));
    text-align: center;
}

.mobile-date {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr auto;
}

.mobile-date label {
    grid-column: 1 / -1;
}

.mobile-job {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    display: grid;
    gap: 4px;
    margin-bottom: 10px;
    padding: 14px;
    text-decoration: none;
}

.mobile-assignment-head p {
    margin: 8px 0;
}

.mobile-line {
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 8px;
    padding: 10px 0;
}

.mobile-line label {
    display: grid;
    gap: 5px;
}

.mobile-signature {
    border-top: 1px solid var(--line);
    margin-top: 16px;
    padding-top: 14px;
}

.checkbox-line {
    align-items: center;
    display: flex;
    gap: 8px;
}

.signature-pad {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    display: block;
    height: 150px;
    max-width: 100%;
    touch-action: none;
    width: 100%;
}

.mobile-pin-login {
    background: linear-gradient(180deg, var(--leafgreen) 0%, var(--leafgreendark) 100%);
    border: 0;
    border-radius: 8px;
    color: var(--creamwhite);
    display: grid;
    gap: 14px;
    margin-bottom: 18px;
    overflow: hidden;
    padding: 24px 14px 18px;
    width: 100%;
}

.mobile-pin-title {
    color: var(--creamwhite);
    display: none;
    font-family: 'Oswald', Arial, Helvetica, sans-serif;
    font-size: 34px;
    font-weight: 600;
    line-height: 1.1;
    text-align: center;
}

.mobile-pin-login[hidden],
.mobile-face-button[hidden],
.mobile-pin-fallback-button[hidden],
.mobile-pin-field[hidden],
#mobile-pin-submit[hidden] {
    display: none;
}

.mobile-pin-field {
    min-height: 0;
}

.mobile-face-button,
.mobile-pin-fallback-button {
    width: 100%;
}

.mobile-pin-login .hint {
    color: rgba(233, 215, 171, 0.82);
    text-align: center;
}

.mobile-pin-dots {
    display: flex;
    gap: 14px;
    justify-content: center;
    margin: 4px 0 18px;
}

.mobile-pin-dots span {
    border: 3px solid var(--creamwhite);
    border-radius: 50%;
    display: block;
    height: 18px;
    opacity: 0.95;
    width: 18px;
}

.mobile-pin-dots span.is-filled {
    background: var(--creamwhite);
}

.mobile-pin-keypad {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, 82px);
    justify-content: center;
    margin: 0 auto;
    max-width: 274px;
    width: 100%;
}

.mobile-pin-key {
    align-items: center;
    aspect-ratio: 1;
    background: rgba(233, 215, 171, 0.16);
    border: 1px solid rgba(233, 215, 171, 0.22);
    border-radius: 50%;
    color: var(--creamwhite);
    display: inline-flex;
    font-size: 38px;
    font-weight: 400;
    height: 82px;
    justify-content: center;
    line-height: 1;
    padding: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    width: 82px;
}

.mobile-pin-key:active {
    background: rgba(233, 215, 171, 0.28);
    transform: scale(0.98);
}

.mobile-pin-biometric,
.mobile-pin-backspace {
    font-size: 26px;
    font-weight: 700;
}

.mobile-pin-biometric svg {
    display: block;
    height: 32px;
    width: 32px;
}

.mobile-pin-actions {
    justify-content: center;
}

.mobile-pin-actions .btn {
    background: transparent;
    border-color: rgba(233, 215, 171, 0.45);
    color: var(--creamwhite);
}

@media (max-width: 820px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
    .content { margin: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .invoice-dialog-meta { grid-template-columns: 1fr; }
    .invoice-dialog { width: calc(100vw - 18px); }
    .assignment-mini-grid,
    .planning-mini-grid { grid-template-columns: 1fr; }
    .app-header, .app-footer { align-items: flex-start; flex-direction: column; gap: 8px; }

    .login-page {
        align-items: stretch;
        padding: 16px;
    }

    .login-card {
        align-self: center;
        max-height: calc(100svh - 32px);
        overflow: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-pin-keypad {
        gap: 12px;
        grid-template-columns: repeat(3, 74px);
        max-width: 246px;
    }

    .mobile-pin-key {
        font-size: 34px;
        height: 74px;
        width: 74px;
    }

    .mobile-pin-biometric svg {
        height: 28px;
        width: 28px;
    }
    .mobile-header-actions {
        left: 14px;
        min-width: 0;
    }
    .mobile-brand img { height: 36px; max-width: 108px; }
    .mobile-brand span { font-size: 17px; }
}

@media (max-width: 820px) {
    .mobile-login-body {
        background: var(--leafgreen);
    }

    .mobile-login-body .login-page {
        background: var(--leafgreen);
    }

    .mobile-login-body.mobile-trusted-login {
        background: var(--leafgreen);
        height: 100svh;
        overflow: hidden;
    }

    .mobile-login-body.mobile-trusted-login .login-page {
        align-items: center;
        background: var(--leafgreen);
        height: 100svh;
        min-height: 100svh;
        overflow: hidden;
        padding: max(14px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
    }

    .mobile-login-body.mobile-trusted-login .login-card {
        background: transparent;
        border: 0;
        box-shadow: none;
        display: grid;
        max-height: calc(100svh - 20px);
        max-width: 390px;
        overflow: hidden;
        padding: 0;
        width: 100%;
    }

    .mobile-login-body.mobile-trusted-login .login-logo {
        display: none;
    }

    .mobile-login-body.mobile-trusted-login .login-card > h1,
    .mobile-login-body.mobile-trusted-login .login-card > .hint,
    .mobile-login-body.mobile-trusted-login .mobile-face-button,
    .mobile-login-body.mobile-trusted-login #mobile-pin-submit,
    .mobile-login-body.mobile-trusted-login #mobile-face-status {
        display: none !important;
    }

    .mobile-login-body.mobile-trusted-login .mobile-pin-login {
        background: transparent;
        border-radius: 0;
        gap: 22px;
        margin: 0;
        padding: 0;
    }

    .mobile-login-body.mobile-trusted-login .mobile-pin-title {
        display: block;
        margin: 8px 0 8px;
    }

    .mobile-login-body.mobile-trusted-login .mobile-pin-dots {
        gap: 12px;
        margin: 0 0 18px;
    }

    .mobile-login-body.mobile-trusted-login .mobile-pin-dots span {
        border-color: var(--creamwhite);
        height: 15px;
        width: 15px;
    }

    .mobile-login-body.mobile-trusted-login .mobile-pin-keypad {
        gap: 18px;
        grid-template-columns: repeat(3, 76px);
        max-width: 264px;
    }

    .mobile-login-body.mobile-trusted-login .mobile-pin-key {
        background: rgba(233, 215, 171, 0.14);
        border-color: rgba(233, 215, 171, 0.32);
        box-shadow: none;
        color: var(--creamwhite);
        font-size: 35px;
        height: 76px;
        width: 76px;
    }

    .mobile-login-body.mobile-trusted-login .mobile-pin-biometric svg {
        height: 30px;
        width: 30px;
    }

    .mobile-login-body.mobile-trusted-login .mobile-pin-backspace {
        font-size: 25px;
    }
}
