/* ============================================
   AI 绘图工坊 - 样式表 v2
   ============================================ */

:root {
    --sidebar-width: 250px;
    --gap: 16px;
    --radius: 14px;
    --radius-sm: 10px;
    --transition: 0.28s cubic-bezier(0.4, 0, 0.2, 1);

    --bg-primary: #0f1117;
    --bg-secondary: #151722;
    --bg-card: #1a1d2e;
    --bg-hover: #252840;
    --text-primary: #eaeaf2;
    --text-secondary: #8888a8;
    --accent: #6c63ff;
    --accent-hover: #5a52e0;
    --accent-soft: rgba(108, 99, 255, 0.12);
    --danger: #ff4d6a;
    --success: #4ade80;
    --warning: #fbbf24;
    --border: #2a2d40;
    --hero-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
    --shadow: 0 4px 16px rgba(0,0,0,0.35);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
}

html.light-theme body {
    --bg-primary: #f4f4f7;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #eeeef3;
    --text-primary: #1a1a2e;
    --text-secondary: #6b6b80;
    --border: #e0e0e8;
    --hero-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Microsoft YaHei", "PingFang SC", "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    transition: background var(--transition), color var(--transition);
    line-height: 1.5;
}

/* ============================================
   Layout
   ============================================ */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 22px 20px 18px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h4 {
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid var(--border);
}
.sidebar-user:hover { background: var(--bg-hover); }

.user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
    flex-shrink: 0;
    border: 2px solid var(--accent);
}
.user-info { min-width: 0; }
.user-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-credits { font-size: 12px; color: var(--accent); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 10px 0; }
.sidebar-nav ul { list-style: none; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    margin: 2px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    transition: all var(--transition);
}
.sidebar-nav a:hover { background: var(--bg-hover); color: var(--accent); }
.sidebar-nav a i { font-size: 17px; width: 22px; text-align: center; }
.nav-divider { border-top: 1px solid var(--border); margin: 8px 10px; }

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

/* Hamburger */
.menu-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 200;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 22px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.menu-toggle:hover { box-shadow: var(--shadow-lg); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: opacity var(--transition);
}
.sidebar-overlay.show { display: block; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: var(--gap);
    min-height: 100vh;
}

/* ============================================
   Page Header
   ============================================ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    margin-bottom: var(--gap);
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.page-header h3 { font-size: 1.15rem; font-weight: 600; margin: 0; }
.page-header small { line-height: 1; color: var(--text-secondary) !important; }

/* ============================================
   Cards
   ============================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    overflow: hidden;
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 14px;
    padding: 14px 18px;
    color: var(--text-primary);
}
.card-body { padding: 18px; }

/* ============================================
   Gallery
   ============================================ */
.gallery-hero {
    padding: 50px 20px;
    text-align: center;
    background: var(--hero-bg);
    margin: calc(-1 * var(--gap));
    margin-bottom: var(--gap);
    border-radius: 0 0 var(--radius) var(--radius);
}
.gallery-hero h1 { font-weight: 700; }

.gallery-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: var(--gap);
}

.category-pill {
    display: inline-block;
    padding: 7px 18px;
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    border: 1px solid var(--border);
}
.category-pill:hover, .category-pill.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Image Grid */
.row.g-3 { --bs-gutter-x: var(--gap); --bs-gutter-y: var(--gap); }

.gallery-card {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    aspect-ratio: 1;
    max-width: 300px;
    background: var(--bg-card);
    transition: box-shadow var(--transition);
    border: 1px solid var(--border);
}
.gallery-card:hover {
    box-shadow: var(--shadow-lg);
}
.gallery-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s;
}
.gallery-card:hover img { }

.gallery-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 36px 14px 14px;
    background: linear-gradient(transparent, rgba(0,0,0,0.82));
    opacity: 0;
    transition: opacity var(--transition);
    pointer-events: none;
}
.gallery-card:hover .gallery-card-overlay { opacity: 1; }
.gallery-card-overlay h6 { margin: 0; font-size: 13px; color: #fff; }
.gallery-card-overlay small { color: rgba(255,255,255,0.65); font-size: 11px; }

.task-status-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(0,0,0,0.55);
}

.admin-img-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition);
}
.gallery-card:hover .admin-img-actions { opacity: 1; }
.admin-img-actions .btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

/* ============================================
   Form Controls
   ============================================ */
