/* ============================================================
   theme.css - 主题系统（主题色 × 深浅模式）
   - 外壳（layout/sidebar）通过 <html data-theme="x" data-mode="dark"> 生效
   - iframe 业务页由 theme.js 注入 data 属性 + 变量覆盖层
   ============================================================ */

/* ---------- 主题色定义（默认红，未匹配时兜底） ---------- */

:root {
    --primary: #e50914;
    --primary-hover: #b81d24;
    --primary-rgb: 229, 9, 20;

    /* 深浅模式基础色（light 为默认） */
    --theme-bg: #f1f5f9;
    --theme-bg-grad-a: #f1f5f9;
    --theme-bg-grad-b: #f1f5f9;
    --theme-surface: #ffffff;
    --theme-surface-2: #f8fafc;
    --theme-line: #e2e8f0;
    --theme-line-soft: #f1f5f9;
    --theme-text: #1e293b;
    --theme-text-sub: #475569;
    --theme-text-faint: #94a3b8;
    --theme-logo-a: var(--primary);
    --theme-logo-b: var(--primary-hover);
}

/* ---------- 深色模式基础色 ---------- */
html[data-mode="dark"] {
    --theme-bg: #0f172a;
    --theme-bg-grad-a: #131c31;
    --theme-bg-grad-b: #0d1526;
    --theme-surface: #1e293b;
    --theme-surface-2: #243247;
    --theme-line: #334155;
    --theme-line-soft: #2a3a52;
    --theme-text: #e2e8f0;
    --theme-text-sub: #94a3b8;
    --theme-text-faint: #64748b;
}

/* ============================================================
   外壳（layout.php）深色适配 - 变量化关键面
   ============================================================ */
/* ---------- 标签页区域（从 layout.php 迁移，变量化） ---------- */
.sidebar {
    width: 180px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), left 0.3s;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    z-index: 100;
    flex-shrink: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}
