/* ============================================================
   水管处费用明细台账 · 全局样式
   主色 #2F3B52 / 背景 #E5EDF7（偏蓝）/ 文字 #333 / 强调 #FF8C42 / 预警 #E74C3C
   ============================================================ */

:root {
  --primary: #2F3B52;
  --primary-light: #3E4D6B;
  --primary-dark: #232D3F;
  --bg: #E5EDF7;
  --card: #FFFFFF;
  --text: #333333;
  --text-sub: #6B7488;
  --text-light: #9AA3B5;
  --accent: #FF8C42;
  --accent-dark: #F07826;
  --accent-soft: #FFF3E8;
  --danger: #E74C3C;
  --danger-soft: #FDECEA;
  --success: #27AE60;
  --success-soft: #E8F8EF;
  --border: #E6E9F0;
  --border-strong: #D3D8E3;
  --sidebar-w: 240px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(47, 59, 82, 0.06), 0 4px 16px rgba(47, 59, 82, 0.05);
  --shadow-lg: 0 8px 32px rgba(47, 59, 82, 0.16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }

/* ---------------- 侧边栏 ---------------- */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--primary);
  color: #fff;
  display: flex; flex-direction: column;
  z-index: 100;
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
  box-shadow: 2px 0 12px rgba(0, 0, 0, .06);
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.brand-icon {
  width: 38px; height: 38px; flex-shrink: 0;
  background: rgba(255, 255, 255, .12);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.brand-text { flex: 1; min-width: 0; }
.brand-title { font-size: 15px; font-weight: 600; letter-spacing: .3px; }
.brand-sub { font-size: 12px; color: rgba(255, 255, 255, .55); margin-top: 1px; }
.sidebar-close {
  display: none;
  width: 32px; height: 32px; flex-shrink: 0;
  background: rgba(255, 255, 255, .12); border: none; border-radius: 8px;
  color: #fff; font-size: 15px; cursor: pointer;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .18); border-radius: 3px; }

.nav-group-label {
  font-size: 11px; color: rgba(255, 255, 255, .4);
  padding: 12px 12px 6px; letter-spacing: 1px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; min-height: 44px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, .78);
  cursor: pointer;
  margin-bottom: 2px;
  font-size: 14.5px;
  transition: background .18s, color .18s;
  user-select: none;
  border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-item.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(255, 140, 66, .35);
}
.nav-item .nav-emoji { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-item .nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .lock-badge { font-size: 12px; opacity: .7; }

.static-note {
  margin: 14px 8px 0;
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.6;
  color: rgba(255, 255, 255, .65);
  background: rgba(255, 255, 255, .06);
  border-radius: 10px;
  border: 1px dashed rgba(255, 255, 255, .15);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, .1);
}
.db-status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: rgba(255, 255, 255, .6); }
.db-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-light); flex-shrink: 0; }
.db-status.ok .dot { background: #2ECC71; box-shadow: 0 0 0 3px rgba(46, 204, 113, .22); }
.db-status.err .dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(231, 76, 60, .22); }
.db-status .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- 手机端顶部栏 ---------------- */
.mobile-topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; height: 56px;
  background: var(--primary);
  color: #fff;
  align-items: center;
  padding: 0 8px 0 4px;
  z-index: 90;
  box-shadow: 0 1px 8px rgba(0, 0, 0, .12);
}
.hamburger {
  width: 44px; height: 44px;
  background: transparent; border: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; padding: 0;
}
.hamburger span {
  display: block; width: 20px; height: 2px;
  background: #fff; border-radius: 2px; transition: .25s;
}
.mobile-title {
  flex: 1; text-align: center; font-size: 16px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 44px;
}
.topbar-spacer { width: 0; }

/* ---------------- 遮罩 ---------------- */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(23, 30, 43, .5);
  z-index: 95;
  opacity: 0; transition: opacity .28s;
}
.overlay.show { display: block; opacity: 1; }

/* ---------------- 主内容区 ---------------- */
.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 24px;
  transition: margin-left .28s cubic-bezier(.4, 0, .2, 1);
}
.page { max-width: 1240px; margin: 0 auto; }

/* ---------------- 页头 ---------------- */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.page-title { font-size: 24px; font-weight: 700; margin: 0; color: var(--primary); letter-spacing: .3px; }
.page-desc { font-size: 13px; color: var(--text-sub); margin-top: 4px; }
.page-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
  border: 1px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
.card-title {
  font-size: 16px; font-weight: 600; color: var(--primary);
  margin: 0 0 14px; display: flex; align-items: center; gap: 8px;
}

