:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --surface2: #f9f8f5;
  --border: #e4e0d8;
  --border-strong: #ccc8bf;
  --accent: #4a7c6f;
  --accent-light: #eaf2ef;
  --accent-mid: #d0e7e2;
  --red: #c0392b;
  --red-light: #fdf2f0;
  --amber: #b8860b;
  --amber-light: #fdf8ec;
  --text: #2c2a26;
  --text-mid: #5a5650;
  --text-muted: #928e86;
  --serif: 'Lora', Georgia, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.07), 0 1px 3px rgba(0,0,0,0.05);
}

[data-theme="dark"] {
  --bg: #161714;
  --surface: #1e201d;
  --surface2: #252721;
  --border: #333530;
  --border-strong: #4a4d45;
  --accent: #6aab98;
  --accent-light: #1a2e28;
  --accent-mid: #243d36;
  --red: #e06c5e;
  --red-light: #2a1a18;
  --amber: #d4a843;
  --amber-light: #2a2210;
  --text: #e8e5de;
  --text-mid: #a8a49c;
  --text-muted: #6b6860;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 62px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.logo { display: flex; align-items: baseline; gap: 10px; }
.logo-name { font-family: var(--serif); font-size: 20px; font-weight: 600; color: var(--accent); letter-spacing: 0.3px; }
.logo-divider { width: 1px; height: 16px; background: var(--border-strong); align-self: center; }
.logo-sub { font-size: 12px; color: var(--text-muted); font-weight: 400; letter-spacing: 0.3px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ── Buttons ── */
.btn {
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--border);
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s ease; text-decoration: none;
  background: var(--surface); color: var(--text-mid);
}
.btn:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface2); color: var(--text); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: #3d6b5f; border-color: #3d6b5f; color: #fff; }

.btn-secondary { color: var(--accent); border-color: #4b7d70; }
.btn-secondary:hover:not(:disabled) { background: #45b19442; border-color: #4b7d70; color: #4b7d70; }

.btn-danger { color: var(--red); border-color: #e8ccc9; }
.btn-danger:hover:not(:disabled) { background: var(--red-light); border-color: #d4a8a4; color: var(--red); }

/* ── Stats ── */
.stats-section {
  padding: 24px 32px 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-family: var(--serif); font-size: 28px; font-weight: 500; color: var(--text); line-height: 1; }
.stat-value.green { color: var(--accent); }
.stat-value.amber { color: var(--amber); }
.stat-value.red   { color: var(--red); }

/* ── Main ── */
main { padding: 24px 32px 40px; }

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title { font-family: var(--serif); font-size: 16px; font-weight: 500; color: var(--text); }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; gap: 8px; }
.pagination button {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-mid);
  padding: 5px 12px; border-radius: var(--radius); cursor: pointer;
  font-size: 12px; font-family: var(--sans); transition: all 0.12s;
}
.pagination button:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface2); }
.pagination button:disabled { opacity: 0.35; cursor: not-allowed; }
.pagination span { font-size: 12px; color: var(--text-muted); }

/* ── Table ── */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--surface2); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.7px; color: var(--text-muted);
  padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap; user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--text); }
thead th .sort-icon { margin-left: 4px; opacity: 0.4; font-style: normal; }
thead th.sort-asc .sort-icon, thead th.sort-desc .sort-icon { opacity: 1; color: var(--accent); }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }

/* ── Search bar ── */
.search-bar {
  display: flex; align-items: center; margin-top: 25px; gap: 10px;
  padding: 14px 32px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.search-input-wrap {
  display: flex; align-items: center; gap: 8px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 12px;
  flex: 1; min-width: 200px; transition: border-color 0.15s;
}
.search-input-wrap:focus-within { border-color: var(--accent); }
.search-input-wrap input { border: none; background: transparent; outline: none; font-family: var(--sans); font-size: 13px; color: var(--text); width: 100%; }
.search-input-wrap input::placeholder { color: var(--text-muted); }
.search-clear { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 12px; padding: 0; }
.search-clear:hover { color: var(--text); }
.filter-select {
  font-family: var(--sans); font-size: 12px; font-weight: 500; color: var(--text);
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 10px; cursor: pointer; outline: none; transition: border-color 0.15s;
}
.filter-select:focus { border-color: var(--accent); }
.filter-count { font-size: 12px; color: var(--text-muted); white-space: nowrap; margin-left: 4px; }

.resp-id { font-weight: 500; color: var(--accent); font-size: 13px; }
.resp-id-raw { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.datetime { font-size: 12px; color: var(--text-muted); line-height: 1.6; }
.answers-count { font-size: 13px; color: var(--text-mid); }

/* ── Sync badge ── */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500; padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.badge.synced  { background: var(--accent-light); color: var(--accent); }
.badge.synced .badge-dot  { background: var(--accent); }
.badge.pending { background: var(--amber-light);  color: var(--amber);  }
.badge.pending .badge-dot { background: var(--amber); }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 13px 18px;
  font-size: 13px; max-width: 340px; box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(6px); transition: all 0.2s ease; z-index: 999; color: var(--text-mid);
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.success { border-left: 3px solid var(--accent); color: var(--accent); }
#toast.error   { border-left: 3px solid var(--red);   color: var(--red); }
#toast.info    { border-left: 3px solid var(--amber); color: var(--amber); }

/* ── Loading ── */
.loading-overlay {
  display: none; position: fixed; inset: 0; background: rgba(245,243,239,0.75);
  z-index: 200; align-items: center; justify-content: center; flex-direction: column;
  gap: 14px; backdrop-filter: blur(2px);
}
.loading-overlay.show { display: flex; }
.spinner { width: 32px; height: 32px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 13px; color: var(--text-muted); font-family: var(--sans); }

@media (max-width: 900px) {
  .stats-section { grid-template-columns: repeat(2, 1fr); }
  header { padding: 0 16px; }
  main, .stats-section { padding-left: 16px; padding-right: 16px; }
}

/* ── Auto-sync bar ── */
.autosync-bar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 32px; height: 44px; display: flex; align-items: center; gap: 16px;
}
.autosync-label { font-size: 12px; color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.toggle-wrap { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle { width: 36px; height: 20px; background: var(--border-strong); border-radius: 10px; position: relative; transition: background 0.2s; flex-shrink: 0; }
.toggle.on { background: var(--accent); }
.toggle::after { content: ''; position: absolute; width: 14px; height: 14px; background: #fff; border-radius: 50%; top: 3px; left: 3px; transition: left 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.15); }
.toggle.on::after { left: 19px; }
.toggle-text { font-size: 12px; font-weight: 500; color: var(--text-mid); min-width: 24px; }
.autosync-sep { width: 1px; height: 18px; background: var(--border); }
.interval-wrap { display: flex; align-items: center; gap: 8px; }
.interval-wrap label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.interval-select { font-family: var(--sans); font-size: 12px; font-weight: 500; color: var(--text); background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 8px; cursor: pointer; outline: none; transition: border-color 0.15s; }
.interval-select:focus { border-color: var(--accent); }
.interval-select:disabled { opacity: 0.4; cursor: not-allowed; }
.next-sync-text { font-size: 11px; color: var(--text-muted); margin-left: 4px; }

/* ── Sync progress bar ── */
.sync-progress-wrap { display: none; align-items: center; gap: 10px; margin-left: 4px; }
.sync-progress-wrap.show { display: flex; }
.sync-progress-track { width: 120px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.sync-progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 2px; transition: width 0.3s ease; }
.sync-progress-fill.indeterminate { width: 40%; animation: indeterminate 1.2s ease-in-out infinite; }
@keyframes indeterminate { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }
.sync-progress-label { font-size: 11px; color: var(--accent); white-space: nowrap; font-weight: 500; }

/* ── CSV export buttons ── */
.btn-csv {
  font-size: 11px; padding: 4px 10px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-mid); cursor: pointer; font-family: var(--sans); font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px; transition: all 0.12s; text-decoration: none; white-space: nowrap;
}
.btn-csv:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.btn-csv.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-csv.primary:hover { background: #3d6b5f; }

.empty-state { text-align: center; padding: 56px 32px; color: var(--text-muted); font-size: 14px; }
.empty-icon { font-size: 28px; margin-bottom: 10px; opacity: 0.4; }