.form-control, .form-select {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    padding: 10px 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-label { font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--text-secondary); }
.form-control::placeholder { color: #555; }

/* ============================================
   Buttons
   ============================================ */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    padding: 10px 22px;
    transition: all var(--transition);
}
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline-light {
    border-color: var(--border);
    color: var(--text-primary);
}
.btn-outline-light:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

/* ============================================
   Generator Page
   ============================================ */
.generator-container { max-width: 1100px; }

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.upload-area:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.upload-placeholder {
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.upload-placeholder i { font-size: 2rem; }
.upload-preview-container {
    position: relative;
    display: inline-block;
}
.upload-preview-container img { max-height: 180px; border-radius: var(--radius-sm); }

.upload-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 60px;
}
.upload-tile {
    width: 88px;
    height: 88px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 12px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}
.upload-tile:hover { border-color: var(--accent); color: var(--accent); }
.upload-tile img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.ref-order {
    position: absolute;
    top: -4px;
    left: -4px;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    box-shadow: var(--shadow-sm);
}
.preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--danger);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    padding: 0;
    border: none;
}

.prompt-textarea {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    min-height: 160px;
    resize: vertical;
    font-size: 15px;
    line-height: 1.6;
}
.prompt-textarea:focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--accent-soft) !important;
}
.prompt-textarea::placeholder { color: #555 !important; opacity: 0.7; }

/* ============================================
   Lightbox (unchanged, in _Lightbox.cshtml)
   ============================================ */

/* ============================================
   My Images Dual-Panel
   ============================================ */
.my-images-container {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    display: flex;
    z-index: 1;
}

.category-sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: var(--gap);
    overflow-y: auto;
    border-radius: 0;
}

.my-images-main {
    flex: 1;
    padding: var(--gap);
    min-width: 0;
    overflow-y: auto;
}

.category-sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: var(--gap);
    overflow-y: auto;
    border-radius: 0;
    min-height: calc(100vh - 2 * var(--gap));
}
.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.category-header h6 { font-size: 14px; font-weight: 600; }

.category-tree {
    font-size: 13px;
    padding: 4px 0;
}

/* 树节点包装器 */
.tree-wrapper { }

/* 树行（每行可点击） */
.tree-row {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    margin: 1px 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 13px;
    white-space: nowrap;
    border-left: 3px solid transparent;
}
.tree-row:hover { background: var(--bg-hover); }
.tree-row.active { background: var(--accent-soft); border-left-color: var(--accent); }

/* 子节点容器 */
.tree-children {
    border-left: 2px solid var(--border);
    margin-left: 12px;
    padding-left: 0;
}

/* 展开/折叠箭头 */
.tree-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    font-size: 10px;
    color: var(--text-secondary);
    margin-right: 2px;
    flex-shrink: 0;
    cursor: pointer;
    border-radius: 3px;
    transition: transform 0.15s;
}
.tree-arrow:hover { background: var(--bg-hover); color: var(--accent); }

/* 文件夹图标 */
.tree-icon {
    margin-right: 6px;
    color: #d4a853;
    font-size: 14px;
    flex-shrink: 0;
}
.tree-row.active .tree-icon { color: var(--accent); }

/* 名称 */
.tree-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 操作按钮 */
.tree-actions {
    margin-left: auto;
    display: none;
    gap: 2px;
    flex-shrink: 0;
    padding-left: 8px;
}
.tree-row:hover .tree-actions { display: flex; }
.tree-actions a {
    color: var(--text-secondary);
    font-size: 12px;
    padding: 3px 5px;
    text-decoration: none;
    border-radius: 4px;
}
.tree-actions a:hover { color: var(--accent); background: var(--bg-hover); }

/* 默认标签 */
.tree-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 6px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

/* 空状态 */
.tree-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
}

.my-images-main {
    flex: 1;
    padding: var(--gap);
    min-width: 0;
}

/* ============================================
   Admin
   ============================================ */
.admin-container {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    display: flex;
    z-index: 1;
}
.admin-sidebar {
    width: 210px;
    min-width: 210px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    border-radius: 0;
    overflow-y: auto;
}
.admin-sidebar-menu .nav-link {
    color: var(--text-primary);
    padding: 10px 20px;
    font-size: 14px;
    transition: background var(--transition);
    border-radius: 0;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
}
.admin-sidebar-menu .nav-link:hover { background: var(--bg-hover); }
.admin-sidebar-menu .nav-link.active { background: var(--accent-soft); color: var(--accent); }
.admin-content {
    flex: 1;
    padding: var(--gap);
    min-width: 0;
    overflow-y: auto;
}
.admin-content .text-white-50,
.admin-content p.text-white-50 { color: var(--text-secondary) !important; }

