:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #162033;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --success: #16a34a;
  --warn: #d97706;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  background: #eef2ff;
  color: #1e3a8a;
  transition: .15s ease;
}
button:hover { transform: translateY(-1px); }
button.primary { background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.danger { background: var(--danger-bg); color: var(--danger); }
button.small { padding: 7px 11px; font-size: 13px; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}
textarea { min-height: 88px; resize: vertical; }
label { display: block; font-weight: 650; margin-bottom: 6px; }
.container { max-width: 1180px; margin: 0 auto; padding: 22px; }
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px;
}
.login-card h1 { margin: 0 0 8px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.error {
  margin-top: 12px;
  color: var(--danger);
  background: var(--danger-bg);
  padding: 10px 12px;
  border-radius: 12px;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(246, 247, 251, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand h1 { font-size: 22px; line-height: 1.1; margin: 0; }
.brand span { color: var(--muted); font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0;
}
.nav button.active { background: var(--text); color: #fff; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card h2, .card h3 { margin: 0 0 12px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.space-between { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: #f3f4f6;
  border-radius: 999px;
  font-size: 13px;
  color: #374151;
  margin: 2px 4px 2px 0;
}
.visit-card { border-left: 4px solid var(--primary); }
.visit-meta { display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.money { font-weight: 800; color: var(--success); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-size: 13px; }
.toolbar { display: grid; grid-template-columns: 1.2fr .8fr .8fr auto; gap: 10px; margin-bottom: 14px; }
.pre { white-space: pre-wrap; line-height: 1.55; }
.notice {
  background: #ecfeff;
  color: #155e75;
  border: 1px solid #a5f3fc;
  padding: 12px;
  border-radius: 14px;
}
.warning {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
  padding: 12px;
  border-radius: 14px;
}
.empty { text-align: center; padding: 34px 12px; color: var(--muted); }
.footer-space { height: 34px; }
@media (max-width: 820px) {
  .topbar-inner { align-items: flex-start; flex-direction: column; }
  .form-grid, .grid.two, .grid.three, .toolbar { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; }
}

.visit-summary {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: center;
}
.summary-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}
.summary-value {
  font-size: 30px;
  font-weight: 800;
}
.summary-pills { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.total-pill {
  background: #ecfdf5;
  color: var(--success);
  font-weight: 700;
}
.attachment-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.attachment-card {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  text-align: left;
  color: var(--text);
}
.attachment-card:hover { box-shadow: var(--shadow); }
.attachment-image { padding: 8px; }
.thumb-wrap {
  aspect-ratio: 1 / 1;
  width: 100%;
  overflow: hidden;
  border-radius: 12px;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attachment-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attachment-name {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-file {
  justify-content: center;
  align-items: center;
  min-height: 130px;
}
.file-icon {
  font-size: 32px;
  line-height: 1;
}
@media (max-width: 820px) {
  .visit-summary { grid-template-columns: 1fr; }
}

.page-heading h2 { margin: 0; }
.form-card { max-width: 880px; margin: 0 auto; }
.attachment-hint {
  font-size: 12px;
  color: var(--muted);
  opacity: .8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .72);
  backdrop-filter: blur(6px);
}
.image-modal-card {
  position: relative;
  z-index: 1;
  width: min(1100px, 96vw);
  max-height: 92vh;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: 0 22px 80px rgba(0, 0, 0, .32);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.image-modal-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.image-modal-header strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-modal-img {
  max-width: 100%;
  max-height: calc(92vh - 64px);
  object-fit: contain;
  background: #0f172a;
}
@media (max-width: 820px) {
  .image-modal { padding: 10px; }
  .image-modal-header { align-items: flex-start; flex-direction: column; }
}
