/* PT Anime Subscribe - Styles */

/* ========== CSS 变量 - 主题系统 ========== */
:root {
    --sidebar-width-expanded: 220px;
    --sidebar-width-collapsed: 64px;
    --top-bar-height: 56px;
    --downloads-panel-width: 480px;
    --transition-speed: 0.3s;
}

/* 主题一: 阿里云浅色系 (智能浅) */
[data-theme="light"] {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #edf0f4;
    --bg-sidebar: #001529;
    --bg-sidebar-hover: rgba(255,255,255,0.08);
    --bg-sidebar-active: rgba(24,144,255,0.25);
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-input: #f5f7fa;
    --bg-modal: #ffffff;
    --bg-overlay: rgba(0,21,41,0.45);
    --text-primary: #1a2332;
    --text-secondary: #556173;
    --text-tertiary: #949fae;
    --text-sidebar: rgba(255,255,255,0.65);
    --text-sidebar-active: #ffffff;
    --accent-primary: #1890ff;
    --accent-primary-hover: #096dd9;
    --accent-gradient: linear-gradient(135deg, #1890ff, #00c1de);
    --border-color: rgba(0,0,0,0.06);
    --border-color-strong: rgba(0,0,0,0.12);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --scrollbar-track: #edf0f4;
    --scrollbar-thumb: #c9ced6;
    --success: #52c41a;
    --warning: #fa8c16;
    --danger: #ff4d4f;
}

/* 主题二: 阿里云深色系 (智能深) */
[data-theme="dark"] {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2035;
    --bg-sidebar: #0d1117;
    --bg-sidebar-hover: rgba(24,144,255,0.1);
    --bg-sidebar-active: rgba(24,144,255,0.2);
    --bg-card: #161b2c;
    --bg-card-hover: #1e2538;
    --bg-input: rgba(255,255,255,0.04);
    --bg-modal: #161b2c;
    --bg-overlay: rgba(0,0,0,0.7);
    --text-primary: #d4dae6;
    --text-secondary: #8b95a8;
    --text-tertiary: #596378;
    --text-sidebar: #6e7b91;
    --text-sidebar-active: #1890ff;
    --accent-primary: #1890ff;
    --accent-primary-hover: #40a9ff;
    --accent-gradient: linear-gradient(135deg, #1890ff, #00c1de);
    --border-color: rgba(255,255,255,0.06);
    --border-color-strong: rgba(255,255,255,0.1);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.4);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);
    --scrollbar-track: rgba(255,255,255,0.04);
    --scrollbar-thumb: rgba(255,255,255,0.12);
    --success: #52c41a;
    --warning: #fa8c16;
    --danger: #ff4d4f;
}

/* ========== 基础样式 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow: hidden;
}

/* ========== 主布局 ========== */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ========== 左侧垂直导航 (企业微信风格) ========== */
.sidebar {
    width: var(--sidebar-width-expanded);
    min-width: var(--sidebar-width-expanded);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-speed) ease, min-width var(--transition-speed) ease;
    z-index: 100;
    overflow: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
    min-width: var(--sidebar-width-collapsed);
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-logo .logo-svg {
    width: 40px;
    height: 40px;
}

.nav-list {
    list-style: none;
    padding: 8px;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin: 4px 0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-sidebar);
    white-space: nowrap;
    overflow: hidden;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.nav-item.active {
    background: var(--bg-sidebar-active);
    color: var(--text-sidebar-active);
}

.nav-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.nav-text {
    font-size: 0.95em;
    font-weight: 500;
    opacity: 1;
    transition: opacity 0.2s ease, width 0.2s ease;
}

.sidebar.collapsed .nav-text {
    opacity: 0;
    width: 0;
}

.sidebar-bottom {
    padding: 8px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-bottom .nav-item {
    justify-content: center;
}

.sidebar.collapsed .sidebar-bottom .nav-item {
    justify-content: center;
}

/* 收起按钮箭头旋转 */
#sidebar-toggle .nav-icon {
    transition: transform 0.3s ease;
}

.sidebar.collapsed #sidebar-toggle .nav-icon {
    transform: rotate(180deg);
}

/* ========== 主内容区域 ========== */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
    overflow: hidden;
}

