:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #202a2f;
  --muted: #6d7a82;
  --line: #dfe6e8;
  --green: #1f7a5c;
  --green-dark: #155b45;
  --red: #b3413c;
  --yellow: #b47a1d;
  --blue: #276a90;
  --teal-soft: #e8f4ef;
  --yellow-soft: #fff6df;
  --red-soft: #fff0ef;
  --shadow: 0 14px 34px rgba(40, 54, 61, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px;
  background: linear-gradient(135deg, #eef6f2 0%, #f8faf9 48%, #eef3f7 100%);
}

.login-screen[hidden],
.app-shell[hidden] {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(24, 53, 47, 0.14);
}

.login-brand {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 18px;
  border-bottom-color: var(--line);
  color: var(--ink);
  text-align: left;
}

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

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 10px;
  color: #f8fbfa;
  background: #18352f;
}

.brand {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 2px 2px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  text-align: center;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: #d7efe6;
  color: #18352f;
  font-size: 20px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.brand p,
.eyebrow,
.panel-head span,
.metric span,
.side-panel small {
  margin: 0;
  color: var(--muted);
}

.brand p {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 11px;
}

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

.nav-item {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  text-align: center;
  font-size: 14px;
}

.nav-item:hover,
.nav-item.active {
  background: #e9f5ef;
  color: #18352f;
  font-weight: 700;
}

.side-panel {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 10px 8px;
  background: rgba(255, 255, 255, 0.08);
  text-align: center;
}

.side-label,
.side-panel strong,
.side-panel small {
  display: block;
}

.side-label {
  color: rgba(255, 255, 255, 0.65);
  font-size: 13px;
}

.side-panel strong {
  margin: 8px 0;
  font-size: 24px;
}

.side-panel small {
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.55;
}

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

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

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

.topbar h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

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

.account-switch,
.current-user {
  min-width: 210px;
}

.current-user {
  display: grid;
  align-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  background: #fff;
}

.current-user span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.current-user strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.3;
}

.account-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  border: 1px solid #cfe1da;
  border-radius: 8px;
  padding: 12px 14px;
  background: #eaf6f1;
  color: #23443b;
  font-size: 14px;
}

.account-banner span {
  color: #4b625b;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 15px;
  border: 1px solid transparent;
  font-weight: 700;
}

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

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

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

.danger-button {
  background: var(--red-soft);
  color: var(--red);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 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: 8px;
  font-size: 14px;
}

.metric strong {
  display: block;
  color: var(--green);
  font-size: 34px;
  line-height: 1;
}

.metric.warning strong {
  color: var(--yellow);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  margin-bottom: 16px;
  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-head h3 {
  margin: 0;
  font-size: 17px;
}

.panel-head span {
  font-size: 13px;
}

.bar-list {
  display: grid;
  gap: 12px;
  padding: 16px 18px 18px;
}

.bar-row {
  display: grid;
  grid-template-columns: 105px minmax(80px, 1fr) 48px;
  align-items: center;
  gap: 12px;
  min-height: 28px;
  font-size: 14px;
}

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

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.bar-row b {
  text-align: right;
}

.split-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
  align-items: start;
}

.wide-tools {
  grid-template-columns: minmax(360px, 1fr) minmax(600px, 680px);
  align-items: stretch;
}

.machine-main {
  display: grid;
  min-width: 0;
  gap: 12px;
}

.machine-table-panel {
  margin-bottom: 0;
}

.compact-panel .panel-head {
  padding: 10px 12px;
}

.compact-panel .panel-head h3 {
  font-size: 14px;
}

.compact-bars {
  grid-template-columns: repeat(auto-fit, minmax(98px, 1fr));
  gap: 6px;
  padding: 8px 10px;
}

.compact-bars .bar-row {
  grid-template-columns: minmax(54px, 1fr) 28px;
  gap: 6px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 7px;
  background: #fbfdfc;
}

.compact-bars .bar-track {
  display: none;
}

.compact-bars .bar-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-bars .bar-row b {
  color: var(--green);
  font-size: 14px;
}

.vertical-bars {
  grid-template-columns: 1fr;
  gap: 5px;
  padding: 8px 10px;
}

.vertical-bars .bar-row {
  min-height: 26px;
  padding: 3px 7px;
}

.two-row-bars {
  grid-template-columns: repeat(5, minmax(106px, 1fr));
  gap: 5px;
  padding: 8px 10px 9px;
}

.two-row-bars .bar-row {
  grid-template-columns: minmax(48px, 1fr) 24px;
  min-height: 26px;
  padding: 3px 6px;
}

.inventory-page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
  align-items: start;
}

.inventory-main {
  display: grid;
  min-width: 0;
  gap: 12px;
}

.inventory-form-panel {
  max-width: none;
}

.model-side-panel {
  overflow: hidden;
}

.model-side-panel .panel-head {
  display: grid;
  gap: 4px;
}

.model-side-panel .panel-head span {
  justify-self: start;
}

.side-select {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 9px;
  font-size: 13px;
  font-weight: 700;
}

.side-bars {
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 8px 10px 10px;
}

.side-bars .bar-row {
  grid-template-columns: minmax(74px, 1fr) 34px;
  min-height: 31px;
  padding: 4px 7px;
}

.side-bars .bar-row span {
  text-overflow: clip;
}

.time-filter {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 190px)) 96px;
  gap: 10px;
  padding: 10px 12px;
  align-items: end;
}

.time-filter label {
  gap: 5px;
  font-size: 12px;
}

