:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: #111827;
  color: #e5e7eb;
  padding: 20px 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  padding: 0 20px 20px;
  color: #fff;
}
.menu-toggle { display: none; }
.sidebar nav a {
  display: block;
  padding: 12px 20px;
  color: #d1d5db;
  text-decoration: none;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: #1f2937; color: #fff; }
.sidebar nav a.active {
  background: #1f2937;
  color: #fff;
  border-left-color: var(--accent);
}

.main { flex: 1; min-width: 0; }
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 28px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.shop-selector label { margin-right: 8px; color: var(--muted); }

.content { padding: 28px; max-width: 1080px; }

h1 { font-size: 24px; margin: 0 0 6px; }
.subtitle { color: var(--muted); margin-top: 0; }
.section-title { font-size: 16px; margin: 28px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin: 16px 0;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.card-label { color: var(--muted); font-size: 13px; }
.card-value { font-size: 30px; font-weight: 700; margin: 6px 0; }
.card-note { color: var(--muted); font-size: 12px; }
.card.highlight { background: var(--accent-soft); border-color: var(--accent); }

.alert {
  border-radius: 10px;
  padding: 16px 20px;
  margin: 16px 0;
}
.alert.error { background: #fef2f2; border: 1px solid #fecaca; color: var(--err); }

.flash {
  padding: 10px 16px;
  border-radius: 8px;
  margin: 12px 28px 0;
}
.flash.ok, .flash.message { background: #f0fdf4; color: var(--ok); border: 1px solid #bbf7d0; }
.flash.error { background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.table th, .table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th { background: #f9fafb; color: var(--muted); font-weight: 600; font-size: 13px; }
.table tr:last-child td { border-bottom: none; }
.table a { color: var(--accent); text-decoration: none; }

.order-product-images { display: flex; flex-wrap: wrap; gap: 6px; min-width: 64px; max-width: 140px; margin-bottom: 4px; }
.order-image-frame { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; flex-shrink: 0; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #f9fafb; }
.order-image-fallback { color: var(--muted); font-size: 11px; }
.order-product-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #eef2ff;
  color: var(--accent);
}
.badge.unpaid { background: #fef2f2; color: var(--err); }
.badge.unshipped { background: #fffbeb; color: var(--warn); }
.badge.shipped { background: #eff6ff; color: #2563eb; }
.badge.delivered, .badge.success { background: #f0fdf4; color: var(--ok); }
.badge.canceled { background: #f3f4f6; color: var(--muted); }
.badge.running, .badge.queued { background: #fffbeb; color: var(--warn); }
.badge.error { background: #fef2f2; color: var(--err); }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 800px) { .detail-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.form .field { margin-bottom: 16px; }
.form label { display: block; margin-bottom: 6px; font-weight: 600; }
.form input[type="text"], .form input[type="email"], .form input[type="password"], .form select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.form input[type="file"] { font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
.req { color: var(--err); }

/* Password fields with an inline show/hide toggle */
.pw-wrap { position: relative; }
.pw-wrap input[type="text"], .pw-wrap input[type="password"] { padding-right: 62px; }
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  padding: 3px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
  cursor: pointer;
}
.pw-toggle:hover { background: var(--accent-soft); color: var(--accent); }
.pw-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }


/* Drag-and-drop upload zones */
.dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 22px 18px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  outline: none;
}
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); border-color: var(--accent); }
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.dz-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.dz-body {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.dz-icon { font-size: 28px; line-height: 1; }
.dz-text { text-align: left; }
.dz-title { display: block; font-size: 14px; }
.dz-sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; word-break: break-all; }

.checks label { display: block; margin: 8px 0; font-weight: 400; }

.filters {
  display: flex;
  gap: 10px;
  margin: 16px 0;
  flex-wrap: wrap;
}
.filters input[type="text"] {
  flex: 1;
  min-width: 220px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.filters select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.inline-form {
  display: flex;
  gap: 6px;
  align-items: center;
}
.inline-form input[type="text"] {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  width: 170px;
}
.inline-form .btn {
  padding: 5px 10px;
  font-size: 13px;
}

.cell-input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  width: 150px;
}
.cell-input-num {
  width: 76px;
}
td.actions {
  white-space: nowrap;
  text-align: right;
}

.btn {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { border-color: var(--err); color: var(--err); background: #fff; }
.btn.danger:hover { background: #fef2f2; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.empty { color: var(--muted); padding: 30px 0; text-align: center; }
.address { white-space: pre-line; line-height: 1.6; }
.note { background: #f9fafb; border-radius: 8px; padding: 10px 12px; margin: 12px 0; }

.shop-list { list-style: none; margin: 16px 0 0; padding: 0; }
.shop-list li { margin-bottom: 8px; }
.shop-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}
.shop-list a:hover { background: #f9fafb; }
.shop-list a.active { border-color: var(--accent); background: #eef2ff; }
.shop-list .shop-name { font-weight: 600; }

.kv code, .shop-info code { font-size: 12px; word-break: break-all; }

.log {
  background: #0b1220;
  color: #d1d5db;
  padding: 16px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 600px;
}

/* Sidebar footer (logout) */
.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid #1f2937;
}
.sidebar-email {
  color: #9ca3af;
  font-size: 12px;
  margin-bottom: 10px;
  word-break: break-all;
}
.btn-logout {
  width: 100%;
  background: transparent;
  border-color: #374151;
  color: #d1d5db;
}
.btn-logout:hover { background: #1f2937; color: #fff; }

/* Landing / auth pages */
body.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-wrap {
  width: 100%;
  max-width: 720px;
}
.auth-brand {
  font-size: 28px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 6px;
}
.auth-tagline {
  color: var(--muted);
  text-align: center;
  margin: 0 0 24px;
}
.auth-flashes { margin-bottom: 16px; }
.auth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 640px) { .auth-grid { grid-template-columns: 1fr; } }

/* ===== Mobile / responsive ===== */

/* On narrow screens the fixed sidebar collapses into a top bar with a
   hamburger button; the nav and footer stay hidden until toggled open. */
@media (max-width: 768px) {
  body { flex-direction: column; }

  .sidebar {
    width: 100%;
    flex-direction: column;
    padding: 0;
    overflow: visible;
  }
  .brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0;
  }
  .brand span {
    padding: 14px 16px;
    font-size: 16px;
    white-space: nowrap;
  }
  .menu-toggle {
    display: block;
    background: transparent;
    border: none;
    color: #e5e7eb;
    font-size: 24px;
    line-height: 1;
    padding: 10px 16px;
    cursor: pointer;
  }
  .menu-toggle:hover { color: #fff; }

  /* Collapsed by default; toggle .open to reveal the nav and footer. */
  .sidebar nav { display: none; }
  .sidebar.open nav { display: block; }
  .sidebar nav a {
    padding: 14px 16px;
    border-left: 3px solid transparent;
    border-bottom: 1px solid #1f2937;
    white-space: normal;
    font-size: 15px;
  }
  .sidebar nav a.active {
    border-left-color: var(--accent);
  }
  .sidebar-footer {
    display: none;
    margin-top: 0;
    padding: 16px;
    border-top: 1px solid #1f2937;
  }
  .sidebar.open .sidebar-footer { display: block; }
  .sidebar-email { display: block; }
  .btn-logout { width: 100%; }

  .content { padding: 16px; }
  .flash { margin: 12px 16px 0; }
  h1 { font-size: 20px; }

  /* Wide tables (orders, jobs, line items) scroll horizontally instead of
     overflowing off-screen. */
  .table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
}

/* Key-value lists and filter bars stack vertically on phones. */
@media (max-width: 640px) {
  .kv { grid-template-columns: 1fr; gap: 2px 12px; }
  .kv dt { margin-top: 8px; }

  .filters { flex-direction: column; align-items: stretch; }
  .filters input[type="text"] { min-width: 0; width: 100%; flex: none; }
  .filters select { width: 100%; }
  .filters .btn { width: 100%; }

  .inline-form { flex-wrap: wrap; }
  .inline-form input[type="text"] { width: 100%; flex: 1 1 100%; }
}

/* Stat cards sit two-across on small phones. */
@media (max-width: 480px) {
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 12px; }
  .card-value { font-size: 24px; }
  .btn { padding: 10px 14px; }
}
