@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@300;400;500;600;700&display=swap');

:root {
  --emerald-50:  #F0F7F4;
  --emerald-100: #D9ECE3;
  --emerald-200: #B3D9C7;
  --emerald-300: #7FBCA1;
  --emerald-500: #2C7858;
  --emerald-600: #1F5F44;
  --emerald-700: #0F4C3A;
  --emerald-800: #0A3A2C;
  --emerald-900: #06281F;
  --gold-50:  #FBF8F0;
  --gold-100: #F5EDD6;
  --gold-200: #EBDAA8;
  --gold-300: #DEC177;
  --gold-400: #D2AC4F;
  --gold-500: #C9A961;
  --gold-600: #A88340;
  --gold-700: #83642F;
  --cream-100: #FAFAF7;
  --cream-200: #F5F4ED;
  --cream-300: #EBE9DC;
  --ink-50:  #7B8A82;
  --ink-100: #5C6E64;
  --ink-200: #3F5347;
  --ink-300: #1A2E22;
  --shadow-soft: 0 2px 8px -2px rgba(15,76,58,.08);
  --shadow-card: 0 4px 20px -4px rgba(15,76,58,.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--cream-100);
  color: var(--ink-300);
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* === Layout === */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; margin-left: 256px; padding: 32px; }
@media (max-width: 768px) {
  .main { margin-left: 0; padding: 16px; }
}

/* === Sidebar === */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: 256px; background: var(--emerald-800); color: var(--cream-100);
  display: flex; flex-direction: column; z-index: 30;
}
.sidebar-head { padding: 20px; border-bottom: 1px solid var(--emerald-700); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 0; }
.sidebar-section { padding: 0 16px; margin: 16px 0 4px; font-size: 11px; font-weight: 600; color: var(--gold-300); text-transform: uppercase; letter-spacing: 0.08em; }
.sidebar-section:first-of-type { margin-top: 0; }
.sidebar-group { margin-top: 8px; }
.sidebar-group:first-child { margin-top: 0; }
.sidebar-group-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 6px; margin: 0 4px;
  font-size: 11px; font-weight: 700; color: var(--gold-300);
  text-transform: uppercase; letter-spacing: 0.08em; cursor: pointer;
  border-radius: 6px; user-select: none;
  transition: background .12s;
}
.sidebar-group-head:hover { background: rgba(255,255,255,.04); }
.sidebar-group-head .caret { font-size: 9px; opacity: .7; transition: transform .2s; }
.sidebar-group.collapsed .caret { transform: rotate(-90deg); }
.sidebar-group.collapsed .sidebar-group-items { display: none; }
.sidebar-group-items { display: flex; flex-direction: column; gap: 1px; padding: 2px 0; }
.sidebar-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 14px;
  margin: 0 8px; border-radius: 8px; font-size: 13.5px; color: var(--cream-100);
  transition: all .15s; position: relative;
}
.sidebar-item:hover { background: rgba(15,76,58,.5); }
.sidebar-item.active {
  background: linear-gradient(90deg, var(--emerald-700), rgba(15,76,58,.6));
  color: var(--gold-300); font-weight: 600;
  box-shadow: var(--shadow-soft);
}
.sidebar-item.active::before {
  content: ''; position: absolute; left: -8px; top: 6px; bottom: 6px; width: 3px;
  background: var(--gold-500); border-radius: 0 3px 3px 0;
}
.sidebar-item .icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--emerald-700); }
.brand-logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--gold-500), var(--gold-300));
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: bold; color: var(--emerald-900); font-size: 18px;
}
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-name { font-size: 16px; font-weight: 700; color: var(--cream-100); }
.brand-sub { font-size: 11px; color: var(--gold-300); }

/* === Card === */
.card {
  background: white; border-radius: 12px;
  border: 1px solid var(--cream-300);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.card-header { padding: 16px 24px; border-bottom: 1px solid var(--cream-300); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { margin: 0; color: var(--emerald-800); font-weight: 600; font-size: 15px; }
.card-body { padding: 24px; }

/* === Page header === */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.page-head .icon-box {
  width: 48px; height: 48px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.icon-box.emerald { background: var(--emerald-100); color: var(--emerald-700); }
.icon-box.gold { background: var(--gold-100); color: var(--gold-700); }
.page-head h1 { margin: 0; color: var(--emerald-800); font-size: 22px; font-weight: 700; }
.page-head p { margin: 0; font-size: 13px; color: var(--ink-100); }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 500; transition: all .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--emerald-700); color: white; box-shadow: var(--shadow-soft); }
.btn-primary:hover:not(:disabled) { background: var(--emerald-800); }
.btn-gold {
  background: linear-gradient(135deg, var(--gold-500), var(--gold-300));
  color: var(--emerald-900); font-weight: 600;
}
.btn-gold:hover:not(:disabled) { box-shadow: 0 0 0 3px rgba(201,169,97,.15); }
.btn-ghost { background: transparent; color: var(--emerald-700); }
.btn-ghost:hover:not(:disabled) { background: var(--emerald-50); }
.btn-danger { background: #FEE2E2; color: #B91C1C; }
.btn-danger:hover:not(:disabled) { background: #FECACA; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }

/* === Form === */
.label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-200); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; padding: 10px 14px; background: white;
  border: 1px solid var(--cream-300); border-radius: 8px;
  color: var(--ink-300); font-size: 14px; font-family: inherit;
  transition: border-color .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--emerald-500);
  box-shadow: 0 0 0 3px rgba(44,120,88,.15);
}
.textarea { min-height: 80px; resize: vertical; }
.select { appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%231A2E22' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-repeat: no-repeat; background-position: right 10px center;
  background-size: 16px; padding-right: 36px;
}

