:root {
    --template-ink: #07143d;
    --template-brand: #0647c9;
    --template-brand-dark: #05369a;
    --template-line: #e5ebf3;
    --template-soft: #f6f8fc;
    --template-panel: #ffffff;
    --template-muted: #64748b;
    --template-success: #047857;
}

body.template-ui {
    background:
        linear-gradient(180deg, #fbfcff 0%, var(--template-soft) 18rem, #f8fafc 100%) !important;
    color: var(--template-ink);
}

.template-app-header {
    border-bottom: 1px solid rgba(203, 213, 225, 0.72) !important;
    background: rgba(255, 255, 255, 0.96) !important;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04) !important;
    backdrop-filter: blur(14px);
}

.template-app-header .template-header-inner {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center !important;
    gap: 1.25rem !important;
    max-width: 94rem !important;
}

.template-header-left {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center !important;
    gap: 1.25rem !important;
    min-width: 0;
}

.template-brand-mark {
    display: inline-flex;
    align-items: center;
    gap: 0.8rem;
    color: var(--template-ink);
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: 0;
    white-space: nowrap;
}

.template-brand-mark:hover {
    color: var(--template-brand);
}

.template-logo {
    display: inline-flex;
    width: 2.5rem;
    height: 2.5rem;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--template-brand);
    border-radius: 0.55rem;
    color: var(--template-brand);
    background: #fff;
}

.template-logo svg,
.template-action svg,
.template-status svg,
.template-back-button svg,
.template-privacy-card svg {
    width: 1.1rem;
    height: 1.1rem;
    flex: 0 0 auto;
}

.template-title-block {
    min-width: 0;
}

.template-breadcrumbs {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
    color: #64748b;
    font-size: 0.78rem;
    font-weight: 700;
}

.template-breadcrumbs a {
    color: var(--template-brand);
}

.template-breadcrumbs span:last-child {
    overflow: hidden;
    color: #334155;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-title-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
    margin-top: 0.15rem;
}

.template-page-title {
    overflow: hidden;
    color: var(--template-ink);
    font-size: 1.05rem;
    font-weight: 900;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-header-badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid #dbeafe;
    border-radius: 999px;
    background: #eff6ff;
    padding: 0.28rem 0.65rem;
    color: var(--template-brand);
    font-size: 0.68rem;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
}

.template-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.8rem;
}

.template-status {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 1px solid #bbf7d0;
    border-radius: 0.75rem;
    background: #f0fdf4;
    padding: 0.58rem 0.85rem;
    color: #166534;
    font-size: 0.75rem;
    font-weight: 800;
    white-space: nowrap;
}

.template-back-button,
.template-action,
.template-zoom-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.45rem;
    font-weight: 900;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.template-back-button {
    gap: 0.45rem;
    border: 1px solid #cbd5e1;
    background: #fff;
    padding: 0.68rem 0.9rem;
    color: #0f172a;
    font-size: 0.78rem;
}

.template-back-button:hover {
    border-color: #94a3b8;
    background: #f8fafc;
}

.template-action {
    gap: 0.5rem !important;
    border: 1px solid var(--template-brand) !important;
    background: var(--template-brand) !important;
    padding: 0.7rem 1rem !important;
    color: #fff !important;
    font-size: 0.78rem !important;
    box-shadow: 0 12px 24px rgba(6, 71, 201, 0.16) !important;
}

.template-action:hover {
    background: var(--template-brand-dark) !important;
    box-shadow: 0 16px 30px rgba(6, 71, 201, 0.2) !important;
}

.template-ui .template-workspace {
    max-width: 94rem !important;
    align-items: flex-start !important;
    gap: 1.25rem !important;
    padding-top: 1.4rem !important;
}

.template-ui .template-editor {
    width: 100% !important;
    max-width: 32rem;
    border: 1px solid var(--template-line) !important;
    border-radius: 0.6rem !important;
    background: rgba(255, 255, 255, 0.97) !important;
    padding: 1rem !important;
    box-shadow: 0 18px 48px rgba(7, 20, 61, 0.06) !important;
}

.template-ui .template-editor-title {
    display: flex !important;
    align-items: center;
    gap: 0.6rem;
    border-bottom: 1px solid #eef2f7 !important;
    padding-bottom: 0.9rem !important;
    color: var(--template-ink) !important;
    font-size: 1.02rem !important;
    font-weight: 900 !important;
    letter-spacing: 0;
}

.template-editor-icon {
    display: inline-flex;
    width: 1.95rem;
    height: 1.95rem;
    align-items: center;
    justify-content: center;
    border: 1px solid #dbeafe;
    border-radius: 0.48rem;
    background: #eff6ff;
    color: var(--template-brand);
}

.template-ui .template-editor > div:not(.template-privacy-card) {
    border: 1px solid #eef2f7;
    border-radius: 0.55rem;
    background: #fff;
    padding: 0.85rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.03);
}

.template-ui .template-editor h3 {
    position: relative;
    margin-bottom: 0.65rem;
    color: #172554 !important;
    font-size: 0.76rem !important;
    font-weight: 900 !important;
    letter-spacing: 0;
    text-transform: none !important;
}

.template-ui .template-editor h3::after {
    content: "^";
    position: absolute;
    right: 0;
    top: 0;
    color: #94a3b8;
    font-size: 0.8rem;
}

.template-ui .template-editor label {
    color: #475569 !important;
    font-size: 0.69rem !important;
    font-weight: 800 !important;
    letter-spacing: 0;
    text-transform: none !important;
}

