:root {
    --bg: #f0f4f8;
    --panel: #ffffff;
    --text: #1a1a2e;
    --muted: #5a6475;
    --line: #cbd5e1;
    --accent: #1e40af;
    --accent-mid: #2563eb;
    --accent-light: #dbeafe;
    --accent-dark: #1e3a8a;
    --success: #15803d;
    --error: #b91c1c;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 16px rgba(30,64,175,0.10), 0 1px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 20px 48px rgba(30,64,175,0.12), 0 4px 12px rgba(0,0,0,0.07);
    --radius: 12px;
    --radius-sm: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Times New Roman", Times, serif;
    background: linear-gradient(135deg, #e8f0fe 0%, #f0f4f8 40%, #e2e8f0 100%);
    color: var(--text);
}

/* ── Page layout ── */
.page {
    min-height: 100vh;
    display: grid;
    justify-items: center;
    padding: 32px 20px 60px;
}

/* ── Card ── */
.card {
    width: min(100%, 880px);
    background: var(--panel);
    border-radius: var(--radius);
    padding: 0;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.card::before {
    display: none;
}

/* ── Document header ── */
.card-header {
    padding: 28px 44px 24px;
    border-bottom: 1px solid #e2e8f0;
    border-radius: var(--radius) var(--radius) 0 0;
    background: linear-gradient(180deg, #f0f6ff 0%, #ffffff 100%);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.card-header::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: linear-gradient(90deg, var(--accent) 0%, var(--accent-mid) 60%, #60a5fa 100%);
    border-radius: var(--radius) var(--radius) 0 0;
}

h1 {
    margin: 0 0 6px;
    font-size: clamp(1.4rem, 2.8vw, 2rem);
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent-dark);
}

.card-meta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--muted);
    font-family: Arial, Helvetica, sans-serif;
}

.card-meta::before,
.card-meta::after {
    content: "";
    flex: 1;
    max-width: 80px;
    height: 1px;
    background: var(--line);
}

/* ── Form ── */
.form {
    padding: 8px 44px 40px;
    display: grid;
    gap: 0;
}

/* ── Field group ── */
.field-group {
    display: grid;
    gap: 8px;
    padding: 18px 0;
    border-bottom: 1px solid #f1f5f9;
}

.field-group:last-of-type {
    border-bottom: none;
}

.form > .field-label {
    padding-top: 20px;
    padding-bottom: 8px;
}

/* ── Labels ── */
.field-label {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--accent-dark);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: Arial, Helvetica, sans-serif;
}

/* ── Tooltip ── */
.tooltip {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.82rem;
    font-weight: 900;
    cursor: help;
    outline: none;
    border: 1.5px solid #93c5fd;
    font-family: Arial, sans-serif;
    flex-shrink: 0;
    transition: background 140ms;
}

