:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.admin-shell {
  min-height: 100vh;
}

.login-card {
  width: min(340px, calc(100% - 24px));
  margin: 0 auto;
  padding: 24px 22px 20px;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
  position: relative;
  top: 14vh;
  text-align: center;
}

.login-brand {
  margin-bottom: 18px;
}

.login-brand h1 {
  margin: 8px 0 0;
  font-size: 18px;
  font-weight: 700;
}

.login-brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  margin: 0 auto;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
  font-size: 16px;
  margin: 0;
  border-radius: 10px;
}

.brand.compact {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand.compact strong,
.brand.compact span {
  display: block;
}

.brand.compact strong {
  font-size: 14px;
}

.brand.compact span {
  color: var(--sidebar-text);
  font-size: 12px;
}

.login-tip {
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.stack-form {
  display: grid;
  gap: 10px;
  text-align: left;
}

.stack-form label,
.settings-form label {
  display: grid;
  gap: 4px;
}

.stack-form span,
.settings-form span {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}

input:not([type='checkbox']),
textarea,
.settings-form select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  font-family: inherit;
  line-height: 1.4;
  color: #111827;
}

.settings-form select {
  min-height: 34px;
  cursor: pointer;
  appearance: auto;
}

.settings-form select:focus,
input:not([type='checkbox']):focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea {
  resize: vertical;
  min-height: 64px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 7px;
  min-height: 30px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.stack-form .btn-primary {
  min-height: 34px;
  margin-top: 2px;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.btn-ghost {
  background: #fff;
  color: #374151;
  border-color: #d1d5db;
}

.dashboard {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  text-align: left;
  background: transparent;
  color: var(--sidebar-text);
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
}

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

.sidebar-foot {
  margin-top: auto;
  font-size: 12px;
  color: #94a3b8;
}

.sidebar-foot .btn-logout {
  width: 100%;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.12);
}

.sidebar-foot .btn-logout:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-foot code {
  display: block;
  margin-top: 6px;
  color: #e2e8f0;
  word-break: break-all;
  font-size: 11px;
}

.dashboard-main {
  padding: 0;
  overflow: auto;
  background: var(--bg);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 0;
  padding: 12px 18px;
  background: var(--panel);
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
}

.topbar h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-all;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.content-wrap {
  padding: 14px 18px 24px;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
}

.status-dot i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
}

.status-dot em {
  font-style: normal;
}

.status-dot.ok {
  color: #047857;
}

.status-dot.ok i {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.status-dot.warn {
  color: #c2410c;
}

.status-dot.warn i {
  background: #f97316;
}

.status-dot.offline {
  color: #6b7280;
}

.status-dot.offline i {
  background: #9ca3af;
}

.status-dot.busy {
  color: #2563eb;
}

.status-dot.busy i {
  background: #3b82f6;
  animation: pulse-dot 1s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: none;
  margin-bottom: 12px;
}

.panel-head {
  margin-bottom: 12px;
}

.panel-head h3 {
  margin: 0;
  font-size: 14px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.panel-head-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

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

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 120px;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  background: #fff;
  color: #111827;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  white-space: nowrap;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.table-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 10px !important;
}

.product-name {
  font-weight: 600;
  margin-bottom: 2px;
}

.product-sub {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.commission-cell {
  font-weight: 600;
  color: #c2410c;
  white-space: nowrap;
}

.col-check {
  width: 36px;
}

.col-thumb {
  width: 52px;
}

.product-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.product-thumb-empty {
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 12px;
}

.listing-preview-list {
  display: grid;
  gap: 10px;
}

.listing-preview-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #f8fafc;
}

.listing-preview-item h4 {
  margin: 0 0 8px;
  font-size: 13px;
}

.listing-kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 4px 10px;
  font-size: 12px;
}

.listing-kv span {
  color: var(--muted);
}

.listing-kv code {
  word-break: break-all;
}

.log-detail-body {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 11px;
  line-height: 1.5;
  overflow: auto;
  max-height: 420px;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-ok {
  color: #047857;
  font-weight: 600;
}

.log-fail {
  color: #b91c1c;
  font-weight: 600;
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.table-pagination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-sm {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 12px;
}

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

.span-2 {
  grid-column: span 2;
}

.field-hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.page-view {
  display: none;
}

.page-view.active {
  display: block;
}

.global-actions {
  position: sticky;
  bottom: 0;
  padding: 10px 0;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.stat-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-card strong {
  font-size: 13px;
  word-break: break-all;
}

.actions {
  display: flex;
  gap: 8px;
}

.toggle-row input[type='checkbox'] {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  z-index: 1000;
  max-width: min(90vw, 360px);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .field-grid,
  .overview-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }
}
