/* ==========================================================================
   ChingTech OS - Main CSS (Design System)
   ========================================================================== */

/* ==========================================================================
   Web Fonts - Nerd Font for terminal icons
   ========================================================================== */
@font-face {
  font-family: 'JetBrainsMono NF';
  src: url('../fonts/JetBrainsMonoNerdFont-Regular.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   CSS Variables (Design Tokens)
   ========================================================================== */
:root {
  /* Primary Colors - 統一使用較深色調，白字清晰 */
  --color-primary: #0891b2;           /* ChingTech Cyan - 主要按鈕/品牌色 */
  --color-background: #1a1a1a;        /* 純黑灰背景（無彩度） */
  --color-accent: #ea580c;            /* Orange - 強調/特殊元素 */

  /* Neutral Colors（無彩度灰階） */
  --color-gray-light: #f0f0f0;
  --color-gray-mid: #909090;
  --color-gray-dark: #404040;

  /* Status Colors - 統一使用較深色調 */
  --color-success: #16a34a;           /* Action Green */
  --color-warning: #d97706;           /* Warning Amber */
  --color-error: #dc2626;             /* Error Red */

  /* Text Colors（無彩度） */
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-muted: #888888;

  /* Surface & Border Colors */
  --bg-surface: rgba(0, 0, 0, 0.1);
  --bg-surface-dark: rgba(0, 0, 0, 0.2);
  --bg-surface-darker: rgba(0, 0, 0, 0.3);
  --bg-overlay: rgba(0, 0, 0, 0.7);
  --bg-overlay-dark: rgba(0, 0, 0, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-light: rgba(255, 255, 255, 0.1);
  --border-medium: rgba(255, 255, 255, 0.15);
  --border-strong: rgba(255, 255, 255, 0.2);
  --hover-bg: rgba(255, 255, 255, 0.1);

  /* Accent Variants (for hover/active states) */
  --accent-bg-subtle: rgba(8, 145, 178, 0.1);
  --accent-bg-light: rgba(8, 145, 178, 0.15);
  --accent-bg-medium: rgba(8, 145, 178, 0.2);
  --accent-border: rgba(8, 145, 178, 0.3);

  /* RGB Format (for rgba() calculations) */
  --color-primary-rgb: 8, 145, 178;
  --color-background-rgb: 26, 26, 26;
  --color-accent-rgb: 234, 88, 12;
  --color-success-rgb: 22, 163, 74;
  --color-warning-rgb: 217, 119, 6;
  --color-error-rgb: 220, 38, 38;
  --text-muted-rgb: 136, 136, 136;

  /* 半透明背景色（用於 header、taskbar 等）- 無彩度 */
  --bg-glass: rgba(26, 26, 26, 0.95);
  --bg-glass-light: rgba(26, 26, 26, 0.85);
  --bg-glass-heavy: rgba(26, 26, 26, 0.98);
  /* 視窗不透明背景（比桌面稍亮） */
  --window-bg: #252525;
  --window-titlebar-bg: #1e1e1e;
  --bg-tooltip: rgba(0, 0, 0, 0.9);
  --tooltip-text: #e8e8e8;

  /* 面板/編輯器實心背景色 */
  --bg-primary: #1a1a1a;
  --bg-secondary: #222222;
  --bg-tertiary: #2a2a2a;
  --bg-input: #1e1e1e;

  /* 互動效果（暗色主題用白色半透明） */
  --interactive-hover: rgba(255, 255, 255, 0.08);
  --interactive-active: rgba(255, 255, 255, 0.12);
  --interactive-border: rgba(255, 255, 255, 0.08);
  --scrollbar-hover: rgba(255, 255, 255, 0.35);
  --text-muted-semi: rgba(255, 255, 255, 0.5);
  --text-shadow-contrast: 0 1px 2px rgba(0, 0, 0, 0.8);

  /* Button Hover Colors - 稍亮 */
  --color-primary-hover: #0ea5c9;    /* Cyan hover - 稍亮 */
  --color-accent-hover: #f97316;     /* Orange hover - 稍亮 */

  /* Button Text Colors - 按鈕文字顏色 */
  --btn-text-on-primary: #ffffff;    /* 主要按鈕文字 */
  --btn-text-on-accent: #ffffff;     /* 強調按鈕文字 */
  --btn-text-on-ghost: var(--text-primary);  /* Ghost 按鈕文字 */

  /* Tag Colors (語義化標籤顏色) */
  --tag-color-purple: #818cf8;
  --tag-color-green: #34d399;
  --tag-color-yellow: #fbbf24;
  --tag-color-pink: #f472b6;
  --tag-color-blue: #3b82f6;
  --tag-color-gray: #707070;
  --tag-color-red: #ef4444;
  --tag-color-orange: #f59e0b;
  --tag-color-cyan: #22d3ee;

  /* Tag Background Colors (帶透明度) */
  --tag-bg-purple: rgba(129, 140, 248, 0.2);
  --tag-bg-green: rgba(52, 211, 153, 0.2);
  --tag-bg-yellow: rgba(251, 191, 36, 0.2);
  --tag-bg-pink: rgba(244, 114, 182, 0.2);
  --tag-bg-blue: rgba(59, 130, 246, 0.2);
  --tag-bg-gray: rgba(112, 112, 112, 0.2);
  --tag-bg-red: rgba(239, 68, 68, 0.2);
  --tag-bg-orange: rgba(245, 158, 11, 0.2);

  /* Status Tag Colors (狀態標籤) */
  --status-completed-color: var(--color-success);
  --status-completed-bg: rgba(76, 197, 119, 0.15);
  --status-in-progress-color: var(--tag-color-blue);
  --status-in-progress-bg: rgba(59, 130, 246, 0.15);
  --status-pending-color: var(--tag-color-yellow);
  --status-pending-bg: rgba(251, 191, 36, 0.15);
  --status-cancelled-color: var(--tag-color-gray);
  --status-cancelled-bg: rgba(112, 112, 112, 0.15);

  /* Priority Tag Colors (優先級標籤) */
  --priority-critical-color: #dc2626;
  --priority-critical-bg: rgba(220, 38, 38, 0.3);
  --priority-urgent-color: var(--color-error);
  --priority-urgent-bg: rgba(239, 68, 68, 0.2);
  --priority-high-color: var(--tag-color-orange);
  --priority-high-bg: rgba(245, 158, 11, 0.2);
  --priority-normal-color: var(--tag-color-blue);
  --priority-normal-bg: rgba(59, 130, 246, 0.2);
  --priority-low-color: var(--tag-color-gray);
  --priority-low-bg: rgba(128, 128, 128, 0.2);

  /* Modal Colors (模態框) - 無彩度 */
  --modal-bg: #1e1e1e;
  --modal-bg-alt: #1a1a1a;
  --modal-border: var(--border-light);

  /* Terminal Theme Colors (終端機主題) */
  --terminal-bg: #1a1a1a;
  --terminal-fg: #e0e0e0;
  --terminal-cursor: #ffffff;
  --terminal-cursor-accent: #1a1a1a;
  --terminal-selection: rgba(255, 255, 255, 0.3);
  --terminal-black: #000000;
  --terminal-red: #ff5555;
  --terminal-green: #50fa7b;
  --terminal-yellow: #f1fa8c;
  --terminal-blue: #6272a4;
  --terminal-magenta: #ff79c6;
  --terminal-cyan: #8be9fd;
  --terminal-white: #f8f8f8;
  --terminal-bright-black: #6272a4;
  --terminal-bright-red: #ff6e6e;
  --terminal-bright-green: #69ff94;
  --terminal-bright-yellow: #ffffa5;
  --terminal-bright-blue: #d6acff;
  --terminal-bright-magenta: #ff92df;
  --terminal-bright-cyan: #a4ffff;
  --terminal-bright-white: #ffffff;

  /* Terminal Status Indicators */
  --terminal-status-connected: #4caf50;
  --terminal-status-disconnected: #f44336;
  --terminal-status-idle: #666666;

  /* Code Editor */
  --code-editor-bg: #1e1e1e;

  /* Notification Badge */
  --badge-color: #ef4444;

  /* Markdown 渲染相關 (暗色主題) */
  --md-heading-color: #e2e8f0;
  --md-text-color: #cbd5e1;
  --md-link-color: #60a5fa;
  --md-code-bg: rgba(139, 92, 246, 0.15);
  --md-code-color: #c4b5fd;
  --md-pre-bg: #1e293b;
  --md-pre-border: #334155;
  --md-blockquote-border: #60a5fa;
  --md-blockquote-bg: rgba(96, 165, 250, 0.1);
  --md-table-border: #334155;
  --md-table-header-bg: #1e293b;
  --md-hr-color: #334155;

  /* 格式化資料語法色彩 (暗色主題) */
  --fd-string-color: #a5d6a7;
  --fd-number-color: #90caf9;
  --fd-boolean-color: #ce93d8;
  --fd-null-color: #ef9a9a;
  --fd-key-color: #81d4fa;
  --fd-punctuation-color: #9e9e9e;
  --fd-tag-color: #ef5350;
  --fd-attribute-color: #ffb74d;
  --fd-comment-color: #757575;

  /* Font Families */
  --font-primary: -apple-system, BlinkMacSystemFont, 'Ubuntu', 'Segoe UI', 'Microsoft JhengHei', 'Noto Sans CJK TC', sans-serif;
  --font-technical: -apple-system, BlinkMacSystemFont, 'Ubuntu', 'Segoe UI', 'Microsoft JhengHei', 'Noto Sans CJK TC', sans-serif;
  --font-mono: 'Ubuntu Mono', 'Consolas', 'Monaco', monospace;

  /* Font Sizes */
  --font-size-xs: 0.75rem;    /* 12px */
  --font-size-sm: 0.875rem;   /* 14px */
  --font-size-md: 0.9375rem;  /* 15px */
  --font-size-base: 1rem;     /* 16px */
  --font-size-lg: 1.125rem;   /* 18px */
  --font-size-xl: 1.25rem;    /* 20px */
  --font-size-2xl: 1.5rem;    /* 24px */

  /* Layout */
  --header-height: 40px;
  --desktop-icon-size: 64px;
  --desktop-icon-gap: 24px;

  /* Responsive Breakpoints */
  --breakpoint-mobile: 768px;

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;

  /* Focus Ring (Accessibility) */
  --focus-ring-color: var(--color-primary);
  --focus-ring-offset: 2px;
  --focus-ring-width: 2px;
}

/* ==========================================================================
   Light Theme (亮色主題)
   ========================================================================== */
:root[data-theme="light"] {
  /* Primary Colors */
  --color-primary: #0891b2;           /* ChingTech Cyan - 主要按鈕/品牌色 */
  --color-background: #f5f5f5;        /* 純灰背景（無彩度） */
  --color-accent: #ea580c;            /* Orange - 強調/特殊元素 */

  /* Neutral Colors（無彩度灰階） */
  --color-gray-light: #1a1a1a;        /* 反轉：深灰文字 */
  --color-gray-mid: #707070;          /* 中性灰 */
  --color-gray-dark: #d0d0d0;         /* 淺灰邊框 */

  /* Status Colors（保持高彩度） */
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-error: #dc2626;

  /* Text Colors（無彩度） */
  --text-primary: #1a1a1a;      /* 深灰主要文字 */
  --text-secondary: #505050;    /* 次要文字 */
  --text-muted: #a0a0a0;        /* 靜音文字 */

  /* Surface & Border Colors */
  --bg-surface: rgba(0, 0, 0, 0.03);
  --bg-surface-dark: rgba(0, 0, 0, 0.05);
  --bg-surface-darker: rgba(0, 0, 0, 0.08);
  --bg-overlay: rgba(0, 0, 0, 0.6);
  --bg-overlay-dark: rgba(0, 0, 0, 0.8);
  --border-subtle: rgba(0, 0, 0, 0.05);
  --border-light: rgba(0, 0, 0, 0.1);
  --border-medium: rgba(0, 0, 0, 0.15);
  --border-strong: rgba(0, 0, 0, 0.2);
  --hover-bg: rgba(0, 0, 0, 0.05);

  /* Accent Variants */
  --accent-bg-subtle: rgba(8, 145, 178, 0.1);
  --accent-bg-light: rgba(8, 145, 178, 0.15);
  --accent-bg-medium: rgba(8, 145, 178, 0.2);
  --accent-border: rgba(8, 145, 178, 0.3);

  /* RGB Format */
  --color-primary-rgb: 8, 145, 178;
  --color-background-rgb: 245, 245, 245;
  --color-accent-rgb: 234, 88, 12;
  --color-success-rgb: 22, 163, 74;
  --color-warning-rgb: 217, 119, 6;
  --color-error-rgb: 220, 38, 38;
  --text-muted-rgb: 160, 160, 160;

  /* 半透明背景色（亮色主題用白色基底）- 無彩度 */
  --bg-glass: rgba(255, 255, 255, 0.95);
  --bg-glass-light: rgba(255, 255, 255, 0.88);
  --bg-glass-heavy: rgba(255, 255, 255, 0.98);
  /* 視窗不透明背景 */
  --window-bg: #ffffff;
  --window-titlebar-bg: #f0f0f0;
  --bg-tooltip: rgba(32, 32, 32, 0.95);
  --tooltip-text: #f8f8f8;

  /* 面板/編輯器實心背景色 */
  --bg-primary: #f5f5f5;
  --bg-secondary: #eeeeee;
  --bg-tertiary: #e8e8e8;
  --bg-input: #ffffff;

  /* 互動效果（亮色主題用黑色半透明） */
  --interactive-hover: rgba(0, 0, 0, 0.05);
  --interactive-active: rgba(0, 0, 0, 0.08);
  --interactive-border: rgba(0, 0, 0, 0.1);
  --scrollbar-hover: rgba(0, 0, 0, 0.35);
  --text-muted-semi: rgba(0, 0, 0, 0.5);
  --text-shadow-contrast: 0 1px 2px rgba(255, 255, 255, 0.6);

  /* Button Hover Colors */
  --color-primary-hover: #0e7490;     /* Cyan hover - 更深 */
  --color-accent-hover: #c2410c;      /* Orange hover - 更深 */

  /* Button Text Colors - 按鈕文字顏色 */
  --btn-text-on-primary: #ffffff;    /* 主要按鈕文字 */
  --btn-text-on-accent: #ffffff;     /* 強調按鈕文字 */
  --btn-text-on-ghost: var(--text-primary);  /* Ghost 按鈕文字 */

  /* Tag Colors（稍微深化以在亮色背景上可見） */
  --tag-color-purple: #7c3aed;
  --tag-color-green: #059669;
  --tag-color-yellow: #d97706;
  --tag-color-pink: #db2777;
  --tag-color-blue: #2563eb;
  --tag-color-gray: #555555;
  --tag-color-red: #dc2626;
  --tag-color-orange: #ea580c;
  --tag-color-cyan: #0891b2;

  /* Tag Background Colors */
  --tag-bg-purple: rgba(124, 58, 237, 0.15);
  --tag-bg-green: rgba(5, 150, 105, 0.15);
  --tag-bg-yellow: rgba(217, 119, 6, 0.15);
  --tag-bg-pink: rgba(219, 39, 119, 0.15);
  --tag-bg-blue: rgba(37, 99, 235, 0.15);
  --tag-bg-gray: rgba(85, 85, 85, 0.15);
  --tag-bg-red: rgba(220, 38, 38, 0.15);
  --tag-bg-orange: rgba(234, 88, 12, 0.15);

  /* Status Tag Colors */
  --status-completed-color: var(--color-success);
  --status-completed-bg: rgba(22, 163, 74, 0.15);
  --status-in-progress-color: var(--tag-color-blue);
  --status-in-progress-bg: rgba(37, 99, 235, 0.15);
  --status-pending-color: var(--tag-color-yellow);
  --status-pending-bg: rgba(217, 119, 6, 0.15);
  --status-cancelled-color: var(--tag-color-gray);
  --status-cancelled-bg: rgba(85, 85, 85, 0.15);

  /* Priority Tag Colors */
  --priority-critical-color: #b91c1c;
  --priority-critical-bg: rgba(185, 28, 28, 0.2);
  --priority-urgent-color: var(--color-error);
  --priority-urgent-bg: rgba(220, 38, 38, 0.15);
  --priority-high-color: var(--tag-color-orange);
  --priority-high-bg: rgba(234, 88, 12, 0.15);
  --priority-normal-color: var(--tag-color-blue);
  --priority-normal-bg: rgba(37, 99, 235, 0.15);
  --priority-low-color: var(--tag-color-gray);
  --priority-low-bg: rgba(85, 85, 85, 0.15);

  /* Modal Colors - 無彩度 */
  --modal-bg: #ffffff;
  --modal-bg-alt: #fafafa;
  --modal-border: var(--border-light);

  /* Terminal Theme Colors（亮色終端機主題 - 中性灰） */
  --terminal-bg: #f5f5f5;
  --terminal-fg: #1e1e1e;
  --terminal-cursor: #1e1e1e;
  --terminal-cursor-accent: #f5f5f5;
  --terminal-selection: rgba(0, 0, 0, 0.15);
  --terminal-black: #1e1e1e;
  --terminal-red: #cd3131;
  --terminal-green: #14ce14;
  --terminal-yellow: #b5a000;
  --terminal-blue: #0451a5;
  --terminal-magenta: #bc05bc;
  --terminal-cyan: #0598bc;
  --terminal-white: #e5e5e5;
  --terminal-bright-black: #666666;
  --terminal-bright-red: #f14c4c;
  --terminal-bright-green: #23d18b;
  --terminal-bright-yellow: #f5f543;
  --terminal-bright-blue: #3b8eea;
  --terminal-bright-magenta: #d670d6;
  --terminal-bright-cyan: #29b8db;
  --terminal-bright-white: #ffffff;

  /* Terminal Status Indicators */
  --terminal-status-connected: #16a34a;
  --terminal-status-disconnected: #dc2626;
  --terminal-status-idle: #a0a0a0;

  /* Code Editor */
  --code-editor-bg: #ffffff;

  /* Notification Badge */
  --badge-color: #dc2626;

  /* Markdown 渲染相關 (亮色主題) */
  --md-heading-color: #1e293b;
  --md-text-color: #334155;
  --md-link-color: #2563eb;
  --md-code-bg: rgba(139, 92, 246, 0.1);
  --md-code-color: #7c3aed;
  --md-pre-bg: #f1f5f9;
  --md-pre-border: #e2e8f0;
  --md-blockquote-border: #2563eb;
  --md-blockquote-bg: rgba(37, 99, 235, 0.05);
  --md-table-border: #e2e8f0;
  --md-table-header-bg: #f8fafc;
  --md-hr-color: #e2e8f0;

  /* 格式化資料語法色彩 (亮色主題) */
  --fd-string-color: #2e7d32;
  --fd-number-color: #1565c0;
  --fd-boolean-color: #7b1fa2;
  --fd-null-color: #c62828;
  --fd-key-color: #0277bd;
  --fd-punctuation-color: #616161;
  --fd-tag-color: #d32f2f;
  --fd-attribute-color: #ef6c00;
  --fd-comment-color: #9e9e9e;

  /* Shadows（亮色主題使用較淺的陰影） */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.12);
}

/* ==========================================================================
   Reset & Base Styles
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ==========================================================================
   Global Focus-Visible Styles (無障礙焦點指示器)
   策略：全域 :focus-visible 確保鍵盤導航時所有互動元素顯示焦點環，
   同時以 :focus:not(:focus-visible) 隱藏滑鼠操作時的焦點環。
   各模組 CSS 可覆寫個別元素的焦點樣式（如 desktop.css、window.css 等）。
   ========================================================================== */
:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

/* 滑鼠操作時不顯示焦點環（僅鍵盤操作才出現） */
:focus:not(:focus-visible) {
  outline: none;
}

/* ==========================================================================
   Global Scrollbar Styles (全局捲軸樣式)
   ========================================================================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-hover);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* 亮色主題捲軸 */
:root[data-theme="light"] ::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   Theme Transition (主題切換過渡效果)
   ========================================================================== */
/* 只有在切換主題時才啟用過渡，避免初始載入時的閃爍 */
.theme-transitioning,
.theme-transitioning * {
  transition: background-color 0.5s ease-in-out,
              border-color 0.5s ease-in-out,
              color 0.5s ease-in-out,
              box-shadow 0.5s ease-in-out !important;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-primary);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background-color: var(--color-background);
  line-height: 1.5;
  min-height: 100vh;
  overflow: hidden;
}

/* 手機版：允許 body 滾動以啟用瀏覽器原生 pull-to-refresh */
@media (max-width: 768px) {
  body {
    overflow: auto;
    overscroll-behavior-y: auto;
  }
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary);
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* SVG Icons */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon svg {
  width: 1em;
  height: 1em;
}

input {
  font-family: inherit;
  font-size: inherit;
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--color-accent); }

