/* ============================================================
   BD 线索台 — Dashforge-inspired
   参考：Dashforge v2.0 (ThemePixels) 设计系统
   基调：白底、4px 圆角、38px 控件、IBM Plex 风格字体
   ============================================================ */

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

:root {
  /* Color Tokens — Dashforge palette adapted */
  --ink:        #001737;   /* 主文字 */
  --ink-soft:   #1b2e4b;   /* 辅文字 */
  --ink-muted:  #8392a5;   /* 弱文字 */
  --surface:    #FFFFFF;   /* 卡片/表格背景 */
  --page-bg:    #f5f6fa;   /* 页面底色 */
  --border:     rgba(72, 94, 144, 0.16); /* 细线 */
  --border-strong: #c0ccda;/* 强线 */
  --navy:       #1E2E68;   /* 主色 */
  --navy-hover: #2A3E82;   /* 悬停 */
  --blue:       #0168fa;   /* 强调蓝 */
  --blue-subtle:#eef3fc;   /* 蓝底 */
  --teal:       #1ce1ac;   /* 交易绿 */
  --teal-subtle:#e8faf5;   /* 绿底 */
  --amber:      #f49917;   /* 警示 */
  --amber-subtle:#fef5e7;  /* 琥珀底 */
  --red:        #dc3545;   /* 危险红 */
  --red-subtle: #fef2f3;   /* 红底 */
  --gray-subtle:#ebeef3;   /* 灰底（表头/斑马） */

  /* Typography */
  --font-ui:      "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono:    "SF Mono", "JetBrains Mono", "Menlo", "Consolas", monospace;

  /* Spacing & Sizing */
  --gutter: 28px;
  --radius:   4px;    /* Dashforge: 0.25rem */
  --ctrl-h:   38px;   /* Dashforge: $height-base */

  /* Shadows */
  --shadow-sm: 0 0 10px rgba(28,39,60,0.05);
  --shadow-md: 0 0 15px rgba(28,39,60,0.08);

  /* Transitions */
  --ease: 150ms ease;
}

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

body {
  font-family: var(--font-ui);
  font-size: 1rem;        /* 16px */
  line-height: 1.5;
  color: var(--ink);
  background: var(--page-bg);
  min-height: 100vh;
}

/* ---- Skip Link ---- */
.skip-link {
  position: absolute;
  top: -100px;
  left: 8px;
  z-index: 1000;
  padding: 8px 16px;
  background: var(--navy);
  color: #fff;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 0.9375rem;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

/* ---- Typography ---- */
h1 {
  font-size: 1.5rem;      /* 24px */
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
}
h2 {
  font-size: 1.125rem;    /* 18px */
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}
h3 {
  font-size: 0.9375rem;   /* 15px */
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}
.sub      { font-size: 0.9375rem; color: var(--ink-muted); margin-top: 2px; }
.muted    { color: var(--ink-muted); }
a         { color: var(--blue); text-decoration: none; }
a:hover   { text-decoration: underline; }

/* ---- Top Bar ---- */
.topbar {
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  height: 55px;          /* Dashforge header height */
}
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  height: 100%;
  gap: 20px;
}

.brand {
  font-size: 1.125rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  text-decoration: none;
  letter-spacing: 0.02em;
}
.brand em {
  font-style: normal;
  color: var(--teal);
  font-weight: 400;
  font-size: 0.9375rem;
  margin-left: 4px;
  letter-spacing: 0.04em;
}
.brand:hover { text-decoration: none; opacity: 0.9; }

.main-nav {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
}
.main-nav a {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  border-radius: var(--radius);
  text-decoration: none;
  transition: background var(--ease), color var(--ease);
  white-space: nowrap;
}
.main-nav a:hover {
  color: #fff;
  background: rgba(255,255,255,0.08);
  text-decoration: none;
}
.main-nav a.active {
  color: #fff;
  background: rgba(255,255,255,0.14);
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-shrink: 0;
}
.role-badge {
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.03em;
}
.nav-toggle { display: none; }

