:root {
    color-scheme: light;
    --bg: #f2f6f9;
    --panel: #fff;
    --ink: #142b3d;
    --muted: #4f6576;
    --line: #dce6ed;
    --primary: #007197;
    --primary-dark: #005877;
    --sidebar: #102737;
    --radius: 9px;
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.5 var(--font);
}

h1, h2, h3, p, dl, dd { margin: 0; }
h1 { font-size: clamp(25px, 3vw, 35px); line-height: 1.2; letter-spacing: -.025em; overflow-wrap: anywhere; }
h2 { font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
h3 { font-size: 14px; }
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button, summary { cursor: pointer; }
:focus-visible { outline: 2px solid #0092bf; outline-offset: 3px; }
[hidden] { display: none !important; }
small, .muted { color: var(--muted); }
small { font-size: 12px; }
.multiline { white-space: pre-line; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.amount { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 5;
    width: 226px;
    display: flex;
    flex-direction: column;
    overflow: auto;
    background: var(--sidebar);
    color: #fff;
}

.brand, .login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 760;
    letter-spacing: .05em;
}

.brand {
    padding: 22px 17px;
    color: #fff;
    border-bottom: 1px solid #2c4759;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 37px;
    height: 37px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 4px #122e4730;
    flex: 0 0 auto;
}

.brand-mark img, .doc-logo { object-fit: contain; }
.main-nav { padding: 15px 12px; }
.main-nav a {
    display: block;
    padding: 9px 12px;
    margin: 2px 0;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #e1eef5;
}
.main-nav a:hover { background: #1e3f52; text-decoration: none; }
.main-nav a[aria-current] {
    border-color: #306179;
    background: #1c455c;
    color: #fff;
    box-shadow: inset 3px 0 #54d5e9;
    font-weight: 650;
}

.menu-module { margin-top: 5px; }
.menu-module > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 11px;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #e1eef5;
    font-weight: 650;
    list-style: none;
}
.menu-module > summary::-webkit-details-marker { display: none; }
.menu-module > summary::after {
    content: '';
    width: 7px;
    height: 7px;
    margin-right: 3px;
    border-right: 2px solid #95bccd;
    border-bottom: 2px solid #95bccd;
    transform: rotate(-45deg);
}
.menu-module[open] > summary { color: #fff; }
.menu-module[open] > summary::after { transform: rotate(45deg); }
.menu-module > summary:hover { background: #1e3f52; }
.module-links { margin: 3px 0 4px 10px; padding-left: 6px; border-left: 1px solid #345467; }
.module-links a { padding: 6px 9px; font-size: 13px; }

.logout { margin: auto 12px 16px; }
.logout .button { width: 100%; background: transparent; color: #eef7fa; border-color: #4c677a; }
.logout .button:hover { background: #1e3f52; }
.workspace { margin-left: 226px; min-width: 0; min-height: 100vh; }
.topbar {
    min-height: 58px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 9px clamp(14px, 3vw, 32px);
}

.top-caption { color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .11em; }
.profile-link { text-align: right; margin-left: auto; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.profile-link small { display: block; font-weight: 400; }
.mobile-toggle { display: none !important; }
.content { max-width: 1630px; margin: 0 auto; padding: clamp(14px, 3vw, 32px); }
.page-heading { margin-bottom: 18px; }
.page-heading p, .panel-heading p { color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }

.toolbar, .panel-heading, .actions, .filters {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    align-items: center;
}
.toolbar, .panel-heading { justify-content: space-between; }
.toolbar, .panel-heading { margin-bottom: 12px; }
.filters { align-items: flex-end; }
.filters .check { min-height: 36px; }
.filters input[type="search"] { width: min(100%, 275px); min-width: 165px; }

.button {
    display: inline-flex;
    min-height: 36px;
    padding: 7px 12px;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-shrink: 0;
    border: 1px solid #cbd9e4;
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font-weight: 650;
    line-height: 1.3;
}
.button:hover { background: #eaf3f8; text-decoration: none; }
.button.primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.button.danger { color: #91252b; border-color: #e6b8bd; }
.button.danger:hover { background: #fdeef0; }
.button.compact { font-size: 12px; min-height: 30px; padding: 5px 8px; }

.panel, .metrics > div {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: 0 1px 2px #10273708;
}
.panel { padding: 16px; margin-bottom: 14px; }
.panel > h2 { margin-bottom: 12px; }
.panel > p, .panel > .actions { margin-top: 10px; }
.toast-stack {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 20;
    display: grid;
    gap: 8px;
    width: min(385px, calc(100% - 28px));
    pointer-events: none;
}
.toast {
    --toast-ink: #0e6076;
    display: grid;
    grid-template-columns: .5rem minmax(0, 1fr) auto;
    align-items: start;
    gap: 9px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--toast-ink);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    box-shadow: 0 6px 22px #10273723;
    pointer-events: auto;
}
.toast-success { --toast-ink: #10684c; }
.toast-error { --toast-ink: #a52f3c; }
.toast-warning { --toast-ink: #8f5c07; }
.toast strong { color: var(--toast-ink); }
.toast p { margin-top: 2px; overflow-wrap: anywhere; }
.toast-mark { width: .5rem; height: .5rem; margin-top: 6px; border-radius: 50%; background: var(--toast-ink); }
.toast-close {
    display: none;
    padding: 0 5px;
    background: transparent;
    border: 0;
    border-radius: 4px;
    color: var(--muted);
    font-size: 19px;
    line-height: 1.2;
}
.toast-stack[data-ready] .toast-close { display: block; }
.toast-close:hover { background: #eef5f8; color: var(--ink); }

.confirm-dialog {
    width: min(390px, calc(100% - 32px));
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
}
.confirm-dialog::backdrop { background: #1027377a; }
.confirm-dialog p { margin: 9px 0 15px; }
.confirm-dialog .actions { justify-content: flex-end; }

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 185px), 1fr));
    gap: 12px;
    margin: 0 0 15px;
}
.metrics > div { padding: 13px 15px; }
.metrics small, .metrics strong, .metrics a { display: block; }
.metrics strong { margin-top: 4px; font-size: clamp(17px, 1.65vw, 26px); line-height: 1.3; overflow-wrap: anywhere; }
.metrics a { margin-top: 8px; font-size: 12px; font-weight: 650; }
.detail-metrics { margin-top: 10px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 14px; }
.dashboard-grid h2 { margin-bottom: 1px; }

.table-panel { padding: 0; }
.table-scroll { overflow-x: auto; }
.table-panel .table-caption { padding: 13px 15px; margin: 0; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 9px 13px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
th { background: #ecf3f7; color: #354e61; font-size: 12px; font-weight: 700; white-space: nowrap; }
td { max-width: 360px; }
td small { display: block; margin-top: 2px; }
td .actions { flex-wrap: nowrap; }
tbody tr:hover { background: #f8fbfd; }
.empty { color: var(--muted); padding: 23px 14px; text-align: center; }
.record-link { font-weight: 680; }
.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 11px;
    line-height: 1.45;
    font-weight: 700;
    white-space: nowrap;
}
.badge.neutral { background: #e8eef2; color: #405667; }
.badge.good { background: #dff3ea; color: #14654e; }
.badge.warn { background: #fff0cf; color: #794d08; }
.badge.bad { background: #fbe6e8; color: #952b38; }
.pager { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 9px; padding: 9px 13px; color: var(--muted); font-size: 12px; }

.form-grid, .permissions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 12px;
    align-items: start;
}
.field { min-width: 0; display: grid; gap: 4px; }
.field > span { font-size: 12px; font-weight: 650; }
input:not([type="checkbox"], [type="hidden"]), select, textarea {
    width: 100%;
    min-width: 0;
    min-height: 36px;
    padding: 6px 8px;
    border: 1px solid #bccedb;
    border-radius: 6px;
    background: #fff;
}
textarea { resize: vertical; }
.span-all { grid-column: 1 / -1; }
.stack { display: grid; gap: 11px; }
.stack > .panel { margin: 0; }
.narrow { max-width: 520px; }
.check { display: flex; align-items: center; gap: 7px; min-height: 30px; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.check small { margin-left: auto; font-size: 10px; }
.permissions > .check { padding: 8px; background: #f1f6f9; border-radius: 6px; }
.tabs { display: flex; gap: 4px; margin: 0 0 14px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; border-bottom: 2px solid transparent; font-weight: 650; }
.tabs [aria-current] { border-color: var(--primary); }
details summary { color: var(--primary-dark); font-weight: 650; padding: 3px 0; }
details form { margin-top: 8px; }
td details { margin-top: 5px; }

.item-grid {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(50px, 70px) minmax(78px, 130px) minmax(70px, 128px) 34px;
    gap: 8px;
    align-items: center;
}
.item-header { padding: 7px 0; color: var(--muted); font-size: 12px; font-weight: 650; }
.item-header span:nth-child(4) { text-align: right; }
.items, .item-description { display: grid; gap: 8px; }
.invoice-totals { display: grid; gap: 8px; width: min(100%, 315px); margin: 15px 0 0 auto; }
.total-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.total-row.final { padding-top: 7px; border-top: 1px solid var(--line); font-weight: 750; font-size: 16px; }

.login-shell {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 18px;
    background: radial-gradient(ellipse at 20% 0%, #d6edf3 0%, #f3f7fa 65%);
}
.login-card {
    width: min(100%, 385px);
    padding: 27px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 15px 44px #12394c1a;
}
.login-card h1 { margin: 18px 0; }
.login-card .button { margin-top: 4px; }

@media (max-width: 900px) {
    .sidebar { width: 192px; }
    .workspace { margin-left: 192px; }
}
@media (max-width: 700px) {
    .sidebar { display: none; top: 54px; width: min(82vw, 260px); box-shadow: 7px 0 30px #10273745; }
    .sidebar.open { display: flex; }
    .workspace { margin: 0; }
    .topbar { min-height: 54px; position: sticky; top: 0; z-index: 6; }
    .mobile-toggle { display: inline-flex !important; }
    .top-caption { display: none; }
    .content { padding: 14px; }
    .toolbar { align-items: flex-start; }
}
@media (max-width: 560px) {
    .panel { padding: 12px; }
    .table-panel { padding: 0; }
    .table-panel .table-caption { padding: 10px 12px; }
    .item-header { display: none; }
    .item-grid { grid-template-columns: minmax(45px, .6fr) minmax(88px, 1fr) minmax(64px, 1fr) 30px; padding-block: 6px; border-bottom: 1px solid var(--line); }
    .item-grid .item-description { grid-column: 1 / -1; }
    .item-grid output { white-space: normal; overflow-wrap: anywhere; }
}

.record-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
    gap: 9px 16px;
    margin: 12px 0;
}

.record-details dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
}

.record-details dd {
    overflow-wrap: anywhere;
}
