@font-face {
    font-family: 'Inter';
    src: url('../fonts/Inter-Variable.ttf') format('truetype');
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
}

@font-face {
    font-family: 'Noto Serif SC';
    src: url('../fonts/NotoSerifSC-Variable.ttf') format('truetype');
    font-style: normal;
    font-weight: 200 900;
    font-display: swap;
}

@font-face {
    font-family: 'Ma Shan Zheng';
    src: url('../fonts/MaShanZheng-Regular.ttf') format('truetype');
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'Liu Jian Mao Cao';
    src: url('../fonts/LiuJianMaoCao-Regular.ttf') format('truetype');
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'Zhi Mang Xing';
    src: url('../fonts/ZhiMangXing-Regular.ttf') format('truetype');
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'Seal Songti';
    src:
        local('STSongti-SC-Regular'),
        local('Songti SC'),
        local('STSong'),
        url('../fonts/Songti.ttc');
    font-style: normal;
    font-weight: 400;
    font-display: block;
}

/* ========== Design System & Variables ========== */
:root {
    --color-bg: #F5F0ED;
    --color-surface: #FFFFFF;
    --color-brand: #5C2E2E;
    --color-brand-light: #8B5E5E;
    --color-primary: #C4A0A0;
    --color-primary-hover: #B08888;
    --color-primary-dark: #A07878;
    --color-accent: #7B68AE;
    --color-accent-hover: #6A58A0;
    --color-green: #3D8B6F;
    --color-green-hover: #2D7A5E;
    --color-danger: #C0392B;
    --color-danger-hover: #A5301F;
    --color-text: #2C2C2C;
    --color-text-secondary: #777;
    --color-border: #E0D5D0;
    --color-border-light: #F0EAE6;
    --color-stamp: #CC0000;

    --font-ui: 'Inter', -apple-system, 'Segoe UI', sans-serif;
    --font-stamp: 'Seal Songti', serif;
    --font-form: 'Noto Serif SC', 'SimSun', '宋体', serif;
    --font-sig-1: 'Liu Jian Mao Cao', cursive;
    --font-sig-2: 'Ma Shan Zheng', cursive;
    --font-sig-3: 'Zhi Mang Xing', cursive;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
    --shadow-paper: 0 2px 20px rgba(92, 46, 46, 0.08), 0 0 1px rgba(0, 0, 0, 0.1);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --transition: 0.2s ease;
}

/* ========== Reset & Base ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-ui);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-primary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary-dark);
}

/* ========== Toolbar ========== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--color-brand) 0%, var(--color-brand-light) 100%);
    color: #FFF;
    gap: 16px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(92, 46, 46, 0.2);
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.toolbar-title {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 1px;
    white-space: nowrap;
}

.toolbar-user {
    font-size: 0.85rem;
    opacity: 0.85;
    white-space: nowrap;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    user-select: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-pink {
    background: var(--color-primary);
    color: var(--color-brand);
}

.btn-pink:hover {
    background: var(--color-primary-hover);
}

.btn-accent {
    background: var(--color-accent);
    color: #FFF;
}

.btn-accent:hover {
    background: var(--color-accent-hover);
}

.btn-green {
    background: var(--color-green);
    color: #FFF;
}

.btn-green:hover {
    background: var(--color-green-hover);
}

.btn-dark {
    background: var(--color-brand-light);
    color: #FFF;
}

.btn-dark:hover {
    background: var(--color-brand);
}

.btn-danger {
    background: var(--color-danger);
    color: #FFF;
}

.btn-danger:hover {
    background: var(--color-danger-hover);
}

.btn-full {
    width: 100%;
}

.btn-half {
    flex: 1;
}

/* ========== Main Layout ========== */
.main-content {
    display: flex;
    gap: 20px;
    padding: 20px 24px;
    max-width: 1400px;
    margin: 0 auto;
    align-items: flex-start;
}

/* ========== Canvas Area ========== */
.canvas-area {
    flex: 1;
    min-width: 0;
}

.canvas-label {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    margin-bottom: 10px;
    font-weight: 500;
}

.canvas-scroll-wrapper {
    background: var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: 20px;
    overflow: auto;
    max-height: calc(100vh - 120px);
    display: flex;
    justify-content: center;
}

