/* =========================================================================
   审批中心 · Apple 风格设计系统
   浅色/深色双主题，SF Pro 字体栈，圆角卡片，毛玻璃顶栏
   ========================================================================= */

:root {
  /* 品牌色（Apple System Blue） */
  --brand-50: #e8f2ff;
  --brand-100: #cfe5ff;
  --brand-200: #9fcbff;
  --brand-300: #66abff;
  --brand-400: #2e8dff;
  --brand-500: #007aff;
  --brand-600: #0064d6;

  /* 系统灰 */
  --gray-50: #ffffff;
  --gray-100: #f5f5f7;
  --gray-200: #f2f2f7;
  --gray-300: #e5e5ea;
  --gray-400: #d1d1d6;
  --gray-500: #aeaeb2;
  --gray-600: #8e8e93;
  --gray-700: #48484a;
  --gray-800: #1d1d1f;
  --gray-900: #000000;

  /* 状态色（Apple System） */
  --green: #34c759;
  --green-surface: #e9f9ee;
  --red: #ff3b30;
  --red-surface: #ffecea;
  --orange: #ff9500;

  /* 语义令牌（浅色） */
  --bg: var(--gray-50);
  --bg-elevated: var(--gray-50);
  --bg-secondary: var(--gray-200);
  --text: var(--gray-800);
  --text-secondary: var(--gray-600);
  --text-tertiary: var(--gray-500);
  --border: var(--gray-300);
  --border-strong: var(--gray-400);
  --primary: var(--brand-500);
  --primary-foreground: #ffffff;
  --sidebar-bg: var(--gray-100);
  --sidebar-active: var(--gray-300);
  --topbar-bg: rgba(255, 255, 255, 0.72);

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Helvetica Neue", "Segoe UI", "Microsoft YaHei", sans-serif;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 24px 64px rgba(0, 0, 0, 0.16);
}

[data-theme="dark"] {
  --gray-50: #000000;
  --gray-100: #1c1c1e;
  --gray-200: #2c2c2e;
  --gray-300: #3a3a3c;
  --gray-400: #48484a;
  --gray-500: #8e8e93;
  --gray-600: #aeaeb2;
  --gray-700: #d1d1d6;
  --gray-800: #f5f5f7;
  --gray-900: #ffffff;

  --brand-50: #0a2540;
  --brand-100: #123b63;
  --brand-400: #2e8dff;
  --brand-500: #0a84ff;

  --green-surface: #123b2a;
  --red-surface: #3b1d1d;

  --bg: var(--gray-50);
  --bg-elevated: var(--gray-100);
  --bg-secondary: var(--gray-200);
  --text: var(--gray-800);
  --text-secondary: var(--gray-600);
  --text-tertiary: var(--gray-500);
  --border: var(--gray-300);
  --border-strong: var(--gray-400);
  --primary: var(--brand-400);
  --primary-foreground: #ffffff;
  --sidebar-bg: var(--gray-50);
  --sidebar-active: var(--gray-300);
  --topbar-bg: rgba(28, 28, 30, 0.72);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.36), 0 1px 3px rgba(0, 0, 0, 0.36);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.44), 0 2px 4px rgba(0, 0, 0, 0.36);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 24px 64px rgba(0, 0, 0, 0.6);
}

/* 基础 */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.25s ease, color 0.25s ease;
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { flex-shrink: 0; }
::selection { background: var(--brand-200); }

/* 图标尺寸工具类（内联 SVG 使用） */
.h-4 { height: 16px; }
.w-4 { width: 16px; }
.h-5 { height: 20px; }
.w-5 { width: 20px; }
.h-6 { height: 24px; }
.w-6 { width: 24px; }
.h-8 { height: 32px; }
.w-8 { width: 32px; }
.h-\[18px\] { height: 18px; }
.w-\[18px\] { width: 18px; }
.h-\[19px\] { height: 19px; }
.w-\[19px\] { width: 19px; }

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ============ 布局骨架 ============ */
.app-shell { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.app-sidebar {
  width: 236px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--sidebar-bg); border-right: 1px solid var(--border);
  transition: transform 0.25s ease;
}
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  display: flex; align-items: center; gap: 16px; min-height: 64px;
  padding: 0 24px; border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  position: sticky; top: 0; z-index: 20;
}
.app-content { flex: 1; min-height: 0; display: flex; }