/* === Table === */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table thead { background: var(--emerald-50); color: var(--emerald-900); }
.table th { padding: 12px 16px; text-align: left; font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--emerald-100); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--cream-300); color: var(--ink-300); }
.table tbody tr:hover { background: var(--cream-100); }
.table .mono { font-family: 'IBM Plex Mono', monospace; }

/* === Badges === */
.badge { display: inline-flex; align-items: center; padding: 4px 10px;
  border-radius: 999px; font-size: 11px; font-weight: 500; }
.badge-in { background: var(--emerald-100); color: var(--emerald-800); }
.badge-out { background: var(--gold-100); color: var(--gold-700); }
.badge-pending { background: #FEF3C7; color: #92400E; }
.badge-done { background: #D1FAE5; color: #065F46; }
.badge-admin { background: var(--emerald-700); color: white; }
.badge-user { background: var(--cream-300); color: var(--ink-300); }
.badge-red { background: #FEE2E2; color: #B91C1C; }

/* === Grid utils === */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.text-2xl { font-size: 22px; }
.text-3xl { font-size: 28px; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.font-mono { font-family: 'IBM Plex Mono', monospace; }
.text-emerald { color: var(--emerald-700); }
.text-emerald-dark { color: var(--emerald-800); }
.text-gold { color: var(--gold-600); }
.text-ink { color: var(--ink-100); }
.text-red { color: #B91C1C; }
.text-amber { color: #B45309; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.uppercase { text-transform: uppercase; }
.tracking { letter-spacing: 0.05em; }

/* === Login === */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--emerald-700), var(--emerald-900));
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.login-card {
  background: white; border-radius: 16px; padding: 32px;
  border-top: 4px solid var(--gold-500);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  width: 100%; max-width: 420px;
}
.login-brand { text-align: center; margin-bottom: 24px; color: white; }
.login-logo {
  width: 80px; height: 80px; border-radius: 18px;
  background: linear-gradient(135deg, var(--gold-500), var(--gold-300));
  color: var(--emerald-900); font-weight: 700; font-size: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.3);
}
.gold-divider { height: 2px; background: linear-gradient(135deg, var(--gold-500), var(--gold-300));
  border-radius: 999px; margin: 12px auto; width: 100px; }

/* === Autocomplete === */
.ac-wrap { position: relative; }
.ac-dropdown {
  position: absolute; z-index: 50; top: 100%; left: 0; right: 0;
  margin-top: 4px; background: white; border: 1px solid var(--cream-300);
  border-radius: 8px; box-shadow: var(--shadow-card);
  max-height: 256px; overflow-y: auto;
}
.ac-item {
  padding: 10px 16px; cursor: pointer; font-size: 14px;
  border-bottom: 1px solid var(--cream-200);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: var(--emerald-50); color: var(--emerald-800); }
.ac-item .sub { font-size: 11px; color: var(--ink-100); margin-top: 2px; }

/* === Goods picker (compact) === */
.goods-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  padding: 2px;
}
.goods-item {
  position: relative; aspect-ratio: 1; border-radius: 6px;
  border: 1px solid var(--cream-300); background: var(--cream-100);
  overflow: hidden; cursor: pointer; transition: all .12s; padding: 0;
}
.goods-item:hover { border-color: var(--emerald-500); transform: translateY(-1px); }
.goods-item.selected {
  border-color: var(--gold-500);
  box-shadow: 0 0 0 2px rgba(222,193,119,.45);
}
.goods-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.goods-item .empty {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--emerald-300); font-size: 28px;
}
.goods-item .label {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 5px;
  background: linear-gradient(to top, rgba(0,0,0,.78), rgba(0,0,0,0));
  color: white; font-size: 10px; font-weight: 500; line-height: 1.15;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.goods-item .tag {
  position: absolute; top: 3px; right: 3px;
  background: var(--gold-500); color: var(--emerald-900);
  font-size: 8px; font-weight: 700; padding: 1px 4px; border-radius: 3px;
}
.goods-item.goods-more .empty { font-size: 20px; }
.goods-item.goods-more .label {
  position: relative; background: none; color: var(--emerald-700);
  text-align: center; padding: 4px; white-space: normal;
}

/* === Modal === */
.modal-bg {
  position: fixed; inset: 0; background: rgba(6,40,31,.7);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  z-index: 100;
}
.modal {
  background: white; border-radius: 16px; max-width: 520px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.modal-head {
  padding: 16px 24px; background: linear-gradient(135deg, var(--emerald-700), var(--emerald-600));
  color: var(--cream-100); border-radius: 16px 16px 0 0;
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 16px;
}
.modal-head button { background: none; border: none; color: var(--cream-100); font-size: 20px; }
.modal-body { padding: 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--cream-300); background: var(--cream-100);
  border-radius: 0 0 16px 16px; display: flex; justify-content: flex-end; gap: 8px; }

/* === Alerts === */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin: 8px 0; }
.alert-error { background: #FEE2E2; color: #B91C1C; border: 1px solid #FECACA; }
.alert-warn { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }
.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-info { background: var(--emerald-50); color: var(--emerald-800); border: 1px solid var(--emerald-100); }

/* === Print === */
.print-page {
  background: white; border: 2px solid var(--emerald-700);
  border-radius: 12px; max-width: 900px; margin: 0 auto; overflow: hidden;
  box-shadow: var(--shadow-card);
}
.print-head {
  padding: 20px 32px; color: var(--cream-100);
  background: linear-gradient(135deg, var(--emerald-700), var(--emerald-600));
  display: flex; justify-content: space-between; align-items: flex-start;
}
.print-head.gold { background: linear-gradient(135deg, var(--gold-500), var(--gold-300)); color: var(--emerald-900); }
.print-body { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; padding: 24px 32px; }
.detail-row { margin-bottom: 12px; }
.detail-label { font-size: 11px; color: var(--ink-100); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.detail-value { font-size: 15px; color: var(--ink-300); font-weight: 500; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 12px;
  border-left: 2px solid var(--cream-300); padding-left: 24px; }
.print-foot { padding: 12px 32px; background: var(--cream-100);
  border-top: 1px solid var(--cream-300); font-size: 11px; color: var(--ink-100);
  display: flex; justify-content: space-between; }

@media print {
  body { background: white; }
  .no-print { display: none !important; }
  .main { margin-left: 0 !important; padding: 0 !important; }
  .print-page { border: none; box-shadow: none; max-width: 100%; }
}

/* === Quick actions === */
.qa {
  display: block; background: white; border: 1px solid var(--cream-300);
  border-radius: 12px; padding: 20px; box-shadow: var(--shadow-card);
  transition: all .15s;
}
.qa:hover { box-shadow: 0 8px 30px rgba(15,76,58,.15); transform: translateY(-2px); }
.qa-row { display: flex; gap: 16px; }
.qa-icon { width: 56px; height: 56px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 24px; }
.qa-icon.emerald { background: var(--emerald-100); color: var(--emerald-700); }
.qa-icon.gold { background: var(--gold-100); color: var(--gold-700); }
.qa h3 { margin: 0 0 4px; color: var(--emerald-800); font-weight: 600; font-size: 16px; }
.qa p { margin: 0; font-size: 13px; color: var(--ink-100); }

/* === Stat box === */
.stat { display: flex; align-items: center; gap: 16px; padding: 20px;
  background: white; border: 1px solid var(--cream-300);
  border-radius: 12px; box-shadow: var(--shadow-card); }
.stat-icon { width: 48px; height: 48px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 22px; }
.stat-label { font-size: 11px; color: var(--ink-100); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--emerald-900); }

/* === Filter chips === */
.chip {
  padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: 500;
  background: var(--cream-100); color: var(--ink-200); border: none;
}
.chip:hover { background: var(--cream-200); }
.chip.active { background: var(--emerald-700); color: white; }

/* === Goods card grid (admin) === */
.goods-card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px;
}
.goods-card {
  background: white; border-radius: 12px; border: 1px solid var(--cream-300);
  overflow: hidden; box-shadow: var(--shadow-soft); transition: all .15s;
  cursor: pointer; padding: 0; text-align: left; display: block;
}
.goods-card:hover { box-shadow: var(--shadow-card); transform: translateY(-2px); }
.goods-card .thumb { aspect-ratio: 1; background: var(--cream-100); display: flex;
  align-items: center; justify-content: center; position: relative; }
.goods-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.goods-card .info { padding: 12px; }
.goods-card .name { font-size: 14px; font-weight: 500; color: var(--emerald-900);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.goods-card .meta { display: flex; justify-content: space-between; margin-top: 4px; }
.goods-card .meta .k { font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: var(--emerald-50); color: var(--emerald-700); }
.goods-card .meta .c { font-size: 10px; color: var(--ink-100); font-family: 'IBM Plex Mono', monospace; }
