.theme-manage-page .page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.theme-manage-page .page-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.back-link {
    text-decoration: none;
    color: var(--primary);
    margin-right: 0.5rem;
}

.back-link:hover {
    color: var(--primary-dark, #1d4ed8);
}

/* Category sections */
.theme-category {
    margin-bottom: 1.5rem;
}

.theme-category-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--border);
}

/* Theme button grid */
.theme-btn-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.theme-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.4rem 0.75rem;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    max-width: 180px;
    text-decoration: none;
}

.theme-btn:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

.theme-btn .theme-btn-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.theme-btn-grid.expanded .theme-btn {
    max-width: none;
}

.theme-btn-grid.expanded .theme-btn .theme-btn-label {
    overflow: visible;
    white-space: normal;
}

.theme-expand-toggle {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    font-size: 0.8125rem;
}

.theme-expand-toggle input {
    width: auto;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2em 0.6em;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius);
    text-transform: uppercase;
}

.badge-normal {
    background: #dbeafe;
    color: #1e40af;
}

.badge-ws {
    background: #fef3c7;
    color: #92400e;
}

.badge-view {
    background: #d1fae5;
    color: #065f46;
}

.badge-sub {
    background: #ede9fe;
    color: #5b21b6;
}

.badge-warn {
    background: #fef3c7;
    color: #92400e;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.badge-secondary {
    background: #f1f5f9;
    color: #475569;
}

.badge-danger {
    background: #fee2e2;
    color: #b91c1c;
}

/* Button group */
.btn-group {
    display: flex;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
}

.btn-danger {
    background-color: #ef4444;
    color: #fff;
    border-color: #ef4444;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-warning {
    background-color: #f59e0b;
    color: #fff;
    border-color: #f59e0b;
}

.btn-warning:hover {
    background-color: #d97706;
}

.btn-success {
    background-color: #10b981;
    color: #fff;
    border-color: #10b981;
}

.btn-success:hover {
    background-color: #059669;
}

.btn-info {
    background-color: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

.btn-info:hover {
    background-color: #2563eb;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-dialog {
    background: var(--bg-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg, 0 10px 25px rgba(0,0,0,0.15));
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-lg {
    max-width: 640px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    line-height: 1;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
}

/* Form rows */
.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.form-col-6 {
    flex: 1;
    min-width: 200px;
}

.form-col-4 {
    flex: 1;
    min-width: 120px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding-top: 1.75rem;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

/* Table within card */
.table-responsive {
    overflow-x: auto;
}

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

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: var(--bg);
}

.table tbody tr:hover {
    background: var(--bg);
}

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

.text-danger {
    color: #ef4444;
}

/* Source setting section */
.source-setting-section {
    margin-top: 1.5rem;
}

.source-setting-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.source-setting-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

#source-setting-list {
    padding: 1rem 1.5rem;
}

#source-setting-list .source-setting-empty {
    margin: 0;
    padding: 0.5rem 0;
}

#source-setting-list .data-table {
    width: 100%;
    border-collapse: collapse;
}

#source-setting-list .data-table th,
#source-setting-list .data-table td {
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

#source-setting-list .data-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: var(--bg);
}

#source-setting-list .data-table tbody tr:hover {
    background: var(--bg);
}

@media (max-width: 640px) {
    .page-header-row {
        flex-direction: column;
    }
    .form-row {
        flex-direction: column;
    }
    .form-col-6,
    .form-col-4 {
        min-width: 100%;
    }
}

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.card-header-row h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

/* Display matrix table */
.table-compact th,
.table-compact td {
    padding: 0.4rem 0.5rem;
    font-size: 0.8125rem;
    text-align: center;
}

.table-compact th:first-child,
.table-compact td:first-child {
    text-align: left;
}

.table-compact input[type="checkbox"] {
    margin: 0;
}

.table-compact input[type="number"] {
    width: 50px;
    padding: 0.15rem 0.3rem;
    font-size: 0.8125rem;
    text-align: center;
}

/* data_attributes checkboxes */
.card-mt {
    margin-top: 1rem;
}

.da-hint {
    margin-bottom: 0.75rem;
}

#data-attributes-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

#data-attributes-checkboxes label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    cursor: pointer;
}

/* Basic settings tab */
.form-section-title {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 1.25rem 0 0.75rem 0;
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--border);
}
.form-section-title:first-child {
    margin-top: 0;
}

/* Form table: label 左邊, input 右邊 */
.form-table {
    width: 100%;
    border-collapse: collapse;
}
.form-table th,
.form-table td {
    padding: 0.5rem 0.75rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.form-table th {
    width: 140px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: right;
    white-space: nowrap;
    padding-right: 1rem;
}
.form-table td input[type="text"],
.form-table td input[type="number"],
.form-table td select {
    width: 100%;
    max-width: 360px;
}
.form-table td textarea {
    max-width: 480px;
}
.form-inline-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.form-inline-group label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
.checkbox-inline-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}
.checkbox-inline-group label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    cursor: pointer;
}
.form-control-plaintext {
    background: transparent;
    border: none;
    padding: 0.375rem 0;
    font-weight: 600;
}
.form-col-4 { flex: 0 0 33.333%; max-width: 33.333%; }

.default-fields-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
}
.default-fields-grid label {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
}

/* Sub-theme mode field toggle */
.field-enable-toggle {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.field-locked {
    color: var(--text-secondary);
    opacity: 0.6;
}

.sub-mode-notice {
    background: #fef3c7;
    color: #92400e;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    margin-bottom: 0.75rem;
}

.badge-basic {
    background: #e0e7ff;
    color: #3730a3;
}

/* Inline field editing */
.table-fields td {
    vertical-align: middle;
}
.table-fields input[type="text"],
.table-fields input[type="number"],
.table-fields select {
    width: 100%;
    padding: 0.25rem 0.4rem;
    font-size: 0.8125rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-white);
}
.table-fields input[type="number"] {
    width: 80px;
}
.table-fields .field-name-cell {
    font-weight: 600;
    font-size: 0.8125rem;
}
.table-fields .field-readonly {
    color: var(--text-secondary);
    font-size: 0.8125rem;
}
.btn-delete-field-inline {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem;
    line-height: 1;
}
.btn-delete-field-inline:hover {
    color: #dc2626;
}

/* Drag handle & sorting */
.drag-handle {
    cursor: grab;
    color: var(--text-secondary);
    font-size: 1rem;
    user-select: none;
    padding: 0.2rem;
}
.drag-handle:hover {
    color: var(--text);
}
.drag-handle:active {
    cursor: grabbing;
}
tr.dragging {
    opacity: 0.4;
}
tr.drag-over {
    border-top: 2px solid var(--primary);
}
.field-wysiwyg-label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8125rem;
    cursor: pointer;
    white-space: nowrap;
}
