* {
    box-sizing: border-box;
}

:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-soft: #f8faff;
    --surface-strong: #eef4ff;
    --text: #172033;
    --muted: #667085;
    --line: #dbe4f0;
    --primary: #1d4ed8;
    --primary-strong: #163fae;
    --danger: #c52828;
    --success: #0f8a5f;
    --shadow: 0 18px 45px rgba(15, 23, 42, 0.10);
    --radius: 18px;
    --radius-sm: 12px;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, #f5f8ff 0%, #eef3fb 100%);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    display: block;
}

.topbar,
.public-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    backdrop-filter: blur(16px);
    background: rgba(255, 255, 255, 0.88);
    border-bottom: 1px solid rgba(219, 228, 240, 0.95);
}

.topbar__inner,
.public-topbar {
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 18px;
    justify-content: space-between;
}

.brand {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.brand--public {
    margin: 0 auto;
}

.nav {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 1;
}

.nav a {
    padding: 10px 14px;
    border-radius: 999px;
    color: var(--muted);
    font-weight: 600;
}

.nav a:hover,
.nav a.is-active {
    background: var(--surface-strong);
    color: var(--primary);
    text-decoration: none;
}

.topbar__user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar__user-name {
    font-weight: 600;
    white-space: nowrap;
}

.layout,
.public-wrapper {
    max-width: 1120px;
    margin: 28px auto 64px;
    padding: 0 24px;
}

.layout--wide {
    max-width: 1400px;
}

.stack-lg > * + *,
.stack-xl > * + * {
    margin-top: 24px;
}

.stack-xl > * + * {
    margin-top: 32px;
}

.hero-card,
.panel,
.auth-card,
.public-form-card,
.success-card,
.print-panel {
    background: var(--surface);
    border: 1px solid rgba(219, 228, 240, 0.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

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

.hero-card h1,
.public-form-card h1,
.auth-card h1,
.success-card h1 {
    margin: 0 0 8px;
    font-size: clamp(1.6rem, 2vw, 2.2rem);
}

.hero-card p,
.public-form-card p,
.auth-card p,
.success-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.hero-card__actions,
.action-row,
.auth-card__actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.panel {
    padding: 24px;
    margin-bottom: 24px;
}

.panel--soft {
    background: var(--surface-soft);
    box-shadow: none;
    border-style: solid;
}

.panel__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}

.panel__header h2,
.panel__header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.grid {
    display: grid;
    gap: 18px;
}

.grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.form-field--full {
    grid-column: 1 / -1;
}

.form-field span,
.form-label,
.radio-group legend {
    font-weight: 700;
    font-size: 0.95rem;
}

small,
.muted {
    color: var(--muted);
    font-size: 0.92rem;
}

.input,
.textarea,
select.input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 13px 14px;
    font-size: 1rem;
    line-height: 1.45;
    background: #fff;
    color: var(--text);
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.input:focus,
.textarea:focus,
select.input:focus {
    border-color: rgba(29, 78, 216, 0.55);
    box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.12);
    outline: none;
}

.input--compact {
    min-width: 260px;
}

.textarea {
    resize: vertical;
    min-height: 120px;
}

.checkbox-field {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    min-height: 52px;
}

.checkbox-field input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.radio-group {
    border: 0;
    padding: 0;
    margin: 0;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-top: 8px;
    background: var(--surface-soft);
}

.radio-option input {
    accent-color: var(--primary);
}

.field-card {
    background: var(--surface-soft);
    border: 1px solid rgba(219, 228, 240, 0.9);
    border-radius: 16px;
    padding: 18px;
}

.field-error {
    color: var(--danger);
    font-size: 0.92rem;
    margin-top: 8px;
    font-weight: 600;
}

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

.notice-card,
.info-box {
    padding: 16px 18px;
    border-radius: 14px;
    border: 1px solid rgba(29, 78, 216, 0.15);
    background: rgba(29, 78, 216, 0.05);
    color: #1f3b75;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    padding: 12px 18px;
    cursor: pointer;
    text-decoration: none;
    transition: transform .16s ease, opacity .16s ease, background .16s ease;
    white-space: nowrap;
}

.button:hover {
    background: var(--primary-strong);
    text-decoration: none;
    transform: translateY(-1px);
}

.button--ghost {
    background: #fff;
    color: var(--primary);
    border: 1px solid rgba(29, 78, 216, 0.18);
}

.button--ghost:hover {
    background: rgba(29, 78, 216, 0.06);
}

.button--danger {
    background: var(--danger);
    color: #fff;
}

.button--danger:hover {
    background: #a61d1d;
}

.button--small {
    padding: 9px 13px;
    font-size: 0.92rem;
}

.button--large {
    padding: 15px 22px;
    font-size: 1rem;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.link-box {
    display: flex;
    gap: 10px;
    align-items: center;
}

.link-box--full .input {
    flex: 1;
}

.alert {
    padding: 14px 18px;
    border-radius: 14px;
    margin-bottom: 18px;
    font-weight: 600;
}

.alert--success {
    background: rgba(15, 138, 95, 0.10);
    color: #0c6a48;
    border: 1px solid rgba(15, 138, 95, 0.18);
}

.alert--error {
    background: rgba(197, 40, 40, 0.09);
    color: #972626;
    border: 1px solid rgba(197, 40, 40, 0.18);
}

.alert--info {
    background: rgba(29, 78, 216, 0.09);
    color: #1f4ab0;
    border: 1px solid rgba(29, 78, 216, 0.18);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}

.stat-card {
    background: linear-gradient(180deg, #ffffff, #f8fbff);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid rgba(219, 228, 240, 0.9);
    box-shadow: var(--shadow);
}

.stat-card__label {
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 10px;
}

.stat-card__value {
    font-size: clamp(1.8rem, 3vw, 2.6rem);
    font-weight: 900;
}

.table-wrap {
    overflow: auto;
    border-radius: 16px;
    border: 1px solid rgba(219, 228, 240, 0.9);
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 780px;
    background: #fff;
}

.table th,
.table td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(219, 228, 240, 0.9);
    text-align: left;
    vertical-align: top;
}

.table thead th {
    background: #f8fbff;
    color: #4a5671;
    font-size: 0.92rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.table tbody tr:hover {
    background: rgba(29, 78, 216, 0.03);
}

.badge {
    display: inline-flex;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--surface-strong);
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.78rem;
}

.empty-state {
    padding: 28px;
    text-align: center;
    color: var(--muted);
    background: var(--surface-soft);
    border: 1px dashed var(--line);
    border-radius: 16px;
}

.auth-card {
    max-width: 620px;
    margin: 48px auto;
    padding: 28px;
}

.auth-card--wide {
    max-width: 900px;
}

.auth-card__header {
    margin-bottom: 20px;
}

.public-form-shell {
    max-width: 980px;
    margin: 32px auto 56px;
    padding: 0 20px;
}

.public-form-card {
    padding: 32px;
}

.public-form-card__logo {
    display: flex;
    justify-content: center;
    margin-bottom: 18px;
}

.public-form-card__logo img {
    max-height: 90px;
    max-width: 280px;
}

.public-form-card__header {
    text-align: center;
    margin-bottom: 28px;
}

.form-section {
    margin-bottom: 28px;
}

.form-section h2 {
    margin: 0 0 16px;
    font-size: 1.2rem;
}

.pdf-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.pdf-card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.pdf-card__header h3 {
    margin: 0;
    font-size: 1rem;
}

.pdf-frame {
    width: 100%;
    min-height: 520px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.signature-card {
    background: var(--surface-soft);
    border: 1px solid rgba(219, 228, 240, 0.9);
    border-radius: 16px;
    padding: 16px;
    margin-top: 16px;
}

.signature-card__header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
    align-items: center;
}

.signature-pad {
    width: 100%;
    height: 220px;
    border-radius: 14px;
    border: 1px dashed #b9c8df;
    background: #fff;
    touch-action: none;
}

.success-card {
    padding: 36px;
    text-align: center;
    max-width: 760px;
    margin: 60px auto;
}

.builder-row {
    padding: 18px;
    background: var(--surface-soft);
    border: 1px solid rgba(219, 228, 240, 0.95);
    border-radius: 16px;
}

.builder-row__header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
}

.builder-grid {
    display: grid;
    grid-template-columns: 1.1fr 1.8fr auto;
    gap: 16px;
    align-items: start;
}

.builder-extra {
    margin-top: 16px;
}

.logo-preview {
    margin-top: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    background: #fff;
    max-width: 260px;
}

.logo-preview img {
    max-height: 80px;
    width: auto;
}

.sticky-submit {
    position: sticky;
    bottom: 18px;
    display: flex;
    justify-content: flex-end;
    pointer-events: none;
}

.sticky-submit > * {
    pointer-events: auto;
    box-shadow: var(--shadow);
}

.snapshot__logo-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.snapshot__logo {
    max-height: 88px;
    max-width: 260px;
}

.snapshot__title {
    margin: 0 0 8px;
    font-size: clamp(1.6rem, 2vw, 2rem);
    text-align: center;
}

.snapshot__lead {
    color: var(--muted);
    text-align: center;
    margin: 0 0 20px;
}

.snapshot__meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.meta-card,
.snapshot__field,
.snapshot__text-block,
.snapshot__notice,
.snapshot__signature {
    background: var(--surface-soft);
    border: 1px solid rgba(219, 228, 240, 0.95);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 14px;
}

.snapshot__label {
    font-weight: 800;
    margin-bottom: 8px;
}

.snapshot__signature-box {
    border: 1px dashed #c3d0e5;
    border-radius: 14px;
    padding: 12px;
    background: #fff;
}

.snapshot__signature-box img {
    max-width: 100%;
    height: auto;
}

.print-toolbar {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
}

.print-panel {
    max-width: 980px;
    margin: 0 auto 40px;
    padding: 28px;
}

.signature-preview {
    padding: 12px;
    border: 1px dashed #b9c8df;
    border-radius: 14px;
    background: #fff;
    max-width: 420px;
}

@media (max-width: 1024px) {
    .grid--2,
    .stat-grid,
    .builder-grid {
        grid-template-columns: 1fr;
    }

    .hero-card {
        flex-direction: column;
    }

    .topbar__inner {
        flex-wrap: wrap;
    }
}

@media (max-width: 768px) {
    .layout,
    .public-wrapper,
    .public-form-shell {
        padding: 0 14px;
        margin-top: 20px;
    }

    .topbar__inner,
    .public-topbar {
        padding: 14px;
    }

    .nav {
        width: 100%;
        overflow: auto;
        padding-bottom: 2px;
    }

    .button,
    .button--small {
        width: 100%;
    }

    .action-row,
    .hero-card__actions,
    .auth-card__actions,
    .link-box,
    .link-box--full,
    .signature-card__header {
        flex-direction: column;
        align-items: stretch;
    }

    .public-form-card,
    .hero-card,
    .panel,
    .auth-card {
        padding: 20px;
    }

    .pdf-frame {
        min-height: 360px;
    }

    .sticky-submit {
        position: static;
    }
}

@media print {
    body {
        background: #fff;
    }

    .no-print,
    .topbar,
    .public-topbar,
    .alert {
        display: none !important;
    }

    .public-wrapper,
    .layout,
    .layout--wide {
        max-width: none;
        margin: 0;
        padding: 0;
    }

    .panel,
    .print-panel,
    .snapshot__field,
    .snapshot__text-block,
    .snapshot__notice,
    .snapshot__signature,
    .meta-card {
        box-shadow: none !important;
        border-color: #cfd8e6 !important;
        break-inside: avoid;
    }
}
