@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;600;700&display=swap');

/* ═══════════════════════════════════
   变量
   ═══════════════════════════════════ */
:root {
  --sidebar: #0c1f30;
  --sidebar-active: #163a56;
  --accent: #1a6cb4;
  --accent-light: #e6f0fa;
  --accent-dark: #0e4a7a;
  --bg: #f0f2f7;
  --card: #ffffff;
  --input-bg: #f7f8fb;
  --text: #1a2332;
  --text2: #5a6a7e;
  --muted: #94a3b8;
  --border: #e2e6ee;
  --border-l: #eef1f6;
  --gold: #e8a817;
  --silver: #8c9bab;
  --bronze: #c47a2a;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.03);
}

/* ═══════════════════════════════════
   基础重置
   ═══════════════════════════════════ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* 滚动条：原来 6px + 透明轨道，在浅色背景上几乎看不见，
   长表单里容易让人以为页面不能滚。加宽并给轨道一点底色。 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,.04); border-radius: 10px; }
::-webkit-scrollbar-thumb { background: #b4bac6; border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #8f97a6; background-clip: content-box; }
* { scrollbar-width: thin; scrollbar-color: #b4bac6 rgba(0,0,0,.04); }

input, select {
  font-family: inherit;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(26,108,180,.12);
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type=number] { -moz-appearance: textfield; }

button {
  font-family: inherit;
  cursor: pointer;
  transition: all .15s ease;
}
button:active { transform: scale(.97); }

/* ═══════════════════════════════════
   布局
   ═══════════════════════════════════ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── 侧边栏 ─── */
.sidebar {
  width: 230px;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width .25s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.sidebar.collapsed { width: 64px; }

.sidebar-header {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar.collapsed .sidebar-header { padding: 22px 13px 18px; }

.logo-box {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1a6cb4, #0e4a7a);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 700;
  flex-shrink: 0;
}
.logo-text { overflow: hidden; white-space: nowrap; }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-footer { display: none; }

/* flex:1 只是让它占满剩余高度，并不会滚。菜单项比屏幕高时
   会被 .sidebar 的 overflow:hidden 直接切掉，手机上尤其明显。
   min-height:0 是关键 —— flex 子元素默认不会缩到内容高度以下，
   不加这句 overflow-y 也不起作用。 */
.nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 10px;
}
/* 侧边栏里的滚动条细一点，深色背景上不刺眼 */
.nav::-webkit-scrollbar { width: 4px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; border-radius: 10px;
  margin-bottom: 4px; cursor: pointer;
  font-size: 14px;
  color: rgba(255,255,255,.55);
  transition: all .15s;
}
.sidebar.collapsed .nav-item { justify-content: center; padding: 11px 0; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 500; }
.nav-item:hover:not(.active) { color: rgba(255,255,255,.8); }
.nav-icon { font-size: 17px; flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 11px; opacity: .35;
}

/* ─── 主内容区 ─── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  padding: 12px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.period-switch {
  display: flex;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
}
.period-btn {
  padding: 5px 16px; border-radius: 6px;
  border: none; font-size: 13px;
  background: transparent; color: var(--muted);
}
.period-btn.active {
  background: var(--card); color: var(--accent);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.sel {
  padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px; background: var(--card);
  cursor: pointer; color: var(--text);
}

.content { flex: 1; overflow: auto; padding: 24px 28px; }
.content-inner { max-width: 1120px; margin: 0 auto; animation: fadeIn .3s ease; }

/* ═══════════════════════════════════
   动画
   ═══════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes pulse {
  0%, 100% { opacity: .3; transform: translateY(0); }
  50%      { opacity: 1; transform: translateY(-3px); }
}
@keyframes blink {
  0%, 50%  { opacity: 1; }
  51%, 100% { opacity: 0; }
}
.cursor-blink {
  display: inline-block;
  color: var(--accent);
  font-weight: 700;
  animation: blink .8s step-start infinite;
  margin-left: 1px;
}

/* ═══════════════════════════════════
   组件
   ═══════════════════════════════════ */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

/* 网格 */
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 22px; }
.grid21 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; margin-bottom: 22px; }

