/* OSM 缓存服务管理 - 深色主题（微信开发者工具风格灰度配色） */

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

/* hidden 属性优先级最高，确保覆盖任何 display 设置 */
[hidden] { display: none !important; }

:root {
    /* 灰度色阶 */
    --bg-darkest:    #1e1e1e;   /* 全局背景 */
    --bg-dark:       #252526;   /* 主应用背景 */
    --bg-panel:      #2d2d30;   /* 卡片背景 */
    --bg-elevated:   #333335;   /* 悬浮元素 */
    --bg-input:      #3c3c3c;   /* 输入框背景 */
    --bg-hover:      #3a3a3d;

    --border:        #3c3c3c;
    --border-strong: #4a4a4d;

    --text-primary:   #e0e0e0;
    --text-secondary: #a8a8a8;
    --text-muted:     #7a7a7a;

    /* 功能色（低饱和度扁平） */
    --color-blue:    #4a9eff;
    --color-green:   #4ec9b0;
    --color-orange:  #d6a55c;
    --color-red:     #e06c75;
    --color-purple:  #c586c0;

    /* 状态色 */
    --status-idle:    var(--text-secondary);
    --status-running: var(--color-blue);
    --status-success: var(--color-green);
    --status-warning: var(--color-orange);
    --status-error:   var(--color-red);

    /* 尺寸 */
    --topbar-h: 48px;
    --radius: 4px;
    --radius-lg: 6px;
}

html, body {
    height: 100%;
    background: var(--bg-darkest);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
    font-size: 13px;
    line-height: 1.5;
    overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------- 登录页 ---------- */
.login-page {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2c 100%);
}
.login-card {
    width: 360px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 28px 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.logo-icon {
    display: inline-block;
    width: 56px; height: 56px;
    background: var(--color-blue);
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    line-height: 56px;
    border-radius: 50%;
    letter-spacing: -1px;
    margin-bottom: 12px;
}
.login-logo h1 { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); font-size: 12px; }
.login-form { margin-bottom: 12px; }
.login-error {
    background: rgba(224, 108, 117, 0.1);
    border: 1px solid var(--color-red);
    color: var(--color-red);
    padding: 6px 10px;
    border-radius: var(--radius);
    font-size: 12px;
    margin-bottom: 12px;
}
.login-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 8px;
}

/* ---------- 表单元素 ---------- */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 6px;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus {
    border-color: var(--color-blue);
}
.form-hint {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 4px;
}
/* ---------- 磁盘列表（下载目录选择） ---------- */
.disk-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
    max-height: 240px;
    overflow-y: auto;
    padding-right: 2px;
}
.disk-list-loading, .disk-list-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}
.disk-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.disk-item:hover {
    border-color: var(--color-blue);
    background: rgba(0, 122, 255, 0.04);
}
.disk-item.is-current {
    border-color: var(--color-green);
    background: rgba(52, 199, 89, 0.05);
}
.disk-item-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 6px;
    background: rgba(0, 122, 255, 0.1);
    color: var(--color-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}