/* ---- User Menu ---- */
.user-menu    { position: relative; }
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 5px;
  z-index: 200;
}
.user-dropdown a {
  display: block;
  padding: 8px 14px;
  font-size: 0.9375rem;
  color: var(--ink);
  border-radius: var(--radius);
  text-decoration: none;
}
.user-dropdown a:hover { background: var(--gray-subtle); text-decoration: none; }
.user-logout {
  display: block; width: 100%; text-align: left; padding: 9px 12px;
  border: none; background: transparent; border-radius: var(--radius-md);
  color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
}
.user-logout:hover { background: var(--gray-subtle); }
.form-field ul {
  list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px;
  padding: 6px 0 0; margin: 0;
}
.form-field ul li { display: flex; align-items: center; gap: 6px; }
.form-field input[type="date"] { min-height: 32px; padding: 4px 10px; }
.form-field input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--blue, #0168fa); }
.page-ellipsis {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px; padding: 0 4px;
  font-size: 13px; color: var(--ink-muted); user-select: none;
}
.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--blue, #0168fa); }
.col-hidden { display: none; }
.td-actions .btn-ghost { border-color: var(--border-strong); }

/* ---- Icon Button ---- */
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: inherit;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--ease);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }
.icon-btn .icon { width: 20px; height: 20px; }

/* ---- Page Layout ---- */
.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--gutter);
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head .sub { margin-top: 4px; }
.head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--ctrl-h);
  padding: 0 16px;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--ease);
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
  border-color: var(--border-strong);
}
.btn:hover {
  background: var(--gray-subtle);
  text-decoration: none;
}
.btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.btn-primary:hover { background: var(--navy-hover); border-color: var(--navy-hover); }

.btn-accent {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.btn-accent:hover { background: #0158d6; border-color: #0158d6; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}
.btn-ghost:hover { background: var(--gray-subtle); color: var(--ink); }

.btn-danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--red);
}
.btn-danger-ghost:hover { background: var(--red-subtle); }

.btn-sm { height: 30px; padding: 0 10px; font-size: 0.875rem; }

/* ---- Filter Bar ---- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-bar:has(.filter-row) {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
}
.filter-row--secondary {
  border-top: 1px solid var(--border);
}
.filter-row--primary .search-wrap {
  flex: 1;
  max-width: 480px;
}

.search-wrap {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}

.search-input {
  width: 100%;
  height: var(--ctrl-h);
  padding: 0 12px;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.search-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 0.2rem rgba(1,104,250,0.25);
}
.search-input::placeholder { color: var(--ink-muted); }

#regionInput { width: 140px; flex-shrink: 0; }

/* ---- Form Controls ---- */
select {
  height: var(--ctrl-h);
  padding: 0 32px 0 12px;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238392a5' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--ink);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 0.2rem rgba(1,104,250,0.25);
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
input[type="file"] {
  height: var(--ctrl-h);
  padding: 0 12px;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  transition: border-color var(--ease), box-shadow var(--ease);
}
input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 0.2rem rgba(1,104,250,0.25);
}
input::placeholder { color: var(--ink-muted); }
input.invalid {
  border-color: var(--red);
  box-shadow: 0 0 0 0.2rem rgba(220,53,69,0.25);
}

textarea {
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  resize: vertical;
  min-height: 56px;
  transition: border-color var(--ease), box-shadow var(--ease);
}
textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 0.2rem rgba(1,104,250,0.25);
}

/* ---- Range Inputs ---- */
.range-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--ctrl-h);
  padding: 0 10px;
  font-size: 0.875rem;
  color: var(--ink-soft);
  white-space: nowrap;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.range-inputs span:first-child {
  font-weight: 500;
  margin-right: 2px;
}
.range-inputs input[type="number"] {
  width: 68px;
  height: auto;
  padding: 0 4px;
  border: none;
  background: transparent;
  font-size: 0.9375rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}
