:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --ink: #16202a;
    --muted: #687482;
    --line: #d9dee5;
    --primary: #176b5b;
    --primary-dark: #0f4d42;
    --accent: #b74b33;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
}

.receipt-link {
    background: transparent;
    border: 0;
    color: #00689f;
    display: inline;
    font: inherit;
    font-weight: 650;
    padding: 0;
    text-decoration: none;
}

.receipt-link:hover,
.receipt-link:focus {
    text-decoration: underline;
}

.table-link {
    color: #00689f;
    font-weight: 650;
    text-decoration: none;
}

.table-link:hover,
.table-link:focus {
    text-decoration: underline;
}

.supplier-picker-field,
.location-picker-field {
    display: grid;
    gap: 7px;
    min-width: 0;
    position: relative;
}

.grid > .supplier-picker-field,
.grid > .location-picker-field {
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
}

.supplier-picker-control,
.location-picker-control {
    position: relative;
}

.supplier-picker-control input,
.location-picker-control input {
    padding-right: 42px;
}

.supplier-picker-search,
.location-picker-search {
    align-items: center;
    border-left: 1px solid var(--line);
    bottom: 1px;
    color: #00689f;
    display: flex;
    font-size: 24px;
    justify-content: center;
    pointer-events: none;
    position: absolute;
    right: 1px;
    top: 1px;
    width: 40px;
}

.supplier-picker-options,
.location-picker-options {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 8px 22px rgb(22 32 42 / 18%);
    left: 0;
    max-height: 240px;
    overflow-y: auto;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 40;
}

.supplier-picker-options button,
.location-picker-options button {
    background: #fff;
    border-radius: 0;
    color: var(--ink);
    display: block;
    font-weight: 500;
    padding: 10px 12px;
    text-align: left;
    width: 100%;
}

.supplier-picker-options button:hover,
.supplier-picker-options button:focus,
.supplier-picker-options button.active,
.location-picker-options button:hover,
.location-picker-options button:focus,
.location-picker-options button.active {
    background: #edf6fa;
    color: #005985;
}

.supplier-picker-options button.supplier-picker-create {
    color: #00689f;
    font-weight: 700;
}

.location-picker-options button.location-picker-create {
    color: #00689f;
    font-weight: 700;
}

.supplier-picker-options button.supplier-picker-error {
    color: #b42318;
    cursor: default;
}

.location-picker-options button.location-picker-error {
    color: #b42318;
    cursor: default;
}

.receipt-dialog {
    border: 1px solid var(--line);
    border-radius: 8px;
    height: min(88vh, 900px);
    max-width: 1100px;
    overflow: hidden;
    padding: 0;
    width: min(92vw, 1100px);
}

.receipt-dialog::backdrop {
    background: rgb(22 32 42 / 58%);
}

.receipt-dialog-head {
    align-items: center;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    height: 56px;
    justify-content: space-between;
    padding: 0 18px;
}

.section-title-row {
    align-items: center;
    display: flex;
    gap: 14px;
    justify-content: space-between;
    margin-bottom: 8px;
}

.section-title-row h2 {
    margin: 0;
}

.receipt-navigation {
    align-items: center;
    display: flex;
    gap: 8px;
}

.receipt-navigation > button:not(.dialog-close) {
    background: #34465a;
    font-size: 22px;
    height: 34px;
    line-height: 1;
    min-width: 34px;
    padding: 0 8px;
}

.receipt-navigation button:disabled,
.section-title-row button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.receipt-navigation span {
    color: var(--muted);
    font-size: 13px;
    min-width: 58px;
    text-align: center;
}

.receipt-dialog iframe {
    border: 0;
    display: block;
    height: calc(100% - 56px);
    width: 100%;
}

.link-receipt-dialog {
    border: 1px solid var(--line);
    border-radius: 8px;
    height: calc(100dvh - 16px);
    max-height: none;
    max-width: 1500px;
    margin: 8px auto;
    overflow: hidden;
    padding: 0;
    width: 96vw;
}

.link-receipt-dialog::backdrop {
    background: rgb(22 32 42 / 62%);
}

