:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #5c6b7a;
  --line: #d5dde5;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: rgba(29, 78, 216, 0.1);
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --warn: #b54708;
  --radius: 8px;
  --shadow: 0 8px 28px rgba(26, 35, 50, 0.12);
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --topbar-h: 56px;
  --bottom-h: 56px;
  --sidebar-w: 220px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

body {
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.hidden {
  display: none !important;
}

/* —— Login —— */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(29, 78, 216, 0.14), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 80%, rgba(26, 35, 50, 0.08), transparent 50%),
    var(--bg);
}

.login-panel {
  width: min(100%, 380px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 36px 28px 28px;
  box-shadow: var(--shadow);
}

.brand {
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
}

.login-sub {
  margin: 4px 0 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

/* —— App shell —— */
.app-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand {
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-size: 1.15rem;
}

.topbar-brand:hover {
  color: var(--accent-hover);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.current-user {
  color: var(--muted);
  font-size: 0.9rem;
  margin-right: 4px;
}

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-group {
  display: flex;
  flex-direction: column;
}

.nav-group-title {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.nav-group-title .fa {
  width: 1.1em;
  text-align: center;
  flex-shrink: 0;
}

.nav-group-title:hover {
  background: var(--bg);
}

.nav-group.current .nav-group-title {
  color: var(--accent);
}

.nav-group-items {
  display: none;
  flex-direction: column;
}

.nav-group.open .nav-group-items {
  display: flex;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 20px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92rem;
}

.nav-link .fa {
  width: 1.1em;
  text-align: center;
  flex-shrink: 0;
}

.nav-link:hover {
  background: var(--bg);
  color: var(--ink);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.main {
  flex: 1;
  padding: 20px;
  min-width: 0;
  position: relative;
}

#page-home:not(.hidden) {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.home-watermark {
  font-size: clamp(1.25rem, 3.6vw, 2.4rem);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--ink);
  opacity: 0.12;
  user-select: none;
  pointer-events: none;
  text-align: center;
  line-height: 1.6;
}

.bottom-nav {
  display: none;
  position: sticky;
  bottom: 0;
  height: var(--bottom-h);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 20;
}

.bottom-nav .nav-group {
  flex: 1;
  position: relative;
}

.bottom-nav .nav-group-title {
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  text-align: center;
  padding: 6px 2px;
  font-size: 0.8rem;
  border-radius: 0;
}

.bottom-nav .nav-group-items {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  min-width: 128px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  padding: 4px;
}

.bottom-nav .nav-link {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.9rem;
}

/* —— Page —— */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-header h1 {
  margin: 0;
  font-size: 1.35rem;
}

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

.toolbar-meta {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 12px;
}

.empty-state {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty-state-error {
  color: var(--danger);
  border-color: #fecdca;
  background: var(--danger-bg);
}

/* —— Table (desktop) —— */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.925rem;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table th {
  background: #f6f8fa;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: none;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table .cell-wrap {
  white-space: normal;
  max-width: 280px;
}

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

.col-check {
  width: 36px;
  text-align: center;
}

.text-link {
  color: var(--accent);
  text-decoration: underline;
}

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

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 20px 0 10px;
}

.section-head .section-title {
  margin: 0;
}

.card-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.data-card .card-check .card-title {
  margin: 0;
}

.form [data-part-field] {
  display: block;
}

.form [data-part-field] input,
.form [data-part-field] select {
  width: 100%;
}

.lookup-field {
  display: flex;
  gap: 8px;
  align-items: stretch;
  width: 100%;
}

.lookup-field .lookup-display {
  flex: 1;
  min-width: 0;
  cursor: default;
  background: #f7f8fa;
}

.lookup-field .lookup-display:disabled {
  opacity: 0.65;
}

.lookup-field .btn {
  flex-shrink: 0;
}

/* —— Cards (mobile) —— */
.card-list {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.data-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
}

.data-card .card-title {
  font-weight: 600;
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.data-card dl {
  margin: 0 0 12px;
  display: grid;
  gap: 6px;
}

.data-card dt {
  font-size: 0.75rem;
  color: var(--muted);
}

.data-card dd {
  margin: 0;
  font-size: 0.925rem;
  word-break: break-word;
}

.data-card .card-field {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 4px 8px;
  align-items: baseline;
}

.data-card .card-actions {
  display: flex;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

/* —— Forms & buttons —— */
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--muted);
}

.form label span {
  font-weight: 500;
}

.form input,
.form select,
.form textarea {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.form input:focus,
.form select:focus,
.form textarea:focus {
  outline: 2px solid rgba(29, 78, 216, 0.35);
  border-color: var(--accent);
}

.form textarea {
  min-height: 88px;
  resize: vertical;
}

.form-error {
  margin: 0;
  min-height: 1.25em;
  color: var(--danger);
  font-size: 0.875rem;
}

.form-hint {
  margin: -6px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  line-height: 1.2;
}

.btn:hover:not(:disabled) {
  background: var(--bg);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  background: var(--danger-bg);
  border-color: #fecdca;
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #fee4e2;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg);
  color: var(--ink);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.825rem;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
  border: none;
  background: transparent;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-muted {
  background: var(--bg);
  color: var(--muted);
}

/* —— Modal —— */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 35, 50, 0.45);
}

.modal-panel {
  position: relative;
  width: min(100%, 480px);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  padding: 16px;
}

.picker-modal {
  z-index: 150;
}

.picker-panel {
  width: min(100%, 720px);
  max-height: min(90vh, 800px);
}

.picker-toolbar {
  margin-bottom: 12px;
}

.picker-search {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.picker-search:focus {
  outline: 2px solid rgba(29, 78, 216, 0.35);
  border-color: var(--accent);
}

.picker-list {
  max-height: min(60vh, 520px);
  overflow: auto;
}

.picker-row,
.picker-card {
  cursor: pointer;
}

.picker-row:hover,
.picker-card:hover {
  background: rgba(29, 78, 216, 0.06);
}

.picker-row.is-selected,
.picker-card.is-selected {
  background: rgba(29, 78, 216, 0.12);
}

/* —— Toast —— */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(92vw, 420px);
  padding: 12px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  text-align: center;
}

.toast.toast-error {
  background: var(--danger);
}

.toast.toast-success {
  background: var(--accent);
}

/* —— Responsive —— */
@media (max-width: 767px) {
  .sidebar {
    display: none;
  }

  .bottom-nav {
    display: flex;
  }

  .main {
    padding: 14px 12px calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .table-wrap,
  .data-table {
    display: none;
  }

  .card-list {
    display: flex;
  }

  .current-user {
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .toast {
    bottom: calc(var(--bottom-h) + 16px);
  }
}

@media (min-width: 768px) {
  .card-list {
    display: none !important;
  }

  .table-wrap {
    display: block;
  }
}

/* —— Inventory / inbound extras —— */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 220px;
  flex: 1;
}

.filter-bar select,
.filter-bar input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.filter-bar .lookup-field .lookup-display {
  padding: 8px 10px;
}

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

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 10px 0;
}

.pagination-meta {
  color: var(--muted);
  font-size: 0.875rem;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-size {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--muted);
}

.pagination-size select {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.badge-warn {
  background: #fff4e5;
  color: var(--warn);
}

.badge-info {
  background: #e8f1fb;
  color: #175cd3;
}

.detail-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px 16px;
  margin-bottom: 14px;
}

.detail-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 2px;
}

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

.detail-actions a.btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: auto;
  cursor: not-allowed;
}

.section-title {
  margin: 20px 0 10px;
  font-size: 1.05rem;
}

.scan-form {
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.scan-input {
  font-size: 1.15rem !important;
  letter-spacing: 0.04em;
  padding: 12px !important;
}

.optional-fields {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.optional-fields summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 8px;
}

.optional-fields label {
  margin-bottom: 10px;
}

.scan-result {
  margin-top: 14px;
  max-width: 480px;
  padding: 12px 14px;
  background: rgba(29, 78, 216, 0.08);
  border: 1px solid rgba(29, 78, 216, 0.25);
  border-radius: var(--radius);
}

.scan-result strong {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
}

@media (max-width: 767px) {
  .bottom-nav .nav-group-title {
    font-size: 0.8rem;
    padding: 6px 4px;
  }

  .filter-bar label {
    min-width: 100%;
  }

  .detail-actions {
    flex-direction: column;
  }

  .detail-actions .btn,
  .detail-actions a.btn {
    width: 100%;
  }
}

