/* =========================================================
   法小筑管理后台 · macOS 风格设计系统
   令牌优先 · 毛玻璃侧栏 · 圆角卡片 · 移动端抽屉 · 暗色自适应
   ========================================================= */

:root {
  /* ---------- 颜色：原始值 ---------- */
  --blue-50:  #e8f1ff;
  --blue-100: #d1e4ff;
  --blue-400: #4a9bff;
  --blue-500: #0a84ff;   /* macOS systemBlue */
  --blue-600: #0070e0;
  --blue-700: #0058b0;

  --gray-0:   #ffffff;
  --gray-20:  #fbfbfd;
  --gray-50:  #f5f5f7;   /* 窗口底色 */
  --gray-100: #ececf0;
  --gray-200: #e2e2e8;
  --gray-300: #d2d2da;
  --gray-400: #aeaeb8;
  --gray-500: #8a8a93;
  --gray-600: #63636a;
  --gray-700: #48484e;
  --gray-800: #2c2c30;
  --gray-900: #1d1d1f;

  --green-500: #34c759;
  --amber-500: #ff9f0a;
  --red-500:   #ff3b30;
  --red-50:    #fff0ef;
  --green-50:  #eafaf0;
  --amber-50:  #fff5e6;

  /* ---------- 颜色：语义层 ---------- */
  --bg-window:        var(--gray-50);
  --bg-surface:       var(--gray-0);
  --bg-surface-2:     var(--gray-20);
  --bg-subtle:        var(--gray-100);
  --bg-muted:         var(--gray-200);
  --bg-sidebar:       rgba(245, 245, 247, 0.72);

  --text-primary:    var(--gray-900);
  --text-secondary:  var(--gray-700);
  --text-muted:      var(--gray-500);
  --text-inverse:    #ffffff;

  --accent:            var(--blue-500);
  --accent-hover:      var(--blue-600);
  --accent-active:     var(--blue-700);
  --accent-subtle:     var(--blue-50);
  --accent-contrast:   #ffffff;

  --border-default:  var(--gray-200);
  --border-strong:   var(--gray-300);
  --border-focus:    var(--blue-500);

  --success: var(--green-500);
  --warning: var(--amber-500);
  --error:   var(--red-500);

  /* ---------- 间距（4px 基准） ---------- */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;

  /* ---------- 圆角 ---------- */
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px; --radius-full: 9999px;

  /* ---------- 阴影（macOS 柔光） ---------- */
  --shadow-xs:  0 1px 2px rgb(0 0 0 / 0.04);
  --shadow-sm:  0 1px 3px rgb(0 0 0 / 0.06), 0 1px 2px rgb(0 0 0 / 0.04);
  --shadow-md:  0 4px 16px rgb(0 0 0 / 0.08);
  --shadow-lg:  0 12px 40px rgb(0 0 0 / 0.18);
  --shadow-focus: 0 0 0 3px rgb(10 132 255 / 0.30);

  /* ---------- 字体 ---------- */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;

  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px; --fs-lg: 16px;
  --fs-xl: 19px; --fs-2xl: 22px; --fs-3xl: 28px;
  --lh-tight: 1.25; --lh-normal: 1.5;

  /* ---------- 动效 ---------- */
  --dur-fast: 150ms; --dur-normal: 300ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --sidebar-w: 248px;
}

/* 统一采用 macOS 浅色主题（不再跟随系统暗色） */

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text-primary);
  background: var(--bg-window);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--text-muted); font-size: var(--fs-sm); }
button { font-family: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; border-radius: var(--radius-sm); }

/* =========================================================
   登录视图 · macOS 浅色双栏
   ========================================================= */
.login-view { display: flex; min-height: 100vh; background: var(--bg-window); }

.login-aside {
  flex: 1 1 50%;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: var(--space-12);
  color: var(--text-primary);
  background:
    radial-gradient(900px 500px at 18% 8%, var(--blue-50), transparent 60%),
    linear-gradient(165deg, #eaf3ff 0%, #f5f5f7 58%, #eef6ff 100%);
}
.login-aside-inner { display: flex; flex-direction: column; gap: var(--space-4); }
.login-aside .brand-mark {
  width: 72px; height: 72px; display: grid; place-items: center;
  font-size: 34px; font-weight: 700; color: #fff;
  background: linear-gradient(160deg, var(--blue-400), var(--accent));
  border-radius: 20px; box-shadow: var(--shadow-md);
}
.login-aside h1 { font-size: var(--fs-3xl); }
.login-aside .muted { font-size: var(--fs-lg); max-width: 30ch; }
.login-aside-footer { font-size: var(--fs-sm); color: var(--text-muted); }

.login-main {
  flex: 1 1 50%;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-8);
  background: var(--bg-surface);
}
.login-form {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: var(--space-4);
}
.login-card-title { font-size: var(--fs-2xl); }
.login-card-sub { margin: calc(-1 * var(--space-2)) 0 0; }
.login-form label {
  display: flex; flex-direction: column; gap: var(--space-1);
  font-size: var(--fs-sm); color: var(--text-secondary); font-weight: 500;
}
.login-form input {
  height: 44px; width: 100%; padding: 0 var(--space-3);
  font-size: var(--fs-base); font-family: inherit;
  color: var(--text-primary); background: var(--bg-surface);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.login-form input::placeholder { color: var(--text-muted); }
.login-form input:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--shadow-focus); }
.login-submit { height: 44px; margin-top: var(--space-2); font-size: var(--fs-base); }
.error-message { color: var(--error); font-size: var(--fs-sm); min-height: 1em; margin: 0; }