.range-inputs input[type="number"]:focus {
  outline: none;
  box-shadow: none;
}

/* ---- Table ---- */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  line-height: 1.5;
}
.data-table thead {
  background: var(--gray-subtle);
}
.data-table th {
  padding: 9px 14px;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
}
.data-table th.sortable:hover {
  color: var(--ink);
  background: rgba(0,0,0,0.03);
}
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  white-space: nowrap;
}
.data-table td.trunc {
  white-space: nowrap;
}
.data-table tbody tr:hover {
  background: rgba(1,104,250,0.02);
}
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 0.875rem;
}
.data-table td.trunc {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.th-actions, .td-actions { text-align: right; white-space: nowrap; }
.data-table th:last-child { text-align: center; }
.td-actions .btn { margin-left: 4px; }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: 100px;
  white-space: nowrap;
  line-height: 1.6;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.badge-gray   { background: var(--gray-subtle); color: var(--ink-soft); }
.badge-gray::before   { background: var(--ink-muted); }
.badge-blue   { background: var(--blue-subtle); color: var(--blue); }
.badge-blue::before   { background: var(--blue); }
.badge-green  { background: var(--teal-subtle); color: #0b6e54; }
.badge-green::before  { background: var(--teal); }
.badge-dark   { background: #e4e7ed; color: var(--ink); }
.badge-dark::before   { background: var(--ink); }
.badge-amber  { background: var(--amber-subtle); color: #b86d08; }
.badge-amber::before  { background: var(--amber); }

/* ---- Tags ---- */
.tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.9375rem;
  font-weight: 500;
  background: var(--gray-subtle);
  color: var(--ink-soft);
  border-radius: 3px;
  margin: 1px 3px 1px 0;
}

/* ---- Pagination ---- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.pager .jump {
  margin-left: 16px;
  font-size: 0.875rem;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.pager .jump input {
  width: 52px;
  height: 32px;
  padding: 0 6px;
  text-align: center;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}

/* ---- Detail Page ---- */
.detail-section { margin-bottom: 16px; }
.detail-section h3 {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 24px;
}
.detail-row {
  display: flex;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9375rem;
  line-height: 1.5;
}
.detail-row:last-child,
.detail-row:nth-last-child(2):nth-child(odd) {
  border-bottom: none;
}
.detail-label {
  width: 150px;
  flex-shrink: 0;
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 0.875rem;
  padding-right: 16px;
}
.detail-value { flex: 1; color: var(--ink); word-break: break-word; }
.detail-value .tag { font-size: 0.9375rem; }

.history-list { list-style: none; font-size: 0.875rem; }
.history-list li {
  display: flex;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  color: var(--ink-soft);
}
.history-list li:last-child { border-bottom: none; }
.history-list span { flex-shrink: 0; width: 130px; font-size: 0.8125rem; color: var(--ink-muted); }
.history-list b    { flex-shrink: 0; width: 60px; color: var(--ink); font-size: 0.875rem; }

/* ---- Home Page ---- */
.desk-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
}
.desk-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}
.live-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--teal);
  flex-shrink: 0;
}
.microlabel { font-size: 0.875rem; color: var(--ink-muted); letter-spacing: 0.03em; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.stat-card:hover {
  border-color: var(--blue);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}
.stat-card .icon { width: 28px; height: 28px; color: var(--ink-muted); flex-shrink: 0; }
.stat-num {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.stat-label { font-size: 0.875rem; color: var(--ink-muted); margin-top: 2px; }

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.home-grid .card h2 { margin-bottom: 14px; }

.recent-list { list-style: none; }
.recent-list li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.recent-list li:last-child { border-bottom: none; }
.recent-list a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.9375rem;
}
.recent-list a:hover { color: var(--blue); text-decoration: none; }
.recent-list b { font-weight: 500; }
.recent-list .muted { font-size: 0.875rem; }

/* ---- Login Page ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: var(--page-bg);
}
.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 44px 40px;
  box-shadow: var(--shadow-md);
}
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card > .sub { text-align: center; margin-bottom: 32px; }

.role-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
.role-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
  text-align: center;
}
.role-card:hover { border-color: var(--blue); }
.role-card.selected {
  border-color: var(--navy);
  background: rgba(30,46,104,0.04);
}
.role-card input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }
.role-name { font-weight: 600; font-size: 0.875rem; color: var(--ink); }
.role-desc { font-size: 0.875rem; color: var(--ink-muted); }

.login-field { margin-bottom: 16px; }
.login-field label {
  display: block;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.login-field input { width: 100%; height: var(--ctrl-h); font-size: 0.875rem; }
.login-error { font-size: 0.9375rem; color: var(--red); min-height: 20px; margin-bottom: 12px; }
.login-hint {
  margin-top: 24px;
  padding: 12px 14px;
  background: var(--gray-subtle);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--ink-muted);
  line-height: 1.5;
  text-align: center;
}

/* ---- Error Page ---- */
.error-wrap {
  min-height: calc(100vh - 55px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.error-card { text-align: center; max-width: 420px; }
.err-code {
  font-size: 5rem;
  font-weight: 700;
  color: var(--border-strong);
  line-height: 1;
  margin-bottom: 8px;
}
.error-card h1 { margin-bottom: 8px; }
.error-card p { color: var(--ink-soft); margin-bottom: 24px; font-size: 0.875rem; }

/* ---- Query Page ---- */
.query-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.query-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.query-toolbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}
.query-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.query-field {
  display: flex;
  align-items: center;
  gap: 6px;
}
.query-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-muted);
  white-space: nowrap;
}

