/* ============================================================
   Coze数据存储插件 - 管理后台样式
   ============================================================ */

:root {
    --primary: #4F46E5;
    --primary-dark: #4338CA;
    --primary-light: #EEF2FF;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --info: #3B82F6;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;
    --sidebar-width: 260px;
    --header-height: 64px;
    --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 rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
}

a {
    text-decoration: none;
    color: inherit;
}

/* ============================================================
   登录页面
   ============================================================ */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-container {
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header .logo {
    width: 64px;
    height: 64px;
    background: var(--primary);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 28px;
    color: white;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 4px;
}

.login-header p {
    color: var(--gray-500);
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
}

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

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

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    gap: 8px;
}

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

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

.btn-success {
    background: var(--success);
    color: white;
}

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

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

.btn-danger:hover {
    background: #DC2626;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-warning:hover {
    background: #D97706;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}

.btn-outline:hover {
    background: var(--gray-100);
}

/* ============================================================
   布局
   ============================================================ */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--gray-200);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-header .logo {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-900);
}

.sidebar-header p {
    font-size: 11px;
    color: var(--gray-500);
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: var(--gray-600);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-item .icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--primary);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 600;
}

.user-details {
    flex: 1;
}

.user-details .name {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-900);
}

.user-details .role {
    font-size: 12px;
    color: var(--gray-500);
}

.logout-btn {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    transition: color 0.2s;
}

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

/* 主内容区 */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.top-header {
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--gray-900);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content-body {
    padding: 32px;
}

/* ============================================================
   统计卡片
   ============================================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-icon.blue { background: #EFF6FF; color: #3B82F6; }
.stat-icon.green { background: #ECFDF5; color: #10B981; }
.stat-icon.yellow { background: #FFFBEB; color: #F59E0B; }
.stat-icon.red { background: #FEF2F2; color: #EF4444; }

.stat-info { flex: 1; }

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

.stat-info .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-info .sub {
    font-size: 12px;
    color: var(--gray-400);
    margin-top: 2px;
}

/* ============================================================
   表格
   ============================================================ */

.table-container {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.table-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.table-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.search-input {
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
    width: 200px;
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

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

thead {
    background: var(--gray-50);
}

th {
    padding: 12px 20px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--gray-200);
}

td {
    padding: 12px 20px;
    font-size: 14px;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-100);
}

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

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.status-badge.active {
    background: #ECFDF5;
    color: #059669;
}

.status-badge.inactive {
    background: #FEF2F2;
    color: #DC2626;
}

.status-badge.info {
    background: #EFF6FF;
    color: #2563EB;
}

.action-btns {
    display: flex;
    gap: 6px;
}

/* ============================================================
   分页
   ============================================================ */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
}

.page-btn {
    padding: 6px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    background: white;
    color: var(--gray-600);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.page-btn:hover {
    background: var(--gray-100);
}

.page-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================================
   模态框
   ============================================================ */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

.modal {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px;
}

.modal-close:hover {
    color: var(--gray-600);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ============================================================
   空状态
   ============================================================ */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--gray-600);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
}

/* ============================================================
   加载状态
   ============================================================ */

.loading {
    text-align: center;
    padding: 40px;
    color: var(--gray-400);
}

.spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   提示消息
   ============================================================ */

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    padding: 12px 20px;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    transform: translateX(120%);
    transition: transform 0.3s ease;
    max-width: 400px;
}

.toast.show {
    transform: translateX(0);
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.info { background: var(--info); }

/* ============================================================
   表格布局
   ============================================================ */

.table-wrapper {
    overflow-x: auto;
}

table.data-table {
    table-layout: fixed;
    width: 100%;
    min-width: 900px;
}

table.data-table .col-id { width: 60px; }
table.data-table .col-key { width: 160px; }
table.data-table .col-type { width: 110px; }
table.data-table .col-content { width: auto; }
table.data-table .col-source { width: 140px; }
table.data-table .col-status { width: 72px; }
table.data-table .col-version { width: 60px; }
table.data-table .col-time { width: 170px; }

table.data-table td:nth-child(4) {
    max-width: 0;
    width: auto;
}

tr.row-deleted {
    opacity: 0.6;
}

tr.row-deleted td {
    text-decoration: line-through;
    color: var(--gray-400);
}

/* ============================================================
   JSON预览
   ============================================================ */

.json-preview {
    background: var(--gray-800);
    color: #E5E7EB;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    line-height: 1.5;
    height: 80px;
    overflow-y: auto;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============================================================
   响应式
   ============================================================ */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .content-body {
        padding: 16px;
    }

    .top-header {
        padding: 0 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .table-toolbar {
        flex-direction: column;
        width: 100%;
    }

    .search-input {
        width: 100%;
    }

    .modal {
        margin: 10px;
    }
}

/* ============================================================
   系统设置页面
   ============================================================ */

.settings-page {
    max-width: 700px;
}

.settings-section {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.settings-section-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
}

.settings-section-header h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

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

.settings-form {
    padding: 20px;
}

.settings-form .form-group {
    margin-bottom: 18px;
}

.settings-form .form-group:last-child {
    margin-bottom: 0;
}

.settings-form label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 5px;
}

.settings-form input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    color: var(--gray-900);
    transition: border-color 0.2s;
}