.file-type-switch {
    background: #eef1f4;
    border: 1px solid var(--line);
    border-radius: 6px;
    display: grid;
    gap: 4px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    height: 48px;
    padding: 4px;
    width: 100%;
}

.file-type-switch button {
    align-items: center;
    background: transparent;
    color: var(--muted);
    display: flex;
    font-size: 12px;
    height: 38px;
    justify-content: center;
    line-height: 1.15;
    padding: 5px 8px;
    text-align: center;
}

.file-type-switch button.active {
    background: var(--primary);
    color: #fff;
}

.link-receipt-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(420px, 0.75fr);
    height: calc(100% - 56px);
}

.link-receipt-preview {
    align-items: center;
    background: #eef1f4;
    border-right: 1px solid var(--line);
    display: flex;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
    padding: 16px;
}

.link-receipt-preview iframe {
    border: 0;
    height: 100%;
    width: 100%;
}

.receipt-image-stage {
    height: 100%;
    position: relative;
    width: 100%;
}

.receipt-image-scroll {
    align-items: center;
    display: flex;
    height: 100%;
    justify-content: center;
    overflow: auto;
    width: 100%;
}

.link-receipt-preview img {
    display: block;
    flex: 0 0 auto;
    height: 100%;
    object-fit: contain;
    width: 100%;
}

.receipt-zoom-controls {
    align-items: center;
    background: rgb(255 255 255 / 94%);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 4px 14px rgb(22 32 42 / 14%);
    display: flex;
    gap: 6px;
    left: 12px;
    padding: 5px;
    position: absolute;
    top: 12px;
    z-index: 2;
}

.receipt-zoom-controls button {
    background: #34465a;
    min-width: 32px;
    padding: 7px 9px;
}

.receipt-zoom-controls span {
    color: var(--ink);
    font-size: 13px;
    min-width: 44px;
    text-align: center;
}

.link-receipt-preview [hidden] {
    display: none;
}

.link-receipt-form,
.link-document-form,
.link-existing-expense-form {
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    padding: 22px;
}

.link-receipt-form fieldset {
    flex: 0 0 auto;
    min-width: 0;
    padding: 14px;
}

.link-receipt-form > :not(.link-receipt-actions),
.link-document-form > :not(.link-receipt-actions),
.link-existing-expense-form > :not(.link-receipt-actions) {
    flex-shrink: 0;
}

#link-trip-fields {
    display: grid;
    gap: 16px;
}

#link-trip-fields.is-hidden {
    pointer-events: none;
    visibility: hidden;
}

.trip-choice-list,
#matching-trip-options {
    display: grid;
    gap: 10px;
}

#matching-trip-options:empty {
    display: none;
}

.radio-option {
    align-items: center;
    display: flex;
    gap: 9px;
    margin: 0;
}

.radio-option input[type="radio"] {
    flex: 0 0 auto;
    margin: 0;
    width: auto;
}

.link-document-form[hidden] {
    display: none;
}

.link-existing-expense-form[hidden] {
    display: none;
}

.link-receipt-form[hidden] {
    display: none;
}

.document-field-placeholder {
    min-height: 66px;
    visibility: hidden;
}

.document-trip-placeholder {
    min-height: 330px;
    pointer-events: none;
    visibility: hidden;
}

.link-receipt-actions {
    background: #fff;
    bottom: -22px;
    display: grid;
    gap: 10px;
    margin-top: auto;
    padding: 10px 0 22px;
    position: sticky;
    width: 100%;
    z-index: 5;
}

.link-receipt-actions button {
    align-items: center;
    display: flex;
    height: 40px;
    justify-content: center;
    line-height: 1.15;
    padding: 6px 12px;
    text-align: center;
    width: 100%;
}

.link-existing-expense-spacer {
    flex: 1 1 auto;
    min-height: 0;
}

.existing-expense-summary {
    color: var(--muted);
    min-height: 22px;
}

.receipt-edit-actions {
    align-items: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.receipt-edit-actions .field-help {
    flex-basis: 100%;
}

#edit-trip-fields {
    display: grid;
    gap: 16px;
}

#edit-trip-fields[hidden] {
    display: none;
}

.trip-expense-table input[type="checkbox"] {
    width: auto;
}