.check-line {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.check-line input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--navy);
  cursor: pointer;
}

.query-conds-label {
  padding: 10px 20px 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#condRows { display: flex; flex-direction: column; padding: 6px 20px 14px; }
.cond-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.cond-row:last-child { border-bottom: none; }
.cond-and {
  width: 32px;
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--ink-muted);
  letter-spacing: 0.1em;
  text-align: center;
}
.cond-f, .cond-op { min-width: 110px; }
.cond-values {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
}
.cond-values input { width: 130px; }
.cond-del {
  flex-shrink: 0;
  color: var(--ink-muted);
  opacity: 0.4;
  transition: opacity var(--ease), color var(--ease);
  margin-left: auto;
}
.cond-del:hover { opacity: 1; color: var(--red); }

/* ---- Edit / Form ---- */
.form-section { margin-bottom: 20px; border: none; }
.form-section legend {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink);
  padding-bottom: 8px;
  margin-bottom: 14px;
  width: 100%;
  border-bottom: 1px solid var(--border);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px 18px;
}
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-soft);
}
.form-field label em { color: var(--red); font-style: normal; }
.form-field input,
.form-field select,
.form-field textarea { width: 100%; }
.field-error { font-size: 0.875rem; color: var(--red); min-height: 16px; }

.check-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 4px 0;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ---- Admin ---- */
.admin-tabs {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--gray-subtle);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow-x: auto;
}
.admin-tab {
  padding: 8px 18px;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--ease), color var(--ease);
}
.admin-tab:hover { color: var(--ink); }
.admin-tab.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.admin-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.audit-detail {
  font-size: 0.875rem;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.role-select {
  min-width: auto;
  width: 100px;
  padding: 0 24px 0 8px;
  font-size: 0.875rem;
  height: 32px;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,23,55,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 150ms ease;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0,0,0,0.15);
  max-width: 480px;
  width: 100%;
  animation: scaleIn 200ms ease;
}
.modal-overlay.out { animation: fadeOut 150ms ease forwards; }
.modal-overlay.out .modal { animation: scaleOut 150ms ease forwards; }
.modal-body { padding: 24px 28px 16px; }
.modal-body h3 {
  font-size: 1.0625rem;
  margin-bottom: 8px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 28px 20px;
}
.modal-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.modal-form label {
  font-size: 0.9375rem;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.modal-form input,
.modal-form select { width: 100%; }

/* ---- Toast ---- */
.toast-box {
  position: fixed;
  top: 71px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: slideIn 200ms ease;
}
.toast.out { animation: slideOut 200ms ease forwards; }
.toast-info    { background: var(--navy); color: #fff; }
.toast-success { background: #0b6e54; color: #fff; }
.toast-error   { background: var(--red); color: #fff; }

/* ---- Cols Panel ---- */
.cols-wrap { position: relative; }
.cols-panel {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 8px;
  z-index: 50;
  flex-direction: column;
  gap: 2px;
}
.cols-panel.open { display: flex; }

/* ---- Empty State ---- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 20px;
  color: var(--ink-muted);
  text-align: center;
  font-size: 0.875rem;
}
.empty .icon { width: 36px; height: 36px; opacity: 0.4; }

/* ---- Mobile Card List ---- */
.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}
.card-head b { font-size: 0.875rem; font-weight: 600; }
.card-head .muted { display: block; font-size: 0.875rem; margin-top: 2px; }
.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin-bottom: 10px;
}
.card-field { font-size: 0.875rem; }
.card-field span { color: var(--ink-muted); margin-right: 6px; }
.card-field b { font-weight: 500; color: var(--ink); }
.card-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ---- Import Report ---- */
#importReport {
  background: var(--gray-subtle);
  border-radius: var(--radius);
  padding: 16px;
}
#importReport h3 {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.875rem;
  color: var(--ink);
}