.bg-primary { background-color: var(--color-primary); }
.bg-background { background-color: var(--color-background); }

.flex { display: flex; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ==========================================================================
   Button Styles
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  font-weight: 500;
  transition: all var(--transition-fast);
}

.btn-primary {
  background-color: var(--color-primary);
  color: var(--btn-text-on-primary);
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
}

.btn-accent {
  background-color: var(--color-accent);
  color: var(--btn-text-on-accent);
}

.btn-accent:hover {
  background-color: var(--color-accent-hover);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background-color: var(--interactive-hover);
  color: var(--btn-text-on-ghost);
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.btn-secondary:hover {
  background-color: var(--interactive-hover);
  border-color: var(--border-strong);
}

.btn-danger {
  background-color: var(--color-error);
  color: white;
}

.btn-danger:hover {
  background-color: #b91c1c;
}

.btn-danger:disabled {
  background-color: var(--bg-surface);
  color: var(--text-muted);
  cursor: not-allowed;
  border: 1px solid var(--border-light);
}

/* ==========================================================================
   Input Styles
   ========================================================================== */
.input {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  background-color: var(--bg-surface);
  border: 1px solid var(--color-gray-dark);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.input:focus {
  border-color: var(--color-accent);
  background-color: var(--bg-surface-darker);
}

.input:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

.input::placeholder {
  color: var(--text-muted);
}

/* ==========================================================================
   Card Styles
   ========================================================================== */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--interactive-border);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
}

