:root {
    --bg: #f4f6f8;
    --surface: rgba(255, 255, 255, 0.88);
    --surface-strong: #ffffff;
    --surface-soft: rgba(255, 255, 255, 0.94);
    --surface-dark: rgba(23, 53, 74, 0.92);

    --text: #17354a;
    --text-strong: #102634;
    --text-on-dark: #ffffff;
    --muted: #5f7382;
    --muted-on-dark: rgba(255, 255, 255, 0.78);

    --border: rgba(23, 53, 74, 0.12);
    --border-strong: rgba(23, 53, 74, 0.18);
    --border-light: rgba(255, 255, 255, 0.16);

    --primary: #17354a;
    --accent: #d85a24;
    --danger: #b42318;
    --success: #117a46;

    --shadow: 0 10px 30px rgba(23, 53, 74, 0.10);
    --shadow-soft: 0 8px 20px rgba(23, 53, 74, 0.06);
    --shadow-strong: 0 24px 80px rgba(0, 0, 0, 0.22);

    --radius: 18px;
    --radius-sm: 12px;
    --radius-lg: 26px;

    --max-width: 1180px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background:
        radial-gradient(circle at top left, rgba(216, 90, 36, 0.12), transparent 22%),
        radial-gradient(circle at top right, rgba(23, 53, 74, 0.10), transparent 24%),
        var(--bg);
    color: var(--text);
}

body {
    min-height: 100vh;
    line-height: 1.5;
}

img {
    max-width: 100%;
    display: block;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea,
select {
    font: inherit;
}

strong {
    font-weight: 800;
}

/* =========================================
   BASE
========================================= */

.page-wrap {
    width: min(var(--max-width), calc(100% - 24px));
    margin: 24px auto 42px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    padding: 20px;
    backdrop-filter: blur(10px);
}

.empty-card {
    text-align: center;
    padding: 34px 20px;
}

.muted {
    color: var(--muted);
}

.small-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--muted);
}

.no-print {
    display: block;
}

/* =========================================
   BUTTONS
========================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 12px 18px;
    border-radius: 14px;
    border: 1px solid transparent;
    font-weight: 700;
    cursor: pointer;
    transition:
        transform 0.18s ease,
        border-color 0.18s ease,
        background 0.18s ease,
        box-shadow 0.18s ease,
        opacity 0.18s ease;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-secondary {
    background: var(--primary);
    color: #fff;
}

.btn-ghost {
    background: #fff;
    color: var(--primary);
    border-color: var(--border);
}

.btn-small {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 0.9rem;
}

.btn-large {
    width: min(760px, calc(100% - 8px));
    margin: 0 auto;
    min-height: 54px;
    font-size: 1rem;
}

/* =========================================
   ALERTS
========================================= */

.alert {
    padding: 12px 14px;
    border-radius: 14px;
    margin-bottom: 14px;
    font-weight: 600;
}

.alert-error {
    background: rgba(180, 35, 24, 0.14);
    color: #7a1f1a;
    border: 1px solid rgba(180, 35, 24, 0.18);
}

/* =========================================
   FORM ELEMENTS
========================================= */

.form-group {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.form-group label {
    font-weight: 700;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea,
.fill-input,
.fill-textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    background: #fff;
    color: var(--text);
    outline: none;
    transition:
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        background 0.18s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.fill-input:focus,
.fill-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(216, 90, 36, 0.12);
    background: #fff;
}

.form-group textarea,
.fill-textarea {
    resize: vertical;
    min-height: 120px;
}

.checkbox-row {
    display: block;
}

/* =========================================
   LOGIN
========================================= */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 22px;
}

.login-shell {
    width: 100%;
    max-width: 500px;
}