/* =========================================================
   应用壳：侧边栏 + 主区
   ========================================================= */
.app-shell { display: flex; min-height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-sidebar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--border-default);
  padding: var(--space-5) var(--space-3);
  display: flex; flex-direction: column; gap: var(--space-2);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3) var(--space-4); }
.brand-logo {
  width: 36px; height: 36px; display: grid; place-items: center;
  font-size: 18px; font-weight: 700; color: var(--accent-contrast);
  background: linear-gradient(160deg, var(--blue-400), var(--accent));
  border-radius: 10px; flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: var(--fs-lg); }
.brand-text span { font-size: var(--fs-xs); color: var(--text-muted); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; padding: var(--space-3) var(--space-3) var(--space-1); }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; padding: var(--space-3);
  border: none; background: transparent;
  color: var(--text-secondary);
  font-size: var(--fs-base); font-weight: 500;
  border-radius: var(--radius-md); cursor: pointer; text-align: left;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item:hover { background: var(--bg-muted); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: var(--accent-contrast); box-shadow: var(--shadow-sm); }
.nav-item.active:hover { background: var(--accent-hover); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.nav-export { margin-top: var(--space-3); color: var(--accent); }
.nav-export:hover { background: var(--accent-subtle); color: var(--accent-active); }

/* ---------- 主区 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  background: var(--bg-sidebar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-default);
}
.topbar-titles { flex: 1; min-width: 0; }
.eyebrow { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 500; }
.topbar h1 { font-size: var(--fs-xl); }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

.icon-button {
  display: none; width: 40px; height: 40px;
  align-items: center; justify-content: center;
  border: 1px solid var(--border-default); background: var(--bg-surface);
  border-radius: var(--radius-md); color: var(--text-secondary);
  cursor: pointer; font-size: 18px;
}

.content { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); max-width: 1180px; width: 100%; }

/* =========================================================
   概览卡片
   ========================================================= */
.overview-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
.overview-card {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-xs);
  display: flex; flex-direction: column; gap: 2px;
  transition: transform var(--dur-normal) var(--ease), box-shadow var(--dur-normal) var(--ease);
}
.overview-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.overview-card span { font-size: var(--fs-sm); color: var(--text-muted); }
.overview-card strong { font-size: var(--fs-3xl); font-weight: 600; letter-spacing: -0.02em; }

/* =========================================================
   面板 / 卡片
   ========================================================= */
.panel {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-xs);
  padding: var(--space-6);
}
.panel-title { font-size: var(--fs-xl); margin-bottom: var(--space-4); }
.panel-subtitle { font-size: var(--fs-base); color: var(--text-secondary); margin: var(--space-4) 0 var(--space-2); }

/* =========================================================
   表单
   ========================================================= */
.filter-form { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.filter-form label { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--fs-sm); color: var(--text-secondary); font-weight: 500; flex: 1 1 200px; }
.filter-form input, .filter-form select {
  height: 40px; width: 100%; padding: 0 var(--space-3);
  font-size: var(--fs-base); font-family: inherit;
  color: var(--text-primary); background: var(--bg-surface);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.filter-form input::placeholder { color: var(--text-muted); }
.filter-form input:focus, .filter-form select:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--shadow-focus); }
.filter-form input[disabled] { opacity: 0.5; cursor: not-allowed; }
.filter-form select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: var(--space-8); cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a8a93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--space-3) center;
}
.filter-form select:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--shadow-focus); }
.compact { align-self: end; }

/* =========================================================
   按钮
   ========================================================= */
.primary-button, .secondary-button, .ghost-button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 40px; padding: 0 var(--space-5);
  font-size: var(--fs-base); font-weight: 600;
  border-radius: var(--radius-md); border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.primary-button { background: var(--accent); color: var(--accent-contrast); }