/* ============ 侧边栏 ============ */
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 24px 24px 20px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  color: #fff; box-shadow: var(--shadow-sm);
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 0 12px; }
.nav-group { padding: 4px 12px 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-tertiary); }
.nav-group + .nav-group { margin-top: 16px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  font-size: 14px; color: var(--text-secondary); transition: background 0.15s ease, color 0.15s ease;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-secondary); color: var(--text); }
.nav-item.active { background: var(--sidebar-active); color: var(--text); font-weight: 500; }
.nav-item .nav-badge {
  margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 8px;
  border-radius: 999px; background: var(--brand-50); color: var(--primary);
}
.sidebar-user {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ============ 顶栏 ============ */
.topbar-title { min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 19px; font-weight: 600; line-height: 1.2; }
.topbar-title p { margin: 2px 0 0; font-size: 12px; color: var(--text-tertiary); }
.search-box { position: relative; flex: 1; max-width: 420px; }
.search-box input {
  width: 100%; height: 40px; border-radius: 12px; border: 1px solid transparent;
  background: var(--bg-secondary); padding: 0 16px 0 38px; font-size: 13px; color: var(--text);
  outline: none; transition: all 0.15s ease;
}
.search-box input::placeholder { color: var(--text-tertiary); }
.search-box input:focus { border-color: var(--primary); background: var(--bg-elevated); box-shadow: 0 0 0 3px var(--brand-100); }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ============ 通用组件 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: 999px; border: none;
  font-size: 13px; font-weight: 600; transition: opacity 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: var(--bg-secondary); color: var(--text); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-secondary); color: var(--text); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--border); }
.btn-danger:hover { background: var(--red-surface); }
.btn-lg { height: 46px; padding: 0 28px; font-size: 14px; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: 999px; background: transparent; color: var(--text-secondary); border: none; display: grid; place-items: center; transition: background 0.15s ease, color 0.15s ease; }
.btn-icon:hover { background: var(--bg-secondary); color: var(--text); }

.avatar {
  border-radius: 999px; display: grid; place-items: center; font-weight: 600;
  background: var(--bg-secondary); color: var(--text); flex-shrink: 0;
}
.avatar-primary { background: var(--primary); color: #fff; }

.icon-chip {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand-50); color: var(--primary); flex-shrink: 0;
}
.icon-chip.muted { background: var(--bg-secondary); color: var(--text-secondary); }

.unread-dot {
  position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 600; display: grid; place-items: center;
  box-shadow: 0 0 0 2px var(--bg);
}

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-brand { background: var(--brand-50); color: var(--brand-500); }
.badge-success { background: var(--green-surface); color: var(--green); }
.badge-error { background: var(--red-surface); color: var(--red); }
.badge-neutral { background: var(--bg-secondary); color: var(--text-secondary); }

.card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-xs);
}

