:root {
  --bg: #f5f5f6;
  --card: #ffffff;
  --ink: #18181b;
  --ink-soft: #3f3f46;
  --muted: #71717a;
  --line: #e4e4e7;
  --line-soft: #f0f0f1;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #eff6ff;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --info: #1d4ed8;
  --info-soft: #eff6ff;
  --radius: 8px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; letter-spacing: -.01em; }

code {
  font-family: var(--mono);
  font-size: 12px;
  background: #f4f4f5;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ------------------------------------------------------------ layout */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 2px 8px 18px;
  color: var(--ink);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--ink);
  display: grid; place-items: center;
  color: #fff;
  flex: 0 0 28px;
}
.brand-mark .ico { width: 16px; height: 16px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 14.5px; font-weight: 650; }
.brand-text small { color: var(--muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
.nav-group {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #a1a1aa;
  padding: 16px 9px 6px;
  font-weight: 600;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--ink-soft);
  font-size: 13.5px;
  text-decoration: none;
}
.nav-link:hover { background: #f4f4f5; color: var(--ink); text-decoration: none; }
.nav-link.is-active { background: #f4f4f5; color: var(--ink); font-weight: 600; }
.nav-link .ico { width: 16px; height: 16px; color: var(--muted); flex: 0 0 16px; }
.nav-link.is-active .ico { color: var(--ink); }

.side-foot { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 10px; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 2px 6px 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: #f4f4f5;
  color: var(--ink-soft);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  flex: 0 0 30px;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.user-meta strong { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--muted); font-size: 11px; }

.icon-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  background: none; border: 0;
  color: var(--muted);
  font: inherit; font-size: 12.5px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}
.icon-btn:hover { background: #f4f4f5; color: var(--ink); }
.icon-btn .ico { width: 15px; height: 15px; }

.main { flex: 1; min-width: 0; padding: 30px 38px 60px; }
.main > * { max-width: 1200px; }

/* ------------------------------------------------------------- header */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-title { font-size: 21px; font-weight: 650; letter-spacing: -.02em; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; align-items: center; }

/* -------------------------------------------------------------- cards */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.card-title { font-size: 14.5px; font-weight: 650; }
.card-note { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

/* -------------------------------------------------------------- stats */

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.grid-stats-sm { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
}
.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-label { margin-top: 3px; font-size: 12.5px; color: var(--ink-soft); }
.stat-hint { margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.stat-success .stat-value { color: var(--success); }
.stat-danger .stat-value { color: var(--danger); }

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: #fff;
  color: var(--ink-soft);
  border: 1px solid #d4d4d8;
  border-radius: 6px;
  padding: 7px 13px;
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .1s, border-color .1s;
  white-space: nowrap;
}
.btn:hover { background: #fafafa; border-color: #a1a1aa; text-decoration: none; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f4f4f5; color: var(--ink); border-color: transparent; }
.btn-danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); border-color: #fca5a5; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn .ico { width: 14px; height: 14px; }
.ico-sm { width: 12px; height: 12px; }

/* ------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td {
  padding: 9px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fafafa; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions-col { text-align: right; width: 1%; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.code-wrap { word-break: break-all; }

/* ------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-muted { background: #f4f4f5; color: #52525b; }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* -------------------------------------------------------------- forms */

.form { display: flex; flex-direction: column; gap: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 500; color: var(--ink-soft); }
.field small { color: var(--muted); font-size: 11.5px; font-weight: 400; line-height: 1.4; }
input, select, textarea {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #d4d4d8;
  border-radius: 6px;
  padding: 7px 10px;
  width: 100%;
  outline: none;
  transition: border-color .1s, box-shadow .1s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, .12);
}
textarea { resize: vertical; min-height: 60px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.field-inline { flex-direction: row; align-items: center; gap: 7px; font-weight: 500; }
.field-inline input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); }
.field-inline select, .field-inline input:not([type="checkbox"]) { width: auto; min-width: 140px; }
.field-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 13px; }
.settings-form .card { margin-bottom: 16px; }
.two-col { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 18px; align-items: start; }
.two-col-wide { grid-template-columns: 320px minmax(0, 1fr); }
.inline-form { display: flex; gap: 5px; align-items: center; justify-content: flex-end; }
.inline-form select { width: auto; padding: 4px 24px 4px 7px; font-size: 11.5px; }
.row-actions { display: flex; gap: 5px; justify-content: flex-end; flex-wrap: wrap; }
.filters { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }

@media (max-width: 1100px) {
  .two-col, .two-col-wide { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------ products */

.product-list { display: flex; flex-direction: column; }
.product-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}
.product-row:last-child { border-bottom: 0; }
.product-row:first-child { padding-top: 2px; }
.product-info { min-width: 0; }
.product-name { font-size: 13.5px; font-weight: 600; }
.product-desc { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.product-action { flex: 0 0 auto; }
.product-row.is-compact .product-desc { font-size: 12px; }

/* -------------------------------------------------------------- detail */

.detail-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.qr-card { text-align: center; }
.qr-box {
  display: inline-block;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.qr-box img { display: block; width: 220px; height: 220px; }
.qr-caption { margin: 10px 0; font-size: 12.5px; color: var(--muted); }
.qr-actions { display: flex; gap: 6px; justify-content: center; }

.kv { display: flex; flex-direction: column; }
.kv-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}
.kv-row:last-child { border-bottom: 0; }
.kv-row > span { color: var(--muted); }
.kv-value { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }

.link-mono {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}

/* ------------------------------------------------------------ timeline */

.timeline { list-style: none; margin: 0; padding: 2px 0 0 4px; }
.timeline li { display: flex; gap: 11px; padding: 0 0 13px; position: relative; }
.timeline li:not(:last-child)::before {
  content: ""; position: absolute; left: 4px; top: 12px; bottom: 0;
  width: 1px; background: var(--line);
}
.timeline .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #d4d4d8; margin-top: 4px; flex: 0 0 9px;
}
.timeline .dot-success { background: var(--success); }
.timeline .dot-danger { background: var(--danger); }
.timeline .dot-info { background: var(--info); }
.timeline strong { display: block; font-size: 13px; font-weight: 600; }
.timeline small { color: var(--muted); font-size: 11.5px; }

/* --------------------------------------------------------------- flash */

.flash {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid;
  font-size: 13px;
  margin-bottom: 16px;
}
.flash-ok { background: var(--success-soft); border-color: #bbf7d0; color: #166534; }
.flash-err { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.flash-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 6px; }
.flash-x { margin-left: auto; background: none; border: 0; color: inherit; opacity: .5; font-size: 17px; line-height: 1; cursor: pointer; padding: 0 2px; }
.flash-x:hover { opacity: 1; }

/* ---------------------------------------------------------------- misc */

.empty { text-align: center; padding: 32px 16px; }
.empty-title { font-weight: 600; font-size: 13.5px; }
.empty-text { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

.pool-table { margin-top: 14px; max-height: 260px; overflow-y: auto; }

.error-page { text-align: center; padding: 60px 20px; }
.error-code { font-size: 48px; font-weight: 700; color: #d4d4d8; line-height: 1; }
.error-page h1 { font-size: 20px; margin: 10px 0 6px; }
.error-page p { color: var(--muted); margin: 0 0 18px; }
.error-inline .error-code { font-size: 40px; }

/* ---------------------------------------------------------------- auth */

.auth-body { background: var(--bg); }
.auth-wrap {
  width: 100%;
  max-width: 370px;
  margin: 0 auto;
  padding: 12vh 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; color: var(--ink);
  padding-left: 2px;
}
.auth-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 26px 24px;
}
.auth-title { font-size: 18px; font-weight: 650; letter-spacing: -.015em; }
.auth-sub { color: var(--muted); font-size: 12.5px; margin: 4px 0 18px; }
.auth-alt { text-align: center; color: var(--muted); font-size: 12.5px; margin: 16px 0 0; }
.auth-card .form { gap: 13px; }
.auth-card .btn-block { margin-top: 2px; padding: 9px; }
.auth-note { text-align: center; color: #a1a1aa; font-size: 11.5px; }

/* ---------------------------------------------------------- responsive */

@media (max-width: 960px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; padding: 12px 12px 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding-bottom: 10px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 3px; }
  .nav-group { display: none; }
  .nav-link { padding: 6px 9px; font-size: 12.5px; }
  .nav-link .ico { width: 14px; height: 14px; flex-basis: 14px; }
  .side-foot { display: flex; align-items: center; justify-content: space-between; border-top: 0; padding-top: 4px; margin-top: 4px; }
  .user-chip { padding-bottom: 0; }
  .icon-btn { width: auto; }
  .main { padding: 20px 16px 44px; }
  .page-title { font-size: 19px; }
  .stat-value { font-size: 21px; }
}

@media (max-width: 640px) {
  .side-foot .user-meta { display: none; }
  .grid-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 14px; }
  .kv-row { grid-template-columns: 1fr; gap: 2px; }
  .filters .field-inline { width: 100%; }
  .filters .field-inline select { flex: 1; }
  .product-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .product-action { width: 100%; }
  .product-action .btn { width: 100%; }
}

@media print {
  .sidebar, .actions, .btn, .flash-x { display: none !important; }
  .main { padding: 0; }
  .card { border: 0; }
  .qr-box img { width: 300px; height: 300px; }
}