.disk-item.is-current .disk-item-icon {
    background: rgba(52, 199, 89, 0.1);
    color: var(--color-green);
}
.disk-item-info {
    flex: 1;
    min-width: 0;
}
.disk-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.disk-item-mount {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.disk-item-device {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}
.disk-item-size {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.disk-item-bar {
    margin-top: 6px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.disk-item-bar-fill {
    height: 100%;
    background: var(--color-blue);
    border-radius: 2px;
    transition: width 0.3s;
}
.disk-item.is-current .disk-item-bar-fill {
    background: var(--color-green);
}
.disk-item-bar-fill.warn { background: var(--color-orange); }
.disk-item-bar-fill.danger { background: var(--color-red); }
.form-actions { margin-top: 18px; }
.form-switch-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.form-switch-group label:first-child { margin-bottom: 0; }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 12px;
    line-height: 1.4;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 12px; height: 12px; }

.btn-primary { background: var(--color-blue); border-color: var(--color-blue); color: #fff; }
.btn-primary:hover { background: #3a8ae5; border-color: #3a8ae5; }

.btn-secondary { background: var(--bg-elevated); }
.btn-warning { background: var(--color-orange); border-color: var(--color-orange); color: #1e1e1e; }
.btn-warning:hover { background: #c4954d; border-color: #c4954d; }

.btn-danger { background: var(--color-red); border-color: var(--color-red); color: #fff; }
.btn-danger:hover { background: #c95f68; border-color: #c95f68; }

.btn-block { width: 100%; padding: 10px; font-size: 14px; justify-content: center; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn .icon { width: 16px; height: 16px; }

/* ---------- 主应用 ---------- */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    height: var(--topbar-h);
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    flex-shrink: 0;
}
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    margin-right: 32px;
}
.brand-icon {
    display: inline-block;
    width: 24px; height: 24px;
    background: var(--color-blue);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 24px;
    text-align: center;
    border-radius: var(--radius);
}
.brand-text { font-size: 14px; }

.topbar-nav {
    display: flex;
    gap: 4px;
    flex: 1;
}
.nav-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    transition: all 0.15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
    background: var(--bg-elevated);
    color: var(--color-blue);
    border-color: var(--border);
}
.nav-item .icon { width: 14px; height: 14px; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-name {
    color: var(--text-secondary);
    font-size: 12px;
}

/* ---------- 主体 ---------- */
.main {
    flex: 1;
    overflow: auto;
    padding: 16px;
}
.page { display: none; }
.page.active { display: block; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.page-header h2 {
    font-size: 16px;
    font-weight: 600;
}
.page-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.muted-text { color: var(--text-muted); font-size: 12px; }

/* ---------- 统计卡片 ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    border-left: 3px solid var(--text-muted);
}
.stat-card.stat-blue   { border-left-color: var(--color-blue); }
.stat-card.stat-green  { border-left-color: var(--color-green); }
.stat-card.stat-orange { border-left-color: var(--color-orange); }
.stat-card.stat-red    { border-left-color: var(--color-red); }
.stat-card.stat-purple { border-left-color: #a855f7; }
.stat-label { color: var(--text-secondary); font-size: 12px; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 600; }
.stat-value-sm { font-size: 13px; font-weight: 500; line-height: 1.6; }
.date-row { display: flex; align-items: center; gap: 6px; }
.date-label { color: var(--text-muted); font-size: 11px; min-width: 28px; }
.date-val { color: var(--text-primary); font-family: 'SF Mono', 'Menlo', monospace; font-size: 12px; }

/* ---------- 通用卡片 ---------- */
.card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.card-header h3 {
    font-size: 14px;
    font-weight: 600;
}
.card-actions { display: flex; gap: 8px; }

/* ---------- 同步卡片 ---------- */
.sync-status { padding: 16px; }
.status-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    font-size: 13px;
}
.status-label {
    color: var(--text-secondary);
    width: 90px;
    flex-shrink: 0;
}
.status-text { color: var(--text-primary); }
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-input);
    color: var(--text-secondary);
}
.status-badge.status-idle    { background: rgba(168,168,168,0.15); color: var(--text-secondary); }
.status-badge.status-running { background: rgba(74,158,255,0.15);  color: var(--color-blue); }
.status-badge.status-stopping{ background: rgba(214,165,92,0.15);  color: var(--color-orange); }

.progress-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0 12px 90px;
}
.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--color-blue);
    width: 0%;
    transition: width 0.3s;
}
.progress-text {
    color: var(--text-secondary);
    font-size: 11px;
    min-width: 40px;
    text-align: right;
}

/* ---------- 磁盘卡片 ---------- */
.disk-info { padding: 16px; }
.disk-bar {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}
.disk-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-green), var(--color-orange), var(--color-red));
    width: 0%;
    transition: width 0.3s;
}
.disk-text { color: var(--text-secondary); font-size: 12px; }

/* ---------- 表格 ---------- */
.table-container { overflow: auto; max-height: calc(100vh - 220px); }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.data-table thead { background: var(--bg-dark); position: sticky; top: 0; z-index: 1; }
.data-table th, .data-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
}
.data-table td { color: var(--text-primary); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table .col-check { width: 40px; text-align: center; }
.data-table .col-actions { width: 80px; text-align: center; }
.data-table .empty-row {
    text-align: center;
    color: var(--text-muted);
    padding: 30px;
}

.tag {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 11px;
}
.tag-synced      { background: rgba(78,201,176,0.15); color: var(--color-green); }
.tag-pending     { background: rgba(214,165,92,0.15); color: var(--color-orange); }
.tag-failed      { background: rgba(224,108,117,0.15); color: var(--color-red); }
.tag-downloading { background: rgba(74,158,255,0.15); color: var(--color-blue); }
.tag-download    { background: rgba(74,158,255,0.15); color: var(--color-blue); }
.tag-delete      { background: rgba(224,108,117,0.15); color: var(--color-red); }
.tag-success     { background: rgba(78,201,176,0.15); color: var(--color-green); }

/* ---------- 文件下载进度条 ---------- */
.dl-progress {
    margin-top: 6px;
    min-width: 180px;
}
.dl-progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.dl-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-blue), #6ab4ff);
    border-radius: 3px;
    transition: width 0.4s ease;
    position: relative;
}
.dl-progress-fill::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: dl-shimmer 1.5s infinite;
}
@keyframes dl-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}
.dl-progress-text {
    display: block;
    margin-top: 3px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    white-space: nowrap;
}

/* ---------- 搜索/选择 ---------- */
.search-input, .select-input {
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    outline: none;
    font-size: 12px;
}
.search-input { width: 220px; }
.search-input:focus, .select-input:focus { border-color: var(--color-blue); }

