:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --sidebar: #17211b;
  --panel: #ffffff;
  --text: #1d2720;
  --muted: #647067;
  --line: #dce4dd;
  --green: #247a4d;
  --green-dark: #155c37;
  --blue: #31658f;
  --amber: #b76e21;
  --red: #b43d34;
  --shadow: 0 12px 28px rgba(31, 45, 36, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.sidebar {
  min-height: 100vh;
  padding: 24px 18px;
  background: var(--sidebar);
  color: #fff;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e4f1df;
  color: var(--green-dark);
  font-weight: 700;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 4px;
  color: #aebcaf;
}

nav {
  display: grid;
  gap: 8px;
}

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

.nav-item.active,
.nav-item:hover {
  background: #263529;
  color: #fff;
}

.app {
  min-width: 0;
  padding: 28px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.top-actions {
  display: flex;
  gap: 10px;
}

input,
select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

#search {
  width: min(34vw, 360px);
}

.top-actions button,
form button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--green);
  color: #fff;
  font-weight: 700;
}

button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 16px;
}

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

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.metric strong {
  font-size: 28px;
}

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

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-head.split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.bars,
.warning-list,
.supplier-grid {
  padding: 18px;
}

.bar-row {
  display: grid;
  grid-template-columns: 80px 1fr 110px;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #edf2ee;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.warning-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

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

.warning-item strong {
  display: block;
  margin-bottom: 4px;
}

.warning-item small {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: #f8e8df;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

tr.low td {
  background: #fff6f2;
}

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

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

.type-adjust {
  color: var(--blue);
  font-weight: 700;
}

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

.material-form,
.movement-form {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.material-form {
  grid-template-columns: repeat(6, minmax(120px, 1fr));
}

.movement-form {
  grid-template-columns: minmax(240px, 1.4fr) minmax(220px, 1fr) repeat(4, minmax(120px, 1fr)) auto;
}

.segmented {
  display: flex;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segmented label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border-right: 1px solid var(--line);
  white-space: nowrap;
}

.segmented label:last-child {
  border-right: 0;
}

.supplier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.supplier-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfb;
}

.supplier-card strong {
  display: block;
  margin-bottom: 10px;
}

.supplier-card p {
  margin: 6px 0;
  color: var(--muted);
}

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

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

.empty {
  padding: 18px;
  color: var(--muted);
}

.auth-page {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
  background:
    linear-gradient(rgba(23, 33, 27, 0.62), rgba(23, 33, 27, 0.62)),
    url("https://images.unsplash.com/photo-1556905055-8f358a7a47b2?auto=format&fit=crop&w=1600&q=80") center / cover;
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-panel {
  width: min(100%, 420px);
  border-radius: 8px;
  padding: 30px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.24);
}

.login-brand {
  margin-bottom: 28px;
  color: var(--text);
}

.login-brand small {
  color: var(--muted);
}

.login-panel h1 {
  margin-bottom: 8px;
}

.login-panel p {
  margin: 0 0 22px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.login-form input {
  width: 100%;
}

.login-form button {
  margin-top: 4px;
}

.login-error {
  min-height: 20px;
  color: var(--red);
  font-size: 14px;
}

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

  .sidebar {
    min-height: auto;
  }

  nav {
    grid-template-columns: repeat(4, 1fr);
  }

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

  #search {
    width: 100%;
  }

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