/* ========== 顶部工具栏 ========== */
.top-bar {
    height: var(--top-bar-height);
    min-height: var(--top-bar-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
    z-index: 50;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px;
}

.page-title {
    font-size: 1.15em;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-left: auto;
}

.status-bar-inline {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-value {
    font-size: 0.85em;
    color: var(--success);
}

.status-value.clickable {
    cursor: pointer;
}

.status-value.disconnected {
    color: var(--danger);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 用户信息显示 */
.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.user-info:hover {
    background: var(--bg-tertiary);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.user-name {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

/* 用户下拉菜单 */
.user-dropdown {
    position: fixed;
    top: 56px;
    left: 0;
    width: 220px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color, rgba(0,0,0,0.08));
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    padding: 8px;
}

[data-theme="dark"] .user-dropdown {
    border-color: var(--border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.user-dropdown-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
}

.user-dropdown-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.user-dropdown-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-dropdown-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-dropdown-role {
    font-size: 12px;
    color: var(--text-secondary);
}

.user-dropdown-divider {
    height: 1px;
    background: var(--border-color, rgba(0,0,0,0.08));
    margin: 4px 0;
}

[data-theme="dark"] .user-dropdown-divider {
    background: var(--border);
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
    color: var(--text-primary);
}

.user-dropdown-item:hover {
    background: var(--bg-tertiary);
}

.user-dropdown-item svg {
    flex-shrink: 0;
}

.user-dropdown-logout {
    color: var(--danger);
}

.user-dropdown-logout:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* 主题切换按钮 */
#theme-toggle .theme-icon-light {
    display: none;
}

#theme-toggle .theme-icon-dark {
    display: block;
}

[data-theme="light"] #theme-toggle .theme-icon-light {
    display: block;
}

[data-theme="light"] #theme-toggle .theme-icon-dark {
    display: none;
}

/* ========== 内容区域 ========== */
.content-area .tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.content-area .tab-content.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.section-header h2 {
    font-size: 1.3em;
    color: var(--text-primary);
}

.header-btns {
    display: flex;
    gap: 8px;
}

/* ========== 下载面板 (右侧抽屉) ========== */
.downloads-panel {
    width: 0;
    min-width: 0;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width var(--transition-speed) ease, min-width var(--transition-speed) ease, opacity var(--transition-speed) ease;
    opacity: 0;
    flex-shrink: 0;
}

.downloads-panel.visible {
    width: var(--downloads-panel-width);
    min-width: var(--downloads-panel-width);
    opacity: 1;
}

.panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 1.1em;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.panel-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.close-panel-btn {
    padding: 6px !important;
}

/* ========== 通用列表/卡片 ========== */
.list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.empty-state {
    text-align: center;
    color: var(--text-tertiary);
    padding: 40px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    transition: background 0.2s;
}

.card:hover {
    background: var(--bg-card-hover);
}

.card.disabled {
    opacity: 0.6;
}

.card.disabled .card-title {
    text-decoration: line-through;
}

.card-info {
    flex: 1;
    min-width: 0;
}

.card-title {
    font-size: 1.1em;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.card-meta {
    font-size: 0.85em;
    color: var(--text-secondary);
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.card-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.subscribe-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
}

.subscribe-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
}

.subscribe-cover-wrapper {
    width: 100%;
    aspect-ratio: 2 / 3;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
    cursor: pointer;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.subscribe-cover {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--bg-tertiary);
}

.subscribe-cover-empty,
.imdb-cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-tertiary);
}

.subscribe-card-body {
    margin-bottom: 10px;
}

.status-disabled-tag {
    font-size: 12px;
    color: var(--danger);
}

.imdb-search-card {
    display: grid;
    grid-template-columns: 80px 1fr auto;
    gap: 12px;
    align-items: center;
}

.imdb-cover {
    width: 80px;
    height: 110px;
    object-fit: cover;
    border-radius: 8px;
    background: var(--bg-tertiary);
}

.imdb-season-row {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.imdb-season-row label {
    flex-shrink: 0;
    color: var(--text-secondary);
    font-size: 0.9em;
}

.imdb-season-row .imdb-season-select-wrapper {
    flex: 0 0 auto;
    min-width: 140px;
    position: relative;
}

.imdb-season-row .imdb-season-select-wrapper .custom-select-wrapper {
    width: 100%;
    min-width: 140px;
}

.imdb-season-row .imdb-season-select-wrapper .custom-select-trigger {
    min-width: 140px;
    padding: 8px 12px;
    min-height: 36px;
    font-size: 0.9em;
}

.imdb-search-card .custom-select-dropdown {
    z-index: 2100;
}

/* ========== 按钮 ========== */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    font-weight: 600;
}

[data-theme="light"] .btn-primary {
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.4);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
}

.btn-danger {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.25);
}

.btn-warning {
    background: rgba(251, 146, 60, 0.15);
    color: var(--warning);
}

.btn-warning:hover {
    background: rgba(251, 146, 60, 0.25);
}

.btn-success {
    background: rgba(74, 222, 128, 0.15);
    color: var(--success);
}

.btn-success:hover {
    background: rgba(74, 222, 128, 0.25);
}

.btn-info {
    background: rgba(24, 144, 255, 0.15);
    color: var(--accent-primary);
}

.btn-info:hover {
    background: rgba(24, 144, 255, 0.25);
}

.btn-retry {
    background: rgba(251, 146, 60, 0.15);
    color: var(--warning);
    font-size: 0.75em;
    padding: 3px 8px;
}

.btn-retry:hover {
    background: rgba(251, 146, 60, 0.3);
}

.btn-small {
    padding: 5px 10px;
    font-size: 0.85em;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

@keyframes btn-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.btn .spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
    flex-shrink: 0;
}

.btn-small .spinner {
    width: 10px;
    height: 10px;
    border-width: 2px;
}

.btn-filter {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid transparent;
}

.btn-filter:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-filter.active {
    background: var(--bg-sidebar-active);
    color: var(--text-sidebar-active);
    border-color: var(--border-color-strong);
}

/* ========== 搜索框 ========== */
.search-box {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-box select,
.search-box input {
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1em;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.search-box select {
    min-width: 150px;
    border-radius: 12px;
}

.search-box select:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-card-hover);
}

.search-box input:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-card-hover);
}

.search-box select:focus,
.search-box input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.15);
}

.search-box input {
    flex: 1;
    min-width: 200px;
}

.search-box input::placeholder {
    color: var(--text-tertiary);
}

/* ========== 表单 ========== */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: 0.9em;
}

.form-group label.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    padding: 8px 0;
}

