:root {
    --ink: #1d1f23;
    --muted: #646b74;
    --line: #d9dde3;
    --panel: #ffffff;
    --surface: #f4f6f8;
    --accent: #145c9e;
    --accent-strong: #0d477d;
    --danger: #b42318;
    --cdu: #f7f7f7;
    --spd: #f7c7c9;
    --fdp: #fffc9a;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--surface);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.45;
}

a {
    color: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 64px;
    padding: 0 28px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.brand {
    font-weight: 800;
    text-decoration: none;
}

.topbar nav {
    display: flex;
    gap: 16px;
    color: var(--muted);
}

.topbar nav a {
    text-decoration: none;
}

.app-version {
    color: #8a929c;
    font-size: 12px;
}

.shell {
    width: min(1180px, calc(100vw - 32px));
    margin: 28px auto;
}

.narrow {
    width: min(760px, calc(100vw - 32px));
}

.hero,
.panel,
.item-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 28px;
    margin-bottom: 20px;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    font-size: clamp(28px, 4vw, 44px);
    line-height: 1.05;
    max-width: 780px;
}

.hero p,
.muted,
.editor-head p,
.agenda-list p {
    color: var(--muted);
}

.panel {
    padding: 24px;
}

.panel-head,
.editor-head,
.row-actions,
.actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 700;
}

.danger {
    color: var(--danger);
}

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

label {
    display: grid;
    gap: 6px;
    color: #3a414a;
    font-weight: 700;
}

input,
textarea {
    width: 100%;
    border: 1px solid #cbd1d8;
    border-radius: 6px;
    padding: 10px 11px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-weight: 400;
}

textarea {
    resize: vertical;
}

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

.compact {
    margin-bottom: 18px;
}

.agenda-list {
    display: grid;
    gap: 12px;
}