/* 指标卡 */
.metric { border-left: 4px solid var(--accent); padding: 18px 20px; }
.metric-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.metric-val { font-size: 28px; font-weight: 700; line-height: 1; }
.metric-unit { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.metric-icon { font-size: 26px; opacity: .7; }

/* 案件卡片上「当事人 / 部门 / 条数」这一行。
   flex 的 gap 在老内核上不生效，用 margin 兜底，
   免得几项挤成一坨看不清分界。 */
.case-meta > span { margin-right: 16px; white-space: nowrap; }
.case-meta > span:last-child { margin-right: 0; }

.section-title { font-size: 15px; font-weight: 500; margin-bottom: 16px; }

/* 徽章 */
.badge {
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 500;
  display: inline-block;
}

/* 排名圆 */
.rank-circle {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.rank-circle-lg { width: 48px; height: 48px; font-size: 19px; font-weight: 700; }

/* 按钮 */
.btn-primary {
  padding: 8px 22px; border-radius: var(--radius); border: none;
  background: var(--accent); color: #fff; font-weight: 500; font-size: 14px;
}
.btn-outline {
  padding: 8px 18px; border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card); color: var(--text2); font-size: 13px;
}
.btn-danger { border-color: #fca5a5; background: #fef2f2; color: var(--red); }
.btn-sm { padding: 6px 14px; font-size: 12px; }

/* 输入框 */
.input {
  width: 100%; padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 14px; background: var(--card); color: var(--text);
}
.input-score { font-weight: 600; font-size: 18px; text-align: center; }

/* 进度条 */
.progress { height: 5px; border-radius: 3px; background: var(--border); margin-top: 10px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 3px; transition: width .3s ease; }

/* 评分项 */
.score-item { background: var(--input-bg); border-radius: var(--radius); padding: 14px 16px; }
.score-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.cat-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }

/* 人员标签 */
.staff-chip {
  padding: 6px 14px; border-radius: 20px; font-size: 12px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text2); cursor: pointer;
}
.staff-chip.active {
  border: 2px solid var(--accent); background: var(--accent-light);
  color: var(--accent); font-weight: 600;
}

/* 总分栏 */
.total-bar {
  background: var(--accent-light);
  border-color: var(--accent);
  display: flex; align-items: center; justify-content: space-between;
}

/* 排名卡片 */
.rank-card {
  display: flex; align-items: center; gap: 18px;
  animation: slideIn .3s ease;
}

/* Toast 消息 */
.toast {
  position: fixed; top: 24px; left: 50%; transform: translateX(-50%); z-index: 999;
  padding: 10px 28px; border-radius: 10px; font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.1);
  animation: fadeIn .25s ease;
}

/* 表格 */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 10px 8px;
  color: var(--muted); font-weight: 500; font-size: 12px;
  white-space: nowrap; border-bottom: 2px solid var(--border);
}
td { padding: 12px 8px; }
tr.data-row { border-bottom: 1px solid var(--border-l); }
tr.data-row:hover { background: var(--input-bg); }

.text-center { text-align: center; }
.text-right { text-align: right; }
.cat-desc-block { background: var(--input-bg); border-radius: var(--radius); padding: 16px; }

/* 移动端菜单 */
.mobile-menu-btn {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 100;
  width: 40px; height: 40px; border-radius: 10px; border: none;
  background: var(--sidebar); color: #fff; font-size: 18px;
  align-items: center; justify-content: center;
}

/* 侧边栏遮罩（移动端） */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 55;
  animation: fadeIn .2s ease;
}