.form-group label.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-primary);
    flex-shrink: 0;
    margin: 0;
}

.form-group label.checkbox-label span {
    font-size: 0.95em;
    color: var(--text-primary);
    line-height: 1.4;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1em;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.form-group select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 36px;
    cursor: pointer;
    border-radius: 12px;
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-card-hover);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.15);
}

/* ========== 自定义下拉选择器 ========== */
.custom-select-wrapper {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1em;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    user-select: none;
    min-height: 42px;
    box-sizing: border-box;
}

.custom-select-trigger:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-card-hover);
}

.custom-select-trigger.open {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.15);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.custom-select-trigger .select-placeholder {
    color: var(--text-tertiary);
}

.custom-select-trigger .select-arrow {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    color: var(--text-secondary);
}

.custom-select-trigger.open .select-arrow {
    transform: rotate(180deg);
}

.custom-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg-modal);
    border: 1px solid var(--accent-primary);
    border-top: none;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    display: none;
}

.custom-select-dropdown.show {
    display: block;
}

.custom-select-option {
    padding: 10px 15px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    color: var(--text-primary);
    font-size: 0.95em;
}

.custom-select-option:hover {
    background: var(--bg-sidebar-active);
    color: var(--text-sidebar-active);
}

.custom-select-option.selected {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--accent-primary);
}

.custom-select-option:last-child {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

/* 搜索框中的自定义下拉 */
.search-box .custom-select-wrapper {
    width: auto;
    min-width: 150px;
}

.search-box .custom-select-wrapper .custom-select-trigger {
    min-width: 150px;
}

/* 表单中的自定义下拉 */
.form-group .custom-select-wrapper .custom-select-trigger {
    width: 100%;
}

/* ========== 原生 select 隐藏（仅用于表单提交） ========== */
/* TMDB 结果等动态场景：原生 select 与 .custom-select-wrapper 为兄弟节点，需按 .hidden-select 隐藏 */
.form-group select.hidden-select,
.custom-select-wrapper select,
select.hidden-select {
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
    height: 0 !important;
    width: 0 !important;
    padding: 0 !important;
    border: none !important;
    background-image: none !important;
    margin: 0 !important;
    min-width: 0 !important;
}

select option {
    background: var(--bg-modal);
    color: var(--text-primary);
    padding: 8px 12px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* ========== 弹窗 ========== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: var(--bg-overlay);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    overflow: hidden;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-modal);
    border-radius: 15px;
    padding: 30px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1.3em;
}

.modal-large {
    max-width: 700px;
}

.modal-medium {
    max-width: 600px;
}

.modal-settings {
    max-width: 600px;
}

/* ========== 订阅弹窗（表单 + 预览） ========== */
.modal-content.modal-subscribe {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-content.modal-subscribe:not(:has(.subscribe-preview:not(:empty))) {
    overflow-y: auto;
}

.modal-subscribe-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.modal-subscribe-body > form {
    flex-shrink: 0;
}

@media (min-width: 769px) {
    .modal-content.modal-subscribe:not(:has(.subscribe-preview:not(:empty))) .modal-subscribe-body {
        flex: 1 1 auto;
        overflow: visible;
    }

    .modal-content.modal-subscribe:not(:has(.subscribe-preview:not(:empty))) .modal-subscribe-body > form {
        overflow: visible;
    }

    .modal-content.modal-subscribe:has(.subscribe-preview:not(:empty)) {
        width: 66.67vw;
        max-width: 66.67vw;
    }

    .modal-content.modal-subscribe:has(.subscribe-preview:not(:empty)) .modal-subscribe-body {
        flex-direction: row;
        gap: 24px;
        align-items: stretch;
    }

    .modal-content.modal-subscribe:has(.subscribe-preview:not(:empty)) .modal-subscribe-body > form {
        flex: 0 0 340px;
        overflow: hidden;
    }

    .modal-content.modal-subscribe:has(.subscribe-preview:not(:empty)) .subscribe-preview {
        flex: 1;
        min-width: 0;
        min-height: 0;
        max-height: none;
        margin-top: 0;
        padding-left: 24px;
        border-left: 1px solid var(--border-color);
        overflow-y: auto;
    }
}

.modal-settings .tabs {
    flex-wrap: nowrap;
    gap: 5px;
    margin-bottom: 20px;
}

.modal-settings .tab {
    white-space: nowrap;
    min-width: fit-content;
    padding: 8px 14px;
    font-size: 0.9em;
}

/* ========== 标签页 (弹窗内) ========== */
.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    background: var(--bg-tertiary);
    padding: 5px;
    border-radius: 10px;
}

.tab {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s;
    font-size: 0.95em;
}

.tab:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.tab.active {
    background: var(--bg-card);
    color: var(--accent-primary);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 10px;
    color: #fff;
    z-index: 2000;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow-md);
}

