:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #667085;
  --line: #e3e7ec;
  --accent: #0b6e99;
  --accent-ink: #ffffff;
  --accent-soft: #e5f2f8;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --panel: #1b2129;
    --ink: #e6eaf0;
    --muted: #98a2b3;
    --line: #2b333e;
    --accent: #3ba7d6;
    --accent-ink: #0b1218;
    --accent-soft: #17303d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; text-decoration: none; white-space: nowrap; }
.search { flex: 1; max-width: 420px; }
.search.mobile { display: none; }
.search input {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg);
}
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.link-btn { text-decoration: none; color: var(--muted); white-space: nowrap; }
.link-btn:hover { color: var(--ink); }
.cart-btn, .primary {
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.cart-btn:hover, .primary:hover { filter: brightness(1.08); }
.secondary {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
.secondary:hover { background: var(--accent-soft); }
.badge {
  display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 4px;
  background: var(--accent-ink); color: var(--accent);
  border-radius: 999px; font-size: 13px; text-align: center;
}
.icon-btn {
  border: 0; background: transparent; font-size: 22px; line-height: 1;
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); }
.menu-btn { display: none; }

/* Layout */
.layout { display: flex; min-height: calc(100vh - 57px); }
.sidebar {
  width: 240px; flex-shrink: 0;
  padding: 16px 10px; border-right: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto;
}
.side-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 8px 8px; }
.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-list a {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: 8px; text-decoration: none; text-transform: capitalize;
}
.cat-list a:hover { background: var(--accent-soft); }
.cat-list a.active { background: var(--accent); color: var(--accent-ink); }
.cat-list .n { opacity: .7; font-size: 13px; }
.main { flex: 1; min-width: 0; padding: 20px 24px 60px; }

h1 { font-size: 22px; margin: 0 0 4px; text-transform: capitalize; }
.sub { color: var(--muted); margin: 0 0 18px; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--accent); text-decoration: none; }

/* Grids */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; box-shadow: var(--shadow);
  display: flex; flex-direction: column; transition: transform .12s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .thumb { aspect-ratio: 1 / 1.41; background: #fff; overflow: hidden; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .meta { padding: 10px 12px; }
.card .title { font-weight: 600; font-size: 14px; }
.card .info { font-size: 13px; color: var(--muted); }
.section-title { font-size: 16px; margin: 26px 0 10px; text-transform: capitalize; display: flex; align-items: baseline; gap: 10px; }
.section-title a { font-size: 13px; color: var(--accent); text-decoration: none; font-weight: normal; }

.pages { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.page-card { position: relative; cursor: pointer; }
.page-card .pnum { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 1px 7px; border-radius: 999px; }
.page-card .pin { position: absolute; right: 8px; top: 8px; background: var(--accent); color: var(--accent-ink); font-size: 12px; padding: 1px 7px; border-radius: 999px; font-weight: 600; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin: 0 0 16px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--ink); border-color: var(--accent); font-weight: 600; }
.sub a { color: var(--accent); }

/* Product cards */
.products { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card.product:hover { transform: none; }
.card.product.in-cart { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pthumb { aspect-ratio: 4 / 3; background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; cursor: zoom-in; }
.pthumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card .spec { font-size: 13px; }
.qadd { display: flex; gap: 6px; margin-top: 8px; }
.qadd input { width: 70px; padding: 5px 7px; min-width: 0; flex: 1; }
.qadd select { padding: 5px 4px; }
.primary.small { padding: 5px 12px; }
.remark { width: 100%; margin-top: 6px; padding: 5px 8px; font-size: 13px; }
.incart { font-size: 12px; color: var(--accent); font-weight: 600; min-height: 16px; margin-top: 4px; }
.more { display: block; margin: 18px auto 0; }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.viewer-title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-nav { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.viewer-body { flex: 1; display: flex; min-height: 0; }
.viewer-img { flex: 1; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 16px; background: #2a2f36; cursor: zoom-in; }
.viewer-img img { max-width: 100%; max-height: calc(100vh - 90px); background: #fff; box-shadow: 0 4px 24px rgba(0,0,0,.4); }
.viewer-img.zoom { cursor: zoom-out; }
.viewer-img.zoom img { max-width: none; max-height: none; width: 1600px; }
.add-panel { width: 360px; flex-shrink: 0; overflow-y: auto; padding: 18px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; }
.add-form { display: flex; flex-direction: column; gap: 10px; }
.add-panel h3 { margin: 0; font-size: 17px; }
#pageProducts:empty { display: none; }
#pageProducts h3 { margin-bottom: 8px; }
#pageProducts + .add-form { border-top: 1px solid var(--line); padding-top: 14px; }
#pageProducts + .add-form h3 { font-size: 14px; color: var(--muted); }
.pp { display: grid; grid-template-columns: 80px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pp img { width: 80px; height: 64px; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--line); }
.pp .small { font-size: 12px; color: var(--muted); }
.pp .qadd { margin-top: 4px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-weight: normal; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.req { color: var(--danger); }
.page-items { margin-top: 8px; font-size: 13px; }
.page-items h4 { margin: 8px 0 6px; font-size: 13px; color: var(--muted); }
.page-items .pi { display: flex; justify-content: space-between; gap: 6px; padding: 6px 8px; background: var(--accent-soft); border-radius: 6px; margin-bottom: 4px; }

/* Drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--panel); z-index: 51; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.2); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.empty { color: var(--muted); text-align: center; padding: 40px 10px; }
.line { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: start; }
.note-in { width: 100%; margin-top: 6px; padding: 5px 8px; font-size: 13px; }
.tphoto { width: 90px; max-height: 70px; object-fit: contain; background: #fff; border-radius: 4px; }
.line img { width: 64px; height: 64px; object-fit: contain; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; background: #fff; }
.line .code { font-weight: 700; }
.line .small { font-size: 12px; color: var(--muted); }
.line .qty { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.line .qty input { width: 90px; padding: 5px 8px; }
.line .qty select { padding: 5px 8px; }
.remove { border: 0; background: none; color: var(--danger); cursor: pointer; font-size: 13px; }
.totals { display: flex; justify-content: space-between; padding: 12px 0; font-weight: 600; }
.checkout { display: grid; gap: 10px; margin-top: 8px; }
.checkout h3 { margin: 10px 0 0; font-size: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

/* Orders */
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: top; }
th { background: var(--accent-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.order-box { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.order-box h3 { margin: 0 0 4px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 60; font-size: 14px; }

/* Print: only the order sheet */
.print-sheet { display: none; }
@media print {
  body > *:not(.print-sheet) { display: none !important; }
  .print-sheet { display: block; color: #000; }
  .print-sheet table { box-shadow: none; }
  .print-sheet th { background: #eee; }
  .print-sheet img { width: 50px; }
}

/* Mobile */
@media (max-width: 860px) {
  .menu-btn { display: inline-block; }
  .sidebar { position: fixed; left: 0; top: 57px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  .sidebar.open { transform: none; }
  .main { padding: 16px; }
  .search { display: none; }
  .search.mobile { display: block; margin-bottom: 14px; max-width: none; }
  .link-btn { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .pages { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .viewer-body { flex-direction: column; }
  .viewer-img { flex: none; height: 58vh; padding: 8px; }
  .viewer-img img { max-height: none; }
  .add-panel { width: 100%; border-left: 0; border-top: 1px solid var(--line); flex: 1; }
}
