*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.45;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0);
    overflow-x: hidden;
}
body.nav-open { overflow: hidden; }

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f4f6f8;
    --text-primary: #1d2939;
    --text-secondary: #667085;
    --border-color: #e4e7ec;
    --accent-color: #1570ef;
    --accent-hover: #0b5ed7;
    --success-color: #12b76a;
    --warning-color: #f79009;
    --danger-color: #f04438;
    --muted-text: #667085;
    --row-alt: #f9fafb;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    padding: env(safe-area-inset-top, 0) max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
    position: sticky;
    top: 0;
    z-index: 1000;
    min-height: 56px;
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    text-decoration: none;
    color: #122C44;
    padding: 10px 8px;
    min-height: 44px;
}
.nav-brand img { display: block; height: 28px; width: auto; }
.nav-brand-text { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }
.nav-toggle {
    display: none;
    width: 44px;
    height: 44px;
    margin: 4px 4px 4px auto;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    z-index: 1003;
    touch-action: manipulation;
}
.nav-toggle-bar {
    display: block;
    width: 20px;
    height: 2px;
    background: #122C44;
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.navbar.is-open .nav-toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.navbar.is-open .nav-toggle-bar:nth-child(2) { opacity: 0; }
.navbar.is-open .nav-toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, 0.4);
    z-index: 1001;
}
.nav-panel {
    display: flex;
    flex: 1;
    justify-content: space-between;
    align-items: center;
    min-width: 0;
    background: #fff;
}
.navbar ul { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; }
.navbar a, .nav-user {
    display: block;
    color: var(--text-primary);
    text-decoration: none;
    padding: 14px 14px;
    font-size: 14px;
    font-weight: 500;
}
.navbar a:hover { color: var(--accent-color); }
.navbar a.is-active { color: var(--accent-color); }
.nav-user { color: var(--text-secondary); }

.index-content {
    max-width: 880px;
    margin: 0 auto;
    padding: 24px 16px 56px;
}
.index-content.public { max-width: 760px; }