.login-card {
    background: var(--surface-dark);
    color: var(--text-on-dark);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.20);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.08);
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.brand-logo {
    width: 78px;
    height: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-title {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    line-height: 1.05;
}

.brand-subtitle {
    font-size: 0.98rem;
    color: rgba(255, 255, 255, 0.86);
    margin-top: 6px;
    font-weight: 500;
}

.login-heading {
    margin: 16px 0 6px;
    font-size: 1.6rem;
}

.login-copy {
    margin: 0 0 20px;
    color: rgba(255, 255, 255, 0.82);
}

.login-form {
    display: grid;
    gap: 10px;
}

.login-form label {
    font-size: 0.95rem;
    font-weight: 600;
    color: rgba(255,255,255,0.88);
}

.login-form input {
    width: 100%;
    border-radius: 14px;
    padding: 12px 14px;
    border: 1px solid var(--border-light);
    background: rgba(255,255,255,0.10);
    color: #ffffff;
    outline: none;
    transition:
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        background 0.18s ease;
}

.login-form input::placeholder {
    color: rgba(255,255,255,0.52);
}

.login-form input:focus {
    border-color: rgba(216, 90, 36, 0.7);
    background: rgba(255,255,255,0.14);
    box-shadow: 0 0 0 3px rgba(216, 90, 36, 0.15);
}

/* =========================================
   APP / TOPBAR
========================================= */

.app-page {
    color: var(--text);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 18px;
    background: rgba(255,255,255,0.85);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-logo {
    width: 58px;
    height: auto;
    flex-shrink: 0;
}

.topbar-brand {
    min-width: 0;
}

.topbar-title {
    font-size: 1.05rem;
    font-weight: 800;
    line-height: 1.05;
}

.topbar-subtitle {
    font-size: 0.92rem;
    color: var(--muted);
    margin-top: 3px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.user-badge {
    background: rgba(23, 53, 74, 0.08);
    color: var(--primary);
    padding: 10px 12px;
    border-radius: 999px;
    font-size: 0.92rem;
    font-weight: 700;
}

/* =========================================
   DASHBOARD
========================================= */

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-head h1 {
    margin: 0 0 6px;
    font-size: 1.9rem;
}

.page-head p {
    margin: 0;
    color: var(--muted);
}

.card-grid {
    display: grid;
    gap: 16px;
}

.form-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.form-card h2 {
    margin: 0;
    font-size: 1.25rem;
}

.meta-line {
    margin-top: 14px;
    color: var(--muted);
    font-size: 0.94rem;
}

.stamp {
    white-space: nowrap;
    background: rgba(216, 90, 36, 0.12);
    color: var(--accent);
    border-radius: 999px;
    padding: 8px 10px;
    font-size: 0.82rem;
    font-weight: 800;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

/* =========================================
   BUILDER
========================================= */

.builder-page {
    display: grid;
    gap: 16px;
}

.builder-top {
    position: sticky;
    top: 78px;
    z-index: 20;
}

.builder-top-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.builder-title-wrap,
.builder-subtitle-wrap {
    flex: 1 1 420px;
}

.builder-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.sections-list {
    display: grid;
    gap: 16px;
}

.section-card {
    padding: 18px;
}

.section-head {
    display: grid;
    grid-template-columns: 42px 1fr auto;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.section-head-main {
    min-width: 0;
}

.section-title-inline {
    font-size: 1.12rem;
    font-weight: 800;
}

.section-head-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.fields-list {
    display: grid;
    gap: 12px;
}

.field-card {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255,255,255,0.92);
    padding: 14px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.field-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-soft);
}

.field-card-top {
    display: grid;
    grid-template-columns: 42px 1fr auto;
    gap: 10px;
    align-items: flex-start;
}

.field-main {
    min-width: 0;
}

.field-chip {
    display: inline-flex;
    margin-bottom: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(216, 90, 36, 0.12);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 800;
}

.field-label-inline {
    font-size: 1rem;
    font-weight: 700;
}

.field-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.field-description {
    margin-top: 12px;
    color: var(--muted);
    font-size: 0.94rem;
    padding-left: 52px;
}

.field-footer {
    margin-top: 12px;
    padding-left: 52px;
}

.options-list {
    display: grid;
    gap: 10px;
    margin-top: 12px;
    padding-left: 52px;
}

.option-item {
    display: grid;
    grid-template-columns: 42px 1fr 36px;
    align-items: center;
    gap: 8px;
}

.option-delete {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(180, 35, 24, 0.10);
    color: var(--danger);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 800;
}

/* =========================================
   INLINE EDIT / DRAG
========================================= */

.inline-edit {
    min-height: 46px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.88);
    border-radius: 14px;
    outline: none;
    white-space: pre-wrap;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.inline-edit:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(216, 90, 36, 0.12);
}

.big-inline {
    font-size: 1.45rem;
    font-weight: 800;
    line-height: 1.2;
}

.inline-edit.is-saving {
    opacity: 0.7;
}

.inline-edit.is-error {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

.drag-handle {
    width: 42px;
    min-height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(23, 53, 74, 0.08);
    cursor: grab;
    user-select: none;
    font-size: 1.1rem;
}

.drag-handle:active {
    cursor: grabbing;
}

/* =========================================
   MODAL
========================================= */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(23, 53, 74, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.modal-card {
    width: min(620px, 100%);
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--shadow-strong);
    overflow: hidden;
}

.modal-card-medium {
    width: min(760px, 100%);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-head h2 {
    margin: 0;
    font-size: 1.2rem;
}

.modal-close {
    border: none;
    background: rgba(23, 53, 74, 0.08);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
}

.modal-body {
    padding: 20px;
}

.modal-loading,
.modal-error {
    color: var(--muted);
}

.field-type-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-top: 14px;
}

.field-type-card {
    width: 100%;
    text-align: left;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    border-radius: 16px;
    padding: 16px;
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
    display: grid;
    gap: 6px;
}

.field-type-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-soft);
    transform: translateY(-1px);
}

.field-type-card:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(216, 90, 36, 0.14);
}