.settings-form input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

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

.form-actions {
    padding-top: 16px;
    border-top: 1px solid var(--gray-100);
    margin-top: 8px;
}

.logo-input-row {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.logo-text-input {
    flex-shrink: 0;
}

.logo-divider {
    display: flex;
    align-items: flex-end;
    padding-bottom: 4px;
    color: var(--gray-400);
    font-size: 13px;
}

.logo-upload-area {
    flex: 1;
}

.logo-upload-row {
    display: flex;
    align-items: center;
}

.logo-preview-box {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: var(--gray-50);
    border-radius: 8px;
    border: 2px dashed var(--gray-300);
}

.logo-preview-img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border-radius: 4px;
}

.logo-preview-label {
    font-size: 11px;
    color: var(--gray-400);
}

.settings-info-grid {
    padding: 20px;
}

.info-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
}

.info-item:last-child {
    border-bottom: none;
}

.info-label {
    flex-shrink: 0;
    width: 80px;
    font-size: 13px;
    color: var(--gray-500);
}

.info-value {
    font-size: 13px;
    color: var(--gray-700);
    background: var(--gray-50);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
}

.settings-preview {
    padding: 20px;
}

.preview-sidebar {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 16px 24px;
    background: var(--primary);
    border-radius: 8px;
    color: white;
}

.preview-logo {
    font-size: 28px;
}

.preview-title {
    font-size: 14px;
    font-weight: 600;
}

.preview-version {
    font-size: 11px;
    opacity: 0.8;
}

.sidebar-footer-text {
    padding: 12px 16px;
    font-size: 11px;
    color: var(--gray-400);
    text-align: center;
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* ============================================================
   工具类
   ============================================================ */

.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* ============================================================
   导航分组 - 二级菜单
   ============================================================ */

.nav-group {
}

.nav-arrow {
    margin-left: auto;
    font-size: 10px;
    color: var(--gray-400);
    transition: transform 0.2s;
}

.nav-sub {
}

.nav-sub-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px 8px 42px;
    border-radius: var(--radius);
    color: var(--gray-500);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.nav-sub-item:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.nav-sub-item.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-sub-item .icon {
    font-size: 14px;
    width: 20px;
    text-align: center;
}

/* ============================================================
   数据标识复制标签
   ============================================================ */

.key-cell {
    display: flex;
    align-items: center;
    gap: 6px;
}

.copy-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    background: var(--gray-100);
    color: var(--gray-400);
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
    flex-shrink: 0;
}

.key-cell:hover .copy-tag,
tr:hover .copy-tag {
    opacity: 1;
}

.copy-tag:hover {
    background: var(--primary);
    color: white;
}

/* ============================================================
   可点击JSON预览
   ============================================================ */

.json-preview-clickable {
    cursor: pointer;
    transition: all 0.2s;
}

.json-preview-clickable:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

/* ============================================================
   JSON查看器（弹窗中）
   ============================================================ */

.json-viewer {
    background: var(--gray-800);
    color: #E5E7EB;
    padding: 20px;
    border-radius: var(--radius);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    max-height: 60vh;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============================================================
   弹窗头部（类型标签 + 复制按钮）
   ============================================================ */

.modal-content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.modal-type-badge {
    flex-shrink: 0;
}

.copy-content-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    white-space: nowrap;
}

.copy-icon {
    font-size: 14px;
}

/* ============================================================
   宽模态框（用于JSON内容展示）
   ============================================================ */

.modal-wide {
    max-width: 800px;
}

@media (max-width: 768px) {
    .modal-wide {
        max-width: 100%;
    }
}

/* ============================================================
   搜索框回车支持
   ============================================================ */

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