.card, .settings-section, .data-container {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 22px;
    margin-bottom: 16px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
h1, h2, h3 { margin: 0 0 12px; letter-spacing: -0.02em; }
h1 { font-size: 22px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; color: var(--text-primary); }
.muted, .help { color: var(--text-secondary); font-size: 14px; }

.brand-bar { margin-bottom: 8px; }
.brand-logos {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.brand-logo { display: block; height: 40px; width: auto; max-width: 160px; object-fit: contain; }
.brand-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}
.brand-title-row h1 { margin: 0; }
.brand-doc-icon { color: var(--accent-color); flex-shrink: 0; }

.address-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 8px 0 16px;
}
.address-card {
    background: var(--row-alt);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 16px;
}
.address-card h3 { margin: 0 0 8px; font-size: 13px; color: var(--text-secondary); text-transform: none; font-weight: 600; }
.address-card p { margin: 0; font-size: 14px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

label { display: block; font-weight: 600; margin: 12px 0 6px; font-size: 13px; color: #344054; }
input[type="text"], input[type="password"], input[type="date"], input[type="email"], input[type="tel"], textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 10px;
    font: inherit;
    background: #fff;
    color: var(--text-primary);
}
input:focus, textarea:focus {
    outline: 2px solid #b2ddff;
    border-color: var(--accent-color);
}
input[readonly], textarea[readonly] { background: var(--row-alt); color: var(--text-secondary); }
textarea { min-height: 96px; resize: vertical; }

.button, button.button, a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 6px 12px;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    color: #fff;
    background: var(--accent-color);
}
.button:hover { background: var(--accent-hover); }
.button.secondary {
    background: #fff;
    color: #344054;
    border-color: var(--border-color);
}
.button.secondary:hover { background: var(--row-alt); color: var(--text-primary); }
.button.success {
    background: #ecfdf3;
    color: #027a48;
    border-color: #abefc6;
}
.button.success:hover { background: #d1fadf; }
.button.danger {
    background: #fff;
    color: var(--danger-color);
    border-color: #fecdca;
}
.button.danger:hover { background: #fef3f2; }
.button.info { background: #15b79e; }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.button-block { display: flex; width: 100%; text-align: center; padding: 10px 14px; font-size: 14px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; align-items: center; }
.link-quiet { color: var(--text-secondary); text-decoration: none; font-size: 14px; }
.link-quiet:hover { color: var(--text-primary); }

.message { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; }
.message.error { background: #fef3f2; color: #912018; }
.message.success { background: #ecfdf3; color: #027a48; }
.message.info { background: #eff8ff; color: #175cd3; }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 12px 8px; border-bottom: 1px solid var(--border-color); vertical-align: top; }
table.data th { color: var(--text-secondary); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }

.badge { display: inline-block; font-size: 12px; padding: 3px 8px; border-radius: 999px; background: #e9ecef; font-weight: 600; }
.badge.entwurf { background: #f2f4f7; color: #344054; }
.badge.versendet { background: #eff8ff; color: #175cd3; }
.badge.unterschrieben { background: #ecfdf3; color: #027a48; }

.checklist { list-style: none; padding: 0; margin: 0; border: 1px solid var(--border-color); border-radius: 10px; overflow: hidden; }
.checklist li {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
    border-bottom: 1px solid var(--border-color);
    background: #fff;
    font-size: 13px;
    line-height: 1.3;
}
.checklist li:nth-child(even) { background: var(--row-alt); }
.checklist li:last-child { border-bottom: 0; }
.checklist .punkt-text { flex: 1; }
.checklist .ok-group { display: flex; gap: 10px; flex-shrink: 0; font-size: 12px; font-weight: 600; }
.ok-group label { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-weight: 600; cursor: pointer; font-size: 12px; }
.ok-group .ok { color: var(--success-color); }
.ok-group .nok { color: var(--danger-color); }
.ok-group input { margin: 0; }

textarea.remarks-field {
    min-height: 220px;
    font-size: 15px;
    line-height: 1.5;
}
.char-count {
    display: block;
    text-align: right;
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--text-secondary);
}
.char-count.is-limit { color: var(--danger-color); font-weight: 600; }

.signature-preview-wrap {
    border: 1.5px dashed #d0d5dd;
    border-radius: 12px;
    padding: 12px;
    background: #fff;
    margin-top: 8px;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.signature-preview-wrap img { width: 100%; max-width: 420px; height: auto; display: block; background: #fff; }
.sig-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 8px; }
.sig-col h3 { font-size: 14px; margin-bottom: 6px; }
.sig-col .sig-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sig-col .sig-head a, .sig-col .sig-head button.linkish {
    background: none; border: 0; color: var(--accent-color); cursor: pointer; font: inherit; font-size: 13px; padding: 0;
}
.link-box { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.link-box input { flex: 1; min-width: 180px; }
.actions-inline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.actions-inline .button {
    padding: 4px 10px;
    font-size: 12px;
    min-height: 0;
}
.delete-protocol { display: inline-flex; margin: 0; }
.page-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.narrow-card { max-width: 420px; margin: 48px auto; }
.narrow-card-wide { max-width: 560px; }

@media (max-width: 860px) {
    .nav-toggle { display: flex; }
    .nav-brand { padding-left: 4px; }
    .nav-panel {
        position: fixed;
        top: calc(56px + env(safe-area-inset-top, 0px));
        left: 0;
        right: 0;
        bottom: auto;
        flex: none;
        width: 100%;
        max-height: min(80dvh, calc(100dvh - 56px - env(safe-area-inset-top, 0px)));
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        background: #fff;
        padding: 8px 0 env(safe-area-inset-bottom, 12px);
        box-shadow: 0 16px 32px rgba(16, 24, 40, 0.16);
        transform: translateY(-8px);
        visibility: hidden;
        pointer-events: none;
        transition: transform 0.2s ease, visibility 0.2s;
        z-index: 1002;
        overflow-y: auto;
    }
    .navbar.is-open .nav-panel {
        transform: none;
        visibility: visible;
        pointer-events: auto;
    }
    .navbar ul {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }
    .navbar-right { margin-top: 8px; border-top: 1px solid var(--border-color); }
    .navbar a, .nav-user {
        padding: 14px 20px;
        font-size: 16px;
        min-height: 48px;
        display: flex;
        align-items: center;
    }
    .navbar a.is-active { background: #eff8ff; }
    .index-content { padding: 16px 12px 40px; }
    .card, .settings-section, .data-container { padding: 16px; border-radius: 12px; }
    .brand-logo { height: 28px; max-width: 120px; }
    .brand-logos { gap: 12px; margin-bottom: 10px; }
    h1 { font-size: 20px; }
    .page-head { align-items: stretch; }
    .page-head > .button { width: 100%; min-height: 38px; padding: 8px 12px; font-size: 14px; }
    .narrow-card { max-width: none; margin: 12px auto; }
    input[type="text"], input[type="password"], input[type="date"], input[type="email"], input[type="tel"], textarea, select {
        font-size: 16px;
        min-height: 44px;
    }
    .form-actions { flex-direction: column; align-items: stretch; }
    .form-actions input { width: 100%; min-width: 0; }
    .form-actions .button, .form-actions button, .form-actions a.button { width: 100%; }
    .form-actions .delete-protocol { width: 100%; }
    .form-actions .delete-protocol .button { width: 100%; }
    .link-box { flex-direction: column; align-items: stretch; }
    .link-box input { min-width: 0; }
    .link-box .button { width: 100%; }
    table.data, table.data thead, table.data tbody, table.data tr, table.data th, table.data td { display: block; }
    table.data thead { display: none; }
    table.data tbody { display: flex; flex-direction: column; gap: 10px; }
    table.data tr {
        background: #fff;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 4px 0;
        overflow: hidden;
    }
    table.data td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        padding: 10px 14px;
        border-bottom: 1px solid var(--border-color);
        text-align: right;
        overflow-wrap: anywhere;
    }
    table.data td:last-child { border-bottom: 0; }
    table.data td::before {
        content: attr(data-label);
        font-size: 12px;
        font-weight: 600;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.02em;
        text-align: left;
        flex-shrink: 0;
    }
    table.data td.actions-inline {
        display: flex;
        flex-wrap: nowrap;
        justify-content: stretch;
        gap: 6px;
        padding: 8px 10px;
    }
    table.data td.actions-inline::before { display: none; }
    table.data td.actions-inline .button {
        flex: 1 1 0;
        min-width: 0;
        min-height: 34px;
        padding: 6px 8px;
        font-size: 13px;
        white-space: nowrap;
    }
    table.data td.actions-inline .delete-protocol { flex: 1 1 0; min-width: 0; }
    table.data td.actions-inline .delete-protocol .button { width: 100%; }
    .address-grid, .field-row, .sig-grid { grid-template-columns: 1fr; }
    .checklist li {
        flex-wrap: wrap;
        align-items: stretch;
        padding: 12px;
        gap: 10px;
    }
    .ok-group {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .ok-group label {
        justify-content: center;
        min-height: 44px;
        padding: 8px 10px;
        border: 1px solid var(--border-color);
        border-radius: 10px;
        background: #fff;
    }
    .button, button.button, a.button {
        min-height: 36px;
        padding: 7px 12px;
        font-size: 13px;
        border-radius: 8px;
        white-space: nowrap;
    }
    .button-block { padding: 10px 14px; font-size: 14px; }
}

@media (min-width: 861px) and (max-width: 1100px) {
    .nav-brand-text { display: none; }
}
