:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --ink: #18212a;
  --muted: #64707d;
  --line: #dce3e8;
  --blue: #1f6feb;
  --blue-dark: #1455b8;
  --green: #20845a;
  --amber: #b7791f;
  --red: #c33838;
  --shadow: 0 10px 30px rgba(20, 33, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 28px;
  background:
    radial-gradient(circle at 20% 20%, rgba(31, 111, 235, 0.12), transparent 34%),
    linear-gradient(135deg, #f5f7f8 0%, #eaf0f4 100%);
}

.login-card {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(20, 33, 45, 0.14);
}

.login-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 22px;
  border-radius: 10px;
  background: #f0b429;
  color: #111820;
  font-size: 22px;
  font-weight: 800;
}

.login-eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-card h1 {
  margin: 0 0 24px;
  font-size: 30px;
}

.login-card label {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: #4f5d69;
  font-size: 13px;
  font-weight: 700;
}

.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  outline: 0;
  background: #fbfcfd;
}

.login-card input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.12);
}

.login-error {
  min-height: 20px;
  margin: 2px 0 16px;
  color: var(--red);
  font-size: 13px;
}

.login-submit {
  width: 100%;
}

body:not(.auth-locked) .login-screen {
  display: none;
}

body.auth-locked .app-shell {
  display: none;
}

.session-user {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #111820;
  color: #f7fafc;
  padding: 24px 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #f0b429;
  color: #111820;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p {
  color: #a8b3bd;
  font-size: 13px;
  margin-top: 4px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c9d3dc;
  padding: 12px 14px;
  text-align: left;
}

.nav-tab:hover,
.nav-tab.active {
  background: #24313d;
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.topbar h2 {
  margin-top: 5px;
  font-size: 28px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.file-btn,
.text-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 9px 13px;
}

.primary-btn {
  background: var(--blue);
  color: #fff;
}

.primary-btn:hover {
  background: var(--blue-dark);
}

.ghost-btn,
.file-btn {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.danger-btn {
  background: #fff4f4;
  border-color: #ffd3d3;
  color: var(--red);
}

.file-btn input {
  display: none;
}

.text-btn {
  background: transparent;
  color: var(--blue);
  padding-inline: 6px;
}

.small {
  min-height: 32px;
  padding: 6px 10px;
}

.hidden {
  display: none;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

.metric.warn strong {
  color: var(--amber);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
}

.panel {
  margin-bottom: 18px;
  overflow: hidden;
}

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

.panel h3 {
  font-size: 17px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.wide-table {
  min-width: 1520px;
}

.summary-table {
  min-width: 1380px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 14px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f8fafb;
  color: #51606d;
  font-size: 13px;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.status-low {
  color: var(--amber);
  font-weight: 700;
}

.status-ok {
  color: var(--green);
  font-weight: 700;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 6px 9px;
}

.row-actions .delete {
  color: var(--red);
}

.product-thumb {
  display: block;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: #f4f6f8;
}

.image-zoom-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border: 0;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  cursor: zoom-in;
}

.image-zoom-btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.image-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.note-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form-panel {
  padding-bottom: 4px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  padding: 18px;
}

.form-grid label {
  display: grid;
  gap: 7px;
  color: #44515e;
  font-size: 13px;
}

.form-grid input,
.form-grid select,
.search-input {
  width: 100%;
  min-height: 39px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

.form-grid input:focus,
.form-grid select:focus,
.search-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.12);
}

.form-grid input:disabled {
  background: #eef2f5;
  color: #8a97a3;
  cursor: not-allowed;
}

.image-upload-field input {
  padding: 7px 9px;
}

.image-preview-row {
  display: flex;
  align-items: end;
  gap: 10px;
}

.image-preview {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 74px;
  height: 74px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafb;
  color: var(--muted);
  font-size: 12px;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.form-submit {
  align-self: end;
}

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

.wide {
  grid-column: span 2;
}

.search-input {
  max-width: 340px;
}

.activity-list {
  display: grid;
  gap: 10px;
  padding: 14px 18px 18px;
}

.activity-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.activity-item:last-child {
  border-bottom: 0;
}

.pill {
  display: inline-flex;
  justify-content: center;
  min-width: 52px;
  border-radius: 999px;
  padding: 4px 8px;
  background: #edf7f3;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.pill.out {
  background: #fff4f4;
  color: var(--red);
}

.pill.adjust {
  background: #fff8e8;
  color: var(--amber);
}

.activity-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-main span,
.empty {
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  background: #111820;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
}

.image-lightbox.hidden {
  display: none;
}

.image-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 15, 24, 0.72);
}

.image-lightbox-panel {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
  max-width: min(920px, 92vw);
  max-height: 90vh;
  padding: 14px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

.image-lightbox-panel img {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 8px;
  background: #f4f6f8;
}

.image-lightbox-panel p {
  max-width: 820px;
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-lightbox-close {
  position: absolute;
  top: -14px;
  right: -14px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #111820;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px;
  }

  .brand {
    padding: 0;
  }

  .nav-tabs {
    display: flex;
    overflow-x: auto;
  }

  .nav-tab {
    width: auto;
    white-space: nowrap;
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .content-grid {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .brand p {
    display: none;
  }

  .metric-grid,
  .content-grid,
  .form-grid,
  .movement-form {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

  .topbar-actions,
  .topbar-actions > * {
    width: 100%;
  }

  .activity-item {
    grid-template-columns: 62px minmax(0, 1fr);
  }
}
