/* =========================================================================
   TG File Monitor · UI Readability（可读性与一致性补丁层）
   -------------------------------------------------------------------------
   引入顺序： ... → ui-aurora → ui-readability（本层，最后加载，优先级最高）

   背景：base.html 内联样式仍残留「蓝色玻璃拟态」（#2563eb / #38bdf8 /
   钢蓝渐变），与外部紫色设计令牌（#8b5cf6）冲突；moviepilot-theme 的
   --mp-muted 对比度偏弱；多处使用非标准字重 550/650/750/850。

   本层只做「配色统一 + 对比度增强 + 字体层级收敛 + 间距对齐」，
   不改变任何布局尺寸、定位逻辑与 DOM 结构，零功能影响、零结构风险。
   ========================================================================= */

/* =========================================================================
   1 · 配色统一：清掉内联残留的蓝色，统一到紫色令牌
   ========================================================================= */

/* 1.1 body 背景：内联钢蓝渐变 → 紫色极光底（仅浅色模式；深色模式交还 ui-aurora 的深空底） */
:root:not([data-theme="dark"]) body {
    background:
        radial-gradient(38% 44% at 26% 0%, rgba(139, 92, 246, 0.14), transparent 68%),
        radial-gradient(42% 48% at 72% 0%, rgba(99, 102, 241, 0.10), transparent 68%),
        linear-gradient(180deg, #f4f2fb 0%, #eceaf6 100%) !important;
}

body {
    color: var(--ui-ink, #2b2933);
}

/* 1.2 蓝色 accent 残留 → 紫色令牌 */
:root {
    --accent-color: var(--ui-primary, #8b5cf6);
    --accent-color-strong: var(--ui-primary-strong, #7c3aed);
    --accent-color-soft: var(--ui-primary-soft, rgba(139, 92, 246, 0.10));
    --icon-color: var(--ui-primary, #8b5cf6);
    --icon-color-strong: var(--ui-primary-strong, #7c3aed);
}

/* 1.3 文本主色统一 */
.text-primary {
    color: var(--ui-primary, #7c3aed) !important;
}

/* 1.4 代码块 / 行内代码：内联的蓝青 → 紫色令牌 */
code {
    background: var(--ui-primary-softer, rgba(139, 92, 246, 0.055)) !important;
    color: var(--ui-primary-deep, #6d28d9) !important;
    border: 1px solid var(--ui-primary-line, rgba(139, 92, 246, 0.26)) !important;
}

pre {
    background: var(--ui-surface-sunken, #f1f2f7) !important;
    color: var(--ui-ink, #2b2933) !important;
    border: 1px solid var(--ui-border, rgba(26, 22, 48, 0.075)) !important;
}

/* 1.5 表格：内联蓝色调 → 紫色发丝线 */
.table > :not(caption) > * > * {
    border-bottom-color: var(--ui-border-hairline, rgba(26, 22, 48, 0.055)) !important;
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: var(--ui-surface-soft, #f8f9fc) !important;
}

/* =========================================================================
   2 · 对比度增强：提升弱灰 / 弱紫文字到 WCAG AA
   ========================================================================= */

/* 2.1 次要文字统一加深（原 --mp-muted #5f5b67 仅 ~4.3:1） */
.text-muted,
.text-secondary,
.form-text,
small,
.small,
.text-muted[class],
.form-label small {
    color: var(--ui-ink-soft, #57545f) !important;
}

/* 2.2 aurora 层过灰的导航项 → 加深 */
.nav-tabs .nav-link,
.nav-pills .nav-link {
    color: var(--ui-ink-soft, #57545f) !important;
}

/* 2.3 表格表头文字：aurora 的 #5b3bb8 偏灰紫 → 加深为高对比紫 */
.table > thead > tr > th {
    color: var(--ui-primary-deep, #5b21b6) !important;
}

/* 2.4 占位符略加深（仍保持可辨识的弱化） */
.form-control::placeholder,
textarea.form-control::placeholder {
    color: var(--ui-placeholder, rgba(122, 119, 135, 0.72)) !important;
}

/* =========================================================================
   3 · 字体层级收敛：非标准字重 → 标准字重，层次更清晰
   ========================================================================= */

/* 550 → 600、650 → 600、750 → 700、850 → 800，避免回退不一致 */
body {
    font-weight: 400;
}

.sidebar .nav-link,
html.home-page-shell .sidebar .nav-link {
    font-weight: 600 !important;
}

.sidebar .nav-link.active {
    font-weight: 700 !important;
}

.log-toolbar-chip,
.log-toolbar-chip strong,
.form-check-label {
    font-weight: 600 !important;
}

.log-toolbar-chip strong {
    font-weight: 700 !important;
}

/* 标题字重收敛为稳定阶梯：h1 800 / h2 700 / h3-h6 600 */
h1 { font-weight: 800 !important; }
h2 { font-weight: 700 !important; }
h3, h4, h5, h6 { font-weight: 600 !important; }

/* =========================================================================
   4 · 间距与对齐：统一卡片/表单节奏，减少视觉噪点
   ========================================================================= */

/* 4.1 卡片标题与正文的呼吸感 */
.card-header {
    padding-top: 0.9rem !important;
    padding-bottom: 0.9rem !important;
}

.card-body {
    line-height: 1.6;
}

/* 4.2 表单标签与输入框间距统一 */
.form-label {
    margin-bottom: 0.4rem !important;
}

.form-control,
.form-select {
    min-height: 2.5rem;
}

/* 4.3 列表项与折叠面板内边距对齐 */
.accordion-button {
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
}

.list-group-item {
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
}

/* =========================================================================
   5 · 组件交互状态增强（hover / focus / active 一致性）
   ========================================================================= */

/* 5.1 所有按钮统一禁用态，避免半透明导致误读 */
.btn:disabled,
.btn.disabled {
    opacity: 0.55 !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    transform: none !important;
}

/* 5.2 链接明确的下划线 affordance（hover 时） */
a:not(.btn):not(.nav-link):not(.dropdown-item):hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* 5.3 焦点环统一：键盘导航清晰可见 */
:focus-visible {
    outline: 2px solid var(--ui-primary, #8b5cf6) !important;
    outline-offset: 2px !important;
}

/* 5.4 表格行 hover 反馈更明显 */
.table > tbody > tr:hover > * {
    background: var(--ui-primary-softer, rgba(139, 92, 246, 0.055)) !important;
}

/* =========================================================================
   6 · 响应式：小屏间距与触控目标优化
   ========================================================================= */

@media (max-width: 767.98px) {
    .main-content {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    /* 移动端触控目标 ≥ 44px */
    .btn,
    .nav-tabs .nav-link,
    .nav-pills .nav-link,
    .dropdown-item {
        min-height: 2.5rem;
    }

    /* 移动端按钮不下沉过狠，保持可点 */
    .btn:active {
        transform: scale(0.97) !important;
    }
}

@media (max-width: 575.98px) {
    .card-header {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

/* =========================================================================
   7 · 公共页（public_base / auth_base）蓝色残留统一
   ========================================================================= */

/* 7.1 公共页蓝色主题 → 紫色令牌（原 #0ea5e9 / #0284c7 / #5f7892） */
.public-shell,
.auth-shell {
    --accent-color: var(--ui-primary, #8b5cf6);
    --accent-color-strong: var(--ui-primary-strong, #7c3aed);
}

.public-topbar-kicker,
.auth-topbar-kicker {
    color: var(--ui-primary-strong, #7c3aed) !important;
}

.public-topbar-title,
.auth-topbar-title {
    color: var(--ui-ink, #2b2933) !important;
}

.public-topbar-desc,
.auth-topbar-desc {
    color: var(--ui-ink-soft, #57545f) !important;
}

.public-shell .btn-outline-primary,
.auth-shell .btn-outline-primary {
    color: var(--ui-primary-strong, #7c3aed) !important;
    border-color: var(--ui-primary-line, rgba(139, 92, 246, 0.26)) !important;
}

.public-shell .btn-outline-primary:hover,
.auth-shell .btn-outline-primary:hover {
    color: #fff !important;
    background: var(--ui-primary, #8b5cf6) !important;
    border-color: var(--ui-primary, #8b5cf6) !important;
}

/* 7.2 公共页卡片/表单 focus 蓝色 → 紫色 */
.public-shell .form-control:focus,
.public-shell .form-select:focus,
.auth-shell .form-control:focus,
.auth-shell .form-select:focus {
    border-color: var(--ui-primary, #8b5cf6) !important;
    box-shadow: 0 0 0 0.16rem var(--ui-primary-ring, rgba(139, 92, 246, 0.18)) !important;
}

/* 7.3 认证页 / 公共页 body 钢蓝渐变 → 紫色极光底（仅浅色模式） */
:root:not([data-theme="dark"]) body:has(.auth-shell),
:root:not([data-theme="dark"]) body:has(.public-shell) {
    background:
        radial-gradient(38% 44% at 26% 0%, rgba(139, 92, 246, 0.16), transparent 68%),
        radial-gradient(42% 48% at 72% 0%, rgba(99, 102, 241, 0.12), transparent 68%),
        linear-gradient(135deg, #f4f2fb 0%, #eceaf6 100%) !important;
}

/* =========================================================================
   8 · 动效偏好：减弱时关闭补丁层引入的动效（虽本层几乎无动画）
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
    .table > tbody > tr,
    .btn {
        transition: none !important;
    }
}

/* =========================================================================
   8b · 深色模式字体清晰度（2026-10-29 主人反馈：深色下字发虚）
   -------------------------------------------------------------------------
   浅色文字在深底上用灰阶抗锯齿（antialiased/grayscale）会偏细发虚，
   深色模式回退到子像素抗锯齿（auto），字形更饱满清晰。
   ========================================================================= */
:root[data-theme="dark"] html,
:root[data-theme="dark"] body {
    -webkit-font-smoothing: auto !important;
    -moz-osx-font-smoothing: auto !important;
}

/* =========================================================================
   9 · 日志可读性：结构化日志行（时间 / 等级徽章 / 模块 / 消息分层）
   ========================================================================= */
.log-console pre {
    font-size: 0.78rem !important;
    line-height: 1.6 !important;
    padding: 0.5rem 0.6rem;
}

.log-line {
    display: block;
    padding: 1px 6px;
    margin: 0 -2px;
    border-radius: 6px;
    border-left: 2px solid transparent;
}

.log-line:hover {
    background: rgba(100, 116, 139, 0.10);
}

/* 行级状态：错误/警告淡底 + 左侧色条，一眼分层 */
.log-line-error {
    background: rgba(220, 38, 38, 0.08);
    border-left-color: #dc2626;
}

.log-line-warning {
    background: rgba(217, 119, 6, 0.08);
    border-left-color: #d97706;
}

.log-line-success {
    border-left-color: rgba(22, 163, 74, 0.55);
}

/* 时间戳：淡化收窄，只保留时分秒 */
.log-ts {
    color: var(--ui-muted, #64748b);
    font-size: 0.7rem;
    margin-right: 6px;
    user-select: none;
}

/* 等级徽章：深底白字，亮暗主题通吃 */
.log-lv {
    display: inline-block;
    min-width: 40px;
    padding: 0 5px;
    margin-right: 6px;
    border-radius: 4px;
    text-align: center;
    font-size: 0.66rem;
    font-weight: 800;
    line-height: 1.5;
    letter-spacing: 0.03em;
    color: #fff;
    background: #64748b;
    user-select: none;
}

.log-lv-info { background: #2563eb; }
.log-lv-success { background: #16a34a; }
.log-lv-warning { background: #d97706; }
.log-lv-error { background: #dc2626; }
.log-lv-debug { background: #64748b; }

/* 模块标签：紫色淡底 */
.log-mod {
    display: inline-block;
    padding: 0 5px;
    margin-right: 6px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--ui-primary-deep, #6d28d9);
    background: var(--ui-primary-softer, rgba(139, 92, 246, 0.10));
    user-select: none;
}

:root[data-theme="dark"] .log-mod {
    color: #c4b5fd;
    background: rgba(139, 92, 246, 0.18);
}

/* 消息体按等级着色 */
.log-msg-error { color: #dc2626; font-weight: 600; }
.log-msg-warning { color: #d97706; font-weight: 600; }
.log-msg-success { color: #16a34a; font-weight: 600; }
.log-msg-info { color: inherit; }
.log-msg-debug { color: var(--ui-muted, #64748b); }

:root[data-theme="dark"] .log-msg-error { color: #f87171; }
:root[data-theme="dark"] .log-msg-warning { color: #fbbf24; }
:root[data-theme="dark"] .log-msg-success { color: #4ade80; }

/* URL 高亮 */
.log-url {
    color: #d97706;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

:root[data-theme="dark"] .log-url { color: #fbbf24; }