/* ---- Keyboard & Accessibility ---- */
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ---- Animations ---- */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes scaleIn  { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes scaleOut { from { transform: scale(1); opacity: 1; } to { transform: scale(0.96); opacity: 0; } }
@keyframes slideIn  { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

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

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .home-grid { grid-template-columns: 1fr; }
  .form-grid  { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  :root { --gutter: 16px; }

  .nav-toggle { display: flex; color: rgba(255,255,255,0.8); }
  .main-nav {
    display: none;
    position: absolute;
    top: 55px;
    left: 0; right: 0;
    flex-direction: column;
    background: var(--navy);
    padding: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  }
  .main-nav.open { display: flex; }

  .filter-bar,
  .filter-bar:has(.filter-row) {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-row { flex-direction: column; align-items: stretch; }
  .filter-row--primary .search-wrap { max-width: none; }
  .search-wrap { max-width: none; }
  #regionInput { width: 100%; }

  .stat-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 14px; }

  .detail-grid { grid-template-columns: 1fr; }
  .detail-row { flex-direction: column; gap: 2px; border-bottom: 1px solid var(--border); }
  .detail-row:last-child { border-bottom: none; }
  .detail-row:nth-last-child(2):nth-child(odd) { border-bottom: 1px solid var(--border); }
  .detail-label { width: auto; }

  .form-grid { grid-template-columns: 1fr; }

  .role-cards { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .role-card  { padding: 10px 6px; }

  .query-toolbar { flex-direction: column; align-items: stretch; }
  .query-toolbar-left { flex-direction: column; align-items: stretch; }
  .cond-row { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 0; }
  .cond-and   { width: auto; text-align: left; }
  .cond-values { flex-direction: column; align-items: stretch; }
  .cond-values input { width: 100%; }

  .page-head { flex-direction: column; }
  .head-actions { flex-wrap: wrap; }

  .topbar-inner { padding: 0 12px; gap: 12px; }
  .brand { font-size: 1rem; }

  .login-card { padding: 28px 20px; }
  .modal { margin: 0 8px; }
}

@media (max-width: 480px) {
  .role-cards { grid-template-columns: 1fr; }
  .pager { gap: 2px; }
  .pager .jump { margin-left: 4px; }
}
