﻿:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #5b6675;
    --primary: #0b63ce;
    --danger: #b42318;
    --success: #067647;
    --warning: #b54708;
    --border: #d8e1ec;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
    background: radial-gradient(circle at top right, #eaf2ff 0%, var(--bg) 45%, #f9fbff 100%);
}

.container {
    width: min(1600px, 96vw);
    margin: 28px auto 40px;
}

.page-header h1 {
    margin: 0 0 8px;
}

.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.page-header-row h1 {
    margin: 0;
}

.page-header p {
    margin: 8px 0 0;
    color: var(--muted);
}

.card {
    margin-top: 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

h2 {
    margin-top: 0;
}

.breadcrumbs {
    margin-top: 10px;
    display: flex;
    gap: 6px;
    color: var(--muted);
}

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

.alert {
    margin-top: 14px;
    border-radius: 8px;
    padding: 10px 12px;
}

.alert.success {
    border: 1px solid #a8e6cc;
    background: #eafaf2;
    color: var(--success);
}

.alert.error {
    border: 1px solid #f8c9c5;
    background: #fff1f0;
    color: var(--danger);
}

.alert.info {
    border: 1px solid #bfd7fa;
    background: #edf5ff;
    color: var(--primary);
}

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

label {
    display: grid;
    gap: 6px;
    font-weight: 600;
}

input,
textarea,
select,
button {
    font: inherit;
}

input,
textarea,
select {
    border: 1px solid #c8d2de;
    border-radius: 8px;
    padding: 10px;
    width: 100%;
    color: var(--text);
    background: #fff;
}

textarea {
    resize: vertical;
}

button,
.button-link {
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

button.secondary,
.button-link.secondary {
    background: #475467;
}

.button-small {
    padding: 8px 12px;
    font-size: 0.9rem;
}

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

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    border-bottom: 1px solid var(--border);
    padding: 10px 8px;
    text-align: left;
    vertical-align: top;
}

.table th {
    color: var(--muted);
    font-weight: 700;
}

.table.compact th,
.table.compact td {
    padding: 8px 6px;
}

.truncate {
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.actions a {
    margin-right: 10px;
}

.muted {
    color: var(--muted);
}

.checkbox {
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px;
}

.checkbox input {
    width: auto;
}

.hint {
    color: var(--muted);
    font-weight: 500;
}

.actions-row {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.footer-note {
    margin-top: 24px;
    color: var(--muted);
    font-size: 0.92rem;
}

.inline-form {
    margin: 0;
}

.auth-card {
    max-width: 560px;
}

.auth-form {
    grid-template-columns: 1fr;
}

.builder-layout {
    margin-top: 16px;
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

.side-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.save-status {
    color: #98a2b3;
    font-weight: 600;
}

.save-status.unsaved {
    color: var(--warning);
}

.builder-save-bar {
    position: sticky;
    bottom: 0;
    margin-top: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.98);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
    z-index: 2;
}

.builder-save-bar button:disabled {
    background: #98a2b3;
    color: #eef2f6;
    cursor: not-allowed;
}

.builder-save-bar button:not(:disabled) {
    background: var(--primary);
    color: #fff;
    cursor: pointer;
}

.doc-editor {
    margin-top: 10px;
    background: #fff;
    border: 1px solid #cfd8e6;
    border-radius: 10px;
    min-height: 70vh;
    padding: 24px;
    outline: none;
    line-height: 1.5;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
    overflow: auto;
}

.doc-editor:focus {
    border-color: #7aa7e4;
    box-shadow: 0 0 0 3px rgba(11, 99, 206, 0.16);
}

.doc-editor .var-box {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px dashed var(--var-border, #8fb2ea);
    background: var(--var-bg, #edf4ff);
    color: var(--var-text, #0b3f86);
    font-size: 0.92em;
    font-weight: 600;
}

.doc-editor .cond-block {
    background: var(--cond-bg, rgba(250, 204, 21, 0.16));
    outline: 1px dotted var(--cond-border, #b98200);
    outline-offset: 1px;
    border-radius: 3px;
    transition: background 120ms ease, outline-color 120ms ease;
}

.doc-editor .cond-block[data-cond-mode="hide"] {
    text-decoration: line-through;
    text-decoration-thickness: 1px;
}

.spaced {
    margin-top: 18px;
}

.field-editor-list {
    margin-top: 10px;
    display: grid;
    gap: 10px;
}

.rule-card {
    margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: #f9fbff;
}

.rule-card h4 {
    margin: 0;
}

.rule-help {
    margin-top: 4px;
    margin-bottom: 0;
    font-size: 0.88rem;
}

.rule-grid {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.rule-grid > button {
    width: 100%;
}

.rule-grid > button:disabled {
    background: #98a2b3;
    color: #eef2f6;
    cursor: not-allowed;
}

.rule-note {
    margin: 0;
    font-size: 0.84rem;
}

.field-item {
    border: 1px solid #cfd9e7;
    border-radius: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
    overflow: hidden;
}

.field-item-summary {
    cursor: pointer;
    padding: 12px;
    background: #f3f8ff;
    border-bottom: 1px solid var(--border);
    margin: 0;
    list-style: none;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 12px;
}

.field-item-summary::-webkit-details-marker {
    display: none;
}

.field-item-summary::marker {
    content: "";
}

.field-item-header-main {
    min-width: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 10px;
}

.field-item-title-wrap {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.field-item-title {
    font-size: 0.95rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-item-meta {
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.3;
}

.field-collapse-btn {
    width: 30px;
    min-width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid #b9c9df;
    background: #fff;
    color: var(--primary);
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
}

.field-collapse-btn:hover {
    background: #eaf2ff;
}

.field-item-body {
    padding: 12px;
    display: grid;
    gap: 12px;
}

.token-chip {
    display: inline-block;
    background: #edf4ff;
    border: 1px dashed #9bb8e5;
    color: #0b3f86;
    border-radius: 999px;
    font-size: 0.86rem;
    padding: 4px 10px;
    cursor: grab;
    user-select: none;
}

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

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

.inline-check {
    display: flex;
    align-items: center;
    gap: 6px;
}

.inline-check input {
    width: auto;
}

.field-options-panel {
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid #d7e2f0;
    border-radius: 10px;
    background: #f8fbff;
}

.field-options-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.field-options-title {
    font-weight: 700;
    font-size: 0.9rem;
}

.field-option-add-btn {
    padding: 7px 10px;
    font-size: 0.82rem;
}

.field-options-list {
    display: grid;
    gap: 8px;
}

.field-option-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
}

.field-list-panel,
.field-total-panel {
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid #d7e2f0;
    border-radius: 10px;
    background: #f8fbff;
}

.field-total-sources {
    display: grid;
    gap: 6px;
}

.total-source-row {
    display: flex;
    gap: 8px;
    align-items: center;
    font-weight: 500;
    color: var(--text);
}

.total-source-row input {
    width: auto;
}

.field-option-remove-btn {
    border: 1px solid #f1bbb6;
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff1f0;
    color: var(--danger);
    font-weight: 600;
}

.field-option-remove-btn:hover {
    background: #ffe5e2;
}

.field-options-empty {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
    font-style: italic;
}

.field-item-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}

.field-bind-rule-btn:disabled {
    background: #98a2b3;
    color: #eef2f6;
    cursor: not-allowed;
}

.field-delete-btn {
    border: 1px solid var(--danger);
    background: var(--danger);
    color: #fff;
}

.field-delete-btn:hover {
    background: #951b13;
}

.field-options-panel[hidden],
.field-list-panel[hidden],
.field-total-panel[hidden] {
    display: none !important;
}

.fill-preview {
    display: grid;
    gap: 8px;
}

.preview-field {
    display: grid;
    gap: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
}

.preview-field small {
    color: var(--muted);
}

.hidden-textarea {
    display: none;
}

@media (min-width: 860px) {
    .grid-form {
        grid-template-columns: 1fr 1fr;
    }

    .grid-form .full,
    .grid-form > button {
        grid-column: 1 / -1;
    }

    .builder-layout {
        grid-template-columns: 1fr 2fr 1fr;
        align-items: start;
    }

    .builder-doc,
    .builder-side {
        position: sticky;
        top: 14px;
    }

    .builder-doc-center {
        max-height: calc(100vh - 40px);
        overflow: auto;
    }

    .builder-side-left,
    .builder-side-right {
        max-height: calc(100vh - 40px);
        overflow: auto;
    }
}


