:root {
  color-scheme: light;
  --page: #ffffff;
  --surface: #f5f5f7;
  --surface-strong: #ececf0;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --blue: #0071e3;
  --blue-soft: #e8f2ff;
  --green: #16834f;
  --red: #c62d27;
  --orange: #a86200;
  --purple: #7352a6;
  --radius: 24px;
  --shadow: 0 18px 55px rgba(0, 0, 0, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #000;
    --surface: #1d1d1f;
    --surface-strong: #2b2b2e;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --line: #3a3a3c;
    --blue: #65aef8;
    --blue-soft: #132c46;
    --green: #5fd18c;
    --red: #ff746d;
    --orange: #ffc466;
    --purple: #c6a8f5;
    --shadow: 0 18px 60px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(2.1rem, 5vw, 3.7rem); line-height: 1.03; letter-spacing: -.055em; }
h2 { font-size: 1.2rem; letter-spacing: -.025em; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 9px; color: var(--blue); font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }

.app-shell { min-height: 100vh; }
.side-nav {
  position: fixed; inset: 0 auto 0 0; z-index: 20; display: flex; flex-direction: column;
  width: 238px; padding: 26px 18px 20px; border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--page) 91%, transparent);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
}
.brand { display: flex; align-items: center; gap: 11px; margin: 0 8px 36px; color: var(--text); font-weight: 650; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: .68rem; font-weight: 400; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px;
  background: var(--text); color: var(--page); font-size: .92rem; font-weight: 700;
}
.brand-mark.large { width: 56px; height: 56px; border-radius: 18px; font-size: 1.35rem; }
.desktop-nav { display: grid; gap: 5px; }
.desktop-nav a {
  display: flex; min-height: 46px; align-items: center; padding: 0 14px; border-radius: 13px;
  color: var(--muted); font-weight: 520;
}
.desktop-nav a:hover, .desktop-nav a.active { background: var(--surface); color: var(--text); }
.desktop-nav .scan-link.active { background: var(--text); color: var(--page); }
.profile {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line);
}
.profile strong, .profile small { display: block; }
.profile strong { font-size: .8rem; }
.profile small { color: var(--muted); font-size: .68rem; }
.profile-avatar {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--blue-soft); color: var(--blue); font-weight: 700;
}
.profile-avatar.small { width: 28px; height: 28px; font-size: .74rem; }
.icon-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: .72rem; }