/* ============================================
   Table
   ============================================ */
.table { color: var(--text-primary); margin: 0; }
.table-dark { --bs-table-bg: transparent; --bs-table-color: var(--text-primary); --bs-table-border-color: var(--border); }
.table tbody td { vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); }

/* ============================================
   Pagination
   ============================================ */
.pagination { gap: 4px; }
.pagination .page-link {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 13px;
    transition: all var(--transition);
}
.pagination .page-link:hover { background: var(--bg-hover); }
.pagination .active .page-link { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ============================================
   Modal
   ============================================ */
.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
}
.modal-header { border-bottom: 1px solid var(--border); padding: 16px 20px; }
.modal-footer { border-top: 1px solid var(--border); padding: 14px 20px; }
.modal-body { padding: 20px; }
.btn-close { filter: invert(1); }

/* ============================================
   Auth Pages
   ============================================ */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 44px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}
.auth-card .form-control {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
}

/* ============================================
   Misc
   ============================================ */
.badge { font-weight: 500; font-size: 11px; padding: 5px 10px; border-radius: 6px; }
.alert { border: none; border-radius: var(--radius-sm); }
.breadcrumb { margin: 0; }
.breadcrumb-item a { color: var(--accent); text-decoration: none; }

.cdkey-container { padding: 40px 20px; }

/* ============================================
   Light Theme Overrides
   ============================================ */
body.light-theme .sidebar { background: #fff; }
body.light-theme .sidebar-header { border-color: var(--border); }
body.light-theme .sidebar-user { border-color: var(--border); }
body.light-theme .sidebar-footer { border-color: var(--border); }
body.light-theme .nav-divider { border-color: var(--border); }
body.light-theme .card-header { background: #f8f9fa; }
body.light-theme .gallery-card-overlay h6,
body.light-theme .gallery-card-overlay small { color: #fff; }
body.light-theme .page-header { background: #fff; }
body.light-theme .form-control { background: #f8f9fa; }
body.light-theme .form-control:focus { background: #fff; }
body.light-theme .form-select { background-color: #fff; }
body.light-theme .table-dark tbody tr:hover { background: #f0f0f5; }
body.light-theme .prompt-textarea { background: #f8f9fa !important; }
body.light-theme .prompt-textarea:focus { background: #fff !important; }
body.light-theme .prompt-textarea::placeholder { color: #aaa !important; }
body.light-theme .upload-area { border-color: #ccc; }
body.light-theme .upload-area:hover { border-color: var(--accent); background: rgba(108,99,255,0.04); }
body.light-theme .upload-tile { border-color: #ccc; color: #666; }
body.light-theme .category-pill { background: #fff; color: #1a1a2e; box-shadow: var(--shadow-sm); }
body.light-theme .gallery-card { box-shadow: var(--shadow-sm); }
body.light-theme .gallery-card:hover { box-shadow: var(--shadow-lg); }
body.light-theme .card { box-shadow: var(--shadow-sm); }
body.light-theme .modal-content { background: #fff; color: #1a1a2e; }
body.light-theme .btn-close { filter: none; }
body.light-theme .pagination .page-link { background: #fff; }
body.light-theme .admin-sidebar { background: #fff; }
body.light-theme .category-sidebar { background: #fff; }
body.light-theme .gallery-hero h1,
body.light-theme .gallery-hero p { color: #fff !important; }
body.light-theme .badge.bg-secondary { background: #6c757d !important; }
body.light-theme .badge.bg-dark { background: #6c757d !important; }

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .menu-toggle { display: flex; }
    .main-content { margin-left: 0; }

    .category-sidebar, .admin-sidebar {
        position: fixed;
        z-index: 101;
        left: 0;
        transform: translateX(-100%);
        transition: transform var(--transition);
        border-radius: 0;
    }
    .category-sidebar.open, .admin-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }

    .auth-card { padding: 28px 24px; }
    .gallery-hero { padding: 36px 16px; }
    .gallery-hero h1 { font-size: 1.6rem; }
    .generator-container { max-width: 100%; }
}

@media (max-width: 576px) {
    .generator-container { padding: 8px; }
    .page-header { padding: 12px 14px; flex-direction: column; gap: 8px; align-items: flex-start; }
}