/* ==========================================================================
   Icon Styles
   ========================================================================== */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-sm { font-size: 16px; }
.icon-md { font-size: 24px; }
.icon-lg { font-size: 32px; }
.icon-xl { font-size: 48px; }

/* ==========================================================================
   Markdown Rendered Content (通用類別)
   ========================================================================== */
.markdown-rendered {
  font-size: var(--font-size-sm);
  line-height: 1.7;
  color: var(--md-text-color);
}

.markdown-rendered h1,
.markdown-rendered h2,
.markdown-rendered h3,
.markdown-rendered h4,
.markdown-rendered h5,
.markdown-rendered h6 {
  color: var(--md-heading-color);
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 600;
}

.markdown-rendered h1:first-child,
.markdown-rendered h2:first-child,
.markdown-rendered h3:first-child {
  margin-top: 0;
}

.markdown-rendered h1 {
  font-size: 1.5em;
  border-bottom: 1px solid var(--md-hr-color);
  padding-bottom: 0.3em;
}

.markdown-rendered h2 {
  font-size: 1.3em;
  border-bottom: 1px solid var(--md-hr-color);
  padding-bottom: 0.3em;
}

.markdown-rendered h3 {
  font-size: 1.1em;
}

.markdown-rendered p {
  margin: 0.8em 0;
}

