:root {
  --wms-bg: #eef3f2;
  --wms-surface: #ffffff;
  --wms-surface-soft: #f7faf9;
  --wms-border: #d8e2df;
  --wms-border-strong: #c4d1cd;
  --wms-text: #172026;
  --wms-muted: #65757c;
  --wms-primary: #1f6f5b;
  --wms-primary-dark: #155141;
  --wms-primary-soft: #e5f2ee;
  --wms-accent: #b07a2a;
  --wms-danger: #9b2f2f;
  --wms-warning: #8a6318;
  --wms-shadow: 0 10px 28px rgba(21, 45, 39, 0.08);
}

html {
  position: relative;
  min-height: 100%;
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 15px;
  }
}

body {
  min-height: 100vh;
  margin-bottom: 56px;
  background:
    linear-gradient(180deg, rgba(31, 111, 91, 0.08), rgba(31, 111, 91, 0) 260px),
    var(--wms-bg);
  color: var(--wms-text);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
}

a {
  color: var(--wms-primary);
}

a:hover {
  color: var(--wms-primary-dark);
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  border-color: var(--wms-primary);
  box-shadow: 0 0 0 0.16rem rgba(31, 111, 91, 0.18);
}

.app-navbar {
  min-height: 64px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--wms-border);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 1px 0 rgba(23, 32, 38, 0.03);
}

.navbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
  margin-right: 18px;
  color: var(--wms-text);
  font-weight: 700;
}

.navbar-brand:hover {
  color: var(--wms-text);
}

.brand-mark {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--wms-primary);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 800;
}

.brand-title,
.brand-subtitle {
  display: block;
  line-height: 1.05;
}

