:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #6b7484;
  --border: #e3e6eb;
  --accent: #2f5bea;
  --accent-dark: #2147c4;
  --danger: #c93b3b;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .5rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); }
.topbar nav a { margin-left: 1.2rem; color: var(--muted); font-weight: 500; }
.topbar nav a.active { color: var(--accent); }

main { max-width: 1150px; margin: 1.5rem auto; padding: 0 1rem; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.4rem;
}
.narrow { max-width: 560px; margin: 0 auto; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-error { background: #fdecec; color: #8a2020; border: 1px solid #f5c6c6; }
.flash-ok { background: #e9f7ef; color: #17633a; border: 1px solid #bfe5cf; }
.flash-note { background: #fff8e6; color: #7a5212; border: 1px solid #f1deaa; }

/* Upload */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .6rem;
  min-height: 220px; margin: 1rem 0; padding: 1rem; text-align: center; cursor: pointer;
  border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: #f3f6ff; }
.dropzone input { display: none; }
.dropzone img { max-width: 100%; max-height: 320px; border-radius: 6px; }

.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .6rem 1.1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: #f0f2f5; }
.btn.primary { width: 100%; justify-content: center; background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.primary:disabled { opacity: .55; cursor: not-allowed; }
.btn.danger { color: var(--danger); border-color: #f0c8c8; }
.btn.danger:hover { background: #fdecec; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin .8s linear infinite; display: inline-block;
}
.spinner.dark { border-color: rgba(0,0,0,.15); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Records table */
.count { font-size: .85rem; color: var(--muted); font-weight: 500; margin-left: .3rem; }
.search { padding: .5rem .8rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; min-width: 260px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f8f9fb; }
.thumb { width: 84px; height: 54px; object-fit: cover; border-radius: 5px; border: 1px solid var(--border); display: block; }
.empty { color: var(--muted); padding: 2rem 0; text-align: center; }

.badge { font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; text-transform: capitalize; }
.badge-done { background: #e9f7ef; color: var(--ok); }
.badge-failed { background: #fdecec; color: var(--danger); }
.badge-pending { background: #fff4e0; color: var(--warn); }

/* Detail page */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.photo-card img { width: 100%; border-radius: 8px; display: block; }
.fields th { width: 40%; color: var(--muted); font-weight: 500; }
.actions { display: flex; gap: .6rem; margin-top: 1.2rem; }
.raw { margin-top: 1.2rem; }
.raw summary { cursor: pointer; color: var(--muted); }
.raw pre { background: #f5f6f8; padding: .8rem; border-radius: 8px; overflow-x: auto; font-size: .8rem; }

@media (max-width: 800px) {
  .detail { grid-template-columns: 1fr; }
  .search { min-width: 0; width: 100%; }
}

/* Record deletion */
.toolbar { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.btn.small { padding: .4rem .8rem; font-size: .85rem; }
.btn.danger:disabled { opacity: .45; cursor: not-allowed; background: var(--card); }
.check-col { width: 36px; }
.check-col input { width: 16px; height: 16px; cursor: pointer; }
.icon-btn {
  border: 1px solid transparent; background: none; border-radius: 6px; padding: .3rem .5rem;
  color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer;
}
.icon-btn:hover { color: var(--danger); background: #fdecec; border-color: #f0c8c8; }
tr.selected { background: #f3f6ff; }

/* Login */
.topbar nav { display: flex; align-items: center; }
.logout { display: inline; margin-left: 1.2rem; }
.logout button { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); font-weight: 500; cursor: pointer; }
.logout button:hover { color: var(--text); }
.login-card { max-width: 380px; margin: 3rem auto; }
.field { display: block; margin: .9rem 0; font-weight: 500; font-size: .9rem; }
.field input { display: block; width: 100%; margin-top: .3rem; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
.field input:focus { outline: 2px solid #c9d6fb; border-color: var(--accent); }
.login-card .btn.primary { margin-top: .6rem; }