/* ---------------- 统计卡片网格 ---------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s, border-color .2s;
  position: relative;
  overflow: hidden;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card.warn-half { border-color: var(--accent); }
.stat-card.warn-full { border-color: var(--danger); }

.stat-card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.stat-emoji {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.stat-name { font-size: 16px; font-weight: 600; color: var(--primary); }
.stat-sub { font-size: 12px; color: var(--text-light); }

.stat-rows { display: flex; flex-direction: column; gap: 7px; }
.stat-row { display: flex; align-items: baseline; justify-content: space-between; font-size: 13.5px; }
.stat-row .k { color: var(--text-sub); }
.stat-row .v { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-row .v.accent { color: var(--accent); font-size: 15px; }
.stat-row .v.warn-half { color: var(--accent); font-size: 15px; }
.stat-row .v.warn-full { color: var(--danger); font-size: 15px; }

.progress {
  height: 8px; background: #EDF0F6; border-radius: 5px;
  overflow: hidden; margin-top: 14px;
}
.progress-bar {
  height: 100%; border-radius: 5px;
  background: var(--primary);
  transition: width .6s cubic-bezier(.4, 0, .2, 1), background .3s;
}
.progress-bar.warn-half { background: var(--accent); }
.progress-bar.warn-full { background: var(--danger); }

.stat-foot {
  margin-top: 12px; display: flex; align-items: center; justify-content: space-between;
}
.btn-detail {
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: 0 16px; min-height: 44px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .18s;
}
.btn-detail:hover { background: var(--primary-light); }

/* ---------------- 预警通知条 ---------------- */
.alert-zone { max-width: 1240px; margin: 0 auto 16px; }
.alert-bar {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  margin-bottom: 10px; font-size: 14px;
  background: var(--accent-soft); color: #B35A15;
  border-left: 4px solid var(--accent);
}
.alert-bar.danger { background: var(--danger-soft); color: #A93226; border-left-color: var(--danger); }
.alert-bar .icon { font-size: 16px; flex-shrink: 0; line-height: 1.5; }
.alert-bar .body { flex: 1; }
.alert-bar strong { font-weight: 600; }

.banner-db {
  background: #FFF8E1; border-left: 4px solid #F5B041;
  color: #7D5A00; padding: 14px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; line-height: 1.7; margin-bottom: 16px;
}
.banner-db code {
  background: rgba(0, 0, 0, .06); padding: 1px 6px; border-radius: 4px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
}

/* ---------------- 筛选标签 ---------------- */
.filter-tabs {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px;
}
.filter-tab {
  min-height: 44px; padding: 0 16px;
  background: var(--card); color: var(--text-sub);
  border: 1.5px solid var(--border-strong); border-radius: 22px;
  font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .18s;
}
.filter-tab:hover { border-color: var(--primary); color: var(--primary); }
.filter-tab.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
  font-weight: 600;
}

/* ---------------- 表单 ---------------- */
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px;
}
.form-item { display: flex; flex-direction: column; gap: 7px; }
.form-item.full { grid-column: 1 / -1; }
.form-label { font-size: 13.5px; font-weight: 600; color: var(--primary); }
.form-label .req { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%; min-height: 44px;
  padding: 10px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color .18s, box-shadow .18s;
  font-size: 14.5px;
}
.form-control:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 140, 66, .14);
}
select.form-control { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B7488' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 34px;
}
textarea.form-control { min-height: 76px; resize: vertical; }
.form-hint { font-size: 12px; color: var(--text-light); }