.brand-title {
  font-size: 1rem;
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--wms-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

.navbar-nav {
  gap: 3px;
}

.nav-link {
  border-radius: 8px;
  color: #314047;
  font-weight: 600;
  line-height: 1.2;
}

.nav-link:hover {
  background: var(--wms-surface-soft);
  color: var(--wms-primary-dark);
}

.nav-link.active {
  background: var(--wms-primary-soft);
  color: var(--wms-primary-dark);
}

.user-nav {
  align-items: center;
  gap: 10px;
}

.navbar-text {
  max-width: 220px;
  color: var(--wms-muted);
  font-size: 0.92rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell {
  max-width: 1680px;
  padding-right: 24px;
  padding-left: 24px;
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--wms-border);
}

.page-heading h1 {
  margin: 0;
  color: var(--wms-text);
  font-size: 1.65rem;
  font-weight: 760;
  line-height: 1.18;
}

.page-heading p {
  max-width: 780px;
  margin: 7px 0 0;
  color: var(--wms-muted);
}

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

.page-actions {
  justify-content: flex-end;
}

.btn {
  border-radius: 8px;
  font-weight: 650;
}

.btn-primary {
  border-color: var(--wms-primary);
  background: var(--wms-primary);
}

.btn-primary:hover,
.btn-primary:active {
  border-color: var(--wms-primary-dark) !important;
  background: var(--wms-primary-dark) !important;
}

.btn-outline-primary {
  border-color: var(--wms-primary);
  color: var(--wms-primary);
}

.btn-outline-primary:hover,
.btn-outline-primary:active {
  border-color: var(--wms-primary);
  background: var(--wms-primary);
  color: #ffffff;
}

.btn-outline-success {
  border-color: #2f7c62;
  color: #23634e;
}

.btn-outline-success:hover,
.btn-outline-success:active {
  border-color: #2f7c62;
  background: #2f7c62;
  color: #ffffff;
}

.btn-outline-secondary {
  border-color: var(--wms-border-strong);
  color: #435158;
}

.btn-outline-secondary:hover,
.btn-outline-secondary:active {
  border-color: #435158;
  background: #435158;
  color: #ffffff;
}

.alert {
  border-radius: 8px;
  border-width: 1px;
  box-shadow: var(--wms-shadow);
}

.alert-success {
  border-color: #c9e1d7;
  background: #edf7f2;
  color: #1d5c48;
}

.alert-danger {
  border-color: #edcaca;
  background: #fff4f4;
  color: var(--wms-danger);
}

.alert-warning {
  border-color: #ead7a8;
  background: #fff8e6;
  color: var(--wms-warning);
}

.inventory-filter {
  display: grid;
  grid-template-columns: minmax(180px, 320px) minmax(220px, 420px) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
}

.accounting-filter {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(260px, 420px) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 18px;
}

.shortage-alert {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  padding: 18px;
  border: 2px solid var(--wms-danger);
  border-radius: 8px;
  background: #fff0f0;
  color: var(--wms-danger);
  box-shadow: var(--wms-shadow);
}

.shortage-alert strong {
  font-size: 1.25rem;
  letter-spacing: 0;
}

.shortage-documents {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.metric {
  min-height: 94px;
  padding: 16px;
  border: 1px solid var(--wms-border);
  border-radius: 8px;
  background: var(--wms-surface);
  box-shadow: 0 1px 0 rgba(23, 32, 38, 0.03);
}

.metric span {
  display: block;
  color: var(--wms-muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 10px;
  color: var(--wms-primary-dark);
  font-size: 1.75rem;
  line-height: 1;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

section {
  margin-bottom: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 32px;
  margin-bottom: 9px;
}

.section-title h2 {
  margin: 0;
  color: #25343b;
  font-size: 1.03rem;
  font-weight: 760;
}

.section-title a {
  font-size: 0.88rem;
  font-weight: 650;
}

.list-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.list-tools .form-control {
  width: min(100%, 380px);
}

.list-empty {
  margin: 0 0 10px;
  padding: 9px 12px;
  border: 1px dashed var(--wms-border-strong);
  border-radius: 8px;
  background: var(--wms-surface);
  color: var(--wms-muted);
}

.data-surface,
.form-surface {
  border: 1px solid var(--wms-border);
  border-radius: 8px;
  background: var(--wms-surface);
  box-shadow: 0 1px 0 rgba(23, 32, 38, 0.03);
}

.data-surface {
  overflow: auto;
}

.form-surface {
  padding: 18px;
}

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

.form-label {
  color: #34454d;
  font-size: 0.88rem;
  font-weight: 700;
}

.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.field-label-row a {
  flex: 0 0 auto;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
}

[data-quick-create-content] > form {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

[data-quick-create-content] .modal-body {
  overflow-y: auto;
}

.quick-create-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 160px;
  color: var(--wms-muted);
}

.form-control,
.form-select {
  border-color: var(--wms-border-strong);
  border-radius: 8px;
  color: var(--wms-text);
}

.form-control::placeholder {
  color: #8a989e;
}

.table {
  margin-bottom: 0;
  color: var(--wms-text);
}

.table thead th {
  border-bottom: 1px solid var(--wms-border-strong);
  background: #edf3f2;
  color: #435158;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  vertical-align: middle;
  white-space: nowrap;
}

.table td,
.table th {
  padding: 0.62rem 0.72rem;
}

.table tbody td {
  border-top-color: #e7eeeb;
  vertical-align: middle;
}

.table tbody tr:hover td {
  background: #f8fbfa;
}

.text-muted {
  color: var(--wms-muted) !important;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid #d2dfdb;
  border-radius: 999px;
  background: #edf3f2;
  color: #304249;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.inline-form {
  display: grid;
  grid-template-columns: 130px minmax(120px, 1fr) auto;
  gap: 6px;
  min-width: 360px;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 56px;
  border-color: var(--wms-border) !important;
  background: var(--wms-surface);
  color: var(--wms-muted);
  font-size: 0.9rem;
  line-height: 56px;
}

.login-shell {
  display: grid;
  min-height: calc(100vh - 180px);
  place-items: center;
}

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

.login-panel h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 760;
}

.login-panel p,
.login-hint {
  color: var(--wms-muted);
}

.login-hint {
  margin-top: 16px;
  font-size: 0.9rem;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.permission-group {
  padding: 14px;
  border: 1px solid var(--wms-border);
  border-radius: 8px;
  background: var(--wms-surface-soft);
}

.permission-group h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 760;
}

.permission-row {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--wms-border);
}

.permission-row:first-of-type {
  border-top: 0;
}

.permission-row small {
  display: block;
  color: var(--wms-muted);
}

.audit-label {
  margin-top: 8px;
  color: #526069;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.audit-json {
  max-width: 520px;
  max-height: 220px;
  margin: 4px 0 0;
  padding: 8px;
  overflow: auto;
  border: 1px solid var(--wms-border);
  border-radius: 8px;
  background: #f8fbfa;
  color: #28383f;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
}

details summary {
  color: var(--wms-primary);
  cursor: pointer;
  font-weight: 700;
}

.count-progress {
  width: 150px;
  height: 8px;
  margin-bottom: 5px;
  overflow: hidden;
  border-radius: 4px;
  background: #dfe8e5;
}

.count-progress span {
  display: block;
  height: 100%;
  background: var(--wms-primary);
}

.count-create-form fieldset {
  margin: 0 0 22px;
  padding: 0 0 20px;
  border: 0;
  border-bottom: 1px solid var(--wms-border);
}

.count-create-form legend {
  margin-bottom: 14px;
  color: var(--wms-text);
  font-size: 1rem;
  font-weight: 760;
}

.count-command-bar,
.close-location-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px;
}

.lot-summary {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(300px, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}

.lot-summary dl {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px 14px;
  margin: 0;
}

.lot-summary dt {
  color: var(--wms-muted);
}

.lot-summary dd {
  margin: 0;
  font-weight: 650;
}

.expiry-buckets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.expiry-bucket {
  padding: 7px 10px;
  border: 1px solid var(--wms-border-strong);
  border-radius: 6px;
  background: var(--wms-surface);
  font-weight: 700;
}

.expiry-critical,
.expiry-overdue td {
  background: #fff0f0;
  color: var(--wms-danger);
}

.command-with-reason,
.recount-form {
  display: flex;
  gap: 6px;
}

.command-with-reason .form-control {
  min-width: 260px;
}

.count-metrics {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.difference-row td {
  background: #fff8e6;
}

.blind-count-notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 2px solid #276c5a;
  border-radius: 8px;
  background: #edf7f2;
  color: #174c3d;
  font-weight: 750;
}

.mobile-count-list {
  display: grid;
  gap: 12px;
  margin-bottom: 22px;
}

.count-line {
  border: 1px solid var(--wms-border-strong);
  border-left: 5px solid var(--wms-accent);
  border-radius: 8px;
  background: var(--wms-surface);
  box-shadow: 0 1px 0 rgba(23, 32, 38, 0.03);
}

.count-line-done {
  border-left-color: var(--wms-primary);
}

.count-line > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--wms-border);
}