button.danger-button {
    background: #b42318;
}

button.danger-button:hover,
button.danger-button:focus {
    background: #8f1c13;
}

.dashboard-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
}

.trips-panel {
    margin-top: 18px;
}

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

.topbar {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 24px;
    justify-content: space-between;
    padding: 14px 28px;
}

.brand {
    color: var(--primary-dark);
    font-size: 20px;
    font-weight: 800;
    text-decoration: none;
}

nav {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

nav a,
.nav-dropdown-label {
    color: var(--muted);
    font-weight: 650;
    text-decoration: none;
}

.nav-customer-selector {
    align-items: center;
    display: flex;
    gap: 7px;
}

.nav-customer-selector label {
    font-size: 12px;
    gap: 0;
}

.nav-customer-selector select {
    font-size: 13px;
    max-width: 230px;
    padding: 7px 9px;
}

.impersonate-trigger {
    background: #34465a;
    padding: 8px 12px;
}

.impersonate-trigger.active {
    background: #b42318;
}

.impersonation-dialog {
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    max-width: 520px;
    padding: 0;
    width: calc(100% - 32px);
}

.impersonation-dialog::backdrop {
    background: rgb(22 32 42 / 50%);
}

.dialog-head {
    align-items: flex-start;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 20px;
    justify-content: space-between;
    padding: 22px;
}

.dialog-close {
    background: transparent;
    color: var(--muted);
    font-size: 28px;
    line-height: 1;
    padding: 0;
}

.dialog-form {
    border: 0;
    border-radius: 0;
}

.stop-impersonation-form {
    border-top: 1px solid var(--line);
    padding: 18px 22px 22px;
}

.stop-impersonation-form button {
    background: #b42318;
    width: 100%;
}

.nav-dropdown {
    position: relative;
}

.nav-dropdown-label::after {
    content: " ▾";
    font-size: 11px;
}

.nav-dropdown-menu {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 10px 24px rgb(22 32 42 / 14%);
    display: none;
    min-width: 180px;
    padding: 6px;
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    z-index: 20;
}

.nav-dropdown-left .nav-dropdown-menu {
    left: 0;
    right: auto;
}

.nav-dropdown:hover .nav-dropdown-menu {
    display: grid;
}

.nav-dropdown-menu::before {
    content: "";
    height: 12px;
    left: 0;
    position: absolute;
    right: 0;
    top: -12px;
}

.nav-dropdown-menu a {
    border-radius: 4px;
    padding: 10px 12px;
    white-space: nowrap;
}

.nav-dropdown-menu a:hover,
.nav-dropdown-menu a:focus {
    background: var(--bg);
    color: var(--primary-dark);
}

.container {
    margin: 0 auto;
    max-width: 1120px;
    padding: 32px 20px 56px;
}

.page-head {
    align-items: end;
    display: flex;
    gap: 20px;
    justify-content: space-between;
    margin-bottom: 24px;
}

h1,
h2 {
    margin: 0 0 8px;
}

p {
    color: var(--muted);
    margin: 0;
}

.actions {
    display: flex;
    gap: 10px;
}

.actions .inline-action-form {
    margin-left: 0;
}

.button,
button {
    background: var(--primary);
    border: 0;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 750;
    justify-content: center;
    padding: 11px 16px;
    text-decoration: none;
}

.button.secondary {
    background: #34465a;
}

.auth-panel,
.form,
.grid > div,
.table-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
}

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

.document-list-panel,
.todo-panel {
    margin-top: 22px;
}

.customer-tabs {
    margin-top: 24px;
}

.tabs {
    align-items: flex-end;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 8px;
}

.tab {
    background: #eef3f7;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    color: var(--muted);
    font-weight: 750;
    padding: 10px 18px;
}

.tab.active {
    background: var(--surface);
    color: var(--text);
}

.tab-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 0;
    border-radius: 0 0 8px 8px;
    padding: 22px 24px;
}

.tab-panel-head,
.section-head {
    align-items: center;
    display: flex;
    gap: 14px;
    justify-content: space-between;
    margin-bottom: 16px;
}

.tab-panel-head h2,
.section-head h2 {
    margin: 0;
}