.markdown-rendered ul,
.markdown-rendered ol {
  margin: 0.8em 0;
  padding-left: 1.5em;
}

.markdown-rendered li {
  margin: 0.3em 0;
}

.markdown-rendered a {
  color: var(--md-link-color);
  text-decoration: none;
}

.markdown-rendered a:hover {
  text-decoration: underline;
}

.markdown-rendered code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background-color: var(--md-code-bg);
  padding: 0.2em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--md-code-color);
}

.markdown-rendered pre {
  background-color: var(--md-pre-bg);
  border: 1px solid var(--md-pre-border);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  overflow-x: auto;
  margin: 1em 0;
}

.markdown-rendered pre code {
  background: none;
  padding: 0;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  border: none;
}

.markdown-rendered blockquote {
  border-left: 3px solid var(--md-blockquote-border);
  margin: 1em 0;
  padding: 0.5em 1em;
  background-color: var(--md-blockquote-bg);
  color: var(--text-secondary);
}

.markdown-rendered table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
}

.markdown-rendered th,
.markdown-rendered td {
  border: 1px solid var(--md-table-border);
  padding: 0.5em 0.8em;
  text-align: left;
}

.markdown-rendered th {
  background-color: var(--md-table-header-bg);
  font-weight: 600;
}

.markdown-rendered img {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: 1em 0;
}

