:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-alt: #fafbfc;
  --accent: #f59e0b;
  --accent-strong: #b45309;
  --accent-ink: #3a2205;
  --text: #1a1d23;
  --text-soft: #3f4653;
  --muted: #64748b;
  --danger: #dc2626;
  --success: #15803d;
  --success-bg: #16a34a;
  --border: #e3e6eb;
  --border-strong: #cdd2da;
  --input-bg: #f8f9fb;
  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 2px 6px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 8px 20px rgba(16, 24, 40, 0.08), 0 2px 6px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Inter", Roboto, Arial, sans-serif;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(245, 158, 11, 0.28); }

.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  vertical-align: -3px;
}

.icon-lg { width: 20px; height: 20px; }

/* ---------- Header ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-xs);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: linear-gradient(155deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.brand-text h1 {
  font-size: 15.5px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.1px;
}

.brand-text .brand-subtitle {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.3px;
}

.status {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  white-space: nowrap;
}

main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.hidden { display: none !important; }

/* ---------- Section headers ---------- */

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 4px;
}

.section-heading .icon { color: var(--accent-strong); }

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-strong);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.upload-section h2 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.1px;
}

.tool-block h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text);
}

.tool-block h3 .icon { color: var(--accent-strong); }

.batch-preview-panel h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  margin: 0;
}

.batch-preview-panel h3 .icon { color: var(--accent-strong); }

.hint {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0 0 12px;
}

/* ---------- Buttons ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 1 1 0;
  min-width: 130px;
  padding: 11px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--panel);
  color: var(--text-soft);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: transform 0.06s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); background: #fbfbfc; }
.btn:active { transform: scale(0.98); box-shadow: var(--shadow-xs); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(180deg, #fbbf3d, var(--accent));
  border-color: var(--accent-strong);
  color: var(--accent-ink);
}
.btn-primary:hover { background: linear-gradient(180deg, #fcc655, #eb9106); }

.btn-download {
  background: linear-gradient(180deg, #22b25a, var(--success-bg));
  border-color: var(--success);
  color: #ffffff;
}
.btn-download:hover { background: linear-gradient(180deg, #27c164, #159048); }

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-preview {
  background: var(--panel);
  color: var(--text-soft);
}

.btn-small {
  padding: 7px 12px;
  font-size: 12px;
  min-width: auto;
  flex: 0 0 auto;
}

/* ---------- Upload zone ---------- */

.upload-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.file-label {
  position: relative;
  text-align: center;
  overflow: hidden;
}

.file-input-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.batch-summary {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 10px;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.batch-summary.is-success {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: var(--success);
  font-weight: 700;
}

.batch-summary.is-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
  font-weight: 700;
}

/* ---------- Upload item cards ---------- */

.upload-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-item {
  display: flex;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow 0.15s ease;
}

.upload-item:hover { box-shadow: var(--shadow-sm); }

.upload-item-thumb {
  flex: 0 0 160px;
  width: 160px;
  align-self: stretch;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #0b0d10;
  border: 1px solid var(--border);
}

.upload-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.upload-item-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.meta-table {
  font-family: "Consolas", "SFMono-Regular", monospace;
  font-size: 12px;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: 12px;
  row-gap: 5px;
  align-items: baseline;
}

.meta-row {
  display: contents;
}

.meta-row .label {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.meta-row .value {
  color: var(--text-soft);
  word-break: break-word;
}

.meta-row.missing .value {
  color: var(--danger);
}

.meta-row.disabled .value {
  color: var(--muted);
  font-style: italic;
}

.upload-item-actions {
  margin-top: 6px;
}

.item-edit {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  padding: 14px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

/* ---------- Batch workspace layout ---------- */

.batch-workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
  max-width: 880px;
}

.tool-block {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-xs);
}

.batch-preview-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-xs);
}

.batch-preview-frame {
  background: #0b0d10;
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}

.batch-preview-frame img {
  width: 100%;
  height: auto;
  max-height: 60vh;
  object-fit: contain;
  display: block;
}

.batch-preview-caption {
  font-size: 12px;
  color: var(--muted);
  word-break: break-word;
}

/* ---------- Form controls ---------- */

.tool-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.tool-row:last-child { margin-bottom: 0; }

.folder-picker-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.folder-picker-row .hint {
  margin: 0;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.field-label input,
.field-label select {
  flex: 1;
  min-width: 110px;
}

.tool-row input[type="text"],
.tool-row input[type="number"],
.tool-row input[type="datetime-local"],
.tool-row select,
.item-edit input[type="text"],
.item-edit input[type="datetime-local"],
.item-edit select {
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tool-row input:focus-visible,
.tool-row select:focus-visible,
.item-edit input:focus-visible,
.item-edit select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

#bulkDistrictInput {
  flex: 1;
  min-width: 160px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-soft);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-strong);
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.modal-overlay.hidden { display: none !important; }

.modal-box {
  position: relative;
  max-width: 95vw;
  max-height: 90vh;
}

.modal-box img {
  display: block;
  max-width: 95vw;
  max-height: 90vh;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: -16px;
  right: -16px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.1s ease;
}
.modal-close:hover { transform: scale(1.06); }
