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

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #818cf8;
  --green: #059669;
  --green-dark: #047857;
  --red: #dc2626;
  --orange: #ea580c;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(0,0,0,.06);
}

html, body {
  font-family: 'Sarabun', 'TH Sarabun New', 'IBM Plex Sans Thai', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

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

/* ===== Login ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4338ca, #6d28d9, #9333ea);
  padding: 20px;
}
.login-box {
  background: #fff;
  border-radius: 20px;
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  text-align: center;
}
.login-box h1 { font-size: 24px; margin-bottom: 6px; color: var(--primary-dark); }
.login-box p.sub { color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.login-box input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 18px;
  text-align: center;
  letter-spacing: 4px;
  margin-bottom: 16px;
  outline: none;
}
.login-box input[type="password"]:focus { border-color: var(--primary); }
.login-box button {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: .2s;
}
.login-box button:hover { background: var(--primary-dark); }
.login-error { color: var(--red); font-size: 14px; margin-bottom: 12px; min-height: 20px; }

/* ===== App layout ===== */
.app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 3px 12px rgba(0,0,0,.15);
  position: sticky;
  top: 0;
  z-index: 50;
}
header .brand h1 { font-size: 20px; font-weight: 700; }
header .brand small { font-size: 12px; opacity: .85; display: block; }
header .logout-btn {
  background: rgba(255,255,255,.2);
  border: 1px solid rgba(255,255,255,.4);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

/* bottom nav (mobile) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
  z-index: 50;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 4px;
  font-size: 11px;
  color: var(--muted);
  gap: 2px;
}
.bottom-nav a.active { color: var(--primary); font-weight: 700; }
.bottom-nav a i { font-size: 20px; }

/* top nav (desktop) */
.top-nav {
  display: none;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  gap: 8px;
  flex-wrap: wrap;
  position: sticky;
  top: 60px;
  z-index: 40;
}
.top-nav a {
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.top-nav a:hover { background: #eef2ff; color: var(--primary); }
.top-nav a.active { background: var(--primary); color: #fff; }

main {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  width: 100%;
}

/* ===== Pages ===== */
.page { display: none; }
.page.active { display: block; }

.page-title { font-size: 20px; font-weight: 700; margin-bottom: 16px; color: var(--text); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card h2 { font-size: 17px; margin-bottom: 14px; color: var(--text); }

/* ===== Buttons ===== */
.btn {
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  transition: .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { opacity: .88; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-orange { background: var(--orange); color: #fff; }
.btn-gray { background: #e2e8f0; color: var(--text); }
.btn-block { width: 100%; justify-content: center; padding: 13px; font-size: 15px; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 700; color: var(--text); }
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 15px;
  width: 100%;
  background: #fff;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

/* ===== Table ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; font-size: 14px; }
th, td { padding: 11px 13px; text-align: right; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; color: var(--muted); font-weight: 700; font-size: 13px; position: sticky; top: 0; }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) { text-align: left; }
tr:hover td { background: #fafbff; }
tr:last-child td { border-bottom: none; }

.badge { padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge-in { background: #d1fae5; color: #047857; }
.badge-out { background: #fee2e2; color: #b91c1c; }

/* stock positive/negative */
.stock-pos { color: var(--green); font-weight: 700; }
.stock-neg { color: var(--red); font-weight: 700; }
.money { color: #047857; font-weight: 600; }

/* ===== Stat cards ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
}
.stat small { display: block; color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.stat strong { font-size: 22px; font-weight: 700; }
.stat.green { border-left-color: var(--green); }
.stat.red { border-left-color: var(--red); }
.stat.orange { border-left-color: var(--orange); }

/* ===== Search ===== */
.searchbox { position: relative; margin-bottom: 14px; }
.searchbox input { padding-left: 38px; }
.searchbox i {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.empty { text-align: center; color: var(--muted); padding: 24px; font-size: 14px; }

/* ===== Movement form ===== */
.move-form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}
.move-form-row .btn { margin: 0; height: 44px; }

/* topbar actions */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: end; }

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 16px 14px;
  font-size: 13px;
  color: var(--muted);
  background: #fff;
  border-top: 1px solid var(--border, #e2e8f0);
}
.site-footer strong { color: var(--primary, #b45309); }

/* ===== Status badges ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-in { background: #dcfce7; color: #166534; }
.badge-out { background: #fee2e2; color: #b91c1c; }

/* ===== Responsive ===== */
@media (min-width: 768px) {
  .bottom-nav { display: none; }
  .top-nav { display: flex; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 0 14px; }
  .move-form-row { grid-template-columns: 2fr 1fr 100px; }
  main { padding: 24px; }
}
@media (max-width: 767px) {
  main { padding: 14px 12px 90px; }
  .toolbar { flex-direction: column; }
  .toolbar .btn { width: 100%; justify-content: center; }
}