.markdown-rendered hr {
  border: none;
  border-top: 1px solid var(--md-hr-color);
  margin: 2em 0;
}

/* ==========================================================================
   Formatted Data (JSON/YAML/XML 語法色彩)
   ========================================================================== */
.formatted-data {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text-primary);
}

.formatted-data .fd-string {
  color: var(--fd-string-color);
}

.formatted-data .fd-number {
  color: var(--fd-number-color);
}

.formatted-data .fd-boolean {
  color: var(--fd-boolean-color);
}

.formatted-data .fd-null {
  color: var(--fd-null-color);
}

.formatted-data .fd-key {
  color: var(--fd-key-color);
}

.formatted-data .fd-punctuation {
  color: var(--fd-punctuation-color);
}

.formatted-data .fd-tag {
  color: var(--fd-tag-color);
}

.formatted-data .fd-attribute {
  color: var(--fd-attribute-color);
}

.formatted-data .fd-comment {
  color: var(--fd-comment-color);
  font-style: italic;
}

/* ==========================================================================
   Mobile App Layout Utilities (手機版 App 佈局工具)
   ========================================================================== */

/* --------------------------------------------------------------------------
   底部 Tab Bar (適用於側邊欄導航型 App)
   -------------------------------------------------------------------------- */
.mobile-tab-bar {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-surface-dark);
  border-top: 1px solid var(--border-subtle);
  z-index: 100;
}