.template-ui .template-editor input,
.template-ui .template-editor select,
.template-ui .template-editor textarea {
    border: 1px solid #e2e8f0 !important;
    border-radius: 0.38rem !important;
    background-color: #fff !important;
    color: #0f172a !important;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.025);
}

.template-ui .template-editor input:focus,
.template-ui .template-editor select:focus,
.template-ui .template-editor textarea:focus,
.template-ui .calculator-card input:focus {
    border-color: var(--template-brand) !important;
    box-shadow: 0 0 0 3px rgba(6, 71, 201, 0.1) !important;
    outline: none !important;
}

.template-privacy-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.85rem;
    border: 1px solid #bfdbfe !important;
    border-radius: 0.55rem;
    background: #fbfdff;
    padding: 0.95rem !important;
    color: #1e293b;
}

.template-privacy-icon {
    display: inline-flex;
    width: 2.4rem;
    height: 2.4rem;
    align-items: center;
    justify-content: center;
    border: 1px solid #bfdbfe;
    border-radius: 0.55rem;
    color: var(--template-brand);
    background: #eff6ff;
}

.template-privacy-card strong {
    display: block;
    color: var(--template-ink);
    font-size: 0.82rem;
    font-weight: 900;
}

.template-privacy-card span {
    display: block;
    margin-top: 0.25rem;
    color: #64748b;
    font-size: 0.72rem;
    line-height: 1.45;
}

.template-preview-panel {
    display: flex !important;
    min-width: 0;
    flex-direction: column;
    align-items: stretch !important;
    justify-content: flex-start !important;
    border: 1px solid var(--template-line);
    border-radius: 0.55rem;
    background: #f8fafc;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
    overflow: hidden;
}

.template-sheet-wrap {
    display: flex;
    flex: 1 1 auto;
    min-height: 44rem;
    align-items: flex-start;
    justify-content: center;
    overflow: auto;
    padding: 2.25rem 1.2rem;
}

.template-ui .template-sheet-wrap .preview-page {
    border: 1px solid #e2e8f0;
    box-shadow: 0 16px 42px rgba(15, 23, 42, 0.16) !important;
    zoom: var(--template-zoom, 0.72);
}

.template-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-top: 1px solid var(--template-line);
    background: #fff;
    padding: 1rem 1.2rem;
}

.template-zoom-control,
.template-preview-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.template-zoom-label {
    color: #334155;
    font-size: 0.78rem;
    font-weight: 800;
}

.template-zoom-button {
    width: 2.1rem;
    height: 2.1rem;
    border: 1px solid #dbe3ef;
    background: #fff;
    color: #0f172a;
    font-size: 1rem;
    line-height: 1;
}

.template-zoom-button:hover {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: var(--template-brand);
}

.template-zoom-value {
    min-width: 2.8rem;
    color: #0f172a;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 900;
}

.template-outline-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: 1px solid #9db2d0;
    border-radius: 0.48rem;
    background: #fff;
    padding: 0.75rem 1.05rem;
    color: #0647c9;
    font-size: 0.78rem;
    font-weight: 900;
    transition: background-color 0.18s ease, border-color 0.18s ease;
}

.template-outline-action:hover {
    border-color: var(--template-brand);
    background: #eff6ff;
}

.template-outline-action svg {
    width: 1.1rem;
    height: 1.1rem;
}

.template-ui .calculator-card,
.template-calculator-card {
    border-radius: 0.65rem !important;
    border-color: var(--template-line) !important;
    box-shadow: 0 18px 48px rgba(7, 20, 61, 0.08) !important;
}

.template-ui .calculator-card button,
.template-ui .filter-btn,
.template-ui .tool-card {
    border-radius: 0.55rem !important;
}

@media (max-width: 1024px) {
    .template-app-header .template-header-inner {
        grid-template-columns: 1fr;
    }

    .template-header-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .template-status {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .template-ui .template-workspace {
        padding-top: 1rem !important;
    }

    .template-ui .template-editor {
        max-width: none;
    }

    .template-sheet-wrap {
        min-height: 34rem;
        padding: 1.5rem 0.8rem;
    }

    .template-ui .template-sheet-wrap .preview-page {
        zoom: var(--template-zoom, 0.56);
    }
}

@media (max-width: 640px) {
    .template-header-left {
        grid-template-columns: 1fr;
        gap: 0.7rem !important;
    }

    .template-brand-mark {
        font-size: 0.92rem;
    }

    .template-title-row {
        flex-wrap: wrap;
    }

    .template-page-title {
        width: 100%;
        white-space: normal;
    }

    .template-header-actions,
    .template-preview-toolbar,
    .template-preview-actions,
    .template-zoom-control {
        width: 100%;
    }

    .template-preview-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .template-preview-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .template-action,
    .template-back-button,
    .template-outline-action {
        width: 100%;
    }
}

@media print {
    body.template-ui {
        background: #fff !important;
    }

    .template-app-header,
    .template-preview-toolbar,
    .template-privacy-card {
        display: none !important;
    }

    .template-preview-panel,
    .template-sheet-wrap {
        display: block !important;
        border: 0 !important;
        background: #fff !important;
        box-shadow: none !important;
        min-height: 0 !important;
        overflow: visible !important;
        padding: 0 !important;
    }

    .template-ui .template-sheet-wrap .preview-page {
        zoom: 1 !important;
        border: 0 !important;
        box-shadow: none !important;
    }
}