/* ============ 列表栏 ============ */
.app-list-pane {
  width: 400px; flex-shrink: 0; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--bg);
}
.list-tabs { display: flex; align-items: center; gap: 4px; padding: 16px 16px 12px; }
.list-tabs-scroll { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
.app-tab {
  padding: 6px 14px; border-radius: 999px; border: none; background: transparent;
  font-size: 13px; color: var(--text-secondary); white-space: nowrap; transition: all 0.15s ease;
}
.app-tab:hover { background: var(--bg-secondary); color: var(--text); }
.app-tab.active { background: var(--bg-secondary); color: var(--text); font-weight: 500; }
.list-body { flex: 1; overflow-y: auto; padding: 4px 12px 16px; }
.list-empty { padding: 40px 20px; text-align: center; color: var(--text-tertiary); }

.approval-item {
  display: flex; gap: 12px; padding: 14px; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease;
}
.approval-item:hover { background: var(--bg-secondary); }
.approval-item.active { background: var(--bg-secondary); border-color: var(--border); }
.approval-item .ai-main { min-width: 0; flex: 1; }
.approval-item .ai-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.approval-item .ai-title h3 { margin: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.approval-item .ai-meta { margin-top: 4px; font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.approval-item .ai-foot { margin-top: 6px; display: flex; align-items: center; justify-content: space-between; font-size: 12px; }
.approval-item .ai-amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.approval-item .ai-time { color: var(--text-tertiary); }

/* ============ 详情栏 ============ */
.app-detail-pane { flex: 1; min-width: 0; overflow-y: auto; background: var(--bg); }
.detail-inner { max-width: 720px; margin: 0 auto; padding: 28px 32px 48px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card { padding: 16px; }
.stat-card .stat-label { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 12px; }
.stat-card .stat-value { margin-top: 8px; font-size: 26px; font-weight: 600; line-height: 1; }
.stat-card .stat-value .unit { font-size: 15px; font-weight: 500; color: var(--text-tertiary); margin-left: 2px; }
.stat-card.alert .stat-value { color: var(--red); }

.detail-card { margin-top: 20px; padding: 24px; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.detail-title-wrap { display: flex; gap: 12px; align-items: center; }
.detail-title h2 { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.25; }
.detail-title p { margin: 4px 0 0; font-size: 13px; color: var(--text-secondary); }

.kv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 24px; }
.kv .kv-label { font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-tertiary); }
.kv .kv-value { margin-top: 6px; font-size: 13px; font-weight: 500; }
.kv .kv-value.large { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kv .kv-person { display: flex; align-items: center; gap: 8px; }

.section { margin-top: 24px; }
.section-label { font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-tertiary); }
.section-body { margin-top: 10px; font-size: 14px; line-height: 1.7; }

.attach-list { display: flex; flex-wrap: wrap; gap: 8px; }
.attach {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 12px;
  background: var(--bg-secondary); font-size: 12px;
}

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; position: relative; padding-bottom: 20px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
  content: ''; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--border);
}
.timeline li:last-child::before { display: none; }
.tl-dot { width: 28px; height: 28px; border-radius: 999px; display: grid; place-items: center; flex-shrink: 0; }
.tl-dot.done { background: var(--green-surface); color: var(--green); }
.tl-dot.current { background: var(--primary); color: #fff; }
.tl-dot.todo { background: var(--bg-secondary); color: var(--text-tertiary); }
.tl-step { font-size: 13px; font-weight: 500; }
.tl-step.current { font-weight: 600; }
.tl-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0 0; }

.opinion-box { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
textarea.opinion {
  width: 100%; margin-top: 10px; padding: 12px 14px; border-radius: 12px; resize: none;
  border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text);
  font-family: inherit; font-size: 13px; outline: none; transition: all 0.15s ease;
}
textarea.opinion:focus { border-color: var(--primary); background: var(--bg-elevated); box-shadow: 0 0 0 3px var(--brand-100); }
.action-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; }

