/* ============================================================
   违规记录管理系统 · 样式
   ============================================================ */

:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --ink: #17191d;
  --ink-2: #4b525c;
  --muted: #7d8590;
  --line: #e0e3e8;
  --line-strong: #c9cfd6;
  --accent: #245680;
  --accent-ink: #ffffff;
  --accent-soft: #eaf1f7;
  --danger: #a03e3e;
  --danger-soft: #fbeeee;
  --ok: #2b6b4a;
  --ok-soft: #eaf4ee;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(20, 25, 32, .06), 0 8px 24px rgba(20, 25, 32, .05);
}

* { box-sizing: border-box; }

/* 必须放在这里：本文件里的 display 规则（grid / flex）会覆盖 UA 的 [hidden]，
   导致「未登录时主界面提前显示」这类问题 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------- 登录页 ---------------------------- */

.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(1000px 500px at 50% -10%, #e6edf4 0%, rgba(230, 237, 244, 0) 70%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 28px 28px 22px;
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }

.brand-mark {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .04em;
}

.brand-mark.small { width: 28px; height: 28px; font-size: 11px; border-radius: 6px; }

.brand-text h1 { font-size: 18px; margin: 0; font-weight: 600; letter-spacing: .01em; }
.brand-text p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

.login-hint {
  margin: 16px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

/* ---------------------------- 表单控件 ---------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: .01em;
}

.field .req { color: var(--danger); font-weight: 600; }
.field .opt { color: var(--muted); font-weight: 400; margin-left: 4px; font-size: 11.5px; }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input::placeholder, textarea::placeholder { color: #a5abb3; }

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; min-height: 38px; line-height: 1.55; }

/* ---------------------------- 按钮 ---------------------------- */

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  transition: background-color .15s, border-color .15s, color .15s, opacity .15s;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #1d486c; }
.btn-primary:disabled { opacity: .6; cursor: default; }

.btn-ghost { background: #fff; border-color: var(--line-strong); color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--ink-2); color: var(--ink); }

.btn-block { width: 100%; padding: 10px 16px; margin-top: 4px; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }

.btn-link {
  border: none; background: none; padding: 0;
  color: var(--accent); font-size: 12.5px; cursor: pointer; font-weight: 600;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }

/* ---------------------------- 顶栏 ---------------------------- */

.app-view { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title { font-weight: 600; font-size: 14.5px; letter-spacing: .01em; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { font-size: 12.5px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }

.role-tag {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ---------------------------- 两栏布局 ---------------------------- */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 18px;
  padding: 18px 20px 28px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 18px 14px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.panel-sub { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.panel-foot { margin: 12px 0 0; font-size: 12px; color: var(--muted); }
.panel-foot code { background: #f4f5f7; padding: 1px 4px; border-radius: 3px; font-size: 11.5px; }

/* ---------------------------- 录入表单 ---------------------------- */

.record-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
  padding: 14px;
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.record-form .span-2 { grid-column: span 2; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.form-tip { font-size: 12.5px; color: var(--ok); }
.form-tip.is-error { color: var(--danger); }

/* ---------------------------- 列表 ---------------------------- */

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 10px;
}

.list-head h3 { margin: 0; font-size: 14px; font-weight: 600; }

.count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
}

.search { width: 230px; max-width: 45%; padding: 6px 10px; font-size: 13px; }

.table-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }

.table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }

.table thead th {
  text-align: left;
  padding: 9px 10px;
  background: #f7f8fa;
  color: var(--ink-2);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid #eef0f3;
  vertical-align: top;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fbfcfd; }

.cell-strong { color: var(--ink); font-weight: 600; }
.cell-mono { font-family: Consolas, "Courier New", monospace; font-size: 12.5px; }

.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.muted-dash { color: #a8aeb6; }

.empty-state {
  padding: 26px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.col-actions { text-align: right !important; }
.row-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  white-space: nowrap;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}
.pager-info { font-size: 12.5px; color: var(--muted); }

/* 普通账号隐藏管理员列 */
#appView:not(.is-admin) .admin-only { display: none; }

/* ---------------------------- 账号统计 ---------------------------- */

.user-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fafbfc;
}
.stat span { display: block; font-size: 19px; font-weight: 700; line-height: 1.25; }
.stat label { display: block; font-size: 11.5px; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-admin { background: var(--accent-soft); color: var(--accent); }
.badge-normal { background: #f1f2f4; color: var(--ink-2); }
.badge-active { background: var(--ok-soft); color: var(--ok); }
.badge-disabled { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------- 弹窗 ---------------------------- */

.dlg {
  border: none;
  border-radius: 10px;
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 24px 60px rgba(15, 20, 26, .28);
}

.dlg::backdrop { background: rgba(18, 22, 28, .42); }

.dlg-form { padding: 20px 20px 16px; }

.dlg-form h3 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }

.dlg-note { margin: -6px 0 14px; font-size: 12.5px; color: var(--muted); }

.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.error-text {
  margin: 0 0 12px;
  padding: 7px 10px;
  background: var(--danger-soft);
  border: 1px solid #e7c9c9;
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 12.5px;
}

/* ---------------------------- 轻提示 ---------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(8px);
  background: #1f242b;
  color: #fff;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 100;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------------------- 响应式 ---------------------------- */

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; padding: 14px; gap: 14px; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 8px; }
  .topbar-right { gap: 8px; }
  .record-form { grid-template-columns: 1fr; }
  .record-form .span-2 { grid-column: span 1; }
  .search { width: 100%; max-width: 100%; }
  .list-head { flex-wrap: wrap; }
  .user-stats { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat { padding: 8px; }
  .stat span { font-size: 16px; }
  .login-card { padding: 22px 18px 18px; }

  /* 窄屏表格改为横向滚动，不压缩成不可读的一列 */
  .table-wrap { overflow-x: auto; }
  .table { min-width: 720px; }
}

@media print {
  .topbar, .record-form, .pager, .col-actions, .dlg, .toast { display: none !important; }
  .workspace { grid-template-columns: 1fr; }
  .panel { border: none; box-shadow: none; }
  body { background: #fff; }
}
