:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f6fb;
  --card: #ffffff;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #b45309;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(17, 24, 39, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(100deg, #312e81, #4f46e5);
  color: #fff;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px;
  box-shadow: 0 2px 12px rgba(49, 46, 129, .25);
}
.topbar .brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.topbar .spacer { flex: 1; }
.topbar .who { opacity: .9; font-size: 13px; }
.topbar button, .topbar a.btn-link {
  background: rgba(255,255,255,.14); color: #fff; border: 0;
  padding: 7px 12px; border-radius: 9px; font-size: 13px;
}
.topbar button:hover, .topbar a.btn-link:hover { background: rgba(255,255,255,.25); }

.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 18px 90px; }
.wrap.narrow { max-width: 440px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.right { text-align: right; }

.btn {
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 15px; background: var(--primary); color: #fff;
  font-weight: 600; font-size: 14px;
}
.btn:hover { background: var(--primary-dark); }
.btn.ghost { background: #fff; color: var(--primary); border-color: #c7d2fe; }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.gray { background: #fff; color: var(--text); border-color: var(--line); }
.btn.gray:hover { background: #f9fafb; }
.btn.danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

label.field { display: block; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; border: 1px solid #d1d5db; background: #fff;
  border-radius: 9px; padding: 8px 10px; outline: none; min-height: 38px;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
textarea { min-height: 60px; resize: vertical; }

.grid { display: grid; gap: 12px; }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 760px) {
  .grid.c3, .grid.c2 { grid-template-columns: 1fr; }
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 11px; font-size: 12.5px; color: var(--muted);
}
.chip b { color: var(--text); font-size: 15px; margin-left: 6px; }
.chip.total { background: var(--primary-soft); border-color: #c7d2fe; color: var(--primary-dark); }
.chip.total b { color: var(--primary-dark); }

.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.section-head h3 { margin: 0; }
.section-head .total { margin-left: auto; font-size: 13px; color: var(--muted); }

.entry {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin-bottom: 10px; background: #fff;
}
.entry .entry-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.entry .entry-head .idx { font-size: 12px; color: var(--muted); }
.entry .entry-head .score {
  margin-left: auto; font-weight: 700; color: var(--primary-dark);
  background: var(--primary-soft); border-radius: 8px; padding: 3px 9px; font-size: 13px;
}
.entry .entry-head .score.muted { color: var(--muted); background: #f3f4f6; }
.entry .fields { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.entry .full { grid-column: 1 / -1; }
.entry .foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.entry .foot .hint { color: var(--warn); font-size: 12px; }

.exclude { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--danger); }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.att {
  position: relative; width: 84px; height: 84px; border-radius: 9px; overflow: hidden;
  border: 1px solid var(--line); background: #f3f4f6;
}
.att img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att .del {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; line-height: 18px; padding: 0; font-size: 12px;
}
.att-add {
  width: 84px; height: 84px; border: 1px dashed #a5b4fc; border-radius: 9px;
  background: #f8faff; color: var(--primary); display: flex; align-items: center;
  justify-content: center; text-align: center; font-size: 12px; padding: 8px;
}
.att-add:hover { background: var(--primary-soft); }

.race-wrap { position: relative; }
.race-drop {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20;
  max-height: 260px; overflow: auto; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 12px 30px rgba(17,24,39,.14); display: none;
}
.race-drop.open { display: block; }
.race-drop div { padding: 8px 10px; font-size: 13px; cursor: pointer; border-bottom: 1px solid #f3f4f6; }
.race-drop div:hover { background: var(--primary-soft); }
.race-drop .cat { color: var(--muted); font-size: 11px; margin-left: 6px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table.list { width: 100%; border-collapse: collapse; min-width: 820px; }
table.list th, table.list td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
table.list th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: #fafbff; }
.status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.status.submitted { background: #ecfdf5; color: var(--ok); }
.status.draft { background: #fffbeb; color: var(--warn); }

.empty { padding: 26px; text-align: center; color: var(--muted); }
.notice { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 10px 12px; border-radius: 10px; font-size: 13px; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.success { color: var(--ok); font-size: 13px; margin-top: 8px; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: rgba(255,255,255,.95); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding: 10px 18px;
  display: flex; gap: 10px; align-items: center; justify-content: flex-end;
}
.savebar .dirty { margin-right: auto; color: var(--warn); font-size: 12.5px; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(16px);
  background: #111827; color: #fff; padding: 9px 16px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #b91c1c; }

.login-card { margin-top: 12vh; }
.login-card h1 { font-size: 20px; margin: 0 0 6px; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 8px 14px; border-radius: 9px; font-size: 13px;
}
.tabs button.active { background: var(--primary-soft); border-color: #c7d2fe; color: var(--primary-dark); font-weight: 600; }
.hide { display: none !important; }
.spin {
  width: 16px; height: 16px; border: 2px solid #c7d2fe; border-top-color: var(--primary);
  border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.att-file-link {
  display: flex; align-items: center; justify-content: center; text-align: center;
  width: 100%; height: 100%; padding: 6px; font-size: 11px; color: var(--primary);
  word-break: break-all;
}

input.invalid, select.invalid, textarea.invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12) !important;
}
.att-add.invalid { border-color: var(--danger); color: var(--danger); background: #fef2f2; }

.validation-box {
  border: 1px solid #fca5a5;
  background: #fef2f2;
  color: #991b1b;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 14px;
  font-size: 13px;
}
.validation-box ul { margin: 6px 0 0 18px; padding: 0; }
.validation-box li { margin: 2px 0; }
