:root {
    color-scheme: light;
    --ink: #182940;
    --muted: #52647b;
    --line: #e0e7f1;
    --surface: #fff;
    --surface-subtle: #f7f9fd;
    --canvas: #f4f7fc;
    --navy: #101c30;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --primary-soft: #eaf1ff;
    --focus: #3668dd;
    --radius: 15px;
    font-family: "Segoe UI", system-ui, sans-serif;
    font-size: 15px;
    color: var(--ink);
    background: var(--canvas);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
svg { flex: none; vertical-align: middle; }
h1, h2, h3, p, dl { margin: 0; }
h1, h2, h3, strong { overflow-wrap: anywhere; }
h1 { font-size: clamp(1.85rem, 3vw, 2.45rem); line-height: 1.15; letter-spacing: -.045em; }
h2 { font-size: 1.13rem; line-height: 1.3; letter-spacing: -.024em; }
h3 { font-size: .94rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }

.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 27px 17px 16px; background: var(--navy); color: #eef4ff; overflow: auto; }
.brand { display: flex; align-items: center; gap: 11px; width: fit-content; }
.sidebar .brand { margin: 0 5px 33px; }
.brand-mark { position: relative; display: block; flex: none; width: 44px; aspect-ratio: 11 / 9; overflow: hidden; border-radius: 8px; background: var(--navy); }
.brand-mark img { position: absolute; top: -37%; left: -30%; width: 160%; height: auto; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; letter-spacing: -.025em; }
.brand small { margin-top: 2px; font-size: .72rem; color: #acbbd3; }
.nav-label { margin: 0 10px 7px; color: #9fafd0; font-size: .68rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.nav-link + .nav-label { margin-top: 28px; }
.nav-link { display: flex; min-height: 42px; align-items: center; gap: 10px; padding: 8px 11px; margin-bottom: 3px; border-radius: 9px; color: #c6d3ea; font-weight: 560; font-size: .91rem; }
.nav-link:hover { background: #1b2e4e; color: #fff; }
.nav-link.is-active { background: #243b66; color: #eef4ff; font-weight: 650; }
.nav-link.is-active > svg { color: #a5c6ff; }
.nav-dot { margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: #a5c6ff; }
.sidebar-footer { display: flex; align-items: center; gap: 9px; margin-top: auto; padding: 15px 3px 0; border-top: 1px solid #293a57; }
.avatar { display: grid; flex: none; width: 33px; height: 33px; place-items: center; border-radius: 50%; background: #304b75; color: #edf4ff; font-weight: 700; }
.account-name { flex: 1; min-width: 0; }
.account-name strong, .account-name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-name strong { font-size: .77rem; }
.account-name small { font-size: .71rem; color: #acbbd3; }
.sidebar-footer .logout { color: #c6d3ea; }
.sidebar-footer .logout:hover { background: #243b66; }
.sidebar-footer .logout:focus-visible, .sidebar a:focus-visible { outline-color: #a5c6ff; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 67px; padding: 0 35px; border-bottom: 1px solid var(--line); background: var(--surface); font-size: .84rem; }
.topbar-left, .today { display: flex; align-items: center; gap: 10px; }
.topbar-left > svg, .breadcrumb-home, .today { color: var(--muted); }
.today { gap: 7px; white-space: nowrap; }
.menu-toggle { display: none !important; }
.content { max-width: 1390px; margin: 0 auto; padding: 30px 35px 42px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.page-head p { margin-top: 6px; color: var(--muted); }
.actions, .form-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 7px; padding: 8px 15px; border: 1px solid transparent; border-radius: 8px; font-weight: 650; font-size: .9rem; line-height: 1.25; }
.button.small { min-height: 35px; padding: 6px 11px; font-size: .82rem; }
.button.primary { background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-hover); }
.button.secondary { border-color: #d3def2; background: #fff; color: var(--primary-hover); }
.button.secondary:hover { background: var(--primary-soft); border-color: #b7caf0; }
.button.danger { border-color: #f0c7c0; color: #93332a; background: #fff; }
.button.danger:hover { background: #fff3f0; }
.button:disabled, .icon-btn:disabled { cursor: not-allowed; opacity: .48; }
.icon-btn { display: inline-grid; width: 36px; height: 36px; flex: none; place-items: center; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.icon-btn:hover { color: var(--ink); background: var(--primary-soft); }
.text-link, .back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--primary); font-weight: 650; font-size: .86rem; }
.text-link:hover, .back-link:hover, .table-link:hover { text-decoration: underline; }
.back-link { width: fit-content; margin-bottom: 14px; }
.muted { color: var(--muted); }
.nowrap, .amount { white-space: nowrap; }
.amount { font-variant-numeric: tabular-nums; }
.align-right { text-align: right; }

.dashboard-hero { position: relative; isolation: isolate; display: flex; align-items: center; min-height: 251px; margin-bottom: 21px; overflow: hidden; border-radius: 17px; background: linear-gradient(110deg, #172e60 10%, #1c4198 70%, #245cc1 100%); color: #fff; }
.hero-copy { position: relative; z-index: 1; padding: 27px 34px; }
.hero-kicker { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 9px; color: #d5e5ff; font-size: .7rem; font-weight: 720; letter-spacing: .12em; }
.hero-copy h2 { color: #fff; font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.05; letter-spacing: -.05em; }
.hero-copy p { max-width: 395px; margin: 10px 0 17px; color: #e3edff; font-size: .91rem; }
.hero-button { min-height: 36px; padding: 7px 12px; background: #d7e6ff; color: #15336e; font-size: .84rem; }
.hero-button:hover { background: #edf4ff; }
.hero-button:focus-visible { outline-color: #d7e6ff; }
.hero-art { position: absolute; right: 1%; top: 50%; width: 35%; min-width: 285px; height: 246px; transform: translateY(-50%); }
.art-ring { position: absolute; left: 50%; top: 50%; width: 214px; height: 214px; transform: translate(-50%, -50%); border: 1px solid #c7ddff55; border-radius: 50%; }
.art-ring.outer { width: 275px; height: 275px; border-color: #c7ddff30; }
.art-document { position: absolute; left: calc(50% - 59px); top: 46px; width: 122px; height: 148px; border-radius: 13px; }
.art-back { transform: translate(19px, 0) rotate(13deg); background: #94b8f2a0; border: 1px solid #c4daff; }
.art-front { display: flex; flex-direction: column; gap: 8px; transform: translate(-12px, 2px) rotate(-11deg); padding: 15px 13px; background: #f2f6ff; box-shadow: 0 15px 32px #10214f59; }
.art-icon { display: grid; width: 35px; height: 35px; margin-bottom: 3px; place-items: center; border-radius: 8px; background: #d8e7ff; color: #2852a0; }
.art-line { display: block; width: 78%; height: 4px; border-radius: 5px; background: #b6c7e5; }
.art-heading { width: 67%; background: #5377bc; height: 6px; }
.art-short { width: 53%; }
.art-rule { height: 1px; background: #d0dcf1; }
.art-total { width: 32%; align-self: flex-end; background: #789ad5; }
.art-badge { position: absolute; display: grid; left: calc(50% + 42px); top: 145px; width: 42px; height: 42px; place-items: center; border: 3px solid #2552aa; border-radius: 50%; background: #c7ddff; color: #214891; }
.art-spark { position: absolute; left: calc(50% + 97px); top: 61px; color: #c7ddff; font-size: 1.4rem; line-height: 1; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 21px; }
.stat-card, .panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat-card { display: flex; flex-direction: column; gap: 3px; padding: 14px 16px; }
.stat-card:hover { border-color: #b7caf0; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 4px; color: var(--muted); }
.stat-icon, .quick-icon, .empty-icon { display: inline-grid; place-items: center; border-radius: 9px; }
.stat-icon { width: 37px; height: 37px; }
.tone-green { background: #e8f2e9; color: #22604a; }
.tone-blue, .quick-icon, .empty-icon { background: var(--primary-soft); color: var(--primary); }
.tone-amber { background: #fbf1dd; color: #795318; }
.stat-label { color: var(--muted); font-size: .82rem; }
.stat-card strong { font-size: clamp(1.2rem, 2vw, 1.65rem); line-height: 1.2; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.dashboard-bottom { display: grid; grid-template-columns: minmax(0, 1.85fr) minmax(235px, 1fr); align-items: start; gap: 18px; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 11px; min-height: 62px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { display: flex; align-items: center; gap: 7px; }
.quick-list { padding: 4px 14px 8px; }
.quick-link { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: 61px; padding: 8px 3px; }
.quick-link + .quick-link { border-top: 1px solid var(--line); }
.quick-link:hover strong { text-decoration: underline; }
.quick-icon { width: 34px; height: 34px; }
.quick-link strong { display: block; font-size: .84rem; }
.quick-link small { display: block; color: var(--muted); font-size: .73rem; }
.quick-link > svg { color: var(--muted); }
.empty { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px; min-height: 181px; padding: 24px 15px; text-align: center; }
.empty-icon { width: 43px; height: 43px; margin-bottom: 1px; }
.empty p { color: var(--muted); font-size: .86rem; }
.empty .button { margin-top: 3px; }
.count { display: inline-grid; min-width: 24px; height: 24px; place-items: center; padding: 0 5px; border-radius: 20px; color: var(--primary-hover); background: var(--primary-soft); font-size: .72rem; }

.table-wrap, .item-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: .88rem; }
th { color: var(--muted); font-size: .76rem; font-weight: 700; white-space: nowrap; }
thead { background: var(--surface-subtle); }
tbody tr:last-child td { border-bottom: 0; }
.table-link { color: var(--primary); font-weight: 700; }
.table-title { font-weight: 650; overflow-wrap: anywhere; }
.table-sub { display: block; margin-top: 2px; color: var(--muted); overflow-wrap: anywhere; }
.status { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 20px; white-space: nowrap; font-size: .75rem; font-weight: 650; }
.status > span { width: 6px; height: 6px; border-radius: 100%; background: currentColor; }
.status-green { background: #e5f3e9; color: #205941; }
.status-amber { background: #fbf1dc; color: #745220; }
.status-blue { background: var(--primary-soft); color: var(--primary-hover); }
.status-gray { background: #edf0f4; color: #4f5c70; }
.pager { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px; padding: 14px; color: var(--muted); font-size: .82rem; }
.search-form, .search-field { display: flex; align-items: center; gap: 7px; }
.search-field { padding: 0 9px; border: 1px solid #cfdaeb; border-radius: 8px; color: var(--muted); }
.search-field:focus-within { outline: 2px solid var(--focus); }
.search-field input { width: min(220px, 40vw); min-height: 33px; padding: 5px 0; border: 0; font-size: .84rem; }
.search-field input:focus-visible { outline: 0; }

.form-panel { padding: 20px; }
.form-narrow { max-width: 720px; }
.stack { display: flex; flex-direction: column; gap: 17px; }
.fields { display: grid; gap: 14px; }
.fields.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack label, fieldset > label { display: block; color: #304460; font-size: .87rem; font-weight: 650; }
.stack label > input, .stack label > select, .stack label > textarea { margin-top: 5px; }
.optional { margin-left: 3px; color: var(--muted); font-weight: 400; font-size: .77rem; }
input, select, textarea { min-width: 0; max-width: 100%; border: 1px solid #cfdaeb; border-radius: 8px; background: #fff; color: var(--ink); font-weight: 400; }
.stack input:not([type="hidden"]), .stack select, .stack textarea { width: 100%; min-height: 41px; padding: 7px 10px; }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: #667890; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 7px; padding: 0; font-weight: 700; }
.project-new { margin-top: 11px; }
.inline-detail { color: var(--muted); }
.form-footer { justify-content: flex-end; padding-top: 14px; border-top: 1px solid var(--line); }
.delete-template { margin-top: 15px; }
.item-scroll { margin-bottom: 9px; border: 1px solid var(--line); border-radius: 9px; }
.item-table th, .item-table td { padding: 8px; }
.item-table th:first-child { width: 50%; }
.item-table td:first-child { min-width: 200px; }
.item-table input[type="number"] { min-width: 60px; }
.item-table select { text-overflow: ellipsis; }
.document-bottom { align-items: start; }
.calculator { display: grid; gap: 9px; padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-subtle); }
.calc-line, .totals > div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.grand { padding-top: 8px; border-top: 1px solid var(--line); }
.feedback { display: block; padding: 11px 14px; margin-bottom: 16px; border: 1px solid transparent; border-radius: 9px; font-size: .88rem; overflow-wrap: anywhere; }
.feedback ul { margin: 4px 0 0; padding-left: 20px; }
.feedback.success { display: flex; align-items: center; gap: 7px; border-color: #cde2d4; color: #254f3d; background: #ecf5ee; }
.feedback.error { border-color: #f2d5ce; color: #85362c; background: #fff3ef; }

.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.template-card { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; min-height: 181px; padding: 16px; }
.template-services { display: grid; gap: 5px; width: 100%; margin: 0 0 3px; padding: 0; color: var(--muted); list-style: none; font-size: .84rem; }
.template-services li { display: flex; justify-content: space-between; gap: 7px; }
.template-services li span:first-child { overflow-wrap: anywhere; }
.template-services li span:last-child { white-space: nowrap; }
.template-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; width: 100%; margin-top: auto; padding-top: 11px; border-top: 1px solid var(--line); }

.document-name { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.document-meta, .paper-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; padding: 18px; }
.document-meta > div, .paper-meta > div { display: flex; flex-direction: column; gap: 3px; overflow-wrap: anywhere; }
.document-meta span, .paper-meta span, .document-meta small, .paper-meta small { color: var(--muted); font-size: .82rem; }
.document-summary { display: grid; grid-template-columns: minmax(0, 1fr) minmax(215px, 320px); gap: 16px; padding: 18px; border-top: 1px solid var(--line); }
.doc-notes p { margin: 4px 0 7px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font-size: .88rem; }
.totals { display: grid; gap: 6px; }
.totals dd { margin: 0; white-space: nowrap; font-variant-numeric: tabular-nums; }
.totals .grand, .totals .balance { font-weight: 700; }
.totals .balance { color: var(--primary); }
.payment-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(295px, 1fr); align-items: start; gap: 15px; margin-top: 15px; }
.payment-grid .panel:only-child { grid-column: 1 / -1; }
.payment-form { margin-top: 13px; gap: 12px; }
.payment-form .button { align-self: flex-start; }

.login-page { display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at 15% 15%, #dce9ff, transparent 48%), var(--canvas); }
.login-card { width: min(100%, 420px); padding: 29px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: 0 15px 50px #24437a15; }
.login-brand { margin-bottom: 24px; }
.login-brand .brand-mark { width: 55px; }
.login-brand small { color: var(--muted); }
.login-card h1 { font-size: 1.85rem; }
.login-card > p { margin: 6px 0 14px; }
.login-form button { margin-top: 3px; }
.print-container { width: min(calc(100% - 32px), 840px); margin: 20px auto; }
.print-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 12px; }
.print-toolbar .back-link { margin: 0; }
.paper { padding: 23px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.paper-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 14px; padding-bottom: 15px; border-bottom: 1px solid var(--line); }
.paper-head h1 { font-size: 1.65rem; }
.paper-head p { color: var(--muted); }
.paper-meta { grid-template-columns: repeat(3, minmax(0, 1fr)); padding-inline: 0; }
.paper .document-summary { padding-inline: 0; }
.paper-payments h2 { margin-bottom: 7px; }

@media (max-width: 1100px) {
    .shell { grid-template-columns: 215px minmax(0, 1fr); }
    .content, .topbar { padding-inline: 23px; }
    .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 850px) {
    .shell { grid-template-columns: 184px minmax(0, 1fr); }
    .sidebar { padding-inline: 11px; }
    .sidebar .brand { margin-inline: 1px; }
    .dashboard-bottom, .payment-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hero-art { right: -50px; opacity: .65; }
    .hero-copy { padding-inline: 24px; }
    .fields.three, .document-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 650px) {
    .shell { position: relative; display: block; }
    .sidebar { display: none; position: absolute; z-index: 3; inset: 52px 0 auto; height: auto; max-height: calc(100dvh - 52px); padding: 16px; }
    .sidebar.is-open { display: flex; }
    .sidebar .brand { margin-bottom: 20px; }
    .sidebar-footer { margin-top: 15px; }
    .menu-toggle { display: inline-grid !important; }
    .topbar { min-height: 52px; padding-inline: 10px 15px; }
    .content { padding: 21px 14px 30px; }
    .page-head { align-items: flex-start; flex-direction: column; margin-bottom: 18px; gap: 11px; }
    .hero-copy { padding: 20px 15px; }
    .hero-copy p { max-width: 255px; }
    .hero-art { right: -130px; opacity: .27; }
    .hero-break, .breadcrumb-home, .topbar-left > svg { display: none; }
    .dashboard-hero { min-height: 218px; }
    .stat-card { padding: 11px; }
    .stats-grid, .template-grid { gap: 10px; }
    .template-grid, .fields.two, .fields.three, .document-summary { grid-template-columns: 1fr; }
    .paper { padding: 13px; }
    .paper-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-panel { padding: 14px; }
    th, td { padding-inline: 10px; }
}

@page { size: A4 portrait; margin: 14mm; }
@media print {
    :root, body { background: #fff; color: #172131; font-size: 11pt; }
    .print-toolbar { display: none; }
    .print-container { width: 100%; margin: 0; }
    .paper { padding: 0; border: 0; }
    .table-wrap { overflow: visible; }
    thead { display: table-header-group; }
    tr { break-inside: avoid; }
    th, td { white-space: normal; padding: 5pt; }
    .amount { white-space: nowrap; }
    .paper-head, .paper-meta, .totals { break-inside: avoid; }
    .paper-payments h2 { break-after: avoid; }
    .document-summary { grid-template-columns: minmax(0, 1fr) 245px; }
}