.tooltip:hover,
.tooltip:focus { background: #bfdbfe; }

.tooltip-text {
    position: absolute;
    right: 0;
    left: auto;
    top: calc(100% + 12px);
    width: min(420px, calc(100vw - 32px));
    max-height: min(42vh, 320px);
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: #0f172a;
    color: #e2e8f0;
    font-size: 0.84rem;
    line-height: 1.6;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    box-shadow: 0 20px 44px rgba(0,0,0,0.28);
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 160ms ease, transform 160ms ease, visibility 160ms;
    z-index: 20;
}

.wide-tooltip { width: min(560px, calc(100vw - 32px)); }

.tooltip:hover .tooltip-text,
.tooltip:focus .tooltip-text {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ── Inputs & Textareas ── */
input,
textarea {
    width: 100%;
    min-height: 52px;
    padding: 13px 16px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    font-family: "Times New Roman", Times, serif;
    font-size: 1rem;
    color: var(--text);
    background: #fafcff;
    transition: border-color 160ms, box-shadow 160ms, background 160ms;
}

textarea {
    min-height: 120px;
    resize: vertical;
    line-height: 1.6;
}

input::placeholder,
textarea::placeholder {
    color: #94a3b8;
    font-style: italic;
}

input:focus,
textarea:focus {
    border-color: var(--accent-mid);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
    background: #ffffff;
    outline: none;
}

input.invalid {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(185,28,28,0.10);
    background: #fff5f5;
}

/* ── Validation message ── */
.validation-message {
    min-height: 1.3em;
    margin: 0;
    font-size: 0.88rem;
    color: var(--error);
    font-family: Arial, Helvetica, sans-serif;
}

/* ── Status message ── */
.export-status {
    min-height: 1.4em;
    margin: 10px 0 0;
    font-size: 0.88rem;
    color: var(--muted);
    text-align: right;
    font-family: Arial, Helvetica, sans-serif;
}

.export-status.error  { color: var(--error); }
.export-status.success { color: var(--success); }

/* ── Conclusion block ── */
.conclusion-block {
    margin-top: 24px;
    padding: 28px 32px;
    border-radius: var(--radius);
    background: linear-gradient(180deg, #f8faff 0%, #ffffff 100%);
    border: 1.5px solid #c7d7f5;
    box-shadow: 0 2px 12px rgba(30,64,175,0.07);
}

.conclusion-block h2 {
    margin: 0 0 18px;
    font-size: 0.88rem;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 10px;
}

.conclusion-block h2::after {
    content: "";
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, #93c5fd 0%, transparent 100%);
}

.conclusion-text {
    display: grid;
    gap: 12px;
    color: var(--text);
    line-height: 1.75;
}

.conclusion-text p {
    margin: 0;
    overflow-wrap: anywhere;
}

/* ── Inline inputs ── */
.line-input {
    display: inline-block;
    min-height: 36px;
    padding: 5px 8px;
    border: 0;
    border-bottom: 1.5px solid #334155;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    font-family: "Times New Roman", Times, serif;
    font-size: 1rem;
    line-height: 1.4;
    color: var(--text);
    vertical-align: baseline;
    transition: border-color 160ms, box-shadow 160ms;
}

.line-input:focus {
    outline: none;
    border-color: var(--accent-mid);
    box-shadow: 0 2px 0 0 rgba(37,99,235,0.25);
    background: rgba(37,99,235,0.03);
}

.line-input.small {
    width: 86px;
    margin: 0 5px;
    text-align: center;
}

.line-input.full {
    width: 100%;
    min-height: 50px;
    margin-bottom: 6px;
    padding: 8px 4px;
}

.line-caption {
    font-size: 0.83rem;
    color: var(--muted);
    font-family: Arial, Helvetica, sans-serif;
}

/* ── Signature line ── */
.signature-line {
    width: 100%;
    height: 30px;
    border-bottom: 1.5px solid #334155;
    margin-top: 8px;
}

/* ── Date row ── */
.date-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    font-size: 1rem;
}

.date-part {
    min-height: 36px;
    padding: 5px 6px 7px;
    text-align: center;
    font-size: 0.98rem;
}

.date-part.day   { width: 68px; }
.date-part.month { width: 170px; }
.date-part.year  { width: 52px; }

/* ── Buttons ── */
.document-actions {
    margin-top: 24px;
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

button {
    padding: 13px 26px;
    border: none;
    border-radius: 999px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #ffffff;
    background: linear-gradient(135deg, var(--accent-mid) 0%, var(--accent-dark) 100%);
    box-shadow: 0 4px 14px rgba(30,64,175,0.28);
    cursor: pointer;
    transition: transform 140ms, box-shadow 140ms, filter 140ms;
}

button:hover,
button:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(30,64,175,0.36);
    filter: brightness(1.07);
    outline: none;
}

button:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(30,64,175,0.20);
}

#fill-test-button {
    background: transparent;
    color: var(--muted);
    border: 1.5px solid var(--line);
    box-shadow: none;
    font-weight: 600;
}

#fill-test-button:hover,
#fill-test-button:focus-visible {
    background: #f1f5f9;
    color: var(--accent);
    border-color: #93c5fd;
    box-shadow: 0 2px 10px rgba(30,64,175,0.10);
    filter: none;
}

/* ── DB save button ── */
.btn-db {
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
    box-shadow: 0 4px 14px rgba(21,128,61,0.28);
}

.btn-db:hover,
.btn-db:focus-visible {
    box-shadow: 0 8px 22px rgba(21,128,61,0.38);
    filter: brightness(1.07);
}

/* ── Admin mode styles ── */
.admin-mode .card-header::before {
    background: linear-gradient(90deg, #b45309 0%, #d97706 60%, #f59e0b 100%);
}

.admin-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.admin-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px;
    background: #fef3c7;
    color: #92400e;
    border: 1.5px solid #f59e0b;
    border-radius: 999px;
    font-size: 0.75rem;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.admin-user-link {
    font-size: 0.78rem;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--muted);
    text-decoration: none;
    transition: color 140ms;
}

.admin-user-link:hover {
    color: var(--accent);
}


/* ── Print ── */
@page { size: A4; margin: 12mm; }

@media print {
    body { background: #ffffff; }
    .page { padding: 0; }
    .no-print { display: none !important; }
    .card { width: 100%; box-shadow: none; border-radius: 0; overflow: visible; }
    .card::before { height: 0; }
    .card-header { background: none; padding-left: 0; padding-right: 0; }
    .form { padding-left: 0; padding-right: 0; }
    .tooltip { display: none; }
    input, textarea, .line-input { color: #000; box-shadow: none !important; background: transparent !important; }
    textarea { resize: none; overflow: visible; }
    .conclusion-block { background: #ffffff; border-color: #cccccc; box-shadow: none; }
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .page { padding: 20px 14px 36px; }
    .card-header, .form { padding-left: 28px; padding-right: 28px; }
    .conclusion-block { padding: 22px 20px; }
}

@media (max-width: 640px) {
    .card-header, .form { padding-left: 18px; padding-right: 18px; }
    h1 { font-size: 1.2rem; }

    .tooltip-text {
        left: 0;
        transform: translateY(-6px);
    }
    .tooltip:hover .tooltip-text,
    .tooltip:focus .tooltip-text { transform: translateY(0); }
    .wide-tooltip { width: min(420px, calc(100vw - 32px)); }

    .document-actions { justify-content: stretch; }
    .document-actions button, button { width: 100%; }

    .line-input.small,
    .date-part.day,
    .date-part.month,
    .date-part.year { width: 100%; margin: 0; text-align: left; }

    .date-row { align-items: flex-start; gap: 10px; }
}


* {
    box-sizing: border-box;
}