/* ========== Prescription ========== */
.prescription {
    width: 780px;
    background: #FFF;
    box-shadow: var(--shadow-paper);
    padding: 18px 28px 12px;
    position: relative;
    font-family: var(--font-form);
    font-size: 13px;
    color: #1a1a1a;
    flex-shrink: 0;
    line-height: 1.6;
}

/* Watermark */
.watermark-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    background-repeat: repeat;
    background-size: 240px 170px;
}

.watermark-layer.hidden {
    display: none;
}

/* Header */
.rx-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.rx-header svg {
    max-width: 200px;
    height: 40px;
}

.rx-badge {
    background: var(--color-surface);
    border: 1.5px solid #999;
    padding: 3px 16px;
    font-size: 13px;
    font-family: var(--font-form);
    cursor: pointer;
    letter-spacing: 4px;
    transition: all var(--transition);
}

.rx-badge:hover {
    background: #f5f5f5;
}

/* Title */
.rx-title-section {
    text-align: center;
    margin-bottom: 4px;
}

.rx-hospital {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2px;
    outline: none;
    border-bottom: 1px dashed transparent;
    display: inline-block;
    transition: border-color var(--transition);
}

.rx-hospital:hover,
.rx-hospital:focus {
    border-bottom-color: var(--color-primary);
}

.rx-title {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 12px;
    margin-top: 2px;
}

/* Info Section */
.rx-info {
    margin-bottom: 4px;
}

.rx-info-row {
    display: flex;
    justify-content: space-between;
    font-size: 12.5px;
    line-height: 1.8;
}

.rx-info-item {
    flex: 1;
    text-align: left;
}

.rx-info-item:first-child {
    flex: 2;
}

.editable {
    outline: none;
    border-bottom: 1px dashed transparent;
    transition: border-color var(--transition);
    min-width: 30px;
    display: inline-block;
}

.editable:hover,
.editable:focus {
    border-bottom-color: var(--color-primary);
}

/* Divider */
.rx-divider {
    border: none;
    border-top: 1px solid #333;
    margin: 6px 0;
}

