:root {
  --ink: #202124;
  --muted: #65707a;
  --line: #d9dee4;
  --surface: #ffffff;
  --canvas: #f4f6f8;
  --sidebar: #17352f;
  --sidebar-soft: #d9ebe4;
  --primary: #0f766e;
  --primary-dark: #0a5b55;
  --accent: #c45f1d;
  --danger: #b42318;
  --warning: #b54708;
  --success: #247044;
  --shadow: 0 16px 40px rgba(31, 42, 55, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.is-hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(196, 95, 29, 0.06)),
    var(--canvas);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--sidebar);
  color: #fff;
  font-weight: 800;
  margin-bottom: 18px;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
  margin: 0;
  background: var(--sidebar-soft);
  color: var(--sidebar);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  margin-bottom: 24px;
}

.title-en {
  color: var(--muted);
  font-size: 18px;
  font-weight: 650;
}

h2 {
  font-size: 22px;
}

.stack,
.settings-form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 650;
  white-space: nowrap;
}

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

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

.ghost-button {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.danger-button {
  color: #fff;
  background: var(--danger);
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

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

.sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.sidebar-title strong,
.sidebar-title span {
  display: block;
}

.sidebar-title span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  margin-top: 2px;
}

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

.nav-item {
  width: 100%;
  min-height: 42px;
  text-align: left;
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 255, 255, 0.16);
}

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

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

.topbar-actions,
.toolbar,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-chip {
  display: inline-flex;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  min-height: 92px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.stat-card strong {
  display: block;
  font-size: 26px;
  line-height: 1.1;
}

.view-pane {
  display: grid;
  gap: 14px;
}

.toolbar {
  justify-content: space-between;
}

.search-box {
  width: min(420px, 100%);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
}

.search-box span {
  color: var(--muted);
  font-size: 13px;
}

.search-box input {
  border: 0;
  box-shadow: none;
  padding-left: 0;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafb;
  color: #4f5963;
  z-index: 1;
}

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

.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.product-image {
  width: 58px;
  height: 58px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #eef2f5;
  object-fit: cover;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
}

.product-image.placeholder {
  padding: 6px;
}

.upload-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.image-preview {
  width: 88px;
  height: 88px;
  border-radius: 6px;
  border: 1px solid var(--line);
  object-fit: cover;
  background: #eef2f5;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.status-ok {
  color: var(--success);
  background: #e7f3ec;
}

.status-low {
  color: var(--warning);
  background: #fff1df;
}

.type-in {
  color: var(--success);
  font-weight: 700;
}

.type-out {
  color: var(--accent);
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.form-grid.collapsed {
  display: none;
}

.wide-field {
  grid-column: 1 / -1;
}

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

.mini-button {
  min-height: 32px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 6px 9px;
  cursor: pointer;
}

.mini-button.danger {
  color: var(--danger);
}

.settings-form {
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  padding: 34px 14px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  color: #fff;
  background: var(--ink);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    padding: 16px;
  }

  .stats-grid,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .login-panel {
    padding: 22px;
  }

  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions button,
  .toolbar button,
  .toolbar a {
    flex: 1 1 auto;
  }

  .stats-grid,
  .form-grid,
  .nav-list {
    grid-template-columns: 1fr;
  }

  .upload-row {
    grid-template-columns: 1fr;
  }
}