.toast.success {
    background: linear-gradient(135deg, #4ade80, #22c55e);
}

.toast.error {
    background: linear-gradient(135deg, #f87171, #ef4444);
}

.toast.warning {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1a1a2e;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ========== 下载/种子相关 ========== */
.torrent-item {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 15px 20px;
}

.search-torrent-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
}

.search-torrent-item .torrent-main {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 280px);
}

.search-torrent-item .torrent-title {
    color: var(--text-primary);
    font-size: 0.95em;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-all;
    margin-bottom: 4px;
}

.search-torrent-item .torrent-desc {
    font-size: 0.8em;
    color: var(--text-secondary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-all;
}

.search-torrent-item .torrent-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 120px;
    max-width: 140px;
}

.search-torrent-item .torrent-meta {
    display: flex;
    gap: 10px;
    font-size: 0.8em;
    flex-wrap: nowrap;
}

.search-torrent-item .meta-item {
    color: var(--text-secondary);
    white-space: nowrap;
}

.meta-item.seeders { color: var(--success); font-weight: 600; }
.meta-item.size-small { color: var(--text-secondary); }
.meta-item.size-medium { color: #fbbf24; font-weight: 500; }
.meta-item.size-large { color: var(--danger); font-weight: 600; }

.search-torrent-item .torrent-tags {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

.search-torrent-item .download-btn {
    flex-shrink: 0;
    min-width: 60px;
}

.torrent-header-text {
    flex: 1;
    min-width: 0;
}

.torrent-episode-label {
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 4px;
    word-break: break-all;
}

.torrent-title {
    color: var(--text-primary);
    margin-bottom: 4px;
    word-break: break-all;
}

.torrent-title.torrent-name-sub {
    font-size: 0.85em;
    color: var(--text-secondary);
    font-weight: 400;
    margin-bottom: 0;
}

.torrent-desc {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.torrent-meta {
    display: flex;
    gap: 15px;
    font-size: 0.85em;
    flex-wrap: wrap;
}

.meta-item { color: var(--text-secondary); }

.torrent-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    margin-top: 8px;
    font-size: 0.85em;
}

.meta-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.meta-label {
    color: var(--text-secondary);
    font-size: 0.9em;
    flex-shrink: 0;
    min-width: 2em;
}

.meta-value {
    color: var(--text-primary);
    font-weight: 500;
}

.meta-value.state-text {
    color: var(--info, #60a5fa);
}

.meta-value.progress-text {
    color: var(--warning, #fbbf24);
}

.meta-value.speed-text {
    color: var(--success);
}

.meta-value.added-text {
    color: var(--text-secondary);
}

.download-progress-bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    margin: 6px 0;
    overflow: hidden;
}

.download-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #22c55e);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.download-item { margin-bottom: 10px; }

.download-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    align-items: center;
}

.download-filters {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* 复选框 */
.torrent-header-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.torrent-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background: var(--bg-input);
    border: 2px solid var(--border-color-strong);
    border-radius: 4px;
    position: relative;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.torrent-checkbox:hover {
    border-color: var(--accent-primary);
}

.torrent-checkbox:checked {
    background: var(--accent-gradient);
    border-color: var(--accent-primary);
}

.torrent-checkbox:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* ========== 文件列表 ========== */
.file-list {
    margin-top: 10px;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 0.85em;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid var(--border-color);
}

.file-item:last-child { border-bottom: none; }
.file-item.media-file { color: var(--success); }
.file-item.non-media { color: var(--text-secondary); }

.file-name { flex: 1; word-break: break-all; }
.file-size { color: var(--text-secondary); margin-left: 10px; }

.file-progress {
    width: 60px;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    margin-left: 10px;
    overflow: hidden;
}

.file-progress-bar {
    height: 100%;
    background: var(--accent-primary);
    transition: width 0.3s ease;
}

/* ========== 站点卡片 ========== */
.site-card { display: flex; align-items: center; gap: 15px; }
.site-info { flex: 1; }
.site-name { font-size: 1.1em; color: var(--text-primary); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.site-url { font-size: 0.85em; color: var(--text-tertiary); }

.site-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success);
}

.site-status.disabled { background: var(--danger); }
.site-cookies { font-size: 0.8em; color: var(--success); margin-top: 4px; }

/* 站点类型标签 */
.site-type-badge {
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

.site-type-badge.nyaa {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
}

.site-type-badge.pt {
    background: rgba(99, 102, 241, 0.2);
    color: #6366f1;
}

/* 默认站点标签 */
.site-default-badge {
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(251, 146, 60, 0.2);
    color: #fb923c;
}

/* 默认站点卡片样式 */
.default-site {
    border: 1px solid rgba(251, 146, 60, 0.3);
    background: rgba(251, 146, 60, 0.05);
}

/* ========== 路径映射 ========== */
.path-mapping-card { padding: 14px 16px; margin-bottom: 10px; }
.path-mapping-info { flex: 1; min-width: 0; }

.path-mapping-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}
.path-chip {
    min-width: 0;
    padding: 5px 10px;
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.88em;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.2s;
}
.path-chip:hover { background: var(--bg-card-hover); }
.path-arrow {
    flex-shrink: 0;
    width: 28px;
    height: 24px;
    position: relative;
    opacity: 0.7;
}
/* 箭头横线 */
.path-arrow::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 20px;
    height: 3px;
    background: var(--accent-primary);
    transform: translateY(-50%);
}
/* 箭头三角 */
.path-arrow::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 2px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 8px solid var(--accent-primary);
    transform: translateY(-50%);
}

.path-mapping-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    font-size: 0.8em;
    color: var(--text-tertiary);
}
.path-status-badge {
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.85em;
    line-height: 1.6;
}
.path-status-badge.enabled { background: rgba(74, 222, 128, 0.12); color: var(--success); }
.path-status-badge.disabled { background: rgba(148, 163, 184, 0.12); color: var(--text-secondary); }