.time-filter input,
.time-filter button {
  min-height: 34px;
}

.time-filter .ghost-button {
  padding: 0 10px;
}

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

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

.log-table {
  min-width: 1040px;
}

.log-note {
  min-width: 190px;
  white-space: normal;
  line-height: 1.45;
}

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

th {
  background: #f8faf9;
  color: #445158;
  font-size: 13px;
}

.manage-table th:last-child,
.manage-table td:last-child {
  position: sticky;
  right: 0;
  min-width: 82px;
  background: #fff;
  box-shadow: -10px 0 16px rgba(245, 247, 248, 0.92);
}

.manage-table th:last-child {
  background: #f8faf9;
  z-index: 1;
}

tbody tr:hover {
  background: #fbfdfc;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 700;
}

.pill.hq {
  background: #e8f1fb;
  color: var(--blue);
}

.pill.branch {
  background: var(--teal-soft);
  color: var(--green);
}

.pill.assigned {
  background: var(--yellow-soft);
  color: var(--yellow);
}

.pill.transfer,
.pill.service {
  background: var(--yellow-soft);
  color: var(--yellow);
}

.pill.sold {
  background: #edf2f7;
  color: #59636a;
}

.pill.alert,
.pill.return {
  background: var(--red-soft);
  color: var(--red);
}

.delete-button,
.ghost-small,
.sell-button {
  min-height: 30px;
  border-radius: 8px;
  padding: 0 11px;
  font-size: 13px;
  font-weight: 700;
}

.delete-button {
  border: 1px solid #f0c8c5;
  background: var(--red-soft);
  color: var(--red);
}

.delete-button:hover {
  background: #ffe4e2;
}

.ghost-small {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-small:hover {
  background: #f4f7f8;
}

.sell-button {
  border: 1px solid #cfe1da;
  background: var(--teal-soft);
  color: var(--green);
}

.sell-button:hover {
  background: #d7efe6;
}

.action-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
}

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

.table-filter-row {
  border-top: 1px solid var(--line);
}

.small-filter {
  grid-template-columns: minmax(160px, 1fr) minmax(150px, 180px);
}

.page-actions {
  display: flex;
  justify-content: flex-start;
  margin: -2px 0 14px;
}

.page-actions .primary-button {
  min-width: 132px;
}

.branch-summary {
  display: grid;
  align-content: center;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--teal-soft);
}

.branch-summary span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.branch-summary strong {
  color: var(--green);
  font-size: 24px;
  line-height: 1.25;
}

.transfer-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--teal-soft);
}

.transfer-summary span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.transfer-summary strong {
  color: var(--green);
  font-size: 20px;
}

.form-panel {
  max-width: 980px;
}

label {
  display: grid;
  gap: 7px;
  color: #445158;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cfdadd;
  border-radius: 8px;
  padding: 0 11px;
  background: #fff;
  color: var(--ink);
}

.scan-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.scanner-modal,
.app-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 24, 21, 0.64);
}

.scanner-modal[hidden],
.app-modal[hidden] {
  display: none;
}

.scanner-card,
.modal-card {
  width: min(520px, 100%);
  overflow: hidden;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
}

.modal-form {
  grid-template-columns: 1fr;
  padding: 18px;
}

.modal-form .primary-button {
  width: 100%;
}

#scannerVideo {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0d1715;
  object-fit: cover;
}

#scannerStatus {
  margin: 0;
  padding: 12px 16px 16px;
  color: var(--muted);
  font-size: 14px;
}

textarea {
  min-height: 132px;
  padding: 11px;
  line-height: 1.55;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(31, 122, 92, 0.18);
  border-color: var(--green);
}

.wide {
  grid-column: span 2;
}

.full {
  grid-column: 1 / -1;
}

.form-grid .primary-button {
  align-self: end;
}

button[hidden],
[data-admin-only="true"][hidden],
[data-manager-only="true"][hidden] {
  display: none;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  transform: translateY(80px);
  min-width: 240px;
  max-width: min(420px, calc(100vw - 44px));
  border-radius: 8px;
  padding: 13px 16px;
  background: #18352f;
  color: #fff;
  box-shadow: 0 12px 28px rgba(24, 53, 47, 0.24);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}

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

@media (max-width: 980px) {
  .app-shell {
    display: block;
    min-height: 0;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 14px;
  }

  .brand {
    padding-bottom: 10px;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .side-panel {
    display: none;
  }

  .main {
    padding: 18px;
  }

  .metric-grid,
  .content-grid,
  .split-tools,
  .inventory-page-grid,
  .filter-row,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inventory-page-grid {
    grid-template-columns: 1fr;
  }

  .wide-tools {
    grid-template-columns: 1fr;
  }

  .side-bars {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .time-filter {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .account-switch,
  .current-user {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }

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

  .split-tools {
    grid-template-columns: minmax(0, 1fr) minmax(118px, 140px);
  }

  .wide-tools {
    grid-template-columns: 1fr;
  }

  .two-row-bars {
    grid-template-columns: repeat(3, minmax(72px, 1fr));
  }

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

  .wide {
    grid-column: auto;
  }

  .account-banner {
    align-items: flex-start;
    flex-direction: column;
  }

  .bar-row {
    grid-template-columns: 92px minmax(70px, 1fr) 38px;
  }
}

@media (max-width: 430px) {
  .split-tools,
  .inventory-page-grid,
  .side-bars {
    grid-template-columns: 1fr;
  }
}