.mobile-tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 12px;
  min-width: 64px;
  min-height: 44px;
  color: var(--text-secondary);
  font-size: 10px;
  cursor: pointer;
  background: transparent;
  border: none;
  transition: color var(--transition-fast);
}

.mobile-tab-item:hover {
  color: var(--text-primary);
}

.mobile-tab-item.active {
  color: var(--color-primary);
}

.mobile-tab-item .icon {
  font-size: 20px;
}

.mobile-tab-item .mobile-tab-label {
  font-size: 10px;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   堆疊式導航 (適用於列表+詳情型 App)
   -------------------------------------------------------------------------- */
.mobile-stack-container {
  position: relative;
  height: 100%;
  overflow: hidden;
}

.mobile-stack-page {
  position: absolute;
  inset: 0;
  background: var(--color-background);
  overflow-y: auto;
  transition: transform 0.25s ease-out, opacity 0.25s ease-out;
}

.mobile-stack-page.list-page {
  transform: translateX(0);
  opacity: 1;
}

.mobile-stack-page.detail-page {
  transform: translateX(100%);
  opacity: 1;
}

/* 顯示詳情頁時 */
.mobile-stack-container.showing-detail .list-page {
  transform: translateX(-30%);
  opacity: 0.5;
  pointer-events: none;
}

.mobile-stack-container.showing-detail .detail-page {
  transform: translateX(0);
}

/* --------------------------------------------------------------------------
   手機版返回按鈕
   -------------------------------------------------------------------------- */
.mobile-back-header {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-surface-dark);
  border-bottom: 1px solid var(--border-subtle);
}