/* ========== 订阅详情 ========== */
.subscribe-detail-content {
    max-height: 60vh;
    overflow-y: auto;
    margin: 15px 0;
}

.subscribe-detail-info {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
}

.subscribe-detail-info .info-row {
    display: flex;
    gap: 15px;
    padding: 5px 0;
    flex-wrap: wrap;
}

.subscribe-detail-info .info-label { color: var(--text-secondary); min-width: 80px; }
.subscribe-detail-info .info-value { color: var(--text-primary); }

.subscribe-detail-episodes { margin-top: 15px; }
.subscribe-detail-episodes h4 { color: var(--text-primary); margin-bottom: 10px; font-size: 1em; }

.episode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
}

.episode-grid .episode-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    gap: 4px;
}

.episode-grid .episode-number { color: var(--text-primary); font-weight: 600; }
.episode-grid .episode-status { padding: 2px 6px; border-radius: 4px; font-size: 0.75em; }

/* ========== 集数状态 ========== */
.episode-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
}

.episode-item:last-child { border-bottom: none; }
.episode-item.episode-before-start { opacity: 0.5; }
.episode-number { color: var(--text-primary); }
.episode-status { padding: 2px 8px; border-radius: 4px; font-size: 0.8em; }

.status-pending { background: rgba(128,128,128,0.2); color: var(--text-secondary); }
.status-downloading { background: rgba(79,172,254,0.2); color: #4facfe; }
.status-seeding { background: rgba(74,222,128,0.2); color: var(--success); }
.status-completed { background: rgba(34,197,94,0.2); color: #22c55e; }
.status-failed { background: rgba(239,68,68,0.2); color: var(--danger); }
.status-paused { background: rgba(251,146,60,0.2); color: var(--warning); }
.status-stopped { background: rgba(128,128,128,0.2); color: var(--text-secondary); }

/* ========== 质量标签 ========== */
.torrent-quality { padding: 2px 8px; border-radius: 4px; font-size: 0.8em; }
.quality-4k { background: rgba(79,172,254,0.2); color: #4facfe; }
.quality-1080 { background: rgba(74,222,128,0.2); color: var(--success); }
.quality-720 { background: rgba(251,146,60,0.2); color: var(--warning); }

.episode-badge {
    display: inline-block;
    padding: 3px 10px;
    background: rgba(79,172,254,0.2);
    color: #4facfe;
    border-radius: 20px;
    font-size: 0.85em;
}

/* ========== 预览 ========== */
.subscribe-preview {
    margin-top: 20px;
    max-height: 300px;
    overflow-y: auto;
}

.subscribe-preview:empty {
    display: none;
    margin: 0;
}

.preview-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 10px;
}

.preview-toolbar-left, .preview-toolbar-right { display: flex; align-items: center; gap: 8px; }

.preview-checkbox { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent-primary); }
.preview-select-label { color: var(--text-primary); font-size: 0.9em; cursor: pointer; user-select: none; }

.btn-exclude { background: rgba(239,68,68,0.15); color: var(--danger); }
.btn-exclude:hover:not(:disabled) { background: rgba(239,68,68,0.25); }
.btn-unexclude { background: rgba(74,222,128,0.15); color: var(--success); }
.btn-unexclude:hover:not(:disabled) { background: rgba(74,222,128,0.25); }
.btn-exclude:disabled, .btn-unexclude:disabled { opacity: 0.4; cursor: not-allowed; }

.subscribe-preview .preview-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    transition: background 0.2s;
}

.subscribe-preview .preview-item:hover { background: var(--bg-card-hover); }
.subscribe-preview .preview-item.preview-excluded { opacity: 0.5; background: rgba(239,68,68,0.08); }
.subscribe-preview .preview-item .preview-item-checkbox { width: 18px; height: 18px; cursor: pointer; accent-color: var(--accent-primary); flex-shrink: 0; margin-top: 2px; }
.subscribe-preview .preview-item .preview-content { flex: 1; min-width: 0; }
.subscribe-preview .preview-title { color: var(--text-primary); font-weight: 600; margin-bottom: 8px; }
.subscribe-preview .preview-meta { display: flex; gap: 15px; font-size: 0.85em; color: var(--text-secondary); flex-wrap: wrap; }
.subscribe-preview .preview-meta span { white-space: nowrap; }

/* ========== 确认对话框 ========== */
.confirm-modal-content {
    max-width: 400px;
    text-align: center;
    padding: 35px 30px;
    overflow-x: hidden;
}