.tab-panel-head p {
    color: var(--muted);
    margin: 4px 0 0;
}

.section-head.compact {
    min-height: 34px;
}

.grid.align-start {
    align-items: start;
}

.filter-form {
    margin-bottom: 18px;
    max-width: 420px;
}

.year-selector {
    display: flex;
    gap: 12px;
    min-width: 150px;
}

.year-summary-controls {
    align-items: flex-end;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
}

.year-status-form {
    align-items: center;
    display: flex;
    gap: 10px;
}

.report-status {
    border: 1px solid #d3dfeb;
    border-radius: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    padding: 9px 11px;
}

.report-status.submitted {
    background: #eef8f4;
    border-color: #b8ded1;
    color: var(--primary-dark);
}

.report-status.ongoing {
    background: #fff8e8;
    border-color: #ead39a;
    color: #76520a;
}

.mailbox-log-panel td {
    vertical-align: top;
}

.mailbox-log-meta {
    color: var(--muted);
    display: block;
    font-size: 12px;
    margin-top: 3px;
}

.mail-status {
    border-radius: 999px;
    display: inline-flex;
    font-size: 12px;
    font-weight: 750;
    padding: 4px 9px;
    white-space: nowrap;
}

.mail-status.saved {
    background: #ecfdf5;
    color: #0f766e;
}

.mail-status.skipped {
    background: #fff7ed;
    color: #c2410c;
}

.mail-status.failed {
    background: #fef2f2;
    color: #b42318;
}

.mail-import-output {
    border: 1px solid #d3dfeb;
    border-radius: 8px;
    margin-bottom: 18px;
    padding: 14px 16px;
}

.mail-import-output.ok {
    background: #ecfdf5;
    border-color: #b8ded1;
}

.mail-import-output.failed {
    background: #fef2f2;
    border-color: #f2b8b5;
}

.mail-import-output pre {
    margin: 8px 0 0;
    white-space: pre-wrap;
}

.summary-strip {
    border-bottom: 1px solid var(--line);
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin-bottom: 22px;
}

.summary-strip > div {
    display: grid;
    gap: 5px;
    padding: 16px 18px;
}

.summary-strip > div + div {
    border-left: 1px solid var(--line);
}

.summary-strip span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.summary-strip strong {
    color: var(--ink);
    font-size: 18px;
}

.year-summary-panel {
    margin-top: 18px;
}

.settings-grid {
    display: grid;
    gap: 18px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-section {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 22px;
}

.settings-section h2 {
    margin-top: 0;
}

.settings-section-wide {
    grid-column: 1 / -1;
}

.compact-form {
    align-items: end;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr) auto;
}

.compact-form .checkbox {
    grid-column: 1 / -1;
}

.settings-list {
    border-top: 1px solid var(--line);
    display: grid;
    margin-top: 18px;
}

.settings-list > span,
.settings-list > div,
.settings-list-link {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    padding: 10px 2px;
}

.settings-list-link {
    color: #00689f;
    font-weight: 700;
    text-decoration: none;
}

.settings-list-link:hover,
.settings-list-link:focus {
    text-decoration: underline;
}

[data-travel-settings] {
    display: grid;
    gap: 18px;
}

.table-action {
    text-align: right;
    white-space: nowrap;
}

.table-action a {
    color: var(--primary-dark);
    font-weight: 750;
}

.table-action .table-button {
    color: #fff;
    padding: 7px 11px;
}

.users-panel {
    background: #fff;
    border: 1px solid #d3dfeb;
    border-radius: 8px;
    font-family: Arial, Helvetica, sans-serif;
    max-width: 740px;
    min-height: 300px;
    padding: 20px 22px 28px;
}

.users-panel-head {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 34px;
}

.users-panel-head h1 {
    color: #1c2733;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.25;
    margin: 0;
}

