*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-hover: #15803d;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Navbar ─────────────────────── */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.nav-brand { font-weight: 700; font-size: 1.1rem; color: var(--primary); }
.nav-links { display: flex; align-items: center; gap: 1rem; }
.nav-links a { text-decoration: none; color: var(--text); font-size: .9rem; }
.nav-links a:hover { color: var(--primary); }
.nav-user { color: var(--text-muted); font-size: .85rem; }

/* ── Container ──────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* ── Alerts ─────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Buttons ────────────────────── */
.btn {
  display: inline-block;
  padding: .5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, opacity .15s;
}
.btn:hover { opacity: .9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-block { width: 100%; }

/* ── Login ──────────────────────── */
.login-card {
  max-width: 380px;
  margin: 4rem auto;
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.login-card h2 { margin-bottom: 1.5rem; text-align: center; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .3rem; }
.form-group input {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }

/* ── Dashboard ──────────────────── */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.dashboard-header h1 { font-size: 1.5rem; }
.dashboard-actions { display: flex; gap: .5rem; }

.stats-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1.25rem;
  text-align: center;
  min-width: 100px;
}
.stat-num { display: block; font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-done .stat-num { color: var(--success); }
.stat-pending .stat-num { color: var(--primary); }

/* ── Table ──────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead { background: #f8fafc; }
th { text-align: left; padding: .6rem .75rem; font-weight: 600; color: var(--text-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; border-bottom: 2px solid var(--border); }
td { padding: .55rem .75rem; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: #f1f5f9; }
.row-matched { background: #f0fdf4; }
.row-pending {}
.row-highlighted { background: #eff6ff !important; outline: 2px solid var(--primary); }

.mono { font-family: "Cascadia Code", "Fira Code", monospace; font-size: .82rem; }
.text-muted { color: var(--text-muted); }

/* ── Badges ─────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 10px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-done { background: #dcfce7; color: #166534; }
.badge-pending { background: #e0e7ff; color: #3730a3; }

/* ── Match page ─────────────────── */
.match-header { margin-bottom: 1.5rem; }
.match-header h1 { margin-top: .5rem; font-size: 1.4rem; }

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.product-card h3 { margin-bottom: 1rem; font-size: 1rem; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: .6rem 1.5rem;
}
.detail-item { display: flex; flex-direction: column; }
.detail-label { font-size: .7rem; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }

.current-match-card {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
}
.current-match-card h3 { font-size: .9rem; margin-right: 1rem; }

/* ── Search ─────────────────────── */
.search-section { margin-bottom: 2rem; }
.search-section h3 { margin-bottom: .75rem; font-size: 1rem; }

.search-box {
  position: relative;
  margin-bottom: 1rem;
}
.tag-input-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  padding: .4rem .6rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: text;
  min-height: 44px;
}
.tag-input-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

.search-box input {
  flex: 1;
  min-width: 180px;
  padding: .3rem .4rem;
  border: none;
  font-size: .95rem;
  outline: none;
}

.search-tag {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: #e0e7ff;
  color: #3730a3;
  padding: .2rem .55rem;
  border-radius: 12px;
  font-size: .8rem;
  font-weight: 500;
  white-space: nowrap;
}
.tag-remove {
  background: none;
  border: none;
  color: #6366f1;
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  font-weight: 700;
}
.tag-remove:hover { color: var(--danger); }

.search-hint {
  font-size: .78rem;
  color: var(--text-muted);
  margin-bottom: .75rem;
}
.search-hint kbd {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .1rem .35rem;
  font-size: .75rem;
  font-family: inherit;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

.search-results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  max-height: 400px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.own-id-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
  font-size: .95rem;
}

/* ── Selected matches list ─────── */
.selected-matches-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.selected-matches-card h3 { margin-bottom: .75rem; font-size: 1rem; }

.selected-match-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .4rem;
  background: #f8fafc;
  gap: .5rem;
}
.selected-match-item .mono { margin-right: .5rem; }
.selected-match-item strong { margin-right: .5rem; }

.match-pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: .15rem .45rem;
  font-size: .75rem;
  margin: .1rem 0;
}

/* ── Admin panel ───────────────── */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1.5rem;
}
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.admin-card h3 { margin-bottom: 1rem; font-size: 1rem; }

.form-select {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  background: #fff;
}
.form-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }

/* ── QC page ───────────────────── */
.stat-flagged .stat-num { color: var(--danger); }

.qc-row-flagged { background: #fef2f2; }
.qc-row-clean { background: #f0fdf4; }

.qc-flag {
  border-radius: var(--radius);
  padding: .5rem .6rem;
  margin-bottom: .4rem;
  font-size: .8rem;
}
.qc-flag-error {
  background: #fef2f2;
  border-left: 3px solid var(--danger);
}
.qc-flag-warning {
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
}
.qc-flag strong { display: block; margin-bottom: .2rem; }
.qc-flag-detail { color: var(--text); margin-bottom: .2rem; }
.qc-flag-guideline {
  color: var(--text-muted);
  font-size: .72rem;
  font-style: italic;
}
