/* Sarabun was only ever named in the font-family list below, never
   actually loaded -- it silently fell back to whatever system sans-serif
   font a given machine had (e.g. Segoe UI on Windows), which is why
   printed pages never actually came out in Sarabun. */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;700&display=swap');

:root {
  --brand: #1a3fa0;
  --brand-dark: #12296e;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e1e5ee;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --danger: #c0392b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Sarabun", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.brand-dot {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.brand-logo {
  height: 32px;
  width: auto;
  display: block;
}

.brand-logo-lg {
  height: 60px;
  width: auto;
  display: block;
  margin: 0 auto;
}

.brand-name {
  font-weight: 600;
  color: var(--brand-dark);
  font-size: 15px;
}

h1 {
  font-size: 18px;
  margin: 0 0 18px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
}

input:focus {
  outline: none;
  border-color: var(--brand);
}

button.primary {
  width: 100%;
  padding: 12px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

button.primary:hover { background: var(--brand-dark); }
button.primary:disabled { opacity: 0.6; cursor: not-allowed; }

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: -6px 0 14px;
  min-height: 16px;
}

.muted-link {
  display: block;
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
  color: var(--brand);
  text-decoration: none;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.logout-link {
  font-size: 13px;
  color: var(--brand);
  cursor: pointer;
}

/* Order wizard */
.order-wrap {
  max-width: 420px;
  margin: 0 auto;
  padding: 16px;
}

@media (min-width: 700px) {
  .order-wrap {
    max-width: 600px;
  }
}

.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.cat-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}

.cat-card:hover { border-color: var(--brand); }

.cat-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #e6edfb;
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.customer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #eef2fb;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.chip {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  cursor: pointer;
}

.chip:hover { border-color: var(--brand); background: #f5f8ff; }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-sheet {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 18px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-btn {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  margin-top: 8px;
}

.cart-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
  position: sticky;
  bottom: 16px;
}

.search-result {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}

.search-result:hover { background: #f5f8ff; }

/* Cart page */
.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

.step-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #c7cede;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.step-btn:hover { background: #f5f8ff; }

.step-btn-lg {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid #c7cede;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 24px;
  font-weight: 600;
  line-height: 1;
  color: var(--brand);
  flex-shrink: 0;
  user-select: none;
}

.step-btn-lg:hover { background: #f5f8ff; }
.step-btn-lg:active { background: #e8effe; }

.remove-link {
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.summary-row.total {
  font-size: 17px;
  font-weight: 700;
  color: var(--brand);
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 4px;
}

textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}

button.secondary {
  width: 100%;
  padding: 12px;
  background: var(--surface);
  color: var(--brand);
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
}

button.secondary:hover { background: #f5f8ff; }

/* Admin */
.admin-shell {
  display: flex;
  min-height: calc(100vh - 57px);
}

.admin-nav {
  width: 200px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
}

.admin-nav-item {
  padding: 10px 20px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  border-left: 3px solid transparent;
}

.admin-nav-item:hover { background: #f5f8ff; }

.admin-nav-heading {
  margin: 10px 12px 6px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.admin-nav-heading:first-child { margin-top: 4px; }
.admin-nav-heading.nav-heading-sales { background: #eaf1fd; color: #1a56b3; }
.admin-nav-heading.nav-heading-production { background: #fff4e5; color: #a15c00; }
.admin-nav-heading.nav-heading-admin { background: #fdecea; color: #b3261e; }

.admin-nav-item.active {
  border-left-color: var(--brand);
  color: var(--brand);
  font-weight: 600;
  background: #f5f8ff;
}

.admin-main {
  flex: 1;
  padding: 24px 28px;
  max-width: 1100px;
}

.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 20px;
  overflow-x: auto;
}

@media (max-width: 720px) {
  .admin-shell {
    flex-direction: column;
  }
  .admin-nav {
    width: 100%;
    display: flex;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 4px;
  }
  .admin-nav-item {
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .admin-nav-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--brand);
  }
  .admin-nav-heading {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 10px 10px 10px 16px;
    border-right: 1px solid var(--border);
    margin-right: 4px;
  }
  .admin-nav-heading:first-child { padding-top: 10px; }
  .admin-main {
    padding: 16px;
    max-width: 100%;
  }
  .stock-reorder-col {
    display: none;
  }
}

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.admin-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}

table.admin-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}

/* รายการที่บันทึกล่าสุด (ฝ่ายผลิต) -- กรอบสูงจำกัด เลื่อนดูภายใน หัวตาราง
   ค้างไว้ด้านบนตอนเลื่อน */
.table-scroll {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.table-scroll table.admin-table th {
  position: sticky;
  top: 0;
  background: var(--surface, #fff);
  z-index: 1;
}

/* Tablet/mobile: .mobile-cards tables turn each row into its own labeled
   card instead of a cramped, horizontally-scrolling grid of columns --
   desktop (>1024px) is untouched, still a normal table. data-label on
   each <td> (set in js/admin.js) supplies the caption shown above its
   value. */
@media (max-width: 1024px) {
  table.mobile-cards thead {
    display: none;
  }
  table.mobile-cards,
  table.mobile-cards tbody,
  table.mobile-cards tr {
    display: block;
    width: 100%;
  }
  table.mobile-cards tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--bg);
  }
  table.mobile-cards td {
    display: block;
    padding: 6px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 14px;
    text-align: left !important;
  }
  table.mobile-cards td:last-child {
    border-bottom: none;
  }
  table.mobile-cards td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 2px;
  }
}

/* .admin-toolbar: the filter/action bars above admin tables and reports.
   Desktop keeps its single flexible row; tablet gets evenly-sized chips
   that wrap 2-3 per row instead of shrinking illegibly, phone stacks
   everything full-width so each control is easy to tap and read. */
@media (max-width: 1024px) {
  .admin-toolbar > * {
    flex: 1 1 160px;
  }
}
@media (max-width: 640px) {
  .admin-toolbar {
    flex-direction: column;
    align-items: stretch !important;
  }
  .admin-toolbar > * {
    flex: 0 0 auto;
    width: 100%;
    display: block;
    text-align: center;
  }
}

@media (max-width: 1024px) {
  .visit-row {
    font-size: 14px !important;
  }
  .visit-province-block {
    margin-left: 4px !important;
  }
}

select, input[type="text"], input[type="number"] {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

.pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  display: inline-block;
}