.confirm-icon { font-size: 3em; margin-bottom: 15px; }
.confirm-modal-content h3 { margin-bottom: 10px; text-align: center; word-break: break-word; color: var(--text-primary); }
.confirm-message { color: var(--text-secondary); margin-bottom: 25px; font-size: 1em; line-height: 1.5; text-align: center; word-break: break-word; }
.confirm-modal-content .form-actions { justify-content: center; }
.confirm-modal-content .btn-danger { background: linear-gradient(135deg, #f87171, #ef4444); color: #fff; }
.confirm-modal-content .btn-danger:hover { transform: translateY(-2px); box-shadow: 0 4px 15px rgba(248,113,113,0.4); }
.confirm-modal-content.success .confirm-icon { color: #4ade80; }
.confirm-modal-content.success .btn-danger { background: linear-gradient(135deg, #4ade80, #22c55e); }
.confirm-modal-content.warning .confirm-icon { color: #fbbf24; }
.confirm-modal-content.warning .btn-danger { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #1a1a2e; }

/* ========== 数字输入 ========== */
input[type="number"] { -moz-appearance: textfield; }

.number-input-wrapper { display: flex; align-items: center; gap: 0; }
.number-input-wrapper input[type="number"] { border-radius: 0; text-align: center; width: 80px; -moz-appearance: textfield; }
.number-input-wrapper input[type="number"]::-webkit-outer-spin-button,
.number-input-wrapper input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.number-btn {
    width: 36px; height: 42px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-secondary);
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
    user-select: none;
}

.number-minus { border-radius: 8px 0 0 8px; border-right: none; }
.number-plus { border-radius: 0 8px 8px 0; border-left: none; }
.number-btn:hover { background: var(--bg-sidebar-active); color: var(--accent-primary); }
.number-btn:active { transform: scale(0.98); }

.episode-adjust-wrapper { display: flex; align-items: center; gap: 6px; }
.episode-adjust-wrapper label { color: var(--text-secondary); font-size: 0.85em; white-space: nowrap; }
.episode-adjust-wrapper .number-input-wrapper input[type="number"] { width: 54px; height: 32px; min-height: 32px; margin: 0; padding: 0 6px; line-height: 30px; box-sizing: border-box; background: transparent; color: var(--text-primary); font-weight: 600; border: 1px solid var(--border-color); border-radius: 0; }
.episode-adjust-wrapper .number-btn { height: 32px; width: 28px; min-width: 28px; padding: 0; line-height: 1; box-sizing: border-box; font-size: 1em; }

/* ========== 扫描结果 ========== */
.scan-result-info { margin-top: 16px; }
.scan-result-info .info-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border-color); }
.scan-result-info .info-label { color: var(--text-secondary); font-weight: 500; }
.scan-result-info .info-value { color: var(--text-primary); font-weight: 600; }

/* ========== 目录浏览 ========== */
.input-with-browse { display: flex; gap: 8px; align-items: center; }
.input-with-browse input { flex: 1; }
.browse-btn { flex-shrink: 0; height: 42px; }

.directory-browser { margin-top: 12px; }
.directory-nav { margin-bottom: 12px; }
.directory-current-path { background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 8px; padding: 8px 12px; color: var(--accent-primary); font-family: 'Courier New', monospace; font-size: 0.85em; word-break: break-all; margin-bottom: 8px; }
.directory-roots { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.directory-root-item { background: rgba(79,172,254,0.1); border: 1px solid rgba(79,172,254,0.3); border-radius: 6px; padding: 4px 10px; color: var(--accent-primary); font-size: 0.85em; cursor: pointer; transition: all 0.2s; }
.directory-root-item:hover { background: rgba(79,172,254,0.2); }
.directory-list { max-height: 350px; overflow-y: auto; border: 1px solid var(--border-color); border-radius: 8px; padding: 8px; background: var(--bg-tertiary); }
.directory-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 6px; cursor: pointer; transition: all 0.2s; }
.directory-item:hover { background: var(--bg-sidebar-hover); }
.directory-item.selected { background: var(--bg-sidebar-active); border: 1px solid var(--border-color-strong); }
.directory-icon { font-size: 1.2em; color: var(--accent-primary); flex-shrink: 0; }
.directory-name { flex: 1; color: var(--text-primary); font-size: 0.95em; }
.directory-item .directory-select-check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-color-strong); flex-shrink: 0; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.directory-item.selected .directory-select-check { border-color: var(--accent-primary); background: var(--accent-primary); color: #fff; }

/* ========== 通用切换按钮 ========== */
.toggle-files-btn, .toggle-episodes-btn { margin-top: 0; background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: 6px; padding: 5px 10px; font-size: 0.85em; cursor: pointer; transition: all 0.3s; display: inline-flex; align-items: center; justify-content: center; }
.toggle-files-btn:hover, .toggle-episodes-btn:hover { background: var(--bg-card-hover); }

/* ========== 滚动条 ========== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

html { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track); }

/* ========== 移动端遮罩 ========== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    pointer-events: none;
}

.sidebar-overlay.open {
    pointer-events: auto;
}

/* ========== 响应式: 平板 (<=1024px) ========== */
@media (max-width: 1024px) {
    :root {
        --downloads-panel-width: 400px;
    }
}

/* ========== 响应式: 手机 (<=768px) ========== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        width: var(--sidebar-width-expanded);
        min-width: var(--sidebar-width-expanded);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .mobile-menu-btn {
        display: block;
    }

    .sidebar-bottom {
        display: none;
    }

    .page-title {
        font-size: 1em;
    }

    .status-bar-inline {
        display: none;
    }

    .top-bar {
        padding: 0 12px;
    }

    .content-area .tab-content {
        padding: 16px 12px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .section-header .btn {
        width: 100%;
    }

    .header-btns {
        width: 100%;
        flex-direction: column;
    }

    .header-btns .btn {
        width: 100%;
    }

    .search-box {
        flex-direction: column;
    }

    .search-box select,
    .search-box input {
        width: 100%;
        min-width: 0;
    }

    .search-box .btn {
        width: 100%;
    }

    .card {
        flex-direction: column;
        align-items: flex-start;
    }

    .card-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .card-actions .btn {
        flex: 1;
        min-width: 0;
        justify-content: center;
    }

    /* 下载面板在手机端全屏 */
    .downloads-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 0;
        min-width: 0;
        z-index: 80;
        opacity: 0;
        pointer-events: none;
        transition: width var(--transition-speed) ease, opacity var(--transition-speed) ease, pointer-events var(--transition-speed) ease;
    }

    .downloads-panel.visible {
        width: 100%;
        min-width: 100%;
        opacity: 1;
        pointer-events: auto;
    }

    /* 移动端全屏弹窗：表单区域独立滚动，避免切换输入框时滚到预览区底部 */
    .modal {
        align-items: stretch;
        padding: 0;
        overflow: hidden;
        height: 100%;
        max-height: 100dvh;
    }

    .modal-content {
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        overflow: hidden;
        touch-action: manipulation;
    }

    .modal-content > h3 {
        flex-shrink: 0;
        margin-bottom: 12px;
    }

    .modal-content > form,
    .modal-subscribe-body > form {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        scroll-padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .modal-subscribe-body > form .form-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        margin-top: 20px;
        margin-bottom: 0;
        padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
        background: var(--bg-modal);
        box-shadow: 0 -10px 20px -8px rgba(0, 0, 0, 0.35);
    }

    .modal-content > .modal-subscribe-body {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* 手机端：预览时上下布局，表单与预览各自滚动 */
    .modal-content.modal-subscribe:has(.subscribe-preview:not(:empty)) {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .modal-content.modal-subscribe:has(.subscribe-preview:not(:empty)) .modal-subscribe-body {
        flex-direction: column;
        gap: 0;
    }

    .modal-content.modal-subscribe:has(.subscribe-preview:not(:empty)) .modal-subscribe-body > form {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        scroll-padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    }

    .modal-content.modal-subscribe:has(.subscribe-preview:not(:empty)) .subscribe-preview {
        flex: 0 1 auto;
        min-height: 140px;
        max-height: 40dvh;
        margin-top: 12px;
        padding: 12px 0 0;
        border-left: none;
        border-top: 1px solid var(--border-color);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .modal-content > .subscribe-preview,
    .modal-subscribe-body > .subscribe-preview {
        flex-shrink: 0;
        max-height: min(30dvh, 220px);
        margin-top: 12px;
        padding-left: 0;
        border-left: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-content.modal-settings,
    .modal-content.modal-large,
    .modal-content.modal-medium,
    .modal-content.confirm-modal-content,
    .modal-content:not(:has(> form)) {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        scroll-padding-bottom: 120px;
    }

    .modal .form-group input,
    .modal .form-group textarea,
    .modal .form-group select,
    .modal .custom-select-trigger {
        font-size: 16px;
        scroll-margin-bottom: 80px;
    }

    input,
    select,
    textarea,
    .custom-select-trigger,
    .search-box input {
        font-size: 16px;
    }

    .modal-large {
        max-width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .subscribe-card .card-actions {
        flex-wrap: wrap;
    }

    .episode-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }

    .top-bar-right {
        gap: 8px;
    }

    .user-info .user-name {
        display: none;
    }

    .user-info {
        padding: 6px;
    }

    .top-actions {
        gap: 4px;
    }

    .top-actions .btn {
        padding: 6px 8px;
        font-size: 0.8em;
    }

    .top-actions .btn-small {
        padding: 4px 6px;
        font-size: 0.75em;
    }

    .search-box .custom-select-wrapper {
        width: 100%;
        min-width: 0;
    }

    .search-box .custom-select-wrapper .custom-select-trigger {
        min-width: 0;
        width: 100%;
    }

    .path-mapping-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .path-arrow {
        transform: rotate(90deg);
        width: 24px;
        height: 28px;
    }

    .download-filters {
        flex-wrap: wrap;
    }

    .search-torrent-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .search-torrent-item .torrent-main {
        max-width: 100%;
        width: 100%;
    }

    .search-torrent-item .torrent-info {
        flex-direction: row;
        min-width: auto;
        max-width: 100%;
        width: 100%;
        justify-content: space-between;
        align-items: center;
    }

    .search-torrent-item .download-btn {
        width: 100%;
        margin-top: 8px;
    }

    .search-torrent-item .torrent-tags {
        flex-wrap: wrap;
    }

    .card-actions .btn {
        flex: 0 1 auto;
        min-width: 44px;
        min-height: 44px;
        padding: 8px 12px;
        font-size: 0.85em;
    }

    .modal-settings .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: wrap;
    }

    .modal-settings .tabs::-webkit-scrollbar {
        display: none;
    }

    .modal-settings .tab {
        flex: 0 0 auto;
    }

    .download-filters .btn {
        flex: 0 0 auto;
    }
}

/* ========== 响应式: 小手机 (<=480px) ========== */
@media (max-width: 480px) {
    .top-bar {
        padding: 0 8px;
        gap: 8px;
    }

    .page-title {
        font-size: 0.9em;
    }

    .content-area .tab-content {
        padding: 12px 8px;
    }

    .card {
        padding: 12px;
    }

    .card-title {
        font-size: 1em;
    }

    .card-meta {
        font-size: 0.8em;
        gap: 8px;
    }

    .episode-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        gap: 6px;
    }
}

/* ========== 日志模块样式 ========== */
.log-filters,
.system-log-toolbar {
    --log-control-height: 42px;
}

.log-filters {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.log-filters .custom-select-wrapper {
    width: auto;
    min-width: 150px;
}

.log-filters .custom-select-wrapper .custom-select-trigger {
    min-width: 150px;
    height: var(--log-control-height);
    min-height: var(--log-control-height);
    padding: 0 15px;
    border-radius: 12px;
    font-size: 0.95em;
}

.log-filters input[type="date"] {
    padding: 0 15px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.95em;
    height: var(--log-control-height);
    min-height: var(--log-control-height);
    box-sizing: border-box;
    cursor: pointer;
    color-scheme: dark;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.log-filters .btn,
.system-log-toolbar .btn {
    min-height: var(--log-control-height);
    height: var(--log-control-height);
    padding: 0 16px;
    border-radius: 12px;
    font-size: 0.95em;
    box-sizing: border-box;
}

[data-theme="light"] .log-filters input[type="date"] {
    color-scheme: light;
}

.log-filters input[type="date"]:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-card-hover);
}

.log-filters input[type="date"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.15);
}

.log-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.log-item {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border-color);
    transition: border-color 0.2s ease;
}

.log-item:hover {
    border-color: var(--accent-primary);
}

.log-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.log-module-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 500;
    background: var(--accent-secondary);
    color: white;
}

.log-module-badge.subscribe_check {
    background: #3b82f6;
}

.log-module-badge.subscribe_manage {
    background: #10b981;
}

.log-module-badge.site_manage {
    background: #f59e0b;
}

.log-module-badge.settings {
    background: #8b5cf6;
}

.log-module-badge.download {
    background: #ef4444;
}

.log-module-badge.path_mapping {
    background: #06b6d4;
}

.log-module-badge.auth {
    background: #ec4899;
}

.log-operation {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.log-result-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 500;
}

.log-result-badge.success {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
}

.log-result-badge.failed {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.log-result-badge.partial {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.log-result-badge.skipped {
    background: rgba(107, 114, 128, 0.2);
    color: #6b7280;
}

.log-time {
    color: var(--text-tertiary);
    font-size: 0.85em;
    margin-left: auto;
}

.log-body {
    margin-bottom: 8px;
}

.log-target {
    margin-bottom: 8px;
}

.log-target-name {
    color: var(--text-primary);
    font-weight: 500;
}

.log-description {
    color: var(--text-secondary);
    font-size: 0.95em;
    line-height: 1.5;
}

.log-details {
    color: var(--accent-primary);
    font-size: 0.85em;
    cursor: pointer;
    margin-top: 8px;
}

.log-details:hover {
    text-decoration: underline;
}

.log-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-tertiary);
    font-size: 0.85em;
}

.log-details-content {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 12px;
    margin-top: 12px;
    font-size: 0.85em;
    color: var(--text-secondary);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.log-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: 12px;
    margin-top: 16px;
}

.log-pagination span {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.search-pagination {
    margin-top: 16px;
}

/* 日志模块响应式 */
@media (max-width: 768px) {
    .log-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .log-filters .custom-select-wrapper {
        width: 100%;
        min-width: 0;
    }

    .log-filters .custom-select-wrapper .custom-select-trigger {
        min-width: 0;
        width: 100%;
    }

    .log-filters input[type="date"] {
        width: 100%;
    }

    .log-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .log-time {
        margin-left: 0;
    }

    .log-pagination {
        flex-direction: column;
        gap: 8px;
    }
}

/* ========== 日志子选项卡 ========== */
.log-sub-tabs {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.log-sub-tab-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.log-sub-tab-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.log-sub-tab-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.log-sub-tab-btn svg {
    flex-shrink: 0;
}

/* ========== 系统日志工具栏 ========== */
.system-log-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-label {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.toolbar-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
}

.toolbar-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-primary);
    flex-shrink: 0;
    margin: 0;
    border-radius: 4px;
}

/* 工具栏中的自定义下拉框样式 */
.system-log-toolbar .custom-select-wrapper {
    width: auto;
    min-width: 120px;
    flex-shrink: 0;
}

.system-log-toolbar .custom-select-trigger {
    height: var(--log-control-height);
    min-height: var(--log-control-height);
    padding: 0 15px;
    border-radius: 12px;
    font-size: 0.95em;
}

.system-log-toolbar .custom-select-label {
    font-size: 1em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.system-log-toolbar .custom-select-option {
    padding: 10px 15px;
    font-size: 0.95em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.system-log-toolbar .custom-select-dropdown {
    border-radius: 0 0 12px 12px;
}

.toolbar-actions {
    margin-left: auto;
}

.system-log-toolbar .custom-select-wrapper select {
    min-width: 120px;
}

/* ========== 系统日志进度 ========== */
.system-log-progress {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-secondary);
}

/* ========== 系统日志查看器 ========== */
.system-log-viewer {
    height: calc(100vh - 280px);
    overflow: auto;
    background: var(--bg-primary);
    padding: 12px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
}

.log-display {
    margin: 0;
    white-space: pre;
    word-wrap: normal;
    overflow-x: auto;
    color: var(--text-primary);
}

.system-log-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px;
    color: var(--text-secondary);
    font-size: 14px;
    font-family: sans-serif;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
    to { transform: rotate(360deg); }
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .system-log-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .system-log-toolbar .custom-select-wrapper {
        width: 100%;
        min-width: 0;
    }

    .system-log-toolbar .custom-select-trigger {
        width: 100%;
    }
    
    .toolbar-actions {
        margin-left: 0;
        display: flex;
        gap: 8px;
    }
    
    .system-log-viewer {
        height: calc(100vh - 320px);
    }
}
