:root {
  --bg: #f4f6fa;
  --card: #fff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --green: #15803d;
  --red: #b91c1c;
  --side: #111827;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 200px; background: var(--side); color: #fff; padding: 20px 12px;
  flex-shrink: 0; position: sticky; top: 0; height: 100vh;
}
.logo { font-size: 17px; font-weight: 700; padding: 4px 12px 20px; white-space: nowrap; }
nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  background: none; border: 0; color: #cbd5e1; text-align: left; font-family: inherit;
  padding: 10px 12px; border-radius: 8px; font-size: 15px; cursor: pointer; white-space: nowrap;
}
.nav-item:hover { background: #1f2937; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }

/* ---------- 主区域 ---------- */
main { flex: 1; padding: 28px 32px; min-width: 0; }
.view { display: none; }
.view.active { display: block; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 4px; font-size: 22px; }
.page-head p { margin: 0; }
.head-actions { display: flex; gap: 8px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text); font-family: inherit;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #f9fafb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn-text {
  background: none; border: 0; color: var(--primary); cursor: pointer;
  padding: 4px 6px; font-size: 13px; font-family: inherit; white-space: nowrap;
}
.btn-text:hover { text-decoration: underline; }
.btn-text.danger { color: var(--danger); }
.icon-btn {
  background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted);
  cursor: pointer; padding: 2px 6px; border-radius: 6px;
}
.icon-btn:hover { background: #f3f4f6; color: var(--text); }

/* ---------- 卡片 / 统计 ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px 20px;
  border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(0, 0, 0, .04); margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 12px; padding: 1px 8px; }
.notice { background: #fffbeb; border-color: #fde68a; color: #92400e; line-height: 1.6; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 22px; font-weight: 700; margin: 6px 0 2px; }
.stat-sub { color: var(--muted); font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- 列表 ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 8px; border-bottom: 1px solid #f1f5f9;
}
.list li:last-child { border-bottom: 0; }
.grow { flex: 1; min-width: 160px; }
.right { text-align: right; }
.row-link { cursor: pointer; border-radius: 6px; }
.row-link:hover { color: var(--primary); }
.row-btns { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
li.empty { justify-content: center; color: var(--muted); padding: 20px; }

.seat-list li { background: #fff; }
.seat-list li.seat-empty { background: #f9fafb; border: 1px dashed #cbd5e1; border-radius: 8px; margin-top: 6px; }

details.ended { margin-top: 10px; }
details.ended summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 4px 0; }
details.ended li { color: var(--muted); }

.tag {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px;
  background: #f1f5f9; color: #475569; white-space: nowrap; font-weight: normal;
}
.tag.ok { background: #dcfce7; color: var(--green); }
.tag.warn { background: #fef3c7; color: #b45309; }
.tag.danger { background: #fee2e2; color: var(--red); }
.tag.income { background: #dcfce7; color: var(--green); }
.tag.cost { background: #fee2e2; color: var(--red); }

.secret { font-family: Consolas, Menlo, monospace; }
.form-section {
  grid-column: 1 / -1; font-weight: 600; font-size: 13px; color: var(--primary);
  padding-bottom: 4px; border-bottom: 1px solid var(--line); margin-top: 6px;
}
.form-section:first-child { margin-top: 0; }
.emp-info { display: flex; align-items: flex-end; padding-bottom: 10px; }
.new-emp {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  background: #f9fafb; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 12px;
}
.new-emp.hidden { display: none; }
@media (max-width: 520px) { .new-emp { grid-template-columns: 1fr; } }
.seats { font-weight: 600; }
.seats.full { color: var(--muted); }

/* ---------- 表单控件 ---------- */
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px;
  background: #fff; color: var(--text); width: 100%;
}
input:disabled { background: #f3f4f6; color: var(--muted); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

/* ---------- 表格 ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { width: 240px; }
.toolbar select, .toolbar input[type=month] { width: auto; }
.table-card { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: 13px; background: #f9fafb; }
tbody tr:hover { background: #f8fafc; }
td.actions { text-align: right; }
td.wrap { white-space: normal; min-width: 200px; }
.num { text-align: right; }
td.empty { text-align: center; color: var(--muted); padding: 40px; }
.link { color: var(--primary); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; z-index: 50; overflow-y: auto;
}
.modal.hidden { display: none; }
.modal-box { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0, 0, 0, .2); }
.modal-box.wide { max-width: 760px; }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 17px; word-break: break-all; }
#modal-body { padding: 18px 20px 20px; }
#modal-body > p { margin: 0 0 14px; line-height: 1.7; }

.form .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: #374151; }
.form .hint { margin-top: 10px; }
.form label .hint { margin-top: 0; }
.full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.detail-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; flex-wrap: wrap; }
.detail-top > div { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.info-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  background: #f9fafb; padding: 14px; border-radius: 8px; margin: 0 0 8px;
}
.info-grid dt { font-size: 12px; color: var(--muted); }
.info-grid dd { margin: 2px 0 0; word-break: break-all; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 6px; }
.section-head h4 { margin: 0; font-size: 15px; }

/* ---------- 数据管理 ---------- */
.setting-row {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 0; border-bottom: 1px solid #f1f5f9;
}
.setting-row:last-child { border-bottom: 0; }
.setting-row p { margin: 4px 0 0; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 登录 ---------- */
.hidden { display: none !important; }
body.locked .sidebar, body.locked main { display: none; }
.auth {
  position: fixed; inset: 0; z-index: 80; background: var(--bg);
  display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px; overflow-y: auto;
}
.auth-box {
  width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 28px 28px 24px; box-shadow: 0 10px 30px rgba(0, 0, 0, .06);
}
.auth-box h1 { margin: 0 0 18px; font-size: 20px; text-align: center; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form p { margin: 0; }
.auth-form .btn { width: 100%; padding: 10px; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 1em; }

.sidebar { display: flex; flex-direction: column; }
.user-box { margin-top: auto; padding: 12px; border-top: 1px solid #1f2937; font-size: 13px; }
.user-name { color: #fff; font-weight: 600; margin-bottom: 4px; }
.sync-state { color: #9ca3af; font-size: 12px; margin-bottom: 6px; }
.sync-state::before { content: '●'; margin-right: 4px; }
.sync-state.ok::before { color: #22c55e; }
.sync-state.saving::before { color: #f59e0b; }
.sync-state.error { color: #fca5a5; }
.sync-state.error::before { color: #ef4444; }
.btn-text.light { color: #93c5fd; padding: 0; }

.form label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 10px; }
.form label.check input { width: auto; }
.card-head.padded { padding: 14px 16px 6px; }

/* ---------- 窄屏 ---------- */
@media (max-width: 900px) {
  body { flex-direction: column; }
  .sidebar {
    width: auto; height: auto; position: static;
    display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  }
  .logo { padding: 0 8px; }
  nav { flex-direction: row; overflow-x: auto; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .user-box { margin: 0 0 0 auto; padding: 0 8px; border: 0; display: flex; align-items: center; gap: 10px; }
  .user-name, .sync-state { margin: 0; }
  main { padding: 20px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr 1fr; }
  .toolbar input { width: 100%; }
}
@media (max-width: 520px) {
  .form .grid2 { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
}