.app-main { width: min(1180px, calc(100% - 286px)); margin-left: 258px; padding: 46px 0 80px; }
.mobile-topbar, .mobile-nav { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.page-head p:last-child { margin-bottom: 0; }
.page-head h1 { margin-bottom: 8px; }
.page-head .button { flex: 0 0 auto; }

.button {
  display: inline-flex; min-height: 42px; align-items: center; justify-content: center;
  padding: 9px 18px; border: 0; border-radius: 999px; cursor: pointer; font-size: .84rem;
  font-weight: 600; line-height: 1;
}
.button.primary { background: var(--blue); color: #fff; }
.button.secondary { background: var(--surface-strong); color: var(--text); }
.button.danger { background: var(--red); color: #fff; }
.button.small { min-height: 34px; padding: 7px 13px; font-size: .76rem; }
.button.wide { width: 100%; }
.button.disabled { opacity: .35; pointer-events: none; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { display: grid; min-height: 132px; padding: 23px; border-radius: 22px; background: var(--surface); color: var(--text); }
.stat-card span { color: var(--muted); font-size: .78rem; }
.stat-card strong { align-self: end; font-size: 2.35rem; letter-spacing: -.05em; }
.stat-card.warn { background: color-mix(in srgb, var(--orange) 12%, var(--surface)); }
.stat-card.danger { background: color-mix(in srgb, var(--red) 10%, var(--surface)); }
.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.quick-card { display: grid; gap: 7px; min-height: 152px; padding: 22px; border-radius: 22px; background: var(--surface); color: var(--text); }
.quick-card:hover { transform: translateY(-2px); }
.quick-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: var(--page); color: var(--blue); font-weight: 700; }
.quick-card strong { align-self: end; }
.quick-card small { color: var(--muted); }
.two-column { display: grid; grid-template-columns: 1.15fr .85fr; gap: 18px; }
.panel { min-width: 0; padding: 26px; border-radius: var(--radius); background: var(--surface); }
.panel + .panel { margin-top: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 18px; }
.panel-head h2 { margin: 0; }
.panel-head a { font-size: .78rem; }
.activity-list { display: grid; gap: 2px; }
.activity { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.activity:last-child { border-bottom: 0; }
.activity strong, .activity small { display: block; }
.activity small { margin-top: 3px; color: var(--muted); font-size: .7rem; }
.movement-badge { display: inline-flex; min-width: 46px; justify-content: center; padding: 5px 8px; border-radius: 999px; background: var(--surface-strong); font-size: .7rem; font-weight: 650; }
.movement-badge.inbound { color: var(--blue); background: var(--blue-soft); }
.movement-badge.use { color: var(--green); }
.movement-badge.outbound { color: var(--purple); }
.movement-badge.destroy { color: var(--red); }
.attention-list { display: grid; gap: 8px; }
.attention-list a { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; padding: 12px; border-radius: 14px; background: var(--page); color: var(--text); }
.attention-list span { color: var(--orange); font-size: .7rem; }
.attention-list strong { grid-column: 1 / -1; }
.attention-list small { color: var(--muted); }
.empty { margin: 0; padding: 28px 0; color: var(--muted); text-align: center; }

.flash { margin-bottom: 16px; padding: 13px 17px; border-radius: 14px; background: var(--blue-soft); color: var(--blue); font-size: .82rem; }
.flash.error { background: color-mix(in srgb, var(--red) 12%, var(--surface)); color: var(--red); }
.filter-bar { display: flex; gap: 10px; margin-bottom: 20px; }
.filter-bar input, .filter-bar select { min-width: 0; }
.filter-bar input { flex: 1; }
.item-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.item-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 15px; padding: 18px; border-radius: 20px; background: var(--surface); color: var(--text); }
.item-card:hover { background: var(--surface-strong); }
.item-avatar, .product-symbol {
  display: grid; place-items: center; width: 52px; height: 52px; border-radius: 16px;
  background: var(--page); color: var(--blue); font-size: 1.1rem; font-weight: 700;
}
.product-photo { width: 92px; height: 92px; border-radius: 22px; object-fit: cover; background: var(--surface-strong); }
.item-body strong, .item-body small { display: block; }
.item-body small { margin: 4px 0 8px; color: var(--muted); font-size: .72rem; }
.item-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.pill, .tag { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: var(--page); color: var(--muted); font-size: .66rem; }
.location-pill { color: var(--blue); }
.item-stock { text-align: right; }
.item-stock strong, .item-stock small { display: block; }
.item-stock strong { font-size: 1.35rem; letter-spacing: -.03em; }
.item-stock small { color: var(--muted); font-size: .68rem; }
.item-stock.empty strong { color: var(--muted); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 26px; font-size: .78rem; }

.product-hero { display: flex; align-items: center; gap: 20px; margin-bottom: 20px; padding: 30px; border-radius: var(--radius); background: var(--surface); }
.product-hero h1, .product-hero h2 { margin-bottom: 6px; }
.product-hero p { margin-bottom: 6px; color: var(--muted); }
.detail-hero .grow { flex: 1; }
.location-line { color: var(--text) !important; font-size: .78rem; }
.big-stock { text-align: right; }
.big-stock strong { display: block; font-size: 2.8rem; letter-spacing: -.06em; }
.big-stock span { color: var(--muted); }
.action-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.action-card { display: grid; min-height: 145px; align-content: space-between; padding: 22px; border-radius: 22px; background: var(--surface); color: var(--text); }
.action-card strong { font-size: 1.4rem; }
.action-card small { color: var(--muted); }
.action-card.inbound strong { color: var(--blue); }
.action-card.use strong { color: var(--green); }
.action-card.destroy strong { color: var(--red); }
.empty-state { display: grid; justify-items: center; max-width: 580px; margin: 80px auto; text-align: center; }
.empty-state p { color: var(--muted); }

.form-card { padding: 28px; border-radius: var(--radius); background: var(--surface); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid.compact { gap: 12px; padding: 0; background: transparent; }
.span-2 { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: var(--muted); font-size: .76rem; }
.field-group { display: grid; gap: 7px; color: var(--muted); font-size: .76rem; }
.field-group > label { display: block; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--page); color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--blue) 25%, transparent); outline-offset: 1px;
}
.input-action { display: flex; gap: 8px; }
.input-action input { min-width: 0; }
.input-action .button { flex: 0 0 auto; }
.quick-category { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; padding: 10px; border-radius: 12px; background: var(--page); }
.quick-category[hidden] { display: none; }
.quick-category .input-hint { grid-column: 1 / -1; min-height: 1em; margin: 0; }
.quick-category .input-hint.error { color: var(--red); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.page-toolbar { display: flex; justify-content: flex-end; margin: -4px 0 18px; }
.form-error { padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--red) 12%, var(--surface)); color: var(--red); }
.form-hint, .input-hint { color: var(--muted); font-size: .7rem; }
.input-hint { display: block; margin-top: 5px; }
.scanner-layout { display: grid; grid-template-columns: 1.25fr .75fr; gap: 18px; }
.scanner-card { position: relative; overflow: hidden; min-height: 440px; border-radius: 28px; background: #090909; }
.scanner-card video { width: 100%; height: 100%; min-height: 440px; object-fit: cover; }
.scan-frame { position: absolute; inset: 50% auto auto 50%; width: min(68%, 430px); aspect-ratio: 1.55; transform: translate(-50%, -50%); border: 2px solid rgba(255,255,255,.9); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,.22); }
.scanner-status { position: absolute; right: 16px; bottom: 16px; left: 16px; padding: 10px; border-radius: 999px; background: rgba(0,0,0,.68); color: #fff; font-size: .75rem; text-align: center; }
.scanner-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }
.batch-list { display: grid; gap: 10px; }
.batch-card { display: grid; grid-template-columns: 1.4fr .7fr auto; gap: 16px; align-items: center; padding: 16px; border-radius: 16px; background: var(--page); }
.batch-card.depleted { opacity: .5; }
.batch-card strong, .batch-card small, .batch-card span { display: block; }
.batch-card small { margin-top: 4px; color: var(--muted); font-size: .7rem; }
.batch-actions { display: flex; gap: 12px; font-size: .76rem; }
.danger-text { color: var(--red); }
.table-scroll { overflow-x: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-size: .78rem; }
th { color: var(--muted); font-size: .68rem; font-weight: 550; }
td.positive { color: var(--red); }
td.negative { color: var(--green); }
.table-panel { padding-bottom: 16px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.tag-list.compact-tags { margin: 2px 0 0; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 16px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.member-list { display: grid; gap: 10px; margin-bottom: 18px; }
.member-list > div { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; align-items: center; }
.member-list small { grid-column: 2; color: var(--muted); font-size: .68rem; }

.login-body { min-height: 100vh; background: radial-gradient(circle at 50% 15%, var(--blue-soft), transparent 30rem), var(--page); }
.login-shell { display: grid; grid-template-columns: 1fr minmax(320px, 430px); align-items: center; gap: 70px; width: min(980px, calc(100% - 40px)); min-height: 100vh; margin: 0 auto; }
.login-brand { text-align: center; }
.login-brand .brand-mark { margin: 0 auto 18px; }
.login-brand h1 { margin-bottom: 12px; }
.login-card { box-shadow: var(--shadow); }
.login-card label + label { margin-top: 14px; }
.login-card .button { margin-top: 20px; }
.login-card .form-hint { margin: 16px 0 0; text-align: center; line-height: 1.7; }

@media (max-width: 1020px) {
  .side-nav { width: 210px; }
  .app-main { width: calc(100% - 240px); margin-left: 220px; }
  .stat-grid, .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .item-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .side-nav { display: none; }
  .app-main { width: auto; margin: 0; padding: 72px 14px 100px; }
  .mobile-topbar {
    position: fixed; inset: 0 0 auto; z-index: 20; display: flex; min-height: 54px;
    align-items: center; justify-content: space-between; padding: 0 16px;
    border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--page) 86%, transparent);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); font-weight: 600;
  }
  .mobile-brand { color: var(--text); font-size: .84rem; }
  .mobile-topbar span { color: var(--muted); font-size: .76rem; }
  .mobile-nav {
    position: fixed; z-index: 30; right: 10px; bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px;
    padding: 7px; border: 1px solid var(--line); border-radius: 20px;
    background: color-mix(in srgb, var(--page) 88%, transparent);
    box-shadow: var(--shadow); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  }
  .mobile-nav a { display: grid; min-height: 48px; place-items: center; border-radius: 14px; color: var(--muted); font-size: .68rem; }
  .mobile-nav a.active { background: var(--surface); color: var(--text); }
  .mobile-nav .scan-button { background: var(--blue); color: #fff; font-weight: 700; }
  .mobile-nav .scan-button.active { background: var(--blue); color: #fff; }
  .page-head { align-items: flex-start; flex-direction: column; gap: 16px; }
  .page-head .button { width: 100%; }
  .stat-grid, .quick-grid, .two-column, .settings-grid, .scanner-layout { grid-template-columns: 1fr; }
  .quick-card { min-height: 114px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .filter-bar { flex-direction: column; }
  .item-card { padding: 15px; }
  .product-hero { align-items: flex-start; flex-wrap: wrap; padding: 22px; }
  .product-symbol { width: 44px; height: 44px; }
  .product-photo { width: 68px; height: 68px; border-radius: 18px; }
  .big-stock { width: 100%; padding-top: 14px; border-top: 1px solid var(--line); text-align: left; }
  .action-grid { grid-template-columns: 1fr; }
  .action-card { min-height: 110px; }
  .scanner-card, .scanner-card video { min-height: 340px; }
  .batch-card { grid-template-columns: 1fr 1fr; }
  .batch-actions { grid-column: 1 / -1; }
  .login-shell { grid-template-columns: 1fr; gap: 30px; padding: 52px 0; }
  .login-brand h1 { font-size: 2.7rem; }
}

@media (max-width: 390px) {
  .app-main { padding-inline: 10px; }
  .panel, .form-card { padding: 20px; }
  .stat-grid { gap: 10px; }
  .stat-card { min-height: 110px; padding: 18px; }
  .mobile-nav { right: 6px; left: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