/* ---------- 设置 ---------- */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.settings-form { padding: 16px; }
.settings-form .form-actions { margin-top: 16px; }

.schedule-list { padding: 16px; }
.schedule-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 12px;
}
.schedule-item:last-child { border-bottom: none; }
.schedule-name { color: var(--text-secondary); }
.schedule-value {
    color: var(--color-blue);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- Switch ---------- */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border-radius: 10px;
    transition: 0.2s;
    cursor: pointer;
}
.switch-slider::before {
    content: "";
    position: absolute;
    width: 14px; height: 14px;
    left: 3px; top: 3px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: 0.2s;
}
.switch input:checked + .switch-slider { background: var(--color-blue); }
.switch input:checked + .switch-slider::before {
    transform: translateX(16px);
    background: #fff;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    top: 60px;
    right: 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-left: 3px solid var(--color-blue);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 12px;
    z-index: 9999;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    max-width: 400px;
}
.toast.toast-success { border-left-color: var(--color-green); }
.toast.toast-error   { border-left-color: var(--color-red); }
.toast.toast-warning { border-left-color: var(--color-orange); }

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
}
.modal[hidden] { display: none; }
.toast[hidden] { display: none; }
.modal-card {
    width: 380px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.modal-header { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 14px; }
.modal-body { padding: 16px; font-size: 13px; color: var(--text-primary); }
.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ---------- 地区目录（逐级下钻）---------- */
/* 面包屑导航 */
.catalog-breadcrumb {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 13px;
}
.breadcrumb-item {
    color: var(--color-blue);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: var(--radius);
    transition: background 0.1s;
}
.breadcrumb-item:hover { background: var(--bg-hover); }
.breadcrumb-item.active {
    color: var(--text-primary);
    font-weight: 600;
    cursor: default;
}
.breadcrumb-item.active:hover { background: transparent; }
.breadcrumb-sep {
    color: var(--text-muted);
    font-size: 12px;
    user-select: none;
}

.catalog-toolbar {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-dark);
}
.catalog-stats {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 11px;
}
.catalog-stats strong { color: var(--color-blue); font-weight: 600; }
.dot-sep { color: var(--text-muted); }
.link-btn {
    background: transparent;
    border: none;
    color: var(--color-blue);
    cursor: pointer;
    font-size: 11px;
    padding: 1px 4px;
    border-radius: var(--radius);
}
.link-btn:hover { text-decoration: underline; }

.catalog-table-container {
    max-height: calc(100vh - 260px);
    overflow: auto;
}

/* 表格行 */
.catalog-table-container .data-table th,
.catalog-table-container .data-table td {
    padding: 7px 12px;
}
.catalog-table-container .data-table tr.selected {
    background: rgba(74,158,255,0.08);
}
.catalog-table-container .data-table tr:hover {
    background: var(--bg-hover);
}
.catalog-table-container .data-table tr.selected:hover {
    background: rgba(74,158,255,0.12);
}
/* 目录行特殊样式 */
.catalog-table-container .data-table tr.is-dir .name-cn {
    color: var(--text-primary);
    font-weight: 500;
}

/* 行名称：图标 + 中文 + 英文 */
.row-name {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.row-name.dir {
    cursor: pointer;
    color: var(--text-primary);
}
.row-name.dir:hover .name-cn {
    color: var(--color-blue);
}
.row-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}
.row-icon.folder { color: var(--color-orange); }
.row-icon.file { color: var(--color-green); }
.name-cn {
    font-size: 13px;
    color: var(--text-primary);
}
.name-en {
    font-size: 10px;
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* 类型列 */
.col-type {
    color: var(--text-muted);
    font-size: 11px;
}
/* 大小、日期列 */
.col-size, .col-date {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--text-secondary);
    font-size: 11px;
    white-space: nowrap;
}

/* 状态：圆点 + 文字 */
.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    margin-right: 6px;
    vertical-align: middle;
}
.status-dot.synced      { background: var(--color-green); }
.status-dot.pending     { background: var(--color-orange); }
.status-dot.failed      { background: var(--color-red); }
.status-dot.downloading { background: var(--color-blue); }
.status-dot.stale       { background: var(--color-orange); }
.status-text {
    font-size: 11px;
    color: var(--text-secondary);
    vertical-align: middle;
}

/* 复选框 */
.catalog-check {
    accent-color: var(--color-blue);
    cursor: pointer;
    width: 13px;
    height: 13px;
}

/* 滚动条 */
.catalog-table-container::-webkit-scrollbar { width: 8px; }
.catalog-table-container::-webkit-scrollbar-track { background: var(--bg-dark); }
.catalog-table-container::-webkit-scrollbar-thumb {
    background: var(--bg-input);
    border-radius: 4px;
}
.catalog-table-container::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .settings-grid { grid-template-columns: 1fr; }
    .topbar-nav .nav-item span { display: none; }
    .search-input { width: 140px; }
}