/* ============ 其它视图 ============ */
.single-pane { flex: 1; min-width: 0; overflow-y: auto; }
.single-inner { max-width: 900px; margin: 0 auto; padding: 28px 32px 48px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-heading h2 { margin: 0; font-size: 20px; font-weight: 600; }
.page-heading p { margin: 4px 0 0; font-size: 13px; color: var(--text-secondary); }

.flow-card { padding: 20px; margin-bottom: 12px; }
.flow-steps { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.flow-step { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.flow-arrow { color: var(--text-tertiary); }

.org-dept { padding: 18px 20px; margin-bottom: 12px; }
.org-dept h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.org-members { display: flex; flex-wrap: wrap; gap: 8px; }
.org-member {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px;
  border-radius: 999px; background: var(--bg-secondary); font-size: 13px;
}

/* ============ 弹窗 ============ */
.modal-root { position: fixed; inset: 0; z-index: 100; display: none; }
.modal-root.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(2px); animation: fadeIn 0.2s ease; }
.modal {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto;
  background: var(--bg-elevated); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl);
  animation: popIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 8px; }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-body { padding: 8px 24px 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-secondary); color: var(--text); font-family: inherit; font-size: 14px; outline: none;
  transition: all 0.15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); background: var(--bg-elevated); box-shadow: 0 0 0 3px var(--brand-100); }
.modal-foot { display: flex; justify-content: flex-end; gap: 12px; padding: 0 24px 20px; }

/* ============ Toast ============ */
.toast-root { position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 999px;
  background: var(--gray-800); color: #fff; font-size: 13px; box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.success svg { color: var(--green); }
.toast.error svg { color: #ff6961; }

/* ============ 沟通（聊天） ============ */
.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.chat-list {
  max-height: 340px; overflow-y: auto; padding: 14px 2px 4px;
  display: flex; flex-direction: column; gap: 14px;
}
.msg { display: flex; gap: 8px; align-items: flex-start; }
.msg.mine { flex-direction: row-reverse; }
.msg-body { min-width: 0; display: flex; flex-direction: column; }
.msg.mine .msg-body { align-items: flex-end; }
.msg-name { font-size: 12px; color: var(--text-secondary); margin: 0 4px 4px; }
.msg-bubble {
  max-width: 320px; padding: 10px 14px; border-radius: 16px;
  background: var(--bg-secondary); color: var(--text); font-size: 13px; line-height: 1.55;
  word-break: break-word; white-space: pre-wrap;
}
.msg:not(.mine) .msg-bubble { border-bottom-left-radius: 5px; }
.msg.mine .msg-bubble {
  background: var(--primary); color: #fff; border-bottom-right-radius: 5px;
}
.msg-time { font-size: 11px; color: var(--text-tertiary); margin: 4px 4px 0; }
.chat-input-row { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.chat-input-row input {
  flex: 1; height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-secondary); color: var(--text); font-size: 13px; outline: none;
  transition: all 0.15s ease; font-family: inherit;
}
.chat-input-row input:focus { border-color: var(--primary); background: var(--bg-elevated); box-shadow: 0 0 0 3px var(--brand-100); }

/* ============ 动画 ============ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ============ 响应式 ============ */
@media (max-width: 1024px) {
  .app-sidebar { width: 208px; }
  .app-list-pane { width: 340px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .kv-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  .app-shell { position: relative; }
  .app-sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 60;
    transform: translateX(-100%); box-shadow: var(--shadow-xl);
  }
  .app-sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, 0.4); display: none; }
  .sidebar-scrim.show { display: block; }

  .app-topbar { padding: 0 12px; min-height: 56px; }
  .topbar-title h1 { font-size: 17px; }
  .search-box { display: none; }
  .search-box.show { display: block; position: absolute; left: 12px; right: 12px; max-width: none; }

  .app-content { flex-direction: column; }
  .app-list-pane { width: 100%; border-right: 0; }
  .app-detail-pane {
    position: fixed; inset: 0; z-index: 40; background: var(--bg); transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  .app-detail-pane.show { transform: translateX(0); }
  .detail-inner { padding: 16px 16px 40px; }
  .single-inner { padding: 16px 16px 40px; }

  .mobile-back { display: inline-flex !important; }
  .topbar-desktop-hide { display: none !important; }
  .topbar-mobile-show { display: inline-flex !important; }
}

/* 移动端/桌面元素默认显隐 */
.mobile-back { display: none !important; }
.topbar-mobile-show { display: none !important; }
