:root {
  --bg: #f2efe8;
  --bg-soft: #faf8f2;
  --card: #ffffff;
  --text: #1d2a2c;
  --muted: #607077;
  --primary: #1f6f5f;
  --primary-strong: #115447;
  --accent: #b36f2d;
  --danger: #b23a32;
  --border: #d7ded9;
  --shadow: 0 12px 32px rgba(20, 36, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "IBM Plex Sans", "Noto Sans SC", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 16%, #ebe4d8 0%, rgba(235, 228, 216, 0) 28%),
    radial-gradient(circle at 87% 8%, #d9ece7 0%, rgba(217, 236, 231, 0) 24%),
    linear-gradient(180deg, #f6f3eb 0%, #eff6f3 100%);
  min-height: 100vh;
}

body.page-busy {
  cursor: progress;
}

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

.global-loading {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(242, 239, 232, 0.42);
  backdrop-filter: blur(3px);
}

.global-loading.is-visible {
  display: flex;
}

.global-loading-card {
  min-width: 180px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border: 1px solid rgba(17, 84, 71, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(20, 36, 31, 0.16);
}

.global-loading-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(31, 111, 95, 0.18);
  border-top-color: var(--primary);
  animation: global-spin 0.75s linear infinite;
}

.global-loading-text {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

@keyframes global-spin {
  to {
    transform: rotate(360deg);
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
  background: rgba(246, 243, 235, 0.88);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.brand-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.brand {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.3px;
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
}

.menu-toggle {
  display: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.nav a {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  background: #fff;
}

.nav button {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  background: #fff;
  cursor: pointer;
}

.nav a.active {
  border-color: var(--primary);
  color: #fff;
  background: var(--primary);
}

.nav button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 16px 44px;
}

.page-head {
  margin-bottom: 16px;
}

.page-title {
  margin: 0;
  font-size: 28px;
}

.page-desc {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.card {
  grid-column: span 12;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.card h3,
.card h4 {
  margin: 0 0 12px;
}

.kpi {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.kpi-item {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbfa 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.kpi-label {
  color: var(--muted);
  font-size: 13px;
}

.kpi-value {
  margin-top: 5px;
  font-size: 22px;
  font-weight: 700;
}

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

.field {
  grid-column: span 12;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-6 {
  grid-column: span 6;
}

.field-5 {
  grid-column: span 5;
}

.field-4 {
  grid-column: span 4;
}

.field-3 {
  grid-column: span 3;
}

.field-2 {
  grid-column: span 2;
}

.stack-form .field-6,
.stack-form .field-5,
.stack-form .field-4,
.stack-form .field-3,
.stack-form .field-2 {
  grid-column: span 12;
}

label {
  font-size: 13px;
  color: var(--muted);
}

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

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 68px;
  resize: vertical;
}

button {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
}

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

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

button:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-secondary {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.actions a.btn-secondary,
.actions a.btn-primary,
.actions a.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 10px 14px;
}

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

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
  background: #fff;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid #edf2ef;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  background: #f7fbf9;
  color: #415257;
}

tr:hover td {
  background: #fbfffd;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  border: 1px solid;
}

.badge-ok {
  border-color: #9fd2c0;
  color: #1f6f5f;
  background: #eefaf5;
}

.badge-warn {
  border-color: #f2d28f;
  color: #9a6618;
  background: #fff8e7;
}

.badge-danger {
  border-color: #efbeb9;
  color: #9f2e29;
  background: #fff0ef;
}

.muted {
  color: var(--muted);
}

.row-highlight {
  background: #f9fbff;
}

.row-danger td {
  background: #fff3f1;
}

.row-danger:hover td {
  background: #ffe9e5;
}

.row-voided td {
  background: #ffe9e6;
}

.row-voided:hover td {
  background: #ffd9d3;
}

.row-voided-soft td {
  background: #fff6e8;
}

.row-voided-soft:hover td {
  background: #ffeecf;
}

.row-shifted td {
  background: #fff8e7;
}

.row-shifted:hover td {
  background: #ffefcf;
}

.stock-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.queue-stock-alert {
  display: none;
}

.queue-stock-alert.is-warn {
  display: block;
  border: 1px solid #efbeb9;
  border-radius: 12px;
  background: #fff0ef;
  padding: 10px 12px;
}

.queue-stock-alert-title {
  color: #9f2e29;
  font-weight: 600;
  margin-bottom: 6px;
}

.queue-stock-alert-item {
  color: #7f2521;
  font-size: 13px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 14px;
  bottom: 14px;
  background: #1f6f5f;
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  max-width: 70vw;
  z-index: 99;
}

body.modal-open {
  overflow: hidden;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(17, 35, 29, 0.48);
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-card {
  width: min(720px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: #fffdf9;
  box-shadow: 0 24px 80px rgba(13, 29, 25, 0.2);
  padding: 18px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.modal-summary-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfefd;
  padding: 12px;
}

.modal-summary-label {
  color: var(--muted);
  font-size: 13px;
}

.modal-summary-value {
  margin-top: 6px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
}

.modal-impact {
  margin-top: 14px;
  border: 1px solid #f2d28f;
  border-radius: 14px;
  background: #fff8e7;
  padding: 14px;
}

.modal-impact-title {
  color: #8a5a12;
  font-weight: 700;
}

.modal-impact-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #71470b;
  line-height: 1.6;
}

.modal-actions {
  margin-top: 14px;
  justify-content: flex-end;
}

.inventory-card .kpi-value {
  font-size: 26px;
}

.inventory-table-wrap table {
  min-width: 980px;
}

.inventory-table-wrap th,
.inventory-table-wrap td {
  padding: 12px;
  font-size: 14px;
}

.ledger-card {
  grid-column: span 12;
}

.ledger-card table {
  min-width: 1280px;
}

.outbound-items-table table {
  min-width: 1180px;
}

.outbound-items-table th:nth-child(3),
.outbound-items-table td:nth-child(3) {
  min-width: 180px;
  white-space: nowrap;
}

.log-json {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f7fbf9;
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.45;
  max-height: 320px;
  overflow: auto;
}

.log-detail-row td {
  background: #fbfefd;
}

.log-main {
  font-weight: 600;
  line-height: 1.45;
}

.log-subtext {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.5;
}

.amount-secondary {
  color: #9a6618;
  font-weight: 600;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
}

.checkbox-inline input,
.checkbox-item input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.checkbox-panel {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfefd;
  padding: 10px 12px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.pdf-frame-wrap {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f7fbf9;
}

.pdf-frame {
  width: 100%;
  height: 78vh;
  min-height: 640px;
  border: 0;
  background: #fff;
}

@media (max-width: 980px) {
  .topbar {
    position: static;
  }

  .topbar-inner {
    grid-template-columns: 1fr;
    padding: 10px 10px;
    gap: 8px;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .nav {
    display: none;
    justify-content: flex-start;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 4px;
  }

  .topbar.nav-open .nav {
    display: flex;
  }

  .page-title {
    font-size: 22px;
  }

  .shell {
    padding: 12px 8px 26px;
  }

  .grid > .card {
    grid-column: span 12 !important;
  }

  .card {
    padding: 12px;
  }

  .kpi {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 640px;
  }

  .field-6,
  .field-5,
  .field-4,
  .field-3,
  .field-2 {
    grid-column: span 12;
  }

  .ledger-card {
    grid-column: span 12;
  }

  .pdf-frame {
    height: 68vh;
    min-height: 460px;
  }

  .actions > * {
    flex: 1 1 auto;
  }

  .modal-card {
    padding: 14px;
    border-radius: 14px;
  }

  .modal-head {
    flex-direction: column;
  }

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