.primary-button:hover { background: var(--accent-hover); }
.primary-button:active { background: var(--accent-active); transform: scale(0.98); }
.secondary-button { background: var(--accent-subtle); color: var(--accent-active); }
.secondary-button:hover { background: var(--blue-100); }
.ghost-button { background: var(--bg-surface); color: var(--text-secondary); border-color: var(--border-default); }
.ghost-button:hover { background: var(--bg-subtle); color: var(--text-primary); }
.primary-button.compact, .secondary-button.compact, .ghost-button.compact { height: 36px; padding: 0 var(--space-4); font-size: var(--fs-sm); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* =========================================================
   状态提示
   ========================================================= */
.view-status { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: var(--space-3); min-height: 1em; }
.form-error, .error-message { color: var(--error); }

/* =========================================================
   表格
   ========================================================= */
.table-wrap { width: 100%; overflow-x: auto; margin-top: var(--space-4); border-radius: var(--radius-lg); border: 1px solid var(--border-default); }
table { width: 100%; border-collapse: collapse; min-width: 640px; font-size: var(--fs-sm); }
thead th {
  text-align: left; font-weight: 600; color: var(--text-muted);
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.03em;
  background: var(--bg-subtle); padding: var(--space-3) var(--space-4); position: sticky; top: 0;
}
tbody td { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-default); vertical-align: top; }
tbody tr:hover { background: var(--bg-surface-2); }
.record-title { font-weight: 500; color: var(--text-primary); }
.record-meta { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.row-actions { display: flex; gap: var(--space-2); white-space: nowrap; }
.row-actions button {
  height: 30px; padding: 0 var(--space-3); font-size: var(--fs-sm); font-weight: 500;
  border-radius: var(--radius-sm); border: 1px solid var(--border-default);
  background: var(--bg-surface); color: var(--text-secondary); cursor: pointer;
}
.row-actions button:hover { background: var(--bg-subtle); color: var(--text-primary); }
.row-actions button.delete { color: var(--error); border-color: transparent; background: var(--red-50); }
.row-actions button.delete:hover { background: var(--error); color: #fff; }
.status-pill { display: inline-block; padding: 2px 10px; font-size: var(--fs-xs); font-weight: 600; border-radius: var(--radius-full); background: var(--bg-muted); color: var(--text-secondary); }

.pager { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-4); font-size: var(--fs-sm); color: var(--text-muted); }
.pager-jump { display: inline-flex; align-items: center; gap: var(--space-2); }
.pager-jump input { width: 64px; height: 32px; padding: 0 var(--space-2); border: 1px solid var(--border-default); border-radius: var(--radius-sm); font-family: inherit; font-size: var(--fs-sm); }

/* =========================================================
   知识库统计 / 最近
   ========================================================= */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
.stat-group { grid-column: span 1; padding: var(--space-4); border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-subtle); }
.stat-group .panel-subtitle { margin: 0 0 var(--space-2); }
.stat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.stat-list li { display: flex; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-3); background: var(--bg-surface); border-radius: var(--radius-sm); font-size: var(--fs-sm); }
.stat-list li span { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-list li strong { color: var(--text-primary); }
.stat-list li.empty { color: var(--text-muted); justify-content: center; }
.recent-list { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.recent-list li { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3); background: var(--bg-subtle); border-radius: var(--radius-md); }
.recent-title { font-weight: 500; }
.recent-meta { font-size: var(--fs-xs); color: var(--text-muted); }

/* =========================================================
   详情对话框
   ========================================================= */
.detail-dialog {
  border: none; border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); padding: 0;
  width: min(720px, 92vw); max-height: 86vh;
  background: var(--bg-surface); color: var(--text-primary);
}
.detail-dialog::backdrop { background: rgb(0 0 0 / 0.45); backdrop-filter: blur(4px); }
.detail-dialog h2 { font-size: var(--fs-xl); padding: var(--space-6) var(--space-6) var(--space-3); }
.detail-dialog pre {
  margin: 0; padding: 0 var(--space-6) var(--space-6);
  font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
  max-height: 60vh; overflow-y: auto; color: var(--text-secondary);
}
.dialog-close {
  position: absolute; top: var(--space-4); right: var(--space-4);
  width: 32px; height: 32px; border-radius: var(--radius-full);
  border: none; background: var(--bg-muted); color: var(--text-secondary);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.dialog-close:hover { background: var(--bg-subtle); color: var(--text-primary); }

/* =========================================================
   移动端遮罩
   ========================================================= */
.sidebar-overlay { display: none; position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / 0.35); backdrop-filter: blur(2px); }

/* =========================================================
   响应式
   ========================================================= */
@media (max-width: 1023px) {
  .icon-button { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 40;
    transform: translateX(-100%);
    transition: transform var(--dur-normal) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { display: block; }
  .topbar { padding: var(--space-3) var(--space-4); }
  .content { padding: var(--space-4); gap: var(--space-4); }
  .overview-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: var(--space-5); }
  .filter-form label { flex-basis: 100%; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: var(--fs-lg); }
  .topbar-actions .muted { display: none; }
}

@media (max-width: 768px) {
  .login-view { flex-direction: column; }
  .login-aside { flex: none; padding: var(--space-8) var(--space-6); }
  .login-aside-inner { gap: var(--space-3); }
  .login-aside .brand-mark { width: 56px; height: 56px; font-size: 28px; border-radius: 16px; }
  .login-aside h1 { font-size: var(--fs-2xl); }
  .login-aside-footer { display: none; }
  .login-main { flex: 1 1 auto; padding: var(--space-6); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
