* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1565c0;
  --primary-dark: #0d3f8c;
  --primary-light: #e3f2fd;
  --success: #2e7d32;
  --danger: #c62828;
  --warning: #e65100;
  --gray-border: #dde3ea;
  --gray-bg: #f5f7fa;
  --text: #1f2933;
  --text-light: #6b7280;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Segoe UI', 'Tahoma', 'Noto Sans Thai', 'Leelawadee UI', sans-serif;
  background: var(--gray-bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- Top navigation ---------- */
.topbar {
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}

.brand .ico {
  font-size: 22px;
}

.nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.nav a {
  color: #fff;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.15);
}

.nav a.active {
  background: rgba(255, 255, 255, 0.25);
  font-weight: 600;
}

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  margin: 4px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  padding: 16px;
  margin-bottom: 16px;
}

.card-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 720px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* ---------- Form ---------- */
.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 150px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-light);
}

input[type='text'],
input[type='number'],
input[type='date'],
select,
textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15);
}

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

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s, transform 0.05s;
  color: #fff;
}

.btn:active {
  transform: translateY(1px);
}

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

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

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-success {
  background: var(--success);
}

.btn-success:hover {
  filter: brightness(1.08);
}

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

.btn-danger:hover {
  filter: brightness(1.08);
}

.btn-warning {
  background: var(--warning);
}

.btn-warning:hover {
  filter: brightness(1.08);
}

.btn-outline {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--gray-border);
}

.btn-outline:hover {
  background: var(--gray-bg);
}

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

.btn-lg {
  padding: 12px 20px;
  font-size: 15px;
  width: 100%;
  justify-content: center;
}

/* ---------- Table ---------- */
.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--gray-border);
  white-space: nowrap;
}

th {
  background: var(--gray-bg);
  font-size: 13px;
  color: var(--text-light);
  font-weight: 700;
  position: sticky;
  top: 0;
}

tbody tr:hover {
  background: #f8fafc;
}

.num {
  text-align: right;
}

.center {
  text-align: center;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-in {
  background: #e8f5e9;
  color: var(--success);
}

.badge-out {
  background: #ffebee;
  color: var(--danger);
}

.badge-low {
  background: #fff3e0;
  color: var(--warning);
}

.badge-ok {
  background: #e3f2fd;
  color: var(--primary);
}

/* ---------- Alerts / toast ---------- */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
  display: none;
}

.alert.show {
  display: block;
}

.alert-error {
  background: #ffebee;
  color: var(--danger);
  border: 1px solid #f5c6cb;
}

.alert-success {
  background: #e8f5e9;
  color: var(--success);
  border: 1px solid #c3e6cb;
}

.alert-info {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid #b6d4fe;
}

/* ---------- Search ---------- */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-bar input {
  flex: 1;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop.show {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.modal-title {
  font-weight: 700;
  font-size: 17px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
}

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

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 30px;
  color: var(--text-light);
  font-size: 14px;
}

/* ---------- Print styles (เฉพาะส่วนรายงาน) ---------- */
.print-section {
  display: none;
}

@media print {
  body {
    background: #fff;
  }

  .no-print {
    display: none !important;
  }

  .print-section {
    display: block;
  }

  .print-section table th,
  .print-section table td {
    white-space: normal;
  }
}

/* ---------- Utilities ---------- */
.muted {
  color: var(--text-light);
  font-size: 13px;
}

.mt-12 {
  margin-top: 12px;
}

.mb-12 {
  margin-bottom: 12px;
}

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

.total-row {
  font-weight: 700;
  background: var(--gray-bg);
}

.stock-num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
  cursor: pointer;
}

.item-row.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.item-row .item-name {
  font-weight: 600;
}

.item-row .item-meta {
  font-size: 12px;
  color: var(--text-light);
}

.item-row .item-qty {
  font-weight: 700;
  font-size: 15px;
  text-align: right;
}

.item-picker {
  max-height: 320px;
  overflow-y: auto;
  padding: 2px;
}

.selected-card {
  border: 1px dashed var(--gray-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--gray-bg);
}

.selected-card .selected-title {
  font-size: 15px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.list-footer {
  padding-top: 4px;
}

.low-item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
}

.low-item-row .meta {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 2px;
}

@media print {
  .row-low td {
    background: #fff3e0;
  }
}

.stock-summary {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.summary-box {
  flex: 1;
  min-width: 120px;
  background: var(--gray-bg);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.summary-box .label {
  font-size: 12px;
  color: var(--text-light);
}

.summary-box .value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 2px;
}