/* 设备中心 V2.0 · 明亮 / 暗黑主题（默认暗黑）
 * 系统字体 + CSS 变量，减少外网字体依赖，国内访问更快
 */

:root {
    --sidebar-w: 18rem;
    --radius: 1.25rem;
    --radius-lg: 1.5rem;
    --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", system-ui, sans-serif;
    --font-title: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    --transition: 0.22s ease;
    --primary: #14b8a6;
    --primary-2: #22d3ee;
    --primary-deep: #0d9488;
    --danger: #f87171;
    --success: #34d399;
    --warn: #fbbf24;
}

/* ========== 暗黑（默认） ========== */
html,
html[data-theme="dark"] {
    color-scheme: dark;
    --bg0: #070b14;
    --bg1: #0c1220;
    --bg2: #121a2b;
    --surface: #151e30;
    --surface-2: #1a2438;
    --glass: rgba(18, 26, 43, 0.88);
    --glass-border: rgba(148, 163, 184, 0.12);
    --text: #e8eef7;
    --text-strong: #f8fafc;
    --muted: #94a3b8;
    --muted-2: #64748b;
    --border: rgba(148, 163, 184, 0.16);
    --input-bg: #0b1220;
    --input-border: rgba(148, 163, 184, 0.22);
    --shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.55);
    --shadow-sm: 0 8px 24px -12px rgba(0, 0, 0, 0.45);
    --nav-active-bg: rgba(20, 184, 166, 0.12);
    --nav-active-text: #5eead4;
    --card-bg: #151e30;
    --card-shadow: 0 8px 28px -12px rgba(0, 0, 0, 0.5);
    --scrollbar: #14b8a6;
    --overlay: rgba(2, 6, 23, 0.65);
    --logo-ring: rgba(15, 23, 42, 0.5);
    --accent-glow: rgba(20, 184, 166, 0.25);
    --table-hover: rgba(20, 184, 166, 0.06);
    --pre-bg: #0b1220;
    --pre-color: #5eead4;
    --badge-online: #34d399;
    --excluded-bg: rgba(127, 29, 29, 0.35);
    --excluded-border: #f87171;
}

/* ========== 明亮 ========== */
html[data-theme="light"] {
    color-scheme: light;
    --bg0: #f1f5f9;
    --bg1: #e0f2fe;
    --bg2: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --glass: rgba(255, 255, 255, 0.92);
    --glass-border: rgba(255, 255, 255, 0.85);
    --text: #334155;
    --text-strong: #0f172a;
    --muted: #64748b;
    --muted-2: #94a3b8;
    --border: #e2e8f0;
    --input-bg: #ffffff;
    --input-border: #e2e8f0;
    --shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.1);
    --shadow-sm: 0 4px 12px -2px rgba(0, 0, 0, 0.08);
    --nav-active-bg: #ffffff;
    --nav-active-text: #0f766e;
    --card-bg: #ffffff;
    --card-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.08);
    --scrollbar: #14b8a6;
    --overlay: rgba(15, 23, 42, 0.45);
    --logo-ring: #ffffff;
    --accent-glow: rgba(20, 184, 166, 0.35);
    --table-hover: rgba(15, 23, 42, 0.03);
    --pre-bg: #f8fafc;
    --pre-color: #0f766e;
    --badge-online: #10b981;
    --excluded-bg: #fef2f2;
    --excluded-border: #f87171;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    font-family: var(--font);
    overflow-x: hidden;
    color: var(--text);
    background: var(--bg0);
    transition: background var(--transition), color var(--transition);
}

.title-font {
    font-family: var(--font-title);
    letter-spacing: -0.03em;
}

/* 背景 */
.bg-soft {
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(20, 184, 166, 0.16), transparent 55%),
        radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.12), transparent 50%),
        linear-gradient(160deg, var(--bg0) 0%, var(--bg1) 45%, var(--bg2) 100%) !important;
    min-height: 100vh;
}

