/* ===== 全局样式 ===== */
:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ===== 首页 ===== */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px;
}

.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 32px 20px;
    text-align: center;
    border-radius: 0 0 20px 20px;
    margin-bottom: 24px;
}

.header h1 {
    font-size: 24px;
    margin-bottom: 8px;
}

.header p {
    font-size: 14px;
    opacity: 0.9;
}

.stats-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.stat-card {
    flex: 1;
    min-width: 140px;
    background: white;
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card .num {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .label {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 4px;
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.module-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.module-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.module-card .card-header {
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
}

.module-card .card-header h3 {
    font-size: 16px;
    color: var(--gray-900);
    margin-bottom: 4px;
}

.module-card .card-header p {
    font-size: 13px;
    color: var(--gray-500);
}

.module-card .card-body {
    padding: 16px 20px;
}

.module-card .card-body .desc {
    font-size: 13px;
    color: var(--gray-700);
    margin-bottom: 12px;
    line-height: 1.5;
}

.module-card .card-footer {
    padding: 12px 20px;
    background: var(--gray-50);
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

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

.btn-outline {
    background: white;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }

.qr-preview {
    width: 60px;
    height: 60px;
    border-radius: 4px;
    border: 1px solid var(--gray-200);
    cursor: pointer;
}

/* ===== 表单页面 ===== */
.form-header {
    background: white;
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 20px;
}

.form-header h2 {
    font-size: 20px;
    color: var(--gray-900);
}

.form-header .subtitle {
    font-size: 14px;
    color: var(--gray-500);
    margin-top: 4px;
}

.form-header .desc {
    font-size: 13px;
    color: var(--gray-700);
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--primary-light);
    border-radius: var(--radius);
}

.form-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 20px 40px;
}

.form-group {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

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

.form-field {
    margin-bottom: 16px;
}

.form-field label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-field label .required-mark {
    color: var(--danger);
    margin-left: 2px;
}

.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color 0.2s;
    background: white;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-field input[readonly] {
    background: var(--gray-100);
    color: var(--gray-500);
}

/* 自动填充字段动画 */
.form-field input.auto-filled,
.form-field select.auto-filled {
    background: #d1fae5 !important;
    transition: background 0.4s ease;
}

/* 医院编码搜索框强调样式 */
.form-field input[data-field-type="hospital_autocomplete"] {
    border-color: var(--primary);
    background: #eff6ff;
}

.form-field input[data-field-type="hospital_autocomplete"]:focus {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* 组合框样式（可选择可输入） */
.form-field input.combobox-input {
    background: #fffbeb;
    border-color: #f59e0b;
    cursor: text;
}

.form-field input.combobox-input:focus {
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.form-field input.combobox-input::placeholder {
    color: #b45309;
}

.form-field textarea {
    resize: vertical;
    min-height: 80px;
}

.form-field .hint {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 4px;
}

/* 医院自动补全 */
.hospital-autocomplete {
    position: relative;
}

.hospital-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    max-height: 250px;
    overflow-y: auto;
    display: none;
}

.hospital-dropdown.show { display: block; }

.hospital-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-100);
    font-size: 14px;
}

.hospital-item:hover { background: var(--primary-light); }

.hospital-item .code {
    color: var(--primary);
    font-weight: 500;
    margin-right: 8px;
}

.hospital-item .name {
    color: var(--gray-900);
}

.hospital-item .meta {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 2px;
}

/* 提交反馈 */
.submit-bar {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 20px 0;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
    .container { padding: 12px; }

    .header { padding: 20px 12px; }
    .header h1 { font-size: 18px; }
    .header p { font-size: 12px; }

    .stats-bar {
        gap: 8px;
    }
    .stat-card {
        min-width: 100px;
        padding: 12px;
    }
    .stat-card .num { font-size: 22px; }

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

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

    .form-group { padding: 16px; }

    .form-container { padding: 0 12px 20px; }

    .submit-bar { flex-direction: column; }
    .submit-bar .btn { width: 100%; }

    /* 移动端表单优化 */
    .form-field input,
    .form-field select,
    .form-field textarea {
        font-size: 16px; /* 防止iOS缩放 */
        padding: 12px;
    }

    .form-field label { font-size: 15px; }
}

/* ===== 后台管理 ===== */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.admin-sidebar {
    width: 220px;
    background: var(--gray-900);
    color: white;
    padding: 20px 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 50;
}

.admin-sidebar .logo {
    padding: 0 20px 20px;
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--gray-700);
    margin-bottom: 12px;
}

.admin-sidebar a {
    display: block;
    padding: 10px 20px;
    color: var(--gray-300);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s;
}

.admin-sidebar a:hover,
.admin-sidebar a.active {
    background: var(--gray-700);
    color: white;
}

.admin-sidebar .nav-section {
    padding: 8px 20px 4px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--gray-500);
    letter-spacing: 1px;
}

