/* ============================================================
   ระบบจัดการสต๊อกสินค้า - ร้านชากาแฟ
   Design tokens: โทนอุ่นแบบร้านกาแฟ (เอสเปรสโซ่ / คาราเมล / มัทฉะ)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@500;600;700&family=Sarabun:wght@400;500;600;700&display=swap');

:root {
  /* สี */
  --coffee-900: #2B1D16;   /* เอสเปรสโซ่เข้ม - sidebar/topbar */
  --coffee-700: #4A3327;
  --coffee-500: #6F4E37;
  --paper: #FAF6EF;        /* พื้นหลังหลัก โทนกระดาษอุ่น */
  --card: #FFFFFF;
  --line: #E7DDCC;
  --caramel: #C98A2C;      /* accent หลัก */
  --caramel-dark: #A66F1E;
  --matcha: #5B7B5A;       /* success / กำไร */
  --matcha-bg: #EAF1E8;
  --brick: #B3432B;        /* danger / หมด */
  --brick-bg: #FBEAE6;
  --amber: #C98A2C;        /* warning / ใกล้หมด */
  --amber-bg: #FBF1DE;
  --ink: #2B1D16;
  --ink-soft: #6B5B4F;

  --radius: 10px;
  --shadow: 0 2px 10px rgba(43, 29, 22, 0.08);
  --font-display: 'Kanit', 'Sarabun', sans-serif;
  --font-body: 'Sarabun', 'Kanit', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3, h4, .brand, .stat-value, .btn, th {
  font-family: var(--font-display);
}

a { color: var(--caramel-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- Layout shell ---------------- */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 64px 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}

.topbar {
  grid-area: topbar;
  background: var(--coffee-900);
  color: #F4EEE3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: .3px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-badge { font-size: .88rem; color: #E7DCC8; }
.user-badge small { color: #C9B79B; }

.hamburger {
  display: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: #F4EEE3;
}

.sidebar {
  grid-area: sidebar;
  background: var(--coffee-900);
  color: #EFE6D6;
  padding: 18px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(255,255,255,.06);
}

.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px;
  color: #E7DCC8;
  font-size: .96rem;
  border-left: 3px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}
.nav-list li a:hover { background: rgba(201,138,44,.12); text-decoration: none; }
.nav-list li a.active {
  background: rgba(201,138,44,.18);
  border-left-color: var(--caramel);
  color: #FFF3DF;
  font-weight: 600;
}

.sidebar-toggle-checkbox { display: none; }
.sidebar-backdrop { display: none; }

.main-content {
  grid-area: main;
  padding: 22px 26px 60px;
  max-width: 1300px;
  width: 100%;
}

/* ---------------- Typography helpers ---------------- */
.page-title {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--coffee-900);
}
.page-subtitle { color: var(--ink-soft); margin: 0 0 20px; font-size: .92rem; }

/* ---------------- Alerts ---------------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: .92rem;
  border-left: 4px solid transparent;
}
.alert-success { background: var(--matcha-bg); color: #33502F; border-color: var(--matcha); }
.alert-danger  { background: var(--brick-bg); color: #7A2A1A; border-color: var(--brick); }
.alert-info    { background: var(--amber-bg); color: #7A5312; border-color: var(--amber); }

/* ---------------- Cards / dashboard grid ---------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  border-top: 3px dashed var(--line);
  position: relative;
}
.stat-card .stat-label {
  font-size: .8rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.stat-card .stat-value {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--coffee-900);
}
.stat-card.accent-profit .stat-value { color: var(--matcha); }
.stat-card.accent-warn .stat-value { color: var(--amber); }
.stat-card.accent-danger .stat-value { color: var(--brick); }
.stat-card .stat-unit { font-size: .85rem; color: var(--ink-soft); font-weight: 400; margin-left: 4px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-title {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--coffee-900);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
table.data-table th {
  text-align: left;
  background: #F3ECDD;
  color: var(--coffee-900);
  padding: 10px 12px;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 2px solid var(--line);
}
table.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data-table tbody tr:hover { background: #FBF7EF; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--ink-soft); }
.nowrap { white-space: nowrap; }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
}
.badge-ok      { background: var(--matcha-bg); color: #33502F; }
.badge-warn    { background: var(--amber-bg); color: #7A5312; }
.badge-danger  { background: var(--brick-bg); color: #7A2A1A; }
.badge-owner   { background: #EEE3F3; color: #5A3B72; }
.badge-employee{ background: #E4EEF6; color: #2C5478; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  background: var(--caramel);
  color: #fff;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.btn:hover { background: var(--caramel-dark); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-outline { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #F4EEE3; }
.btn-outline:hover { background: rgba(255,255,255,.1); }
.btn-secondary { background: var(--coffee-700); }
.btn-secondary:hover { background: var(--coffee-900); }
.btn-danger { background: var(--brick); }
.btn-danger:hover { background: #8F2F1F; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------- Forms ---------------- */
.form-group { margin-bottom: 14px; }
label.form-label {
  display: block;
  font-size: .86rem;
  font-weight: 600;
  color: var(--coffee-900);
  margin-bottom: 5px;
}
input[type=text], input[type=number], input[type=password],
input[type=date], input[type=search], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: .92rem;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--caramel);
  outline-offset: 1px;
  border-color: var(--caramel);
}
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }
.help-text { font-size: .78rem; color: var(--ink-soft); margin-top: 4px; }

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 16px;
  border-radius: 8px 8px 0 0;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: .9rem;
}
.tabs a.active { background: var(--card); color: var(--caramel-dark); box-shadow: var(--shadow); }
.tabs a:hover { text-decoration: none; color: var(--caramel-dark); }