html[data-theme="light"] .bg-soft {
    background:
        radial-gradient(1000px 500px at 0% 0%, rgba(20, 184, 166, 0.12), transparent 50%),
        linear-gradient(135deg, #f8fafc 0%, #e0f2fe 50%, #f1f5f9 100%) !important;
}

/* 玻璃卡片 */
.glass {
    background: var(--glass) !important;
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border: 1px solid var(--glass-border) !important;
    box-shadow: var(--shadow) !important;
    color: var(--text);
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

/* 导航 */
.nav-item {
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--muted);
    border-left: 5px solid transparent;
}
.nav-item:hover {
    background: var(--table-hover);
    color: var(--text);
}
.nav-item.active {
    background: var(--nav-active-bg) !important;
    box-shadow: var(--shadow-sm);
    border-left: 5px solid var(--primary) !important;
    color: var(--nav-active-text) !important;
}

/* 输入 */
.input-focus,
input.input-focus,
select.input-focus,
textarea.input-focus,
input[type="text"],
input[type="password"],
select,
textarea {
    background: var(--input-bg) !important;
    border-color: var(--input-border) !important;
    color: var(--text-strong) !important;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.input-focus::placeholder,
input::placeholder,
textarea::placeholder {
    color: var(--muted-2) !important;
}
.input-focus:focus {
    box-shadow: 0 0 0 4px var(--accent-glow) !important;
    border-color: var(--primary) !important;
    outline: none;
}

/* 按钮 */
.btn-gradient {
    background: linear-gradient(90deg, var(--primary), var(--primary-2)) !important;
    color: #fff !important;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: none;
}
.btn-gradient:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 20px 32px -12px var(--accent-glow);
}

.query-row { display: flex; gap: 16px; max-width: 100%; overflow: hidden; }
.query-row input { flex: 1; min-width: 0; }
.query-row button { flex-shrink: 0; }

.results-container {
    max-height: 620px;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    overflow-x: hidden;
}
#parsed, #multiParsed {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr));
    gap: 20px;
    padding-right: 12px;
}
#parsed::-webkit-scrollbar,
#multiParsed::-webkit-scrollbar,
#editParsed::-webkit-scrollbar { width: 6px; }
#parsed::-webkit-scrollbar-thumb,
#multiParsed::-webkit-scrollbar-thumb,
#editParsed::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: 3px;
}

.device-item, .multi-item {
    max-width: 420px;
    width: 100%;
    word-break: break-all;
    overflow-wrap: break-word;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    color: var(--text);
}

.raw-pre {
    max-height: 320px !important;
    max-width: 100% !important;
    overflow: auto !important;
    background: var(--pre-bg) !important;
    color: var(--pre-color) !important;
    border: 1px solid var(--border) !important;
    border-radius: 20px;
    padding: 1.5rem;
    font-size: 0.875rem;
    white-space: pre-wrap !important;
    word-break: break-all !important;
}