.field-type-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(216, 90, 36, 0.12);
    color: var(--accent);
    font-weight: 800;
    font-size: 1.05rem;
}

.field-type-title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-strong);
    line-height: 1.25;
}

.field-type-copy {
    font-size: 0.93rem;
    color: var(--muted);
    line-height: 1.4;
}

/* =========================================
   FILL VIEW
========================================= */

.fill-page {
    display: grid;
    gap: 18px;
    padding-bottom: 120px;
}

.fill-header-card h1 {
    margin: 0 0 8px;
    font-size: 1.85rem;
    line-height: 1.2;
}

.fill-form {
    display: grid;
    gap: 18px;
}

.fill-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.fill-section-card {
    position: relative;
    overflow: hidden;
}

.fill-section-card h2 {
    margin: 0 0 16px;
    font-size: 1.25rem;
    line-height: 1.25;
    color: var(--text);
}

.fill-fields {
    display: grid;
    gap: 14px;
}

.fill-field-card {
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.94);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.fill-field-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-soft);
}

.fill-field-label {
    display: block;
    font-weight: 800;
    margin-bottom: 8px;
    color: var(--text);
    line-height: 1.3;
}

.fill-field-description {
    color: var(--muted);
    margin-bottom: 12px;
    font-size: 0.95rem;
    line-height: 1.45;
}

.choice-list {
    display: grid;
    gap: 10px;
}

.choice-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.choice-item:hover {
    border-color: var(--border-strong);
    background: rgba(255, 255, 255, 0.98);
}

.choice-item:has(input:focus-visible) {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(216, 90, 36, 0.12);
}

.choice-item input {
    width: auto;
    margin: 3px 0 0;
    transform: scale(1.12);
    flex-shrink: 0;
}

.choice-item span {
    line-height: 1.45;
    color: var(--text);
}

.required-star {
    color: var(--danger);
    margin-left: 4px;
    font-weight: 800;
}

.info-box {
    border-left: 4px solid var(--accent);
    background: rgba(216, 90, 36, 0.08);
    border-radius: 12px;
    padding: 14px;
    line-height: 1.45;
}

.sticky-save-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.94);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(12px);
    box-shadow: 0 -8px 20px rgba(23, 53, 74, 0.06);
}

/* =========================================
   PRINT VIEW
========================================= */

.print-body {
    margin: 0;
    background: #eef2f5;
    color: #111;
    font-family: var(--font);
}

.print-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 16px;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.print-sheet {
    width: min(980px, calc(100% - 24px));
    margin: 22px auto;
    background: #fff;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    border-radius: 14px;
}