/* ═══════════════════════════════════
   响应式
   ═══════════════════════════════════ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; z-index: 60;
    /* 手机浏览器的 100vh 把地址栏那块也算进去了，底部菜单会被截。
       dvh 是实际可视高度，不支持的老浏览器落回 vh。 */
    height: 100vh;
    height: 100dvh;
    box-shadow: 2px 0 16px rgba(0,0,0,.25);
  }
  .sidebar.collapsed { width: 0; overflow: hidden; box-shadow: none; }
  .mobile-menu-btn { display: flex; }
  /* 侧边栏展开时显示遮罩 */
  .sidebar-overlay.show { display: block; }
  .grid2, .grid21 { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; padding-left: 60px; }
  .content { padding: 16px; }
  .score-grid { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════
   手机端（≤640px）
   原来只有一条 900px 断点，表格、弹窗、内联网格都没处理，
   手机上表格撑破屏幕、弹窗贴边、两列表单挤成一团。
   ═══════════════════════════════════════ */
@media (max-width: 640px) {

  /* ── 表格：保持表格布局，让外层容器横向滚动 ──
     直接把 table 改成 block 会让列宽塌掉、字一个个竖着排，
     所以改成给表格设最小宽度、让装它的卡片滚动。 */
  table { min-width: 560px; }
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

  /* ── 案件卡片头部：标题和那排操作按钮竖排 ──
     只针对列表卡片。之前写成 .card > div[justify-content:space-between]
     范围太大，把编辑表单的标题栏也套进去了，"取消"被拉成整行。 */
  .card-head { flex-direction: column; align-items: stretch !important; }
  .card-actions { width: 100%; }

  /* ── 内联写死的多列网格一律压成一列 ──
     这些是在 JS 里拼出来的，改不到 class，只能按 style 属性匹配 */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns:1fr 2fr"] { grid-template-columns: 1fr !important; }

  /* ── 弹窗：占满全屏，不再留边和圆角 ── */
  .modal-overlay { padding: 0 !important; align-items: stretch !important; }
  .modal-panel {
    max-width: 100vw !important; width: 100% !important;
    max-height: 100% !important; height: 100% !important;
    border-radius: 0 !important;
    /* 兜底：不管里面什么东西想把面板顶宽，都不许溢出屏幕。
       横向滚动交给 .table-scroll 那一层去做。 */
    overflow-x: hidden;
  }
  .modal-panel[style*="padding:22px"] { padding: 16px !important; }

  /* flex 子元素默认 min-width:auto，里面那张 560px 的表格会把整个面板顶宽，
     结果头部的关闭按钮、底部的保存按钮全被挤出屏幕。这里强制允许收缩。 */
  .modal-panel, .modal-panel > div, .table-scroll { min-width: 0; }
  /* 头部和工具条允许换行，按钮不再被切掉 */
  .modal-panel > div[style*="display:flex"] { flex-wrap: wrap; }
  .modal-panel input, .modal-panel .input, .modal-panel select { max-width: 100%; }

  /* 分级选择器三列在手机上太窄，改成竖排 */
  #regionPickerOverlay .modal-panel > div[style*="display:flex"] { flex-direction: column; }
  #regionPickerOverlay .modal-panel > div[style*="display:flex"] > div {
    border-right: none !important; border-bottom: 1px solid var(--border-l);
    max-height: 33vh;
  }

  /* ── 统计卡：两列排，别一张占一行 ──
     四张卡竖着排要占掉大半屏，数字本身很短，两列足够看清。 */
  /* 用 flex 而不是 grid：老一点的浏览器内核对 grid 支持不全，
     flex 到处都认，两列效果一样。 */
  .grid4 { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
  .grid4 > * { flex: 1 1 calc(50% - 5px); min-width: 0; margin-bottom: 0 !important; }
  .metric { padding: 12px 14px; border-left-width: 3px; }
  .metric-label { font-size: 11px; margin-bottom: 4px; }
  .metric-val { font-size: 22px; }
  .metric-unit { font-size: 11px; }

  /* ── 工具栏：搜索占满一行，两个下拉平分一行，按钮各占一行宽度 ── */
  .page-toolbar { flex-direction: column; align-items: stretch !important; gap: 8px; }
  .toolbar-filters { display: flex; flex-wrap: wrap; gap: 8px; }
  .toolbar-filters > .input { flex: 1 1 100%; width: 100% !important; min-width: 0; }
  .toolbar-filters > .sel { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .toolbar-actions > button { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .toolbar-actions > .btn-primary { flex: 1 1 100%; }

  /* ── 卡片操作按钮：换行排成两排，不要横向滚动藏起来 ── */
  .card-actions { flex-wrap: wrap; overflow-x: visible; }
  .card-actions > button { flex: 1 1 calc(50% - 3px); min-width: 0; }

  /* ── 间距收紧 ── */
  .content { padding: 12px; }
  .card { padding: 14px; margin-bottom: 12px; }
  .topbar { padding: 10px 12px; padding-left: 56px; }

  /* ── 输入框：16px 以下 iOS 会自动放大页面 ── */
  .input, .sel, input, select, textarea { font-size: 16px; }

  /* ── 按钮加大点，手指点得到 ── */
  .btn-primary, .btn-outline { min-height: 38px; }
  .btn-sm { min-height: 32px; padding: 6px 12px; }

  /* ── 卡片里的操作按钮排成一行可横滑，不要挤到换行 ── */
  .card-actions { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
  .card-actions > button { flex-shrink: 0; }

  /* ── 子标签（概览/周检查/台账/行政例会）横向滚动，不换行 ── */
  .period-switch {
    display: flex !important; max-width: 100%;
    overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch;
  }
  .period-switch::-webkit-scrollbar { height: 0; }
  .period-btn { flex-shrink: 0; }
}

/* 打印样式 */
@media print {
  .sidebar, .topbar, .mobile-menu-btn { display: none !important; }
  body { background: #fff; overflow: visible; }
  .content { overflow: visible !important; padding: 0 !important; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}
