:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687386;
  --line: #e5e9f2;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #dc2626;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: inherit; text-decoration: none; }
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: #101827; color: #d9e1ee; padding: 22px 16px; }
.brand { font-weight: 800; font-size: 20px; margin-bottom: 28px; }
.nav a { display: block; padding: 11px 12px; border-radius: 8px; color: #cbd5e1; margin-bottom: 6px; }
.nav a:hover, .nav a.active { background: #1e293b; color: #fff; }
.main { padding: 28px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 24px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 18px; box-shadow: 0 8px 24px rgba(15, 23, 42, .04); }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { font-size: 28px; font-weight: 800; }
.muted { color: var(--muted); }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 13px; font-weight: 700; background: #f8fafc; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  font: inherit;
  background: #fff;
}
textarea { min-height: 92px; resize: vertical; }
label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.btn { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 8px; padding: 9px 13px; font-weight: 700; background: var(--primary); color: #fff; cursor: pointer; }
.btn:hover { background: var(--primary-dark); }
.btn-light { background: #e2e8f0; color: #0f172a; }
.btn-disabled { background: #f1f5f9; color: #94a3b8; cursor: not-allowed; pointer-events: none; }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; background: #e2e8f0; color: #334155; }
.badge.paid, .badge.shipped, .badge.in_stock, .badge.active { background: #dcfce7; color: #166534; }
.badge.pending_ship, .badge.completed { background: #dbeafe; color: #1e40af; }
.badge.pending_payment { background: #fef3c7; color: #92400e; }
.badge.closed, .badge.unmatched, .badge.inactive, .badge.out_of_stock { background: #e5e7eb; color: #374151; }
.badge.matched { background: #ccfbf1; color: #115e59; }
.badge.manual_review { background: #fee2e2; color: #991b1b; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.copy-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.copy-value {
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}
.compact-form { align-items: end; }
.shipment-form { margin-top: 12px; }
.shipment-rows { display: grid; gap: 10px; margin-bottom: 12px; }
.shipment-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: end; }
.shipment-row p { margin: 0; }
.pre-line { white-space: pre-line; }
.drawer {
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .24);
}
.drawer-sm { width: min(640px, calc(100vw - 32px)); }
.drawer::backdrop { background: rgba(15, 23, 42, .38); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.drawer-head h2 { margin: 0; font-size: 20px; }
.table-wrap { overflow-x: auto; }
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
  max-width: 260px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.tab {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 13px;
  background: #f8fafc;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.settings-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #f8fafc;
}
.settings-group + .settings-group { margin-top: 14px; }
.settings-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.settings-group-head h2 {
  margin: 0;
  font-size: 18px;
}
.login { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 28px; }
.error { color: var(--danger); margin-bottom: 12px; }
.hidden { display: none !important; }
.media-editor {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 16px;
  align-items: start;
}
.image-preview {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.empty-preview {
  display: grid;
  place-items: center;
  width: 120px;
  height: 120px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafc;
  text-align: center;
  padding: 12px;
  font-size: 12px;
}
.thumb {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  display: block;
  margin-bottom: 6px;
}
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px;
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 600;
}
.check-row input {
  width: auto;
}
.add-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
  margin: 12px 0 18px;
}
.add-card summary {
  cursor: pointer;
  font-weight: 800;
  margin-bottom: 12px;
}
.media-thumb {
  margin: 8px 0;
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .grid-4, .form-grid { grid-template-columns: 1fr; }
  .shipment-row { grid-template-columns: 1fr; }
  .media-editor { grid-template-columns: 1fr; }
  .image-preview, .empty-preview { width: 120px; max-width: 120px; }
}