.admin-main {
    margin-left: 220px;
    flex: 1;
    padding: 24px;
    min-width: 0;
}

.admin-main h2 {
    font-size: 20px;
    margin-bottom: 16px;
}

/* 数据表格 */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.data-table th {
    background: var(--gray-100);
    padding: 10px 12px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    white-space: nowrap;
    border-bottom: 1px solid var(--gray-200);
}

.data-table td {
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-900);
}

.data-table tr:hover td { background: var(--gray-50); }

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
}

/* 分页 */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 16px;
}

.pagination a, .pagination span {
    padding: 6px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 13px;
    text-decoration: none;
    color: var(--gray-700);
}

.pagination a:hover { background: var(--gray-100); }
.pagination .current { background: var(--primary); color: white; border-color: var(--primary); }

/* 登录页 */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gray-50);
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 360px;
}

.login-box h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 20px;
}

/* QR码弹窗 */
.qr-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.qr-modal.show { display: flex; }

.qr-modal-content {
    background: white;
    padding: 24px;
    border-radius: var(--radius);
    text-align: center;
    max-width: 320px;
}

.qr-modal-content img {
    width: 250px;
    height: 250px;
    margin: 12px 0;
}

.qr-modal-content .url {
    font-size: 12px;
    color: var(--gray-500);
    word-break: break-all;
    margin-top: 8px;
}

.qr-modal-content .close-btn {
    margin-top: 12px;
}

/* 响应式后台 */
@media (max-width: 768px) {
    .admin-sidebar {
        width: 100%;
        position: relative;
        padding: 12px;
    }
    .admin-sidebar .logo { padding: 0 12px 8px; }
    .admin-sidebar a { display: inline-block; padding: 6px 12px; }
    .admin-sidebar .nav-section { display: none; }

    .admin-main {
        margin-left: 0;
        padding: 16px;
    }

    .login-box { width: 90%; padding: 24px; }
}

/* ===== 选项管理 ===== */
.options-section {
    margin-top: 24px;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.options-section h3 {
    font-size: 15px;
    margin-bottom: 12px;
    color: var(--gray-900);
}

.options-section .field-group {
    margin-bottom: 20px;
    padding: 16px;
    background: var(--gray-50);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

.options-section .field-group-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.options-section .field-group-title .badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary-dark);
}

.options-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.option-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 13px;
}

.option-tag .tag-text {
    border: none;
    background: transparent;
    font-size: 13px;
    width: 120px;
    padding: 2px 4px;
    border-radius: 4px;
    outline: none;
}

.option-tag .tag-text:focus {
    background: var(--gray-100);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.option-tag .btn-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
}

.option-tag .btn-remove:hover {
    color: #b91c1c;
}

.option-tag.is-default {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.option-tag.is-custom {
    background: #fffbeb;
    border-color: #fde68a;
}

.option-tag.is-new {
    background: #eff6ff;
    border-color: var(--primary);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.option-add-bar {
    display: flex;
    gap: 8px;
    align-items: center;
}

.option-add-bar input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 13px;
}

.option-add-bar .btn-add {
    padding: 6px 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

.option-add-bar .btn-add:hover {
    background: var(--primary-dark);
}

.option-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
}

.option-actions .btn-save-options {
    padding: 6px 14px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

.option-actions .btn-reset-options {
    padding: 6px 14px;
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

@media (max-width: 768px) {
    .option-tag .tag-text { width: 90px; }
    .options-section { padding: 12px; }
}