/* ---------------- 按钮 ---------------- */
.btn {
  min-height: 44px; padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  font-size: 14.5px; font-weight: 500;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: all .18s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-dark { background: var(--primary); color: #fff; }
.btn-dark:hover { background: var(--primary-light); }
.btn-outline { background: #fff; color: var(--primary); border-color: var(--border-strong); }
.btn-outline:hover { border-color: var(--primary); background: #F8F9FC; }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.table-wrap::-webkit-scrollbar { height: 7px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
table.data-table { width: 100%; border-collapse: collapse; min-width: 560px; font-size: 14px; }
table.data-table th {
  background: #F7F8FC; color: var(--primary);
  font-weight: 600; text-align: left;
  padding: 12px 14px; white-space: nowrap;
  border-bottom: 2px solid var(--border);
  font-size: 13.5px;
}
table.data-table td {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
table.data-table tbody tr:hover { background: #FAFBFD; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data-table .amt { font-weight: 600; color: var(--accent); }
table.data-table .muted { color: var(--text-light); }
.empty-row td { text-align: center; padding: 40px 14px; color: var(--text-light); font-size: 14px; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 500;
  background: #EEF1F7; color: var(--text-sub);
  white-space: nowrap;
}
.tag.orange { background: var(--accent-soft); color: var(--accent-dark); }
.tag.red { background: var(--danger-soft); color: var(--danger); }
.tag.green { background: var(--success-soft); color: var(--success); }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- 弹窗 ---------------- */
.modal-root { position: fixed; inset: 0; z-index: 200; pointer-events: none; }
.modal-mask {
  position: absolute; inset: 0;
  background: rgba(23, 30, 43, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  pointer-events: auto;
  animation: fadeIn .2s ease;
  overflow-y: auto;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: #fff; border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px;
  max-height: 90vh; display: flex; flex-direction: column;
  animation: popIn .24s cubic-bezier(.34, 1.4, .64, 1);
  margin: auto;
}
.modal.lg { max-width: 860px; }
@keyframes popIn { from { opacity: 0; transform: scale(.94) translateY(12px) } to { opacity: 1; transform: none } }
.modal-head {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0;
}
.modal-title { font-size: 17px; font-weight: 600; color: var(--primary); margin: 0; }
.modal-close {
  width: 36px; height: 36px; border: none; background: #F2F4F9;
  border-radius: 8px; cursor: pointer; font-size: 16px; color: var(--text-sub);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.modal-close:hover { background: var(--border); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; flex-wrap: wrap;
}

/* ---------------- Toast ---------------- */
.toast-root {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 10px;
  align-items: center; pointer-events: none; width: max-content; max-width: 90vw;
}
.toast {
  background: var(--primary); color: #fff;
  padding: 11px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow-lg);
  animation: toastIn .28s cubic-bezier(.34, 1.4, .64, 1);
  display: flex; align-items: center; gap: 7px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) } to { opacity: 1; transform: none } }

/* ---------------- 图表 ---------------- */
.chart-box { width: 100%; overflow-x: auto; }
.chart-canvas { display: block; width: 100%; }
.chart-legend {
  display: flex; gap: 18px; justify-content: center;
  margin-top: 12px; font-size: 13px; color: var(--text-sub); flex-wrap: wrap;
}
.chart-legend .item { display: flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 14px; height: 4px; border-radius: 2px; }

/* ---------------- 拍照录入 ---------------- */
.upload-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 40px 20px; text-align: center;
  background: #FAFBFD; cursor: pointer;
  transition: all .2s; min-height: 180px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent); background: var(--accent-soft);
}
.upload-zone .uz-icon { font-size: 42px; }
.upload-zone .uz-title { font-size: 15px; font-weight: 600; color: var(--primary); }
.upload-zone .uz-sub { font-size: 13px; color: var(--text-sub); }

.preview-box {
  margin-top: 16px; text-align: center;
  display: none;
}
.preview-box.show { display: block; }
.preview-box img {
  max-width: 100%; max-height: 280px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}

.ocr-raw {
  margin-top: 14px; padding: 12px 14px;
  background: #F7F8FC; border-radius: var(--radius-sm);
  font-size: 12.5px; color: var(--text-sub);
  white-space: pre-wrap; word-break: break-all; max-height: 160px; overflow-y: auto;
  font-family: ui-monospace, Consolas, monospace;
}

.field-flag { font-size: 12px; margin-left: 6px; }
.field-flag.hit { color: var(--success); }
.field-flag.miss { color: var(--text-light); }

/* ---------------- 杂项 ---------------- */
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hint-box {
  background: #F7F8FC; border-left: 3px solid var(--primary);
  padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text-sub); line-height: 1.8;
}
.spinner {
  display: inline-block; width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
.loading-wrap { padding: 60px 20px; text-align: center; color: var(--text-light); font-size: 14px; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); width: 264px; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; align-items: center; justify-content: center; }
  .mobile-topbar { display: flex; }
  .main { margin-left: 0; padding: 68px 14px 24px; }
  .stat-grid { grid-template-columns: 1fr; gap: 14px; }
  .card { padding: 16px; border-radius: 10px; }
  .page-title { font-size: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-mask { padding: 12px; align-items: flex-start; }
  .modal { max-height: 94vh; }
  .btn { flex: 1; min-width: 130px; }
  .btn-row .btn { flex: 1; }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn { flex: 1; }
  .toast-root { top: 66px; }
}

@media (max-width: 420px) {
  .main { padding: 64px 12px 20px; }
  .btn { padding: 0 12px; font-size: 14px; }
  .filter-tab { padding: 0 13px; font-size: 13.5px; }
  table.data-table { font-size: 13.5px; }
  table.data-table th, table.data-table td { padding: 10px 11px; }
}

@media (min-width: 901px) {
  .overlay { display: none !important; }
}