.agenda-list article {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.workspace {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 24px;
    width: min(1500px, calc(100vw - 32px));
    margin: 24px auto 100px;
}

.sidebar {
    position: sticky;
    top: 88px;
    align-self: start;
    max-height: calc(100vh - 108px);
    overflow: auto;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.sidebar a {
    display: block;
    padding: 9px 0;
    border-top: 1px solid #eef1f4;
    color: #38414a;
    text-decoration: none;
}

.editor {
    min-width: 0;
}

.item-card {
    margin: 18px 0;
    padding: 18px;
}

.item-card > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.item-card > header input {
    width: 90px;
}

.top-number {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 6px;
    background: #e9f1f9;
    color: var(--accent-strong);
    font-weight: 800;
}

.entry-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.entry-grid section {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.entry-grid section:nth-child(1) {
    background: var(--cdu);
}

.entry-grid section:nth-child(2) {
    background: var(--spd);
}

.entry-grid section:nth-child(3) {
    background: var(--fdp);
}

.flash {
    width: min(1180px, calc(100vw - 32px));
    margin: 18px auto 0;
    padding: 12px 14px;
    border-radius: 8px;
    background: #e9f7ef;
    border: 1px solid #b7e2c5;
}

.flash.error {
    background: #fff1f0;
    border-color: #ffd2cc;
}

.import-status {
    padding: 11px 12px;
    border: 1px solid #cbd1d8;
    border-radius: 6px;
    background: #f8fafc;
    color: var(--muted);
}

.import-status[data-type="ok"] {
    border-color: #9bd2ad;
    background: #edf8f1;
    color: #1d6b39;
}

.import-status[data-type="warn"] {
    border-color: #f2c078;
    background: #fff8eb;
    color: #8a5a10;
}

.savebar {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 14px 0;
    background: linear-gradient(180deg, rgba(244, 246, 248, 0), var(--surface) 26%);
}

pre,
code {
    background: #eef1f4;
    border-radius: 4px;
}

pre {
    padding: 14px;
    overflow: auto;
}

code {
    padding: 2px 5px;
}

.print-page {
    background: #dfe3e8;
    color: #111;
    font-family: Arial, Helvetica, sans-serif;
}

.print-toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 12px 24px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.print-toolbar div {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.print-toolbar span {
    color: var(--muted);
}

.pdf-pages {
    display: grid;
    gap: 14px;
    justify-content: center;
    padding: 20px 0;
}

.pdf-page {
    display: flex;
    flex-direction: column;
    width: 210mm;
    height: 297mm;
    padding: 12mm 16mm 10mm;
    background: #fff;
    box-shadow: 0 10px 34px rgba(28, 33, 40, 0.18);
    page-break-after: always;
}

.pdf-page:last-child {
    page-break-after: auto;
}

.pdf-header {
    flex: 0 0 auto;
    padding-bottom: 5mm;
    border-bottom: 1px solid #111;
}

.pdf-header div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 10px;
    line-height: 1.25;
}

.pdf-header h2 {
    margin: 5px 0 0;
    font-size: 14px;
    line-height: 1.2;
}

.pdf-header p {
    margin: 2px 0 0;
    font-size: 10px;
}

.pdf-content {
    flex: 1 1 auto;
    overflow: hidden;
    padding: 7mm 0 5mm;
}

.pdf-footer {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-top: 4mm;
    border-top: 1px solid #111;
    font-size: 10px;
}

.print-source {
    display: none;
}

.small {
    font-size: 11px;
}

.pdf-intro {
    padding: 0 0 8mm;
    border-bottom: 2px solid #111;
}

.pdf-intro h1 {
    margin-bottom: 7px;
    font-size: 22px;
    line-height: 1.18;
}

.print-item {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 10mm;
    font-size: 11px;
    line-height: 1.28;
}

.print-item-compact {
    margin-bottom: 6mm;
    font-size: 9.5px;
    line-height: 1.18;
}

.print-item-compact .item-heading h2 {
    font-size: 11px;
}

.print-item-compact .vote-table th,
.print-item-compact .vote-table td {
    padding: 3px 4px;
}

.print-item-split {
    margin-bottom: 6mm;
}

.print-item-continued {
    border-top: 1px solid #777;
    padding-top: 4mm;
}

.item-continuation {
    margin-bottom: 5mm;
    font-size: 11px;
    font-weight: 800;
}

.doc-refs p,
.doc-ref-piece p,
.extra-notes p,
.extra-note-piece p {
    margin: 0 0 2px;
}

.doc-ref-piece {
    margin-left: 46px;
    font-size: 10.5px;
}

.extra-note-piece {
    margin-top: 3px;
}

.item-heading {
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 12px;
}

.item-heading > span {
    font-weight: 700;
}

.item-heading h2 {
    margin-bottom: 4px;
    font-size: 13px;
    line-height: 1.24;
}

.item-heading p {
    margin-bottom: 3px;
}

.meta-grid {
    display: grid;
    grid-template-columns: 78px 1fr;
    gap: 2px 8px;
    margin: 8px 0;
}

.meta-grid dt {
    font-weight: 800;
}

.meta-grid dd {
    margin: 0;
}

.vote-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 7px;
    table-layout: fixed;
}

.vote-table th,
.vote-table td {
    border: 1px solid #111;
    padding: 4px 6px;
    vertical-align: top;
}

.vote-table th:first-child,
.vote-table td:first-child {
    width: 23%;
    background: #fff;
    font-weight: 400;
}

.vote-table th {
    text-align: center;
    font-weight: 800;
}

.vote-table th:nth-child(2),
.vote-table td:nth-child(2) {
    background: var(--cdu);
}

.vote-table th:nth-child(3),
.vote-table td:nth-child(3) {
    background: var(--spd);
}

.vote-table th:nth-child(4),
.vote-table td:nth-child(4) {
    background: var(--fdp);
}

.hint {
    margin-top: 5px;
    text-decoration: underline;
}

.strong-note {
    margin-top: 5px;
    font-weight: 800;
}

@media (max-width: 900px) {
    .workspace,
    .form-grid,
    .entry-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        max-height: none;
    }

    .hero,
    .agenda-list article,
    .panel-head,
    .editor-head {
        align-items: stretch;
        flex-direction: column;
    }
}

@media print {
    @page {
        size: A4;
        margin: 0;
    }

    body.print-page {
        background: #fff;
    }

    .print-toolbar,
    .print-source {
        display: none;
    }

    .pdf-pages {
        display: block;
        padding: 0;
    }

    .pdf-page {
        width: 210mm;
        height: 297mm;
        margin: 0;
        box-shadow: none;
        page-break-after: always;
    }
}
