:root {
  --primary: #1a5c3a;
  --primary-light: #2d8a5e;
  --primary-dark: #0f3d26;
  --accent: #d4a574;
  --accent-light: #e8c9a8;
  --bg: #f4f7f2;
  --bg-card: rgba(255, 255, 255, 0.92);
  --text: #1a2e1f;
  --text-muted: #5c6b5f;
  --border: rgba(26, 92, 58, 0.12);
  --shadow: 0 8px 32px rgba(15, 61, 38, 0.08);
  --shadow-lg: 0 20px 60px rgba(15, 61, 38, 0.15);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-w: 260px;
  --danger: #e74c3c;
  --success: #27ae60;
  --warning: #f39c12;
  --info: #3498db;
}

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

body {
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary-light); text-decoration: none; transition: color .2s; }
a:hover { color: var(--primary); }

/* ===== Admin Layout ===== */
.admin-body {
  display: flex;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 0% 0%, rgba(45, 138, 94, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 100% 100%, rgba(212, 165, 116, 0.1) 0%, transparent 50%),
    var(--bg);
}

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  box-shadow: 4px 0 24px rgba(15, 61, 38, 0.2);
}

.sidebar-brand {
  padding: 28px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

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

.sidebar-brand .logo-icon {
  width: 44px; height: 44px;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.sidebar-brand h1 {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.sidebar-brand p {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.75);
  font-size: 14px;
  margin-bottom: 4px;
  transition: all .2s;
}

.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.nav-item.active {
  background: rgba(255,255,255,0.2);
  font-weight: 600;
}

.nav-item .icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer .user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.08);
}

.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--primary-dark);
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-dark);
}

.page-content {
  padding: 28px 32px;
  flex: 1;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.card-body { padding: 24px; }

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  border-radius: 0 0 0 80px;
  opacity: 0.1;
}

.stat-card.green::before { background: var(--primary); }
.stat-card.gold::before { background: var(--accent); }
.stat-card.blue::before { background: var(--info); }
.stat-card.orange::before { background: var(--warning); }

.stat-card .stat-icon {
  font-size: 28px;
  margin-bottom: 12px;
}

.stat-card .stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1;
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: #fff;
  box-shadow: 0 4px 12px rgba(26, 92, 58, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(26, 92, 58, 0.4);
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-sm { padding: 6px 14px; font-size: 13px; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 14px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: rgba(26, 92, 58, 0.04);
  border-bottom: 2px solid var(--border);
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.data-table tbody tr {
  transition: background .15s;
}

.data-table tbody tr:hover {
  background: rgba(26, 92, 58, 0.03);
}

/* ===== Badge ===== */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-green { background: rgba(39, 174, 96, 0.12); color: #1e8449; }
.badge-blue { background: rgba(52, 152, 219, 0.12); color: #2471a3; }
.badge-orange { background: rgba(243, 156, 18, 0.12); color: #b7950b; }
.badge-purple { background: rgba(155, 89, 182, 0.12); color: #7d3c98; }
.badge-gray { background: rgba(0,0,0,0.06); color: var(--text-muted); }

/* ===== Forms ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
  color: var(--text);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(45, 138, 94, 0.15);
}

textarea.form-control { resize: vertical; min-height: 100px; }

select.form-control { cursor: pointer; }

.search-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.search-bar .form-control { max-width: 280px; }

/* ===== Pagination ===== */
.pagination-wrap { padding: 16px 24px; }
.pagination-wrap ul { display: flex; gap: 6px; justify-content: center; list-style: none; flex-wrap: wrap; }
.pagination-wrap li a, .pagination-wrap li span { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px; padding: 0 10px; border-radius: 8px; font-size: 14px; border: 1px solid var(--border); color: var(--text); text-decoration: none; }
.pagination-wrap li.active span { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(135deg, rgba(15, 61, 38, 0.95) 0%, rgba(26, 92, 58, 0.85) 50%, rgba(45, 138, 94, 0.8) 100%),
    url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="80" r="30" fill="rgba(255,255,255,0.03)"/><circle cx="80" cy="20" r="40" fill="rgba(255,255,255,0.02)"/></svg>');
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 48px 40px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  text-align: center;
  margin-bottom: 36px;
}

.login-brand .logo-big {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(26, 92, 58, 0.3);
}

.login-brand h1 {
  font-size: 24px;
  color: var(--primary-dark);
  font-weight: 800;
}

.login-brand p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 6px;
}

/* ===== Trace Public Page ===== */
.trace-page {
  min-height: 100vh;
  background:
    linear-gradient(180deg, #0f3d26 0%, #1a5c3a 40%, #f4f7f2 40%);
  padding-bottom: 60px;
}

.trace-hero {
  text-align: center;
  padding: 60px 20px 80px;
  color: #fff;
}

.trace-hero h1 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 8px;
}

.trace-hero p {
  opacity: 0.85;
  font-size: 16px;
}

.trace-search-box {
  max-width: 560px;
  margin: -40px auto 0;
  padding: 0 20px;
  position: relative;
  z-index: 10;
}

.trace-search-inner {
  background: #fff;
  border-radius: 20px;
  padding: 8px;
  display: flex;
  gap: 8px;
  box-shadow: var(--shadow-lg);
}

.trace-search-inner input {
  flex: 1;
  border: none;
  padding: 16px 20px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  border-radius: 14px;
}

.trace-search-inner button {
  padding: 16px 32px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: #fff;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.trace-container {
  max-width: 900px;
  margin: 40px auto 0;
  padding: 0 20px;
}

.trace-timeline {
  position: relative;
  padding-left: 40px;
}

.trace-timeline::before {
  content: '';
  position: absolute;
  left: 15px; top: 0; bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, var(--primary-light), var(--accent));
}

.timeline-item {
  position: relative;
  margin-bottom: 28px;
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -33px; top: 28px;
  width: 12px; height: 12px;
  background: var(--primary-light);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--primary-light);
}

.timeline-item h4 {
  font-size: 16px;
  color: var(--primary-dark);
  margin-bottom: 8px;
}

.timeline-item .time {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.info-item label {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
}

.info-item span {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.product-header {
  background: #fff;
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
  text-align: center;
}

.product-header .trace-code {
  font-family: "Courier New", monospace;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 2px;
  background: rgba(26, 92, 58, 0.08);
  padding: 10px 24px;
  border-radius: 10px;
  display: inline-block;
  margin: 12px 0;
}

.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 20px;
}

.alert-error {
  background: rgba(231, 76, 60, 0.1);
  color: #c0392b;
  border: 1px solid rgba(231, 76, 60, 0.2);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
}

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

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }

.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 14px;
  z-index: 99999;
  animation: toastIn .3s ease;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

@keyframes toastIn {
  from { transform: translate(-50%, -12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.chart-box {
  height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.status-chart {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.status-bar-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-bar-item .label {
  width: 80px;
  font-size: 13px;
  color: var(--text-muted);
}

.status-bar-item .bar {
  flex: 1;
  height: 24px;
  background: rgba(26, 92, 58, 0.08);
  border-radius: 12px;
  overflow: hidden;
}

.status-bar-item .bar-fill {
  height: 100%;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--primary-light), var(--primary));
  transition: width .6s ease;
}

.status-bar-item .count {
  width: 40px;
  text-align: right;
  font-weight: 700;
  font-size: 14px;
}