.sidebar.collapsed { width: 72px; }
.tab-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--theme-bg);
    overflow: hidden;
}
.tab-bar {
    background: var(--theme-surface);
    border-bottom: 1px solid var(--theme-line);
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 8px;
    gap: 2px;
    min-height: 40px;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
html[data-mode="dark"] .tab-bar { scrollbar-color: #334155 transparent; }
.tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    height: 38px;
    background: var(--theme-surface-2);
    border: 1px solid var(--theme-line);
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    margin-top: 4px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 13px;
    color: var(--theme-text-sub);
    transition: all 0.2s;
    position: relative;
}
.tab.active {
    background: var(--theme-surface);
    border-bottom-color: var(--theme-surface);
    color: var(--primary);
    font-weight: 500;
}
.tab:hover { background: var(--theme-bg); }

html[data-mode="dark"] body { background: var(--theme-bg); color: var(--theme-text); }

html[data-mode="dark"] .top-bar {
    background: var(--theme-surface);
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
html[data-mode="dark"] .mobile-menu-btn { color: var(--theme-text-sub); }
html[data-mode="dark"] .mobile-menu-btn:active { background: var(--theme-surface-2); }
html[data-mode="dark"] .logo {
    background: linear-gradient(135deg, var(--theme-logo-a), var(--theme-logo-b));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
html[data-mode="dark"] .top-action { color: var(--theme-text-sub); }
html[data-mode="dark"] .top-action:hover { color: var(--primary); }
html[data-mode="dark"] .logout-btn { color: #f87171; }
html[data-mode="dark"] .logout-btn:hover { color: #ef4444; }
html[data-mode="dark"] .user-name { color: var(--theme-text); }
html[data-mode="dark"] .tenant-pill {
    background: rgba(var(--primary-rgb), 0.12);
    color: rgb(var(--primary-rgb));
    border-color: rgba(var(--primary-rgb), 0.35);
}

html[data-mode="dark"] .app-wrapper { }
html[data-mode="dark"] .tab-container { background: var(--theme-bg); }

/* 标签栏 */
html[data-mode="dark"] .tab-bar {
    background: var(--theme-surface);
    border-bottom-color: var(--theme-line);
}
html[data-mode="dark"] .tab {
    background: var(--theme-surface-2);
    border-color: var(--theme-line);
    color: var(--theme-text-sub);
}
html[data-mode="dark"] .tab.active {
    background: var(--theme-surface);
    color: var(--primary);
    border-bottom-color: var(--theme-surface);
}
html[data-mode="dark"] .tab:hover { background: #2c3c55; }
html[data-mode="dark"] .tab .close-tab:hover { background: rgba(239,68,68,0.18); color: #f87171; }
html[data-mode="dark"] .iframe-container { background: var(--theme-surface); }

/* 密码弹窗（重新设计版：深色适配） */
html[data-mode="dark"] .password-modal-overlay { background: rgba(2, 6, 23, 0.7); }
html[data-mode="dark"] .password-modal {
    background: var(--theme-surface);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.55);
}
html[data-mode="dark"] .password-modal h3 { color: var(--theme-text); }
html[data-mode="dark"] .password-modal .pw-sub { color: var(--theme-text-sub); }
html[data-mode="dark"] .password-modal .pw-icon { background: rgba(var(--primary-rgb), 0.18); color: var(--primary); }
html[data-mode="dark"] .pw-close { color: var(--theme-text-sub); }
html[data-mode="dark"] .pw-close:hover { background: rgba(255, 255, 255, 0.08); color: var(--theme-text); }
html[data-mode="dark"] .password-modal label { color: var(--theme-text); }
html[data-mode="dark"] .password-modal input[type="password"],
html[data-mode="dark"] .password-modal input[type="text"] {
    background: var(--theme-surface-2); color: var(--theme-text); border-color: var(--theme-line);
}
html[data-mode="dark"] .password-modal input::placeholder { color: var(--theme-text-sub); opacity: .7; }
html[data-mode="dark"] .password-modal input:hover { border-color: var(--theme-text-sub); }
html[data-mode="dark"] .password-modal input:focus {
    border-color: var(--primary);
    background: var(--theme-surface-2);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18);
}
html[data-mode="dark"] .pw-field.has-error input { border-color: #f87171; background: rgba(239, 68, 68, 0.08); }
html[data-mode="dark"] .pw-eye { color: var(--theme-text-sub); }
html[data-mode="dark"] .pw-eye:hover { color: var(--theme-text); background: rgba(255, 255, 255, 0.08); }
html[data-mode="dark"] .pw-bars i { background: rgba(255, 255, 255, 0.14); }
html[data-mode="dark"] .pw-strength-label { color: var(--theme-text-sub); }
html[data-mode="dark"] .pw-rules li { color: var(--theme-text-sub); }
html[data-mode="dark"] .pw-rules li.ok { color: #34d399; }
html[data-mode="dark"] .pw-rules li.ok .pw-rule-ico { color: #34d399; }
html[data-mode="dark"] .pw-err { color: #f87171; }
html[data-mode="dark"] .pw-match.ok { color: #34d399; }
html[data-mode="dark"] .pw-match.bad { color: #f87171; }
html[data-mode="dark"] .password-modal .message.success {
    background: rgba(16, 185, 129, 0.12); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.3);
}
html[data-mode="dark"] .password-modal .message.error {
    background: rgba(239, 68, 68, 0.12); color: #fca5a5; border-color: rgba(239, 68, 68, 0.3);
}
html[data-mode="dark"] .password-modal .btn-secondary {
    background: var(--theme-surface-2); color: var(--theme-text-sub);
}
html[data-mode="dark"] .password-modal .btn-secondary:hover { background: rgba(255, 255, 255, 0.08); }
html[data-mode="dark"] .password-modal .btn-primary {
    box-shadow: 0 12px 24px rgba(var(--primary-rgb), 0.3);
}

/* ============================================================
   侧边栏（sidebar.php）- 主题色 + 深色
   ============================================================ */
.sidebar {
    background: #ffffff !important;
    color: var(--theme-text) !important;
    border-right-color: var(--theme-line) !important;
}
html[data-mode="dark"] .sidebar { box-shadow: 4px 0 12px rgba(0,0,0,0.25); }
.sidebar-toggle {
    background: var(--theme-surface);
    border-color: var(--theme-line);
    color: var(--theme-text-faint);
}
.sidebar-toggle:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.nav-group-title { color: var(--theme-text-faint); }
.nav-group-title i { color: var(--theme-line); }
html[data-mode="dark"] .nav-group-title i { color: #475569; }
.nav-item { color: var(--theme-text-sub); }
.nav-item:hover {
    background: rgba(var(--primary-rgb), 0.08);
    color: var(--primary);
}
.nav-item.active {
    background: rgba(var(--primary-rgb), .1);
    color: var(--primary);
}
.menu-popup {
    background: var(--theme-surface);
    border-color: var(--theme-line);
}
html[data-mode="dark"] .menu-popup { box-shadow: 0 20px 35px -12px rgba(0,0,0,0.55); }
.popup-group-title {
    color: var(--theme-text-faint);
    border-bottom-color: var(--theme-line);
}
.menu-popup .popup-item {
    color: var(--theme-text-sub);
    border-right-color: var(--theme-line);
}
.menu-popup .popup-item:hover {
    background: rgba(var(--primary-rgb), 0.07);
    color: var(--primary);
}
.mobile-close-btn {
    background: var(--theme-surface);
    border-color: var(--theme-line);
    color: var(--theme-text-sub);
}

/* ============================================================
   主题切换面板
   ============================================================ */
.theme-pop {
    position: absolute;
    top: 50px; right: 12px;
    background: var(--theme-surface);
    border: 1px solid var(--theme-line);
    border-radius: 16px;
    box-shadow: 0 20px 45px rgba(15,23,42,0.22);
    padding: 16px 18px 14px;
    z-index: 1200;
    width: 264px;
    display: none;
    font-size: 13px;
}
.theme-pop.open { display: block; }
html[data-mode="dark"] .theme-pop { box-shadow: 0 20px 45px rgba(0,0,0,0.55); }
.tp-title {
    font-size: 12px; font-weight: 700; color: var(--theme-text-faint);
    text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px;
}
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.swatch {
    width: 100%; aspect-ratio: 1; border-radius: 12px; border: none; cursor: pointer;
    position: relative; transition: transform .15s;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 14px;
}
.swatch:hover { transform: scale(1.08); }
.swatch.sel::after {
    content: '\f00c'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.28); border-radius: 12px; font-size: 13px;
}
.mode-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-btn {
    padding: 9px 10px; border-radius: 10px; border: 1px solid var(--theme-line);
    background: var(--theme-surface-2); color: var(--theme-text-sub);
    font-size: 12px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: all .15s;
}
.mode-btn:hover { border-color: var(--primary); color: var(--primary); }
.mode-btn.sel {
    background: rgba(var(--primary-rgb), 0.1);
    border-color: rgba(var(--primary-rgb), 0.4);
    color: var(--primary);
}
.tp-tip {
    margin-top: 12px; font-size: 11px; color: var(--theme-text-faint); line-height: 1.5;
    border-top: 1px solid var(--theme-line-soft); padding-top: 10px;
}

/* 顶栏主题按钮 */
.theme-btn {
    background: none; border: none; cursor: pointer;
    color: #475569; font-size: 14px;
    display: flex; align-items: center; gap: 6px;
    padding: 6px 10px; border-radius: 8px;
    transition: color .2s; white-space: nowrap;
    font-family: inherit;
}
.theme-btn:hover { color: var(--primary); }
html[data-mode="dark"] .theme-btn { color: var(--theme-text-sub); }

/* 顶栏文字窄屏隐藏（外壳级，此前只在 product.css 有） */
@media (max-width: 768px) {
    .top-bar .hide-mobile { display: none !important; }
    .theme-btn { padding: 6px; }
}

@media (max-width: 768px) {
    .theme-pop { top: 54px; right: 8px; width: calc(100vw - 32px); max-width: 264px; }
}

/* ---------- 统一外壳视觉 ---------- */
body {
    color: var(--theme-text);
    background: var(--theme-bg);
    -webkit-font-smoothing: antialiased;
}
.top-bar,
html[data-mode="dark"] .top-bar {
    background: #0f172a !important;
    color: #ffffff;
    border-bottom: 0;
    box-shadow: none;
}
.logo {
    background: none !important;
    -webkit-text-fill-color: #ffffff !important;
    color: #ffffff !important;
    font-weight: 700;
}
.top-bar .mobile-menu-btn,
.top-bar .user-name,
.top-bar .top-action,
.top-bar .theme-btn { color: #cbd5e1; }
.top-bar .top-action:hover,
.top-bar .theme-btn:hover { background: #1e293b; color: #ffffff; }
.top-bar .logout-btn { color: #f87171; }
.top-bar .tenant-pill {
    background: #1e293b;
    color: #e2e8f0;
    border-color: #334155;
}
.top-bar .tenant-pill.expiring {
    background: rgba(229, 9, 20, .14);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, .35);
}
.top-bar .fa,
.top-bar .fas,
.top-bar .far,
.top-bar .fab,
.sidebar .fa,
.sidebar .fas,
.sidebar .far,
.sidebar .fab {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: auto;
}
.top-bar .top-action > i,
.top-bar .theme-btn > i,
.top-bar .logout-btn > i {
    width: 1.15em;
    flex: 0 0 1.15em;
    text-align: center;
    line-height: 1;
}
.sidebar .nav-item > i {
    flex: 0 0 20px;
    line-height: 1;
}
.top-bar {
    border-bottom: 1px solid var(--theme-line);
    box-shadow: 0 2px 8px rgba(24, 35, 28, 0.035);
}
.top-bar,
html[data-mode="dark"] .top-bar {
    background: #0f172a !important;
    color: #ffffff;
    border-bottom: 0;
    box-shadow: none;
}
.logo {
    background: none !important;
    -webkit-text-fill-color: #ffffff !important;
    color: #ffffff !important;
    font-weight: 700;
}
.top-bar .mobile-menu-btn,
.top-bar .user-name,
.top-bar .top-action,
.top-bar .theme-btn { color: #cbd5e1; }
.top-bar .top-action:hover,
.top-bar .theme-btn:hover { background: #1e293b; color: #ffffff; }
.top-bar .logout-btn { color: #f87171; }
.top-bar .tenant-pill {
    background: #1e293b;
    color: #e2e8f0;
    border-color: #334155;
}
.top-bar .tenant-pill.expiring {
    background: rgba(229, 9, 20, .14);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, .35);
}
.logo { font-size: 19px; }
.sidebar {
    background: var(--theme-surface) !important;
    border-right-color: var(--theme-line) !important;
    box-shadow: none !important;
}
.nav-group { margin-bottom: 5px; }
.nav-item {
    border-radius: 8px;
    margin: 3px 9px;
    padding-top: 9px;
    padding-bottom: 9px;
}
.nav-item.active {
    background: #fef2f2;
    color: var(--primary);
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 3px;
    border-radius: 3px;
    background: var(--primary);
}
.sidebar.collapsed .nav-item.active::before { left: 5px; }
.tab-bar {
    background: var(--theme-bg);
    padding: 5px 10px 0;
    gap: 5px;
    border-bottom-color: var(--theme-line);
}
.tab {
    height: 34px;
    margin-top: 0;
    border-radius: 7px 7px 0 0;
    background: transparent;
    border-color: transparent;
}
.tab.active {
    background: var(--theme-surface);
    border-color: var(--theme-line);
    border-bottom-color: var(--theme-surface);
    color: var(--primary);
}
.tab .close-tab { color: var(--theme-text-faint); }
.tab .close-tab:hover { background: rgba(var(--primary-rgb), .1); color: var(--primary); }
.theme-pop { border-radius: 12px; }
.theme-btn, .top-action, .logout-btn {
    min-height: 34px;
    padding: 0 9px;
    border-radius: 7px;
    transition: color .16s ease, background .16s ease;
}
.theme-btn:hover, .top-action:hover { background: var(--theme-surface-2); }
.logout-btn:hover { background: #fff1f0; }
.top-bar { gap: 12px; }
.user-info { gap: 6px; }
.user-name { padding: 0 8px; color: var(--theme-text-sub); }
.theme-btn { color: var(--theme-text-sub); }
.tenant-pill { border-radius: 7px; padding: 5px 9px; }
.sidebar-toggle { border-radius: 7px; }
.menu-popup { border-radius: 10px; box-shadow: 0 12px 30px rgba(20, 32, 25, .12); }

html[data-mode="dark"] .tab-bar { background: var(--theme-bg); }
html[data-mode="dark"] .tab { background: transparent; }
html[data-mode="dark"] .tab.active { background: var(--theme-surface); }
html[data-mode="dark"] .sidebar { background: var(--theme-surface) !important; }
html[data-mode="dark"] .nav-item.active { background: rgba(var(--primary-rgb), .16); color: var(--primary); }

/* ============================================================
   账号管理下拉（顶栏统一入口：切换账套 / 平台后台 / 主题 / 密码 / 退出）
   触发改为「首字头像」：--primary 实底 + 白字，8 主题自动跟随、浅深同值不反相。
   按钮本身透明，44×44 只是触摸热区，不撑大视觉；hover/open 只换描边，禁止位移。
   ============================================================ */
.account-wrap { position: relative; }
.account-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-width: 44px; min-height: 44px;              /* ≥44×44 触摸热区（盒透明，视觉不变） */
    padding: 0; border: 0; background: transparent;
    color: var(--text-on-dark, #F8FAFC);
    font-family: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; white-space: nowrap;
    transition: color .16s ease;
}
/* 首字头像 32×32 圆；顶栏 #0F172A 深底用 2px 白描边做分离，白字 ≥4.5:1 */
.account-btn .account-avatar {
    flex: 0 0 32px; width: 32px; height: 32px;
    border-radius: var(--r-full, 999px);
    background: var(--primary); color: #FFFFFF;
    font-size: 13px; font-weight: 700; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 0 0 2px rgba(255,255,255,.18);
    transition: box-shadow .16s ease;
    user-select: none;
}
/* hover / open：只提亮描边，不改底色、不做 transform 位移 */
.account-btn:hover .account-avatar,
.account-wrap.open .account-btn .account-avatar {
    box-shadow: 0 0 0 2px rgba(255,255,255,.42);
}
/* 顶栏深底：3px 白环 + offset 2px，与 tokens.css §3.1 的 .top-bar 覆盖一致 */
.account-btn:focus-visible {
    outline: 3px solid rgba(255,255,255,.88);
    outline-offset: 2px;
}
.acc-caret { font-size: 10px; opacity: .65; color: var(--text-on-dark, #F8FAFC); transition: transform .2s; }
.account-wrap.open .acc-caret { transform: rotate(180deg); }

.account-pop {
    position: absolute; top: calc(100% + 10px); right: 0;
    width: 306px; max-width: calc(100vw - 24px);
    max-height: calc(100vh - 72px); overflow-y: auto;
    background: var(--theme-surface);
    border: 1px solid var(--theme-line); border-radius: 14px;
    box-shadow: 0 20px 45px rgba(15,23,42,.20);
    z-index: 1200; display: none;
    font-size: 13px; color: var(--theme-text);
}
.account-pop.open { display: block; animation: accPopIn .16s ease-out; }
@keyframes accPopIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
html[data-mode="dark"] .account-pop { box-shadow: 0 20px 50px rgba(0,0,0,.6); }

.acc-head { display: flex; align-items: center; gap: 11px; padding: 14px 16px; border-bottom: 1px solid var(--theme-line-soft); }
/* 下拉头部同款首字头像：圆形、--primary 实底、白字 13px/700，点开前后一致 */
.acc-avatar { flex: 0 0 38px; width: 38px; height: 38px; border-radius: var(--r-full, 999px); display: flex; align-items: center; justify-content: center; font-family: inherit; font-size: 13px; font-weight: 700; line-height: 1; color: #FFFFFF; background: var(--primary); user-select: none; }
.acc-meta { min-width: 0; }
.acc-name { font-size: 14px; font-weight: 700; color: var(--theme-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-role { margin-top: 3px; font-size: 11px; color: var(--theme-text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-tenant { margin-top: 3px; font-size: 11px; color: var(--theme-text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-tenant i { margin-right: 3px; }

.acc-section { padding: 8px; }
.acc-section + .acc-theme, .acc-theme + .acc-section { border-top: 1px solid var(--theme-line-soft); }
.acc-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 9px;
    color: var(--theme-text-sub); text-decoration: none; font-size: 13px;
    transition: background .15s, color .15s;
}
.acc-item:hover { background: var(--theme-surface-2); color: var(--primary); }
.acc-item > i:first-child { width: 18px; text-align: center; color: var(--theme-text-faint); }
.acc-item:hover > i:first-child { color: var(--primary); }
.acc-arrow { margin-left: auto; font-size: 10px; opacity: .45; }
.acc-item.danger { color: #dc2626; }
.acc-item.danger > i:first-child { color: #dc2626; }
.acc-item.danger:hover { background: rgba(220,38,38,.09); color: #dc2626; }

.acc-theme { padding: 12px 14px 14px; }
.acc-label { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; color: var(--theme-text-faint); margin-bottom: 10px; }
.acc-label i { color: var(--primary); }
.acc-theme .tp-title { font-size: 11px; margin: 10px 0 7px; }
.acc-theme .tp-title:first-child { margin-top: 0; }
.acc-theme .swatches { gap: 8px; margin-bottom: 4px; }
.acc-theme .swatch { border-radius: 10px; }
.acc-theme .mode-btn { padding: 7px 8px; }
.acc-theme .tp-tip { display: none; }

@media (max-width: 768px) {
    .account-pop { position: fixed; top: 60px; right: 8px; width: calc(100vw - 16px); max-width: 320px; }
    .account-btn { padding: 0; min-width: 44px; min-height: 44px; }
    /* 窄屏头像不得缩到 28px 以下；用户名由 .hide-mobile 隐藏，顶栏只留头像钮 */
    .account-btn .account-avatar { flex: 0 0 32px; width: 32px; height: 32px; min-width: 32px; }
}
