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

:root {
  --bg: #F5F2EE;
  --surface: #FFFFFF;
  --border: #E4DDD6;
  --text: #2C2A27;
  --muted: #8A8078;
  --accent: #7A6152;
  --accent-light: #EDE6DF;
  --accent-hover: #5E4A3D;
  --green: #4A7C5F;
  --green-bg: #E8F2EC;
  --red: #B94A48;
  --red-bg: #FBEAEA;
  --yellow: #A68B3C;
  --yellow-bg: #FDF6E3;
  --blue: #4A6FA5;
  --blue-bg: #EBF0F7;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'DM Mono', 'SF Mono', monospace;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---------- Layout ---------- */

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  margin-bottom: 28px;
}

.sidebar-logo .logo-mark {
  width: 34px;
  height: 34px;
  background: var(--text);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-logo .logo-mark svg { width: 17px; height: 17px; fill: white; }
.sidebar-logo .logo-name { font-size: 13px; font-weight: 600; }
.sidebar-logo .logo-sub { font-size: 10px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }

.sidebar-nav { flex: 1; }

.nav-section {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 16px 20px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--accent-light); color: var(--text); }
.nav-item.active { background: var(--accent-light); color: var(--accent); font-weight: 500; }
.nav-item svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-user {
  font-size: 12px;
  color: var(--muted);
}

.sidebar-user strong {
  color: var(--text);
  font-weight: 500;
  display: block;
}

.btn-logout {
  background: none;
  border: none;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-logout:hover { background: var(--red-bg); color: var(--red); }

.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 32px 40px;
  min-height: 100vh;
}

/* ---------- Page header ---------- */

.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.page-header p {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ---------- Stats row ---------- */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* ---------- Tables ---------- */

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:hover { background: var(--accent-light); }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-completed { background: var(--green-bg); color: var(--green); }
.badge-review { background: var(--yellow-bg); color: var(--yellow); }
.badge-unmatched { background: var(--red-bg); color: var(--red); }
.badge-not-usa { background: var(--blue-bg); color: var(--blue); }
.badge-credit-note { background: var(--accent-light); color: var(--accent); }
.badge-disputed { background: var(--red-bg); color: var(--red); }

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover { border-color: var(--accent); }

.btn-primary {
  background: var(--text);
  color: white;
  border-color: var(--text);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }

/* ---------- Forms ---------- */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-input::placeholder { color: var(--muted); }

/* ---------- File upload ---------- */

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}

.upload-zone:hover { border-color: var(--accent); background: var(--accent-light); }
.upload-zone.active { border-color: var(--accent); background: var(--accent-light); }

.upload-zone p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

.upload-zone .filename {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  margin-top: 4px;
}

/* ---------- Alerts ---------- */

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.alert-error { background: var(--red-bg); color: var(--red); }
.alert-success { background: var(--green-bg); color: var(--green); }
.alert-warning { background: var(--yellow-bg); color: var(--yellow); }

/* ---------- Login page ---------- */

.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 52px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 2px 24px rgba(44,42,39,0.07);
  animation: fadeUp 0.5s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.login-logo .logo-mark {
  width: 40px;
  height: 40px;
  background: var(--text);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-logo .logo-mark svg { width: 20px; height: 20px; fill: white; }

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.login-card .subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 28px;
}

.login-card .form-group { margin-bottom: 18px; }

.login-card .btn-primary {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  justify-content: center;
  margin-top: 4px;
}

.login-footer {
  margin-top: 28px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

/* ---------- Filters row ---------- */

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

.filters-row .form-input {
  width: auto;
  min-width: 180px;
}

.filters-row select.form-input {
  min-width: 140px;
}

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

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 42, 39, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

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

.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(44,42,39,0.15);
}

.modal h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ---------- Spinner ---------- */

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 20px; }
}
