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

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #dee2e6;
  --primary: #0d6efd;
  --primary-dark: #0a58ca;
  --danger: #dc3545;
  --warning-bg: #fff3cd;
  --warning-border: #ffc107;
  --text: #212529;
  --muted: #6c757d;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---- Nav ---- */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
nav .brand { font-weight: 700; font-size: 1.1rem; color: var(--primary); text-decoration: none; }
nav a { text-decoration: none; color: var(--muted); font-size: .95rem; }
nav a:hover { color: var(--text); }
nav a.active { color: var(--primary); font-weight: 600; }
nav .spacer { flex: 1; }
nav button { background: none; border: none; cursor: pointer; color: var(--muted); font-size: .95rem; }
nav button:hover { color: var(--danger); }

/* ---- Layout ---- */
.container { max-width: 1100px; margin: 2rem auto; padding: 0 1rem; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1rem; font-weight: 600; color: var(--muted); margin-bottom: .5rem; text-transform: uppercase; letter-spacing: .05em; }
.card .value { font-size: 2rem; font-weight: 700; }

.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }

/* ---- Forms ---- */
input[type=password], input[type=text], input[type=number], select {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem 1.25rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b02a37; }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }

/* ---- Login page ---- */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box { width: 100%; max-width: 360px; }
.login-box h1 { margin-bottom: 1.5rem; text-align: center; }
.login-box label { display: block; margin-bottom: .4rem; font-weight: 500; }
.login-box .btn { width: 100%; margin-top: 1rem; }
.login-error { color: var(--danger); font-size: .9rem; margin-top: .5rem; min-height: 1.2em; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: .6rem 1rem; font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 2px solid var(--border); }
td { padding: .6rem 1rem; border-bottom: 1px solid var(--border); font-size: .95rem; }
tr:hover td { background: #f1f3f5; }
tr.low-confidence td { background: var(--warning-bg); }

/* ---- Upload zone ---- */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.drop-zone.drag-over { border-color: var(--primary); background: #e7f0ff; }
.drop-zone p { color: var(--muted); margin-top: .5rem; }

.progress-bar-wrap { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin: 1rem 0; display: none; }
.progress-bar { height: 100%; background: var(--primary); width: 0%; transition: width .2s; }

/* ---- Status badge ---- */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 12px;
  font-size: .8rem;
  font-weight: 600;
}
.badge-processed { background: #d1fae5; color: #065f46; }
.badge-failed { background: #fee2e2; color: #991b1b; }
.badge-pending { background: #e0e7ff; color: #3730a3; }

/* ---- Pagination ---- */
.pagination { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  position: relative;
}
.modal-close { position: absolute; top: 1rem; right: 1rem; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--muted); }
.modal-img { max-width: 100%; border-radius: var(--radius); margin-bottom: 1rem; }

/* ---- Chart ---- */
canvas#chart { width: 100% !important; }

/* ---- Details/summary ---- */
details summary { cursor: pointer; color: var(--muted); font-size: .9rem; margin-top: 1rem; }

/* ---- Spinner ---- */
.spinner-msg { color: var(--muted); font-style: italic; margin-top: .5rem; }
.warning-box { background: var(--warning-bg); border: 1px solid var(--warning-border); border-radius: var(--radius); padding: .75rem 1rem; margin-top: 1rem; font-size: .9rem; }

/* ---- Section header ---- */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-header h1 { font-size: 1.4rem; }

/* ---- Category & discount badges ---- */
.badge-category { display:inline-block; padding:.15rem .5rem; border-radius:10px; font-size:.75rem; font-weight:500; background:#e0e7ff; color:#3730a3; margin-left:.3rem; }
.badge-discount { background:#fef9c3; color:#854d0e; }

/* ---- Misc ---- */
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); }
