/* --- 全局与基础样式 --- */
[x-cloak] {
    display: none !important;
}

:root {
    --sidebar-width: 240px;
    --bg-color: #f8f9fa;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --text-color: #212529;
    --text-muted: #6c757d;
    --accent-color: #0d6efd;
    --border-color: #dee2e6;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

/* --- 夜间模式变量覆盖 --- */
body.dark-mode {
    --bg-color: #121212;
    --sidebar-bg: #1e1e1e;
    --card-bg: #2d2d2d;
    --text-color: #e0e0e0;
    --text-muted: #adb5bd;
    --border-color: #495057;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
}

/* 夜间模式下的特定元素适配 */
body.dark-mode .sidebar ul li.active a,
body.dark-mode .sidebar ul li a:hover {
    background-color: #343a40;
    color: #fff;
}

body.dark-mode .sidebar-footer a {
    background-color: #2d2d2d;
    color: var(--text-color);
}
body.dark-mode .sidebar-footer a:hover {
    background-color: #343a40;
}

body.dark-mode .search-input,
body.dark-mode .modal-body input,
body.dark-mode .modal-body select {
    background-color: #2d2d2d;
    color: var(--text-color);
    border-color: var(--border-color);
}

body.dark-mode .modal-footer {
    background-color: #2d2d2d;
    border-top-color: var(--border-color);
}

body {
    margin: 0;
    font-family: "Helvetica Neue", Arial, "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft YaHei", sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    text-decoration: none;
    color: var(--accent-color);
    transition: color 0.2s ease;
}

a:hover {
    color: #0a58ca;
}

ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* --- 主容器布局 --- */
.container {
    display: flex;
}

/* --- 左侧导航栏 --- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    flex-shrink: 0; /* 防止侧边栏被压缩 */
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 20px;
}

.sidebar h1 {
    font-size: 1.5rem;
    margin: 0;
    font-weight: 600;
    color: var(--text-color);
}

.sidebar ul {
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar ul li a {
    display: block;
    padding: 12px 20px;
    margin: 4px 10px;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 500;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar ul li.active a,
.sidebar ul li a:hover {
    background-color: #e9ecef;
    color: var(--text-color);
    text-decoration: none;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.sidebar-footer a {
    display: block;
    text-align: center;
    padding: 10px;
    border-radius: 8px;
    background-color: #f8f9fa;
    font-weight: 500;
}

/* --- 搜索框样式 --- */
.search-box {
    padding: 0 20px 20px 20px;
}

.search-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-sizing: border-box;
    font-size: 0.95rem;
    background-color: #f8f9fa;
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    background-color: #fff;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* --- 右侧主内容区 --- */
.main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width); /* 避开固定的侧边栏 */
    padding: 24px 40px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    box-sizing: border-box;
}

.content-header {
    margin-bottom: 24px;
    /* 使用 Flex 布局让标题和按钮横向排列 */
    display: flex;
    align-items: center;
    gap: 16px;
}

.content-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

/* --- 瀑布流网格 --- */
.content-grid {
    display: grid;
    /* 最小 400px：标题区要同时放下拖拽把手 + 分类名 + 4 个操作按钮（约 160px）。
       300px 时标题可用宽度只剩约 70px，连「音乐资源和制作」(140px) 都放不下；
       400px 后可用约 170px，现有分类名全部能完整单行显示 */
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 24px;
    align-items: start;
}

/* --- 内容卡片 --- */
.card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
    break-inside: avoid; /* 优化打印和某些布局下的表现 */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 16px;
    gap: 8px;
}

/* 左侧标题区允许收缩：不给 min-width:0 的话，nowrap 的标题不会走省略号，而是把卡片撑破。
   用 :not(.card-actions) 排除右侧按钮组，否则按钮会被一起压缩变形 */
.card-header > div:not(.card-actions) {
    min-width: 0;
}

.card-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
    /* 分类名强制单行，过长省略号，避免折行把卡片撑高、与同排卡片高度不齐 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 2px 8px;
    transition: all 0.2s;
}

.icon-btn:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.card ul li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 8px;
}

.card ul li a {
    font-size: 0.95rem;
    /* 避免链接文字过长时挤压删除按钮 */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-actions {
    display: flex;
    align-items: center;
}
.card ul li a {
    font-size: 0.95rem;
}

.loading-indicator {
    width: 100%;
    text-align: center;
    padding: 40px;
    font-size: 1.2rem;
    color: var(--text-muted);
}

.drag-handle {
    cursor: grab;
    color: #ced4da;
    padding: 0 8px;
    font-size: 1.2rem;
    line-height: 1;
}

.drag-handle:hover {
    color: var(--text-muted);
}

.sortable-ghost {
    opacity: 0.4;
    background: #c8ebfb;
}

.sortable-drag {
    opacity: 1 !important;
}

.delete-btn {
    background: none;
    border: none;
    color: #adb5bd;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2rem;
    padding: 0 4px;
    transition: color 0.2s ease;
}

.delete-btn:hover {
    color: #dc3545;
}

.edit-btn {
    background: none;
    border: none;
    color: #adb5bd;
    cursor: pointer;
    font-size: 0.9rem; /* Use a pencil icon or similar from a library in a real app */
    padding: 0 4px;
    transition: color 0.2s ease;
}

.edit-btn:hover {
    color: var(--accent-color);
}

.copy-btn {
    background: none;
    border: none;
    color: #adb5bd;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0 4px;
    transition: color 0.2s ease;
}

.copy-btn:hover {
    color: #198754; /* 成功绿 */
}

/* --- Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-header button {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-body {
    padding: 24px;
}

.modal-body input[type="password"] {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-sizing: border-box;
}

.modal-body input[type="password"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25);
}

.modal-body select {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-sizing: border-box;
    background-color: var(--card-bg);
    color: var(--text-color);
}
.modal-body select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25);
}

.error-message {
    color: #dc3545;
    background-color: #f8d7da;
    border: 1px solid #f5c2c7;
    border-radius: 8px;
    padding: 12px;
    margin: 0 0 16px 0;
    font-size: 0.9rem;
}

.modal-footer {
    padding: 16px 24px;
    background-color: #f8f9fa;
    text-align: right;
    border-top: 1px solid var(--border-color);
}

.primary-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.primary-btn:hover {
    background-color: #0a58ca;
    color: white;
}

/* --- 顶部主题切换按钮 --- */
.theme-toggle-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #f59e0b; /* 使用金黄色，避免黑色边框感 */
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.theme-toggle-btn:hover {
    background-color: transparent; /* 去除灰色背景 */
    transform: scale(1.1); /* 增加一点缩放效果替代背景色 */
}

/* --- Toast Notification (成功提示条) --- */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    pointer-events: none; /* 避免遮挡下方点击 */
}

.toast {
    background-color: #198754; /* 成功绿 */
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-weight: 500;
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    background-color: #dc3545; /* 失败红 */
}