/* Patient Info */
.rx-patient {
    display: flex;
    justify-content: space-between;
    font-size: 14.5px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.rx-patient-item {
    white-space: nowrap;
    flex: 1;
}

/* Main Content */
.rx-main {
    display: flex;
    border: 1.5px solid #333;
    min-height: 260px;
    position: relative;
}

.rx-diagnosis {
    width: 28%;
    border-right: 1px solid #333;
    padding: 8px;
    display: flex;
    flex-direction: column;
}

.rx-diagnosis-label {
    font-weight: 600;
    font-size: 14.5px;
    margin-bottom: 4px;
}

.rx-diagnosis-content {
    flex: 1;
    outline: none;
    font-size: 14px;
    line-height: 1.7;
    min-height: 80px;
    white-space: pre-wrap;
}

.rx-diagnosis-content:hover,
.rx-diagnosis-content:focus {
    background: rgba(196, 160, 160, 0.05);
}

.rx-content {
    flex: 1;
    padding: 8px 12px;
    position: relative;
}

.rx-symbol {
    font-size: 38px;
    font-weight: 400;
    font-family: var(--font-form);
    font-style: normal;
    margin-bottom: 4px;
    color: #333;
}

.rx-drugs {
    outline: none;
    min-height: 150px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: normal;
    overflow-wrap: break-word;
}

.rx-drugs:empty::before {
    content: attr(data-placeholder);
    color: #ccc;
    font-style: italic;
}

.rx-drugs:hover,
.rx-drugs:focus {
    background: rgba(196, 160, 160, 0.05);
}

/* Footer */
.rx-footer {
    border: 1.5px solid #333;
    border-top: none;
    padding: 8px 10px;
}

.rx-footer-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.rx-note {
    font-size: 11.5px;
    color: #555;
    line-height: 1.6;
}

.rx-signature-area {
    font-size: 13px;
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.sig-line {
    display: inline-block;
    width: 120px;
    border-bottom: 1px solid #333;
}

.rx-date {
    text-align: right;
    margin-top: 6px;
    font-size: 12.5px;
}

/* Bottom Row */
.rx-bottom {
    display: flex;
    justify-content: space-around;
    border: 1.5px solid #333;
    border-top: none;
    padding: 8px 0;
    font-size: 13px;
    font-weight: 600;
}

.rx-bottom-item {
    flex: 1;
    text-align: center;
}

/* ========== A4 Diagnostic Certificate ========== */
.diagnosis-cert {
    width: 794px;
    min-height: 1123px;
    background: #FFF;
    box-shadow: var(--shadow-paper);
    padding: 60px 65px 40px;
    position: relative;
    font-family: var(--font-form);
    font-size: 15px;
    color: #1a1a1a;
    flex-shrink: 0;
    line-height: 2;
    display: flex;
    flex-direction: column;
}

.cert-header {
    text-align: center;
    margin-bottom: 10px;
    position: relative;
}

.cert-barcode {
    position: absolute;
    top: 5px;
    right: 0;
}

.cert-hospital {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 2px;
    margin-bottom: 4px;
    outline: none;
    transition: background var(--transition);
    display: inline-block;
}

.cert-hospital:hover,
.cert-hospital:focus {
    background: rgba(196, 160, 160, 0.06);
}

.cert-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 14px;
    margin-top: 2px;
}

.cert-patient-row {
    display: flex;
    justify-content: space-between;
    font-size: 15px;
    line-height: 2.2;
}

.cert-field {
    flex: 1;
}

.cert-name-field {
    text-align: left;
}

.cert-center-field {
    text-align: center;
}

.cert-right-field {
    text-align: right;
}

.cert-divider-bold {
    border: none;
    border-top: 2px solid #000;
    margin: 0 0 8px;
}

.cert-section {
    margin: 8px 0;
    font-size: 15px;
    line-height: 2;
}

.cert-label {
    font-weight: 700;
}

.cert-text {
    outline: none;
    transition: background var(--transition);
    min-width: 100px;
    display: inline;
}

.cert-text:hover,
.cert-text:focus {
    background: rgba(196, 160, 160, 0.06);
}

.cert-text:empty::before {
    content: attr(data-placeholder);
    color: #ccc;
    font-style: italic;
}

.cert-treatment {
    display: block;
    white-space: pre-line;
    min-height: 80px;
    padding: 4px 0;
    margin-top: 4px;
    line-height: 2;
    text-align: left;
    text-indent: 0;
}

.cert-spacer {
    flex-grow: 1;
}

.cert-bottom-wrapper {
    margin-top: 30px;
}

.cert-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    font-size: 14px;
    line-height: 2;
    margin-bottom: 15px;
}

.cert-dates {
    display: flex;
    flex-direction: column;
}

.cert-doctor-area {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.cert-doctor-line {
    display: inline-block;
    width: 120px;
    border-bottom: 1px solid transparent;
}

.bottom-bold-divider {
    margin: 10px 0;
}

.cert-disclaimer {
    text-align: right;
    font-size: 14px;
    color: #1a1a1a;
    font-weight: 700;
}

/* ========== Draggable Elements ========== */
.draggable-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

.draggable-el {
    position: absolute;
    cursor: grab;
    pointer-events: all;
    user-select: none;
    transition: box-shadow 0.15s;
}

.draggable-el:active {
    cursor: grabbing;
}

.draggable-el:hover {
    filter: brightness(1.02);
}

.draggable-el.selected {
    outline: 2px dashed var(--color-accent);
    outline-offset: 4px;
}

.stamp-el {
    opacity: 0.88;
}

.stamp-el svg {
    display: block;
}

.signature-el {
    font-size: 32px;
    color: #1a1a1a;
    padding: 4px 8px;
    white-space: nowrap;
}

/* Delete hint on hover */
.draggable-el::after {
    content: '点击设置';
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    font-family: var(--font-ui);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 2px 8px;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.2s;
    white-space: nowrap;
    pointer-events: none;
}

.draggable-el:hover::after {
    opacity: 1;
}

/* ========== Control Panel ========== */
.control-panel {
    width: 300px;
    flex-shrink: 0;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 20px;
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

.panel-title {
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--color-border-light);
}

.panel-section {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-border-light);
}

.panel-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.panel-hint {
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.panel-hint-box {
    background: linear-gradient(135deg, #FFF8F0, #FFF0E8);
    border-left: 3px solid var(--color-primary-dark);
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    text-align: center;
}

.panel-hint-box p {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-brand);
    line-height: 1.6;
}

.panel-buttons {
    display: flex;
    gap: 8px;
}

.panel-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
}

