* {
  box-sizing: border-box;
}

:root {
  --canvas: #ffffff;
  --page: #f6f7f9;
  --ink: #111111;
  --body: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-soft: #f1f5f9;
  --soft: #f8f9fb;
  --blue: #0066cc;
  --blue-hover: #0071e3;
  --black: #111827;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

body.login-mode {
  grid-template-columns: 1fr;
}

body.login-mode .main {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.hidden {
  display: none;
}

.sidebar {
  background: var(--canvas);
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar h1 {
  color: var(--ink);
  font-size: 20px;
  margin: 0 0 20px;
  padding: 0 10px;
  line-height: 1.25;
}

button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--black);
  color: #ffffff;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
}

button:hover {
  background: var(--blue);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:disabled:hover {
  background: var(--black);
}

button.is-loading {
  opacity: 0.72;
}

.sidebar button {
  width: 100%;
  display: block;
  margin-bottom: 8px;
  background: transparent;
  color: var(--body);
  border-color: transparent;
  text-align: left;
  font-weight: 600;
  min-height: 42px;
}

.sidebar button:hover {
  background: var(--soft);
  color: var(--ink);
}

.sidebar button.active {
  background: #f0f7ff;
  color: var(--blue);
  border-color: #d8eaff;
}

.main {
  padding: 28px 32px;
  overflow: auto;
}

.toast {
  position: fixed;
  top: 22px;
  right: 28px;
  z-index: 20;
  min-width: 220px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 8px;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  box-shadow: 0 12px 24px rgba(17, 24, 39, 0.08);
  font-weight: 700;
}

.toast.info {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #dbeafe;
}

.toast.error {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.topbar h2,
.panel h2,
.panel h3 {
  margin: 0 0 8px;
  color: var(--ink);
  line-height: 1.25;
}

.hint,
#viewDesc {
  color: var(--muted);
  margin: 0;
}

.admin-version {
  margin: -2px 0 14px;
  font-size: 13px;
}

.panel,
.metric,
table {
  background: var(--canvas);
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
  margin-bottom: 20px;
}

.login-panel {
  max-width: 720px;
  width: min(720px, 100%);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 16px;
}

.metric {
  padding: 20px;
}

.metric span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.metric strong {
  color: var(--ink);
  font-size: 28px;
  line-height: 1.15;
}

.form-row,
.form-grid {
  display: grid;
  gap: 12px;
}

.form-row {
  grid-template-columns: 1fr 140px auto;
  margin-bottom: 12px;
}

.agent-search-row {
  grid-template-columns: minmax(280px, 1fr) 128px 96px;
}

.form-grid {
  grid-template-columns: repeat(4, minmax(120px, 1fr));
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #d9dee7;
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--canvas);
  color: var(--ink);
  min-height: 42px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid #e8f2ff;
  border-color: var(--blue);
}

.upload-row {
  display: grid;
  grid-template-columns: 110px 220px 1fr;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

textarea {
  min-height: 80px;
  margin: 12px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

th,
td {
  text-align: left;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
  vertical-align: middle;
}

th {
  background: #fbfbfc;
  color: var(--body);
  font-weight: 800;
}

tbody tr:hover {
  background: #fbfdff;
}

td input,
td select {
  min-width: 90px;
}

.cover-thumb {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
}

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

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted);
  font-size: 12px;
}

.order-id-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-order-btn {
  padding: 4px 8px;
  border: 1px solid #d9dee7;
  border-radius: 999px;
  background: var(--canvas);
  color: var(--blue);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
}

.copy-order-btn:hover {
  background: #f0f7ff;
  border-color: #cfe6ff;
}

.save-btn {
  white-space: nowrap;
}

.secondary-action {
  background: var(--canvas);
  color: var(--body);
  border-color: #d9dee7;
}

.secondary-action:hover {
  background: var(--soft);
}

.danger-action {
  background: var(--canvas);
  color: #b91c1c;
  border-color: #fecaca;
}

.danger-action:hover {
  background: #fef2f2;
}

.order-filter {
  margin-bottom: 16px;
}

.order-filter-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 18px;
}

.order-filter-head h3 {
  margin-bottom: 6px;
}

.order-filter-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(170px, 210px) minmax(170px, 210px) auto;
  gap: 12px;
  align-items: end;
}

.filter-row label span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.filter-actions {
  display: flex;
  gap: 10px;
}

.filter-actions button {
  white-space: nowrap;
}

.export-action {
  min-width: 210px;
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
  white-space: nowrap;
}

.export-action:hover {
  background: var(--blue-hover);
  border-color: var(--blue-hover);
}

.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.status-tab {
  background: var(--canvas);
  color: var(--body);
  border: 1px solid #d9dee7;
  padding: 8px 14px;
}

.status-tab.active {
  background: var(--black);
  color: #ffffff;
  border-color: var(--black);
}

.order-row {
  border-left: 4px solid transparent;
}

.order-row.status-pending {
  border-left-color: #f59e0b;
}

.order-row.status-shipped {
  border-left-color: #16a34a;
}

.order-row.status-cancelled {
  border-left-color: #94a3b8;
  color: #64748b;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-width: 62px;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid transparent;
}

.status-badge.status-pending {
  color: #92400e;
  background: #fffbeb;
  border-color: #fde68a;
}

.status-badge.status-shipped {
  color: #166534;
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.status-badge.status-cancelled {
  color: #475569;
  background: #f8fafc;
  border-color: #cbd5e1;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: #6b7280;
  font-size: 14px;
}

.pagination button {
  padding: 8px 12px;
}

.stats-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 1000px) {
  body {
    grid-template-columns: 1fr;
  }

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

  .sidebar h1 {
    grid-column: 1 / -1;
  }

  .metrics,
  .form-grid,
  .stats-list,
  .export-tools,
  .filter-row {
    grid-template-columns: 1fr;
  }

  .order-filter-head {
    flex-direction: column;
  }

  .export-action,
  .filter-actions {
    width: 100%;
  }

  .filter-actions {
    flex-direction: column;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .upload-row {
    grid-template-columns: 1fr;
  }
}
