:root {
  --primary: #1f3b2c;
  --primary-dark: #163223;
  --primary-light: #6c8f72;
  --dark: #111111;
  --border: #e0e0e0;
  --bg: #ffffff;
  --text: #243126;
  --muted: #677268;
  --red: #c23a3a;
  --green: #2b7a3f;
  --radius: 6px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font-family: inherit; }
button { cursor: pointer; min-height: 44px; touch-action: manipulation; }
input, textarea, select { min-height: 44px; }

/* ---------- Login screen ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 45%, var(--dark) 100%);
}
.login-box {
  background: #fff;
  padding: 36px;
  border-radius: 10px;
  width: 340px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(17, 17, 17, 0.16);
}
.login-box .logo {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}
.login-box .logo img {
  height: 60px;
  width: auto;
  display: block;
}
.login-box p { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 14px;
}
.login-box button {
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 11px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 14px;
}
.login-error { color: var(--red); font-size: 12px; margin-top: 8px; min-height: 16px; }
.login-hint { margin-top: 14px; font-size: 11px; color: #9aa39e; }

/* ---------- Layout ---------- */
.admin-wrap { display: none; min-height: 100vh; }
.admin-wrap.active { display: flex; }

.sidebar {
  width: 220px;
  background: var(--dark);
  color: #fff;
  padding: 20px 0;
  flex-shrink: 0;
}
.sidebar .logo { padding: 0 20px 20px; border-bottom: 1px solid #2d2d2d; margin-bottom: 14px;}
.sidebar .logo img { height: 52px; width: auto; display: block; }
.sidebar nav a, .sidebar nav button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 20px;
  color: #ccc;
  background: none;
  border: none;
  font-size: 14px;
}
.sidebar nav a.active, .sidebar nav a:hover { background: #232323; color: #fff; border-left: 3px solid var(--primary-light); }
.sidebar .logout-btn { margin-top: 30px; color: #ff9b9b; }

.main-panel { flex: 1; padding: 26px 30px; overflow-x: hidden; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.panel-header h1 { font-size: 22px; }
.primary-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 13px;
}
.primary-btn:hover { background: var(--primary-dark); }

.stats-row { display: flex; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 140px;
  flex: 1;
}
.stat-card .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-card .value { font-size: 22px; font-weight: 700; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.toolbar input { flex: 1; min-width: 180px; }

.category-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.category-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.category-card-header h2 { font-size: 16px; }
.category-form { display: flex; gap: 8px; flex-wrap: wrap; }
.category-form input { min-width: 220px; }
.category-list { display: flex; flex-wrap: wrap; gap: 8px; }
.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #f5f7f5;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 13px;
}
.category-pill button {
  border: none;
  background: none;
  color: var(--red);
  font-size: 12px;
  padding: 0;
}

.category-image-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f5f7f5;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.category-image-card .thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 18px;
  flex-shrink: 0;
}
.category-image-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.category-image-card .info { flex: 1; min-width: 0; }
.category-image-card .name { display: block; font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.category-image-card .row-actions { flex-wrap: wrap; }

.table-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #fafafa; font-weight: 700; color: #555; }
tr:last-child td { border-bottom: none; }
td img { width: 42px; height: 42px; object-fit: contain; border: 1px solid var(--border); border-radius: 4px; }

.price-input {
  width: 90px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}
.stock-badge { font-size: 11px; padding: 3px 8px; border-radius: 10px; font-weight: 700; }
.stock-badge.ok { background: #e6f4ea; color: var(--green); }
.stock-badge.low { background: #fdeaea; color: var(--red); }

.panel-view { display: none; }
.panel-view.active { display: block; }

.status-badge { font-size: 11px; padding: 3px 8px; border-radius: 10px; font-weight: 700; text-transform: capitalize; }
.status-badge.paid, .status-badge.delivered { background: #e6f4ea; color: var(--green); }
.status-badge.pending, .status-badge.pending_payment, .status-badge.processing { background: #fff6e0; color: #9a7100; }
.status-badge.shipped { background: #e6effd; color: #2358a8; }
.status-badge.cancelled, .status-badge.payment_failed { background: #fdeaea; color: var(--red); }
.status-select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; }

.row-actions { display: flex; gap: 8px; }
.icon-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 4px;
  padding: 5px 9px;
  font-size: 12px;
}
.icon-btn.save { border-color: var(--green); color: var(--green); }
.icon-btn.delete { border-color: var(--red); color: var(--red); }
.icon-btn.edit { border-color: #888; color: #333; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 8px;
  width: 520px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 17px; }
.modal-header button { background: none; border: none; font-size: 20px; }
.modal-body { padding: 20px 22px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12px; font-weight: 700; color: #555; margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.form-row textarea { resize: vertical; min-height: 70px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.secondary-btn {
  background: #fff;
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
}
.image-preview {
  width: 100%; max-width: 220px; height: 140px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
  overflow: hidden;
  font-size: 12px;
  color: #999;
  background: #fafafa;
}
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.form-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

.image-gallery-editor { display: flex; flex-direction: column; gap: 8px; }
.image-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.image-slot .thumb {
  width: 52px; height: 52px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  font-size: 11px;
  color: #999;
  flex-shrink: 0;
}
.image-slot .thumb img { width: 100%; height: 100%; object-fit: cover; }
.image-slot .slot-label {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}
.image-slot .cover-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--green);
  background: #e6f4ea;
  padding: 4px 8px;
  border-radius: 10px;
  white-space: nowrap;
}
.image-slot .icon-btn { white-space: nowrap; }

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--dark);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all .25s ease;
  z-index: 400;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }

@media (max-width: 900px) {
  .main-panel { padding: 20px; }
  .form-grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .admin-wrap.active { flex-direction: column; }
  .sidebar { width: 100%; padding: 14px 16px; }
  .sidebar .logo { padding: 0 0 10px; margin-bottom: 8px; border-bottom: 1px solid #2d2d2d; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 8px; }
  .sidebar nav a, .sidebar nav button { width: auto; border-left: none; border-radius: 999px; padding: 8px 10px; }
  .sidebar nav a.active, .sidebar nav a:hover { border-left: none; }
  .sidebar .logout-btn { margin-top: 10px; }
  .main-panel { padding: 16px; }
  .panel-header { flex-direction: column; align-items: flex-start; }
  .stats-row { flex-direction: column; }
  .toolbar { flex-direction: column; }
  .toolbar input, .toolbar select { width: 100%; }
  .modal { width: 100%; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions button { width: 100%; }
}
