:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --line: #dfe6e2;
  --text: #17201a;
  --muted: #687569;
  --accent: #176b54;
  --accent-strong: #0d4f3e;
  --accent-soft: #e4f3ec;
  --blue: #1565c0;
  --teal: #0f766e;
  --warn: #b54708;
  --danger: #b42318;
  --shadow: 0 10px 28px rgba(23, 32, 26, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

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

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

.app-shell.guest {
  display: block;
}

.app-shell.guest .main {
  padding: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #14211b;
  color: #eef4ed;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ffffff;
}

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

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

.sidebar .brand small {
  color: #aab8ad;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav a,
.logout-form button {
  min-height: 42px;
  padding: 10px 12px;
  color: #dce6dd;
  background: transparent;
  border: 0;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav a:hover,
.nav a.active,
.logout-form button:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
}

.nav a.active {
  box-shadow: inset 3px 0 0 #6ee7b7;
}

.logout-form {
  margin-top: auto;
}

.main {
  min-width: 0;
  padding: 28px clamp(18px, 3vw, 40px);
}

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

.topbar h1,
.login-panel h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.user-chip,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #245345;
  font-size: 13px;
  white-space: nowrap;
}

.pill.danger,
.message.error {
  background: #fff0ed;
  color: var(--danger);
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.message {
  padding: 12px 14px;
  border-radius: 8px;
  background: #e9f6ef;
  color: #146c43;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  margin-bottom: 16px;
}

.metric-strip.compact {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.metric-strip div {
  min-height: 96px;
  padding: 18px 20px;
  background: var(--surface);
}

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

.metric-strip strong {
  display: block;
  margin-top: 12px;
  font-size: 30px;
  line-height: 1;
}

.command-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.command-item {
  display: grid;
  gap: 4px;
  min-height: 106px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.command-item:hover {
  transform: translateY(-1px);
  border-color: rgba(23, 107, 84, 0.34);
  box-shadow: var(--shadow);
}

.command-item.primary {
  background: #10241c;
  border-color: #10241c;
  color: #ffffff;
}

.command-item span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.command-item.primary span {
  color: #7ee2ba;
}

.command-item strong {
  font-size: 18px;
}

.command-item small {
  color: var(--muted);
  line-height: 1.35;
}

.command-item.primary small {
  color: #bed0c6;
}

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

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.9fr);
  gap: 20px;
  margin-bottom: 20px;
}

.work-surface {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.work-surface.narrow {
  max-width: 760px;
}

.section-head,
.toolbar,
.action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 0;
  font-size: 20px;
}

.search-form {
  display: flex;
  width: min(640px, 100%);
  gap: 8px;
}

.search-form input,
.field-row input,
.field-row select,
.field-row textarea,
.login-panel input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #ccd6cf;
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 12px;
}

.field-row textarea {
  resize: vertical;
}

.primary-action,
.secondary-action,
.search-form button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.primary-action,
.search-form button {
  background: var(--accent);
  color: #ffffff;
}

.primary-action:hover {
  background: var(--accent-strong);
}

.secondary-action {
  background: #eef3ef;
  color: var(--text);
  border-color: var(--line);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.06em;
}

tr:hover td {
  background: var(--surface-muted);
}

.route-cell {
  color: #3f4d43;
  max-width: 360px;
}

.qty-cell {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.danger-value {
  color: var(--danger);
  font-variant-numeric: tabular-nums;
}

.type-pill {
  font-weight: 800;
}

.type-transfer {
  background: #e8f1ff;
  color: var(--blue);
}

.type-return {
  background: #e2f5f2;
  color: var(--teal);
}

.type-receive {
  background: #e7f7ee;
  color: #137547;
}

.type-purchase {
  background: #e7f6fa;
  color: #087d96;
}

.type-cut {
  background: #fff3df;
  color: var(--warn);
}

.type-inter_company {
  background: #f0eaff;
  color: #6d35b3;
}

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

.list-stack,
.form-stack,
.mini-stack {
  display: grid;
  gap: 12px;
}

.mini-stack {
  gap: 2px;
  font-size: 13px;
  color: var(--muted);
}

.line-item,
.location-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.line-item:last-child,
.location-row:last-child {
  border-bottom: 0;
}

.link-row {
  color: var(--text);
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
}

.field-row {
  display: grid;
  gap: 6px;
}

.field-row span {
  color: #2c3a30;
  font-weight: 700;
}

.field-row b,
.field-row em {
  color: var(--danger);
}

.field-row em {
  font-style: normal;
  font-size: 13px;
}

.movement-surface {
  max-width: 840px;
}

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

.movement-form .field-row:nth-last-child(-n + 2),
.movement-form .action-row,
.movement-form .message {
  grid-column: 1 / -1;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  padding: 12px 0 0;
  background: linear-gradient(180deg, rgba(255,255,255,0), #ffffff 32%);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(21, 32, 26, 0.82), rgba(21, 32, 26, 0.48)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='800' viewBox='0 0 1200 800'%3E%3Crect width='1200' height='800' fill='%233f5f50'/%3E%3Cpath d='M0 620h1200v180H0z' fill='%2325332b'/%3E%3Cpath d='M80 180h1040v340H80z' fill='%23dfe8df' opacity='.25'/%3E%3Cpath d='M120 220h260v260H120zm320 0h260v260H440zm320 0h320v260H760z' fill='%23ffffff' opacity='.18'/%3E%3C/svg%3E");
  background-size: cover;
}

.login-panel {
  width: min(430px, 100%);
  padding: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
}

.route-arrow {
  color: var(--muted);
  padding: 0 6px;
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

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

  .nav a,
  .logout-form button {
    white-space: nowrap;
  }

  .logout-form {
    margin-top: 0;
  }

  .main {
    padding: 18px;
  }

  .topbar,
  .toolbar,
  .section-head,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-strip,
  .metric-strip.compact,
  .two-column,
  .command-strip,
  .movement-form {
    grid-template-columns: 1fr;
  }

  .command-item {
    min-height: 86px;
  }

  .movement-form .field-row:nth-last-child(-n + 2),
  .movement-form .action-row,
  .movement-form .message {
    grid-column: auto;
  }
}
