:root {
  --admin-blue: #0b5e8e;
  --admin-deep: #061d2f;
  --admin-green: #1c9a52;
  --admin-danger: #d63b3b;
  --admin-bg: #f3f7f9;
  --admin-card: #ffffff;
  --admin-text: #102436;
  --admin-muted: #587086;
  --admin-border: rgba(11, 94, 142, 0.14);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Inter", sans-serif;
  background: var(--admin-bg);
  color: var(--admin-text);
  line-height: 1.55;
}

button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }

/* Login Screen */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(145deg, #061d2f 0%, #0b4a70 55%, #0e664b 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border-radius: 18px;
  padding: 36px 32px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.32);
}

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

.login-brand img {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  border: 1px solid var(--admin-border);
  object-fit: contain;
  padding: 3px;
}

.login-brand h1 { font-size: 19px; color: var(--admin-deep); }
.login-brand p { font-size: 12.5px; color: var(--admin-muted); }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--admin-deep);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(11, 94, 142, 0.24);
  border-radius: 9px;
  font-size: 14px;
  color: var(--admin-text);
  background: #ffffff;
  outline: none;
}

.form-control:focus {
  border-color: var(--admin-blue);
  box-shadow: 0 0 0 3px rgba(11, 94, 142, 0.12);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 700;
  transition: all 0.18s ease;
}

.btn-primary { background: var(--admin-blue); color: #ffffff; }
.btn-primary:hover { background: #08486e; }
.btn-green { background: var(--admin-green); color: #ffffff; }
.btn-green:hover { background: #147c40; }
.btn-outline { background: #ffffff; color: var(--admin-text); border: 1px solid var(--admin-border); }
.btn-outline:hover { border-color: var(--admin-blue); color: var(--admin-blue); }
.btn-danger { background: rgba(214, 59, 59, 0.1); color: var(--admin-danger); }
.btn-danger:hover { background: var(--admin-danger); color: #ffffff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

.error-msg {
  color: var(--admin-danger);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  min-height: 18px;
}

/* Dashboard Layout */
.admin-shell {
  display: none;
  min-height: 100vh;
}

.admin-shell.visible {
  display: grid;
  grid-template-columns: 248px 1fr;
}

.sidebar {
  background: var(--admin-deep);
  color: #ffffff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}

.sidebar-brand img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #ffffff;
  padding: 2px;
  object-fit: contain;
}

.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand span { font-size: 11px; color: #7ef7b4; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-tab-btn {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: rgba(220, 236, 246, 0.78);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-tab-btn:hover { background: rgba(255, 255, 255, 0.08); color: #ffffff; }
.nav-tab-btn.active { background: var(--admin-blue); color: #ffffff; }

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-footer a,
.sidebar-footer button {
  width: 100%;
  text-align: center;
  padding: 9px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.sidebar-footer a { background: rgba(255, 255, 255, 0.1); color: #ffffff; }
.sidebar-footer button { background: rgba(214, 59, 59, 0.22); color: #ffb3b3; border: none; }

/* Main Area */
.admin-main {
  padding: 26px 32px;
  overflow-y: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 22px;
}

.topbar h2 { font-size: 22px; font-weight: 800; color: var(--admin-deep); }

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

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

.stat-card span { font-size: 12.5px; color: var(--admin-muted); font-weight: 600; }
.stat-card strong { display: block; font-size: 26px; font-weight: 800; color: var(--admin-blue); margin-top: 4px; }

.panel {
  display: none;
}

.panel.active { display: block; }

.card {
  background: #ffffff;
  border: 1px solid var(--admin-border);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 20px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.toolbar-filters .form-control { width: auto; min-width: 170px; }

/* Data Table */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 740px;
}

table.data-table th,
table.data-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--admin-border);
  font-size: 13.5px;
  vertical-align: middle;
}

table.data-table th {
  background: #f5f9fb;
  color: var(--admin-deep);
  font-weight: 700;
  font-size: 12.5px;
}

.prod-mini-thumb {
  width: 58px;
  height: 44px;
  border-radius: 7px;
  object-fit: cover;
  border: 1px solid var(--admin-border);
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge-blue { background: #e8f3fa; color: var(--admin-blue); }
.badge-green { background: #e6f7ed; color: #126f39; }
.badge-gray { background: #edf1f4; color: #5b6e7f; }

/* Categories Tree */
.cat-block {
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
}

.cat-block-head {
  background: #f3f8fb;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid var(--admin-border);
}

.subcat-list {
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.subcat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid var(--admin-border);
  border-radius: 9px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(6, 29, 47, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: #ffffff;
  border-radius: 16px;
  width: 100%;
  max-width: 880px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 26px 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
}

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

.modal-header h3 { font-size: 18px; font-weight: 800; color: var(--admin-deep); }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* Multi-Image Uploader */
.image-uploader-box {
  border: 2px dashed rgba(11, 94, 142, 0.28);
  border-radius: 12px;
  padding: 16px;
  background: #f8fbfd;
  margin-bottom: 14px;
}

.upload-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.img-gallery-editor {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.img-item-card {
  background: #ffffff;
  border: 2px solid var(--admin-border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.img-item-card.is-primary {
  border-color: var(--admin-green);
  box-shadow: 0 0 0 2px rgba(28, 154, 82, 0.18);
}

.img-item-preview {
  aspect-ratio: 4 / 3;
  position: relative;
  background: #eef4f7;
}

.img-item-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.primary-ribbon {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--admin-green);
  color: #ffffff;
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
}

.img-item-controls {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.img-item-controls input {
  width: 100%;
  font-size: 12px;
  padding: 4px 7px;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
}

.img-btn-strip {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.img-btn-strip button {
  flex: 1;
  font-size: 11px;
  padding: 4px 5px;
  border-radius: 5px;
  border: 1px solid var(--admin-border);
  background: #f5f9fb;
  color: var(--admin-deep);
  font-weight: 700;
}

.img-btn-strip button.del { color: var(--admin-danger); }

.spec-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 34px;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}

.spec-row input {
  padding: 7px 8px;
  font-size: 12.5px;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 3000;
  background: var(--admin-deep);
  color: #ffffff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all 0.22s;
}

.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .admin-shell.visible { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .spec-row { grid-template-columns: 1fr 1fr; }
}