/* ---------------- Stock breakdown pill (ลังเต็ม / แกะแยก) ---------------- */
.stock-breakdown { display: flex; gap: 10px; flex-wrap: wrap; font-size: .84rem; }
.stock-breakdown span {
  background: #F3ECDD;
  border-radius: 8px;
  padding: 4px 10px;
  color: var(--coffee-900);
  font-weight: 500;
}

/* ---------------- Login page ---------------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--coffee-900) 0%, var(--coffee-700) 55%, var(--caramel-dark) 130%);
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.login-card h1 {
  font-size: 1.3rem;
  color: var(--coffee-900);
  margin: 0 0 4px;
  text-align: center;
}
.login-card p.sub { text-align: center; color: var(--ink-soft); margin: 0 0 22px; font-size: .86rem; }
.login-emoji { text-align: center; font-size: 2.4rem; margin-bottom: 6px; }

/* ---------------- POS ---------------- */
.pos-grid { display: grid; grid-template-columns: 1fr 360px; gap: 20px; align-items: start; }
.product-pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.product-pick {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color .15s ease, transform .1s ease;
}
.product-pick:hover { border-color: var(--caramel); transform: translateY(-1px); }
.product-pick .p-name { font-weight: 600; color: var(--coffee-900); font-size: .92rem; }
.product-pick .p-meta { font-size: .78rem; color: var(--ink-soft); margin-top: 3px; }
.product-pick .p-stock { font-size: .78rem; margin-top: 6px; }

.cart-box { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; position: sticky; top: 80px; }
.cart-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.cart-item .ci-name { flex: 1; font-size: .86rem; }
.cart-item input[type=number] { width: 60px; padding: 6px 8px; }
.cart-total { display: flex; justify-content: space-between; font-weight: 700; font-size: 1.05rem; margin-top: 12px; padding-top: 12px; border-top: 2px solid var(--line); color: var(--coffee-900); }
.remove-item { color: var(--brick); cursor: pointer; font-size: 1.1rem; padding: 0 4px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 960px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .pos-grid { grid-template-columns: 1fr; }
  .cart-box { position: static; }
}

@media (max-width: 780px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .hamburger { display: block; }
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    width: 240px;
    height: 100vh;
    z-index: 40;
    transition: left .2s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.25);
  }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 30;
  }
  #sidebar-toggle:checked ~ .sidebar { left: 0; }
  #sidebar-toggle:checked ~ .sidebar-backdrop { display: block; }
  .main-content { padding: 16px; }
  .form-row { flex-direction: column; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar-title { font-size: .95rem; }
  .user-badge { display: none; }
}