.print-header {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-start;
    padding-bottom: 18px;
    border-bottom: 2px solid #e6eaee;
}

.print-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.print-logo {
    width: 86px;
    height: auto;
    object-fit: contain;
}

.print-brand-title {
    font-size: 1.08rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    line-height: 1.2;
}

.print-brand-subtitle {
    color: #566573;
    margin-top: 4px;
    line-height: 1.3;
}

.print-meta {
    font-size: 0.95rem;
    text-align: right;
    line-height: 1.65;
    color: #233543;
}

.print-title-block {
    padding: 22px 0 10px;
}

.print-title-block h1 {
    margin: 0 0 8px;
    font-size: 1.7rem;
    line-height: 1.2;
    color: #162d3d;
}

.print-title-block p {
    margin: 0;
    color: #5d6872;
    line-height: 1.45;
}

.print-section {
    margin-top: 24px;
    page-break-inside: avoid;
}

.print-section h2 {
    margin: 0 0 14px;
    font-size: 1.2rem;
    border-bottom: 1px solid #e6eaee;
    padding-bottom: 8px;
    color: #162d3d;
}

.print-field {
    margin-bottom: 18px;
}

.print-field-label {
    font-weight: 800;
    margin-bottom: 6px;
    line-height: 1.35;
}

.print-description {
    color: #5d6872;
    font-size: 0.94rem;
    margin-bottom: 8px;
    line-height: 1.45;
}

.print-choice-list {
    display: grid;
    gap: 8px;
}

.print-choice-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    line-height: 1.45;
}

.print-box {
    min-width: 22px;
    display: inline-block;
    font-weight: 700;
}

.print-text-answer {
    min-height: 24px;
    padding: 8px 0;
    border-bottom: 1px solid #d6dde3;
    white-space: pre-wrap;
    line-height: 1.5;
}

.print-empty-line {
    color: #a0aab3;
}

.print-info-box {
    background: #f7f9fb;
    border-left: 4px solid #d85a24;
    padding: 12px 14px;
    line-height: 1.45;
}

/* =========================================
   RESPONSIVE
========================================= */

@media (max-width: 760px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-right {
        width: 100%;
        justify-content: space-between;
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .page-head .btn {
        width: 100%;
    }

    .form-card-head {
        flex-direction: column;
    }

    .card-actions .btn {
        width: 100%;
    }

    .brand-logo {
        width: 66px;
    }

    .brand-title {
        font-size: 1.1rem;
    }

    .brand-subtitle {
        font-size: 0.92rem;
    }

    .builder-top {
        top: 112px;
    }

    .section-head,
    .field-card-top {
        grid-template-columns: 1fr;
    }

    .field-description,
    .field-footer,
    .options-list {
        padding-left: 0;
    }

    .option-item {
        grid-template-columns: 36px 1fr 32px;
    }

    .builder-actions .btn,
    .section-head-actions .btn,
    .field-actions .btn {
        width: 100%;
    }

    .field-type-grid {
        grid-template-columns: 1fr;
    }

    .fill-page {
        gap: 14px;
        padding-bottom: 110px;
    }

    .fill-meta-grid {
        grid-template-columns: 1fr;
    }

    .fill-header-card h1 {
        font-size: 1.55rem;
    }

    .fill-field-card {
        padding: 14px;
    }

    .choice-item {
        padding: 11px 12px;
    }

    .print-header {
        flex-direction: column;
    }

    .print-meta {
        text-align: left;
    }

    .print-sheet {
        padding: 18px;
    }

    .print-title-block h1 {
        font-size: 1.45rem;
    }
}

/* =========================================
   PRINT
========================================= */

@media print {
    html,
    body {
        background: #fff !important;
    }

    .no-print,
    .topbar,
    .sticky-save-bar,
    .print-toolbar {
        display: none !important;
    }

    .print-sheet {
        width: 100%;
        margin: 0;
        padding: 0;
        box-shadow: none;
        border-radius: 0;
    }

    .print-section,
    .print-field,
    .print-choice-item,
    .print-info-box {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    @page {
        size: A4;
        margin: 14mm;
    }
}