#editParsed {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 28px;
    padding-right: 12px;
}
.edit-item {
    width: 100%;
    max-width: none;
    padding: 2rem;
    border-radius: 20px;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
}
.edit-item.excluded {
    background: var(--excluded-bg);
    border: 3px solid var(--excluded-border);
    box-shadow: 0 10px 30px -10px rgba(248, 113, 113, 0.35);
}
.excluded-badge {
    background: rgba(248, 113, 113, 0.15);
    color: #fca5a5;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
html[data-theme="light"] .excluded-badge {
    background: #fee2e2;
    color: #ef4444;
}

.count-green { background: rgba(16, 185, 129, 0.15); color: #34d399; border-color: #10b981; }
.count-yellow { background: rgba(234, 179, 8, 0.15); color: #fbbf24; border-color: #eab308; }
.count-red { background: rgba(239, 68, 68, 0.15); color: #f87171; border-color: #ef4444; }
html[data-theme="light"] .count-green { background: #ecfdf5; color: #10b981; }
html[data-theme="light"] .count-yellow { background: #fefce8; color: #eab308; }
html[data-theme="light"] .count-red { background: #fef2f2; color: #ef4444; }

#dropZone {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-color: var(--border) !important;
    background: var(--surface-2);
    color: var(--text);
}
#dropZone.dragover {
    border-color: var(--primary) !important;
    background: rgba(20, 184, 166, 0.1) !important;
}

.loader {
    border: 5px solid var(--border);
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    width: 26px;
    height: 26px;
    animation: spin 1s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
button:disabled { opacity: 0.6 !important; cursor: not-allowed !important; pointer-events: none !important; }

/* Toast */
#toast {
    background: var(--glass) !important;
    border: 1px solid var(--border);
    color: var(--text);
    backdrop-filter: blur(20px);
}
#toast.toast-error { color: #fca5a5; }
#toast.toast-success { color: #6ee7b7; }
#toast.toast-info { color: var(--pre-color); }
html[data-theme="light"] #toast.toast-error { color: #b91c1c; }
html[data-theme="light"] #toast.toast-success { color: #047857; }

.export-summary {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1rem 1.25rem;
    font-size: 0.875rem;
    color: var(--muted);
    line-height: 1.6;
}
.export-summary strong { color: var(--text-strong); }

/* 主题切换按钮 */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}
.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.theme-toggle i { font-size: 0.95rem; }

.theme-toggle-float {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 60;
}

/* Logo 光晕 */
.logo-orb {
    background: linear-gradient(135deg, #2dd4bf, #38bdf8);
    box-shadow: 0 12px 40px var(--accent-glow);
}

/* 侧栏 */
#sidebar {
    background: var(--glass) !important;
    border-color: var(--border) !important;
}
#sidebar .border-b,
#sidebar .border-t,
.glass.border-b,
.glass.border-r {
    border-color: var(--border) !important;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 40;
}
.sidebar-overlay.show { display: block; }

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

/* 顶栏状态点 */
.status-dot {
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 999px;
    background: var(--badge-online);
    box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

/* 覆盖 Tailwind 常用色，使主题生效 */
html[data-theme="dark"] .text-slate-800,
html[data-theme="dark"] .text-slate-700,
html[data-theme="dark"] .text-slate-600 { color: var(--text) !important; }
html[data-theme="dark"] .text-slate-500,
html[data-theme="dark"] .text-slate-400 { color: var(--muted) !important; }
html[data-theme="dark"] .bg-white { background-color: var(--surface) !important; }
html[data-theme="dark"] .bg-slate-50 { background-color: var(--surface-2) !important; }
html[data-theme="dark"] .border-slate-100,
html[data-theme="dark"] .border-slate-200,
html[data-theme="dark"] .border-slate-300 { border-color: var(--border) !important; }
html[data-theme="dark"] .hover\:bg-white:hover { background-color: var(--surface-2) !important; }
html[data-theme="dark"] .hover\:bg-slate-50:hover { background-color: var(--table-hover) !important; }
html[data-theme="dark"] .hover\:bg-red-50:hover { background-color: rgba(127, 29, 29, 0.35) !important; }
html[data-theme="dark"] .ring-white { --tw-ring-color: var(--bg1) !important; }
html[data-theme="dark"] .shadow-sm { box-shadow: var(--shadow-sm) !important; }
html[data-theme="dark"] table { color: var(--text); }
html[data-theme="dark"] thead th { color: var(--muted) !important; }
html[data-theme="dark"] tbody tr:hover { background: var(--table-hover); }
html[data-theme="dark"] .bg-emerald-50 { background: rgba(16, 185, 129, 0.12) !important; }
html[data-theme="dark"] .bg-red-50 { background: rgba(239, 68, 68, 0.12) !important; }
html[data-theme="dark"] .text-emerald-600,
html[data-theme="dark"] .text-emerald-700 { color: #5eead4 !important; }
html[data-theme="dark"] .bg-emerald-100 { background: rgba(20, 184, 166, 0.18) !important; }
html[data-theme="dark"] .text-red-500,
html[data-theme="dark"] .text-red-600 { color: #fca5a5 !important; }
html[data-theme="dark"] .bg-blue-600 { background: #2563eb !important; }

html[data-theme="light"] .text-slate-800 { color: #1e293b !important; }
html[data-theme="light"] .text-slate-700 { color: #334155 !important; }
html[data-theme="light"] .text-slate-500 { color: #64748b !important; }
html[data-theme="light"] .text-slate-400 { color: #94a3b8 !important; }

/* 登录页装饰 */
.login-shell {
    position: relative;
}
.login-shell::before {
    content: "";
    position: absolute;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(20, 184, 166, 0.35), transparent 70%);
    top: -80px;
    left: -60px;
    filter: blur(4px);
    pointer-events: none;
}
.login-shell::after {
    content: "";
    position: absolute;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.28), transparent 70%);
    bottom: -60px;
    right: -40px;
    pointer-events: none;
}

.version-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    background: rgba(20, 184, 166, 0.15);
    color: var(--nav-active-text);
    border: 1px solid rgba(20, 184, 166, 0.3);
}

/* 移动端 */
@media (max-width: 900px) {
    .menu-toggle { display: inline-flex; }

    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        width: min(var(--sidebar-w), 86vw);
        transform: translateX(-105%);
        transition: transform 0.25s ease;
    }
    #sidebar.open { transform: translateX(0); }

    .query-row { flex-direction: column; }
    .query-row button { width: 100%; }

    #mainBox .h-16 { padding-left: 1rem; padding-right: 1rem; }
    #pageTitle { font-size: 1.25rem !important; }

    .flex-1.overflow-auto {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        padding-top: 1.25rem !important;
    }

    .device-item, .multi-item { max-width: 100%; }
    .edit-item { padding: 1.25rem; }
    .edit-item .grid-cols-2 { grid-template-columns: 1fr !important; }

    #loginBox .glass { padding: 1.75rem !important; }
    #loginBox h1 { font-size: 1.75rem !important; }

    .theme-toggle-float { top: 0.75rem; right: 0.75rem; }
}