.mobile-back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: none;
  color: var(--color-primary);
  font-size: 14px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast);
}

.mobile-back-btn:hover {
  background: var(--hover-bg);
}

.mobile-back-btn .icon {
  font-size: 18px;
}

.mobile-back-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------------------------------------------------
   可收合篩選器面板 (適用於工具列+表格型 App)
   -------------------------------------------------------------------------- */
.mobile-filter-toggle {
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-surface-dark);
  border-bottom: 1px solid var(--border-subtle);
}

.mobile-filter-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  min-height: 44px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}

.mobile-filter-btn .icon {
  font-size: 16px;
}

.mobile-filter-panel {
  display: none;
  padding: 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.mobile-filter-panel.expanded {
  display: block;
}

.mobile-filter-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.mobile-filter-row:last-child {
  margin-bottom: 0;
}

.mobile-filter-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.mobile-filter-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* --------------------------------------------------------------------------
   卡片式列表 (取代表格)
   -------------------------------------------------------------------------- */
.mobile-card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}

.mobile-card {
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.mobile-card:hover {
  border-color: var(--border-light);
  background: var(--bg-surface-dark);
}

.mobile-card:active {
  background: var(--bg-surface-darker);
}

.mobile-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.mobile-card-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
}

.mobile-card-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.mobile-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mobile-card-label {
  color: var(--text-secondary);
}

.mobile-card-value {
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   手機版響應式工具類別
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* 顯示/隱藏 */
  .hide-on-mobile { display: none !important; }
  .show-on-mobile { display: block !important; }
  .flex-on-mobile { display: flex !important; }

  /* 底部 Tab Bar 顯示 */
  .mobile-tab-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
  }

  /* 返回按鈕 header 顯示 */
  .mobile-back-header {
    display: flex;
  }

  /* 篩選器切換按鈕顯示 */
  .mobile-filter-toggle {
    display: flex;
  }

  /* 觸控友善的按鈕尺寸 */
  .btn {
    min-height: 44px;
    padding: var(--spacing-sm) var(--spacing-md);
  }

  /* 列表項目最小高度 */
  .mobile-list-item {
    min-height: 48px;
  }
}

@media (min-width: 769px) {
  .hide-on-desktop { display: none !important; }
  .show-on-desktop { display: block !important; }
  .flex-on-desktop { display: flex !important; }
}

/* ==========================================================================
   App Lazy-Loading Skeleton & Spinner
   ========================================================================== */

/* 全螢幕半透明遮罩 */
.app-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-overlay, rgba(0, 0, 0, 0.6));
  backdrop-filter: blur(4px);
  transition: opacity var(--transition-normal);
}
.app-loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* Skeleton 容器 */
.app-loading-skeleton {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 48px;
  border-radius: 12px;
  background: var(--bg-surface-dark, rgba(0, 0, 0, 0.2));
  border: 1px solid var(--border-light, rgba(255, 255, 255, 0.1));
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* 旋轉動畫 Spinner */
.skeleton-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-medium, rgba(255, 255, 255, 0.15));
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: skeleton-spin 0.8s linear infinite;
}

@keyframes skeleton-spin {
  to { transform: rotate(360deg); }
}

/* 載入文字 */
.skeleton-label {
  color: var(--text-secondary);
  font-size: 14px;
  letter-spacing: 0.5px;
}

   Prefers-Reduced-Motion：無障礙動態偏好
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .skeleton::after {
    animation: none !important;
    background: var(--bg-tertiary) !important;
  }

  .spinner {
    animation: none !important;
    border-top-color: transparent;
    opacity: 0.6;
  }
}

/* ==========================================================================
   Skeleton 骨架屏元件
   ========================================================================== */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm, 6px);
  color: transparent !important;
  pointer-events: none;
  user-select: none;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.15) 50%,
    transparent 100%
  );
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Skeleton 變體 */
.skeleton--text {
  height: 1em;
  width: 80%;
  margin-bottom: var(--spacing-xs, 4px);
}

.skeleton--circle {
  border-radius: 50%;
}