.users-create-link {
    color: #00689f;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}

.users-create-link:hover,
.users-create-link:focus {
    text-decoration: underline;
}

.users-table th {
    color: #607087;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.users-table td {
    color: #17212b;
    font-size: 14px;
    font-weight: 400;
}

.users-table th,
.users-table td {
    border-bottom-color: #d3dfeb;
    height: 57px;
    padding: 10px;
}

.users-table th:first-child,
.users-table td:first-child {
    width: 34%;
}

.users-table th:nth-child(2),
.users-table td:nth-child(2) {
    width: 42%;
}

.user-name-link {
    color: #00689f;
    font-size: 14px;
    font-weight: 400;
    text-decoration: none;
}

.user-name-link:hover,
.user-name-link:focus {
    text-decoration: underline;
}

.inline-action-form {
    display: inline-block;
    margin-left: 8px;
}

.outline-button,
button.outline-button {
    align-items: center;
    background: #fff !important;
    border: 1px solid #0071ad !important;
    border-radius: 6px;
    color: #00689f !important;
    display: inline-flex;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 13px;
    font-weight: 700;
    height: 32px;
    justify-content: center;
    line-height: 1;
    padding: 0 11px;
    text-decoration: none;
}

.outline-button:hover,
.outline-button:focus,
button.outline-button:hover,
button.outline-button:focus {
    background: #f0f8fc !important;
    color: #005985 !important;
}

.outline-button.danger,
button.outline-button.danger {
    border-color: #c5281c !important;
    color: #b42318 !important;
}

.outline-button.danger:hover,
.outline-button.danger:focus,
button.outline-button.danger:hover,
button.outline-button.danger:focus {
    background: #fff3f2 !important;
    color: #921b13 !important;
}

.admin-links {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.admin-links a {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 6px;
    padding: 22px;
    text-decoration: none;
}

.admin-links a:hover {
    border-color: var(--primary);
}

.admin-links strong {
    color: var(--primary-dark);
    font-size: 18px;
}

.admin-links span {
    color: var(--muted);
}

.auth-panel {
    margin: 80px auto 0;
    max-width: 420px;
}

.form {
    display: grid;
    gap: 18px;
}

.form.wide {
    max-width: 920px;
}

.grid {
    display: grid;
    gap: 18px;
}

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

label {
    color: var(--muted);
    display: grid;
    font-size: 14px;
    font-weight: 700;
    gap: 7px;
}

.field-help {
    color: var(--muted);
    font-size: 13px;
    font-weight: 400;
}

input,
select,
textarea {
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    font: inherit;
    padding: 11px 12px;
    width: 100%;
}

textarea {
    resize: vertical;
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 16px;
    margin: 0;
    padding: 18px;
}

legend {
    font-weight: 800;
    padding: 0 8px;
}

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

.checkbox input {
    width: auto;
}

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

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

th {
    color: var(--muted);
    font-size: 13px;
}

.notice {
    background: #eef8f4;
    border: 1px solid #b8ded1;
    border-radius: 8px;
    color: var(--primary-dark);
    font-weight: 750;
    margin-bottom: 20px;
    padding: 12px 14px;
}

.mail-import-result {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 24px;
    padding: 18px;
}

.mail-import-result.success {
    border-color: #b8ded1;
}

.mail-import-result.error {
    border-color: #efb8b8;
}

.mail-import-result pre {
    background: #0f1720;
    border-radius: 8px;
    color: #e5edf5;
    margin: 10px 0 0;
    overflow-x: auto;
    padding: 14px;
    white-space: pre-wrap;
}

@media (max-width: 760px) {
    .topbar,
    .page-head {
        align-items: stretch;
        flex-direction: column;
    }

    nav {
        align-items: flex-start;
    }

    .nav-dropdown-menu {
        left: 0;
        right: auto;
    }

    .grid.two {
        grid-template-columns: 1fr;
    }

    .admin-links {
        grid-template-columns: 1fr;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .settings-section-wide {
        grid-column: auto;
    }

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

    .year-summary-controls,
    .year-selector {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .summary-strip > div + div {
        border-left: 0;
    }

    .summary-strip > div:nth-child(even) {
        border-left: 1px solid var(--line);
    }

    .link-receipt-dialog {
        height: 96vh;
        width: 96vw;
    }

    .link-receipt-layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(280px, 42vh) 1fr;
    }

    .link-receipt-preview {
        border-bottom: 1px solid var(--line);
        border-right: 0;
    }
}