.count-line > header strong,
.count-line > header span {
  display: block;
}

.count-line > header span:not(.status-pill) {
  margin-top: 5px;
  color: var(--wms-muted);
  font-size: 0.86rem;
}

.count-entry-form {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(150px, 1fr) minmax(170px, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 14px;
}

.count-entry-form details {
  grid-column: 1 / -1;
}

.package-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.count-submit,
.close-location-bar .btn {
  min-height: 44px;
}

.unexpected-section {
  padding-top: 16px;
  border-top: 1px solid var(--wms-border);
}

.close-location-bar {
  position: sticky;
  bottom: 10px;
  justify-content: space-between;
  border: 2px solid var(--wms-primary);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--wms-shadow);
  z-index: 10;
}

@media (max-width: 1200px) {
  .metric-grid,
  .dashboard-grid,
  .form-grid,
  .permission-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 992px) {
  .navbar-nav {
    gap: 4px;
    padding-top: 10px;
  }

  .user-nav {
    align-items: flex-start;
    padding-top: 8px;
  }
}

@media (max-width: 768px) {
  body {
    margin-bottom: 0;
  }

  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .page-heading {
    display: block;
  }

  .page-actions {
    justify-content: flex-start;
    margin-top: 12px;
  }

  .page-actions .btn,
  .page-actions form,
  .page-actions form .btn {
    width: 100%;
  }

  .list-tools {
    align-items: stretch;
  }

  .list-tools .form-control,
  .list-tools .btn {
    width: 100%;
  }

  .metric-grid,
  .dashboard-grid,
  .form-grid,
  .inventory-filter,
  .accounting-filter,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .inline-form {
    grid-template-columns: 1fr;
    min-width: 220px;
  }

  .footer {
    position: static;
    margin-top: 24px;
  }

  .count-entry-form,
  .package-grid,
  .count-metrics {
    grid-template-columns: 1fr;
  }

  .count-entry-form {
    padding: 12px;
  }

  .count-entry-form .form-control,
  .count-entry-form .form-select,
  .count-entry-form .btn {
    min-height: 48px;
    font-size: 1rem;
  }

  .count-line > header,
  .close-location-bar,
  .command-with-reason,
  .recount-form,
  .lot-summary {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .lot-summary dl {
    grid-template-columns: 1fr;
  }

  .close-location-bar .btn,
  .command-with-reason .form-control,
  .command-with-reason .btn {
    width: 100%;
    min-width: 0;
  }
}
