/* ExcelQuery 样式。零外部依赖，全部本地。 */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #2c2c2a;
  --muted: #5f5e5a;
  --hint: #888780;
  --border: rgba(0, 0, 0, 0.12);
  --border-strong: rgba(0, 0, 0, 0.2);
  --primary: #185fa5;
  --primary-bg: #e6f1fb;
  --danger: #a32d2d;
  --danger-bg: #fcebeb;
  --warn-bg: #faeeda;
  --warn-text: #633806;
  --radius: 10px;
  --sidebar: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  /* 抽屉关闭时用 translateX(100%) 藏到屏幕右侧，会撑宽文档，必须裁掉 */
  overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 500; font-size: 15px; color: var(--text); white-space: nowrap; }
.topbar .grow { flex: 1; }

.searchbox {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  min-width: 200px;
  max-width: 380px;
  flex: 1;
}
.searchbox input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  width: 100%;
  color: var(--text);
}

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: calc(100vh - 52px); width: 100%; max-width: 100vw; }

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  border-right: 0.5px solid var(--border);
  background: var(--surface);
  padding: 12px 8px;
  overflow-y: auto;
}
.sidebar h4 {
  font-size: 11px;
  font-weight: 400;
  color: var(--hint);
  margin: 12px 8px 6px;
}
.sidebar .item {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar .item:hover { background: var(--bg); text-decoration: none; }
.sidebar .item.active { background: var(--primary-bg); color: #0c447c; font-weight: 500; }
.sidebar .more { display: block; margin: 14px 8px 0; font-size: 12px; }

.main { flex: 1; min-width: 0; padding: 16px 20px 60px; }

/* ---------- 页头 ---------- */
.pagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.pagehead h1 { font-size: 18px; font-weight: 500; margin: 0; }
.pagehead .meta { font-size: 12px; color: var(--muted); }

/* ---------- 卡片 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card {
  display: block;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--text);
}
.card:hover { border-color: var(--border-strong); text-decoration: none; }
.card .name { font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.card .stat { font-size: 12px; color: var(--muted); }
.card .tag {
  display: inline-block;
  font-size: 11px;
  background: var(--bg);
  color: var(--muted);
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 6px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #144d86; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- 筛选条 ---------- */
.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 12px;
}
.filters select, .filters input {
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.filters .sortsel { margin-left: auto; }

/* ---------- 表格 ---------- */
.tablewrap {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th {
  text-align: left;
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
  padding: 9px 12px;
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
}
table.list td {
  padding: 9px 12px;
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
  vertical-align: top;
}
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: #fafaf8; }
table.list img.thumb { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; }

.empty { padding: 40px 16px; text-align: center; color: var(--hint); font-size: 13px; }

/* ---------- 分页 ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  border-top: 0.5px solid var(--border);
}

/* ---------- 抽屉 ---------- */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 40;
}
.drawer-mask.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 100%;
  background: var(--surface);
  border-left: 0.5px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.18s ease;
  z-index: 41;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 0.5px solid var(--border);
  font-weight: 500;
  flex: 0 0 auto;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.drawer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  border-top: 0.5px solid var(--border);
  flex: 0 0 auto;
}
.notice {
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="tel"],
.field input[type="email"],
.field textarea,
.field select {
  width: 100%;
  border: 0.5px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--primary-bg); border-color: var(--primary); }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.thumbs .ph {
  width: 64px; height: 64px;
  border-radius: 8px;
  background: var(--primary-bg);
  object-fit: cover;
  display: block;
}
.thumbs .add {
  width: 64px; height: 64px;
  border: 1px dashed var(--hint);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer; font-size: 20px;
  background: none; font-family: inherit;
}

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #2c2c2a;
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.2s;
  z-index: 60;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); }

/* ---------- 登录 ---------- */
.loginwrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.logincard {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 340px;
  max-width: 100%;
}
.logincard h1 { font-size: 16px; font-weight: 500; margin: 0 0 6px; }
.logincard p { font-size: 13px; color: var(--muted); margin: 0 0 18px; }

/* ---------- 移动端 ---------- */
@media (max-width: 760px) {
  .sidebar { display: none; }
  .main { padding: 12px 12px 80px; }
  .cards { grid-template-columns: 1fr; }

  /* 顶栏：藏掉站名，让搜索框吃满 */
  .topbar .brand { display: none; }
  .topbar .grow { display: none; }
  .searchbox { min-width: 0; flex: 1; }

  /* 页头：标题一行、按钮一行，避免右侧被挤出屏幕 */
  .pagehead { flex-direction: column; align-items: stretch; gap: 10px; }
  .pagehead > div:last-child { width: 100%; justify-content: flex-end; }
  .filters .sortsel { margin-left: 0; flex: 1 1 42%; }

  /* 筛选条：每个控件按行铺开 */
  .filters { gap: 6px; }
  .filters select, .filters input { flex: 1 1 42%; min-width: 0; }
  .filters button { flex: 0 0 auto; }

  table.list thead { display: none; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list tr {
    border-bottom: 0.5px solid var(--border);
    padding: 10px 12px;
  }
  table.list td {
    border: none;
    padding: 2px 0;
    display: flex;
    gap: 10px;
    font-size: 13px;
  }
  table.list td::before {
    content: attr(data-label);
    color: var(--hint);
    font-size: 12px;
    flex: 0 0 76px;
  }
  table.list td.primary-cell {
    font-size: 15px;
    font-weight: 500;
    padding-bottom: 4px;
  }
  table.list td.primary-cell::before { display: none; }

  .drawer { width: 100%; }
  .field input, .field textarea, .field select { font-size: 16px; }
  .drawer-foot .btn { padding: 10px 16px; }
  .toast { left: 16px; right: 16px; max-width: none; }
}

@media (max-width: 420px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .searchbox { min-width: 0; }
}
