:root {
    --bg: #f5f7f9;
    --surface: #ffffff;
    --text: #17202a;
    --muted: #687381;
    --line: #d9e0e7;
    --accent: #1864ab;
    --accent-dark: #124f86;
    --danger: #b42318;
    --success: #067647;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); font-size: 20px; }
.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar form { margin: 0; }

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

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 22px;
    margin-bottom: 20px;
}
.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.heading-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 18px;
}
h1, h2 { margin: 0 0 12px; }
p { color: var(--muted); margin-top: 0; }

form.stack, .stack { display: grid; gap: 14px; }
.grid-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.span { grid-column: 1 / -1; }
label { display: grid; gap: 6px; font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font: inherit;
}
textarea { min-height: 92px; resize: vertical; }
button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    padding: 9px 13px;
    font: inherit;
    cursor: pointer;
    min-height: 40px;
}
.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.primary:hover { background: var(--accent-dark); }
.danger {
    border-color: #f3b8b2;
    color: var(--danger);
    background: #fff7f6;
}
.inline-create {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: min(460px, 100%);
}

.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--line);
}
th, td {
    text-align: left;
    border-bottom: 1px solid var(--line);
    padding: 11px 12px;
    vertical-align: top;
}
th { background: #eef2f6; }
.badge {
    display: inline-block;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 2px 8px;
    color: var(--muted);
    font-size: 13px;
}
.alert {
    border-radius: 6px;
    padding: 11px 13px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
}
.alert.success { background: #ecfdf3; border-color: #abefc6; color: var(--success); }
.alert.error { background: #fef3f2; border-color: #fecdca; color: var(--danger); }
.requirements { display: grid; gap: 8px; margin-bottom: 18px; }
.ok { color: var(--success); font-weight: 700; }
.bad { color: var(--danger); font-weight: 700; }
.item {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 12px;
}
.item, .item .actions, .compact {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}
.item form { margin: 0; }
.muted { color: var(--muted); display: block; }
.option-editor {
    flex-basis: 100%;
    width: 100%;
    margin-top: 12px;
    display: grid;
    gap: 10px;
}
.logic-row {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}
.delete-form { margin-top: 24px; }
.field { margin-bottom: 18px; }
.field[hidden] { display: none; }
.field small { display: block; color: var(--muted); margin-top: 5px; }
.field-error { color: var(--danger); margin-top: 6px; }
.signature-pad {
    width: 100%;
    height: 220px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    touch-action: none;
}

@media (max-width: 760px) {
    .topbar, .heading-row, .item, .inline-create { flex-direction: column; align-items: stretch; }
    .topbar nav { flex-wrap: wrap; }
    .grid-form, .logic-row { grid-template-columns: 1fr; }
}