/* Color Picker */
.color-picker-wrapper {
    position: relative;
}

.color-picker {
    width: 100%;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-sm);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #ccc;
    border-radius: 24px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: var(--transition);
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--color-green);
}

.toggle-switch input:checked+.toggle-slider::before {
    transform: translateX(20px);
}

.panel-disclaimer {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    background: #FFF5F5;
    border: 1px solid #FFE0E0;
    padding: 10px;
    border-radius: var(--radius-sm);
    line-height: 1.5;
    margin-top: 8px;
}

/* ========== Element Settings Modal ========== */
.element-settings {
    position: fixed;
    z-index: 1000;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    width: 280px;
    overflow: hidden;
    animation: settingsIn 0.2s ease;
}

@keyframes settingsIn {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.element-settings.hidden {
    display: none;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--color-brand);
    color: #FFF;
}

.settings-header h3 {
    font-size: 0.9rem;
}

.settings-close-btn {
    background: none;
    border: none;
    color: #FFF;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background var(--transition);
}

.settings-close-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.settings-body {
    padding: 14px 16px;
}

.setting-row {
    margin-bottom: 12px;
}

.setting-row label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--color-text-secondary);
}

.setting-row input[type="text"],
.setting-row select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.85rem;
    outline: none;
    transition: border-color var(--transition);
}

.setting-row input[type="text"]:focus,
.setting-row select:focus {
    border-color: var(--color-accent);
}

.setting-row input[type="range"] {
    width: 100%;
    accent-color: var(--color-accent);
}

.setting-row input[type="color"] {
    width: 100%;
    height: 30px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 2px;
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 24px;
    background: var(--color-brand);
    color: #FFF;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: toastIn 0.3s ease;
}