.skeleton--rect {
  border-radius: var(--radius-sm, 6px);
}

/* Desktop 圖示骨架 */
.skeleton--icon {
  width: 72px;
  height: 88px;
  border-radius: var(--radius-md, 8px);
  margin: var(--spacing-sm, 8px);
}

/* AI 助手骨架 */
.skeleton--chat-item {
  height: 48px;
  width: 100%;
  margin-bottom: var(--spacing-xs, 4px);
  border-radius: var(--radius-sm, 6px);
}

.skeleton--message {
  height: 60px;
  width: 70%;
  margin-bottom: var(--spacing-sm, 8px);
  border-radius: var(--radius-md, 8px);
}

/* ==========================================================================
   Spinner 載入旋轉元件
   ========================================================================== */
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

.spinner--sm { width: 16px; height: 16px; border-width: 2px; }
.spinner--lg { width: 36px; height: 36px; border-width: 4px; }

@keyframes spinner-rotate {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   統一回饋狀態元件（Loading / Empty / Error）
   各模組共用，取代原本分散的 .kb-loading、.ai-chat-empty 等
   ========================================================================== */

/* ── 共用基底：置中 flex 容器 ── */
.ui-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm, 8px);
  padding: var(--spacing-lg, 24px);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-sm, 13px);
  min-height: 120px;
  width: 100%;
  box-sizing: border-box;
}

/* 填滿父容器高度（用於主內容面板） */
.ui-state--fill {
  height: 100%;
}

/* 固定高度（用於列表區塊） */
.ui-state--compact {
  min-height: 80px;
  padding: var(--spacing-md, 16px);
}

/* ── 圖示共用 ── */
.ui-state .ui-state-icon svg {
  width: 48px;
  height: 48px;
  opacity: 0.3;
}

.ui-state--fill .ui-state-icon svg {
  width: 64px;
  height: 64px;
  opacity: 0.2;
}

.ui-state--compact .ui-state-icon svg {
  width: 32px;
  height: 32px;
  opacity: 0.3;
}

/* ── Loading 狀態 ── */
.ui-state--loading .ui-state-icon svg {
  animation: ui-state-spin 1s linear infinite;
}

@keyframes ui-state-spin {
  to { transform: rotate(360deg); }
}

/* Loading 骨架列表（多行佔位） */
.ui-state-skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs, 4px);
  width: 100%;
  padding: var(--spacing-sm, 8px);
}

.ui-state-skeleton .skeleton {
  height: 44px;
  width: 100%;
  border-radius: var(--radius-sm, 6px);
}

.ui-state-skeleton .skeleton:nth-child(2) { width: 90%; }
.ui-state-skeleton .skeleton:nth-child(3) { width: 75%; }

/* ── Empty 狀態 ── */
.ui-state--empty {
  color: var(--text-muted);
}

.ui-state--empty .ui-state-text {
  max-width: 280px;
  line-height: 1.5;
}

/* ── Error 狀態 ── */
.ui-state--error .ui-state-icon svg {
  opacity: 0.6;
  color: var(--color-error);
}

.ui-state--error .ui-state-text {
  color: var(--color-error);
  opacity: 0.85;
}

.ui-state--error .ui-state-detail {
  font-size: var(--font-size-xs, 12px);
  color: var(--text-muted);
  max-width: 320px;
  word-break: break-word;
}

/* 重試按鈕 */
.ui-state-retry {
  margin-top: var(--spacing-sm, 8px);
  padding: var(--spacing-xs, 4px) var(--spacing-md, 16px);
  border: 1px solid var(--border-light, rgba(255, 255, 255, 0.1));
  border-radius: var(--radius-sm, 6px);
  background: var(--bg-surface, rgba(0, 0, 0, 0.1));
  color: var(--text-secondary);
  font-size: var(--font-size-xs, 12px);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ui-state-retry:hover {
  background: var(--hover-bg, rgba(255, 255, 255, 0.1));
  border-color: var(--border-medium, rgba(255, 255, 255, 0.15));
  color: var(--text-primary);
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  .ui-state--loading .ui-state-icon svg {
    animation: none !important;
    opacity: 0.5;
  }
}

/* ==========================================================================
   Data Attribute 動畫開關：html[data-animations="off"]
   手動停用所有裝飾性動畫（非 prefers-reduced-motion 的 JS 觸發版本）
   ========================================================================== */
html[data-animations="off"] *,
html[data-animations="off"] *::before,
html[data-animations="off"] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* 停用 loading spinner 動畫 */
html[data-animations="off"] .ui-state--loading .ui-state-icon svg,
html[data-animations="off"] .login-btn .spin {
  animation: none !important;
  opacity: 0.5;
}