.toast.hidden {
    display: none;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ========== Responsive: Tablet ========== */
@media (max-width: 1100px) {
    .main-content {
        flex-direction: column;
    }

    .control-panel {
        width: 100%;
        position: static;
        max-height: none;
    }

    .canvas-scroll-wrapper {
        max-height: none;
    }
}

/* ========== Responsive: Small Tablet ========== */
@media (max-width: 860px) {
    .toolbar {
        padding: 10px 16px;
    }

    .toolbar-actions {
        gap: 4px;
    }

    .btn {
        padding: 6px 10px;
        font-size: 0.78rem;
    }

    .canvas-scroll-wrapper {
        padding: 16px;
    }

    .prescription {
        transform: scale(0.85);
        transform-origin: top center;
    }
}

/* ========== Responsive: Phone ========== */
@media (max-width: 768px) {

    /* --- Toolbar: compact 2-row layout --- */
    .toolbar {
        padding: 8px 12px;
        gap: 8px;
    }

    .toolbar-left {
        gap: 8px;
        width: 100%;
        justify-content: space-between;
    }

    .toolbar-title {
        font-size: 1rem;
    }

    .toolbar-user {
        font-size: 0.75rem;
    }

    .toolbar-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .toolbar-actions .btn {
        padding: 8px 4px;
        font-size: 0.72rem;
        justify-content: center;
        border-radius: 6px;
    }

    /* Wider export button spanning full row */
    .toolbar-actions .btn:last-child {
        grid-column: 1 / -1;
    }

    /* --- Main content --- */
    .main-content {
        padding: 10px 8px;
        gap: 12px;
    }

    .canvas-label {
        font-size: 0.8rem;
        margin-bottom: 6px;
    }

    .canvas-scroll-wrapper {
        padding: 8px;
        border-radius: var(--radius-md);
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* --- Prescription: scale to fit viewport --- */
    .prescription {
        transform: none;
        width: 780px;
        min-width: 780px;
        transform-origin: top left;
        font-size: 13px;
    }

    /* --- Cert: fluid mobile layout --- */
    .diagnosis-cert {
        width: 100%;
        min-width: 0;
        min-height: auto;
        padding: 24px 18px 28px;
        font-size: 12px;
        line-height: 1.85;
    }

    .cert-header {
        padding-top: 26px;
        margin-bottom: 8px;
    }

    .cert-barcode {
        top: 0;
        right: 0;
        width: 112px;
        height: 24px;
    }

    .cert-hospital {
        max-width: calc(100% - 124px);
        font-size: 1.05rem;
        letter-spacing: 1px;
    }

    .cert-title {
        font-size: 1.55rem;
        letter-spacing: 0.45rem;
    }

    .cert-patient-row {
        flex-wrap: wrap;
        gap: 2px 12px;
        font-size: 0.95rem;
        line-height: 1.85;
    }

    .cert-field {
        flex: 1 1 calc(50% - 12px);
        min-width: 0;
    }

    .cert-center-field,
    .cert-right-field {
        text-align: left;
    }

    .cert-section {
        font-size: 0.95rem;
        line-height: 1.85;
    }

    .cert-text {
        min-width: 0;
    }

    .cert-treatment {
        min-height: 0;
        line-height: 1.85;
    }

    .cert-bottom-wrapper {
        margin-top: 18px;
    }

    .cert-bottom {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        font-size: 0.9rem;
        margin-bottom: 10px;
    }

    .cert-dates {
        gap: 2px;
    }

    .cert-doctor-area {
        justify-content: flex-end;
        min-height: 40px;
    }

    .cert-disclaimer {
        font-size: 0.9rem;
    }

    /* --- Control panel: collapsible on mobile --- */
    .control-panel {
        width: 100%;
        position: static;
        max-height: none;
        border-radius: var(--radius-md);
        padding: 16px;
    }

    .panel-title {
        font-size: 1rem;
        margin-bottom: 12px;
        cursor: pointer;
    }

    .panel-buttons {
        flex-wrap: wrap;
    }

    .panel-buttons .btn {
        flex: 1;
        min-width: 100px;
    }

    /* --- Element Settings: bottom sheet on mobile --- */
    .element-settings {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100% !important;
        max-height: 65vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        overflow-y: auto;
        animation: settingsSlideUp 0.3s ease;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    @keyframes settingsSlideUp {
        from {
            transform: translateY(100%);
            opacity: 0;
        }

        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* --- Draggable hints: hidden on touch --- */
    .draggable-el::after {
        display: none;
    }

    /* --- Toast: wider on mobile --- */
    .toast {
        left: 10px;
        right: 10px;
        transform: none;
        text-align: center;
        bottom: 20px;
        font-size: 0.85rem;
    }

    @keyframes toastIn {
        from {
            opacity: 0;
            transform: translateY(12px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

/* ========== Responsive: Small Phone ========== */
@media (max-width: 400px) {
    .toolbar-title {
        font-size: 0.9rem;
    }

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

    .toolbar-actions .btn {
        font-size: 0.68rem;
        padding: 7px 3px;
    }

    .toolbar-actions .btn:last-child {
        grid-column: 1 / -1;
    }

    .main-content {
        padding: 8px 4px;
    }

    .diagnosis-cert {
        padding: 18px 12px 22px;
        font-size: 11px;
        line-height: 1.75;
    }

    .cert-header {
        padding-top: 24px;
    }

    .cert-barcode {
        width: 96px;
        height: 22px;
    }

    .cert-hospital {
        max-width: calc(100% - 106px);
        font-size: 0.96rem;
    }

    .cert-title {
        font-size: 1.32rem;
        letter-spacing: 0.28rem;
    }

    .cert-patient-row,
    .cert-section {
        font-size: 0.88rem;
        line-height: 1.75;
    }

    .cert-field {
        flex-basis: 100%;
    }

    .cert-bottom {
        font-size: 0.84rem;
    }

    .cert-doctor-area {
        justify-content: flex-end;
    }

    .cert-disclaimer {
        font-size: 0.84rem;
    }

    .control-panel {
        padding: 12px;
    }

    .panel-buttons .btn {
        font-size: 0.78rem;
        min-width: 80px;
    }
}

/* ========== Print Hidden ========== */
@media print {

    .toolbar,
    .control-panel,
    .canvas-label,
    .element-settings,
    .toast {
        display: none !important;
    }

    .canvas-scroll-wrapper {
        padding: 0;
        background: none;
        overflow: visible;
    }

    .prescription {
        box-shadow: none;
        transform: none;
        width: 780px;
    }
}
