/* ============================================================
   Kitchen Store Management System - Stylesheet
   Mobile-first | IBM Plex Sans Thai
   ============================================================ */

:root {
  --navy:       #1a3a5c;
  --navy-dark:  #0f2440;
  --navy-light: #274d73;
  --gold:       #c9a84c;
  --gold-light: #e8c97a;
  --cream:      #f8f5f0;
  --white:      #ffffff;
  --gray-50:    #f9fafb;
  --gray-100:   #f3f4f6;
  --gray-200:   #e5e7eb;
  --gray-400:   #9ca3af;
  --gray-600:   #4b5563;
  --gray-800:   #1f2937;
  --success:    #16a34a;
  --danger:     #dc2626;
  --warning:    #d97706;
  --info:       #0284c7;
  --sidebar-w:  260px;
  --topbar-h:   60px;
  --radius:     10px;
  --shadow:     0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.12);
  --transition: 0.25s ease;
}

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

html { font-size: 17px; scroll-behavior: smooth; }

body {
  font-family: 'Sarabun', sans-serif;
  font-size: 16px;
  font-weight: 600;
  background: var(--cream);
  color: var(--gray-800);
  line-height: 1.7;
  min-height: 100vh;
}

/* ── App Layout ─────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; position: relative; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--navy-dark) 0%, var(--navy) 100%);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.brand-icon {
  width: 40px; height: 40px;
  background: var(--gold);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--navy-dark); flex-shrink: 0;
}
.brand-title { display: block; font-size: .95rem; font-weight: 700; letter-spacing: .5px; }
.brand-sub   { display: block; font-size: .72rem; opacity: .6; }

.sidebar-user {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.user-avatar {
  width: 36px; height: 36px;
  background: var(--gold); color: var(--navy-dark);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; flex-shrink: 0;
}
.user-name       { display: block; font-size: .85rem; font-weight: 600; }
.user-role-badge { display: block; font-size: .72rem; opacity: .7; }

.nav-menu { list-style: none; padding: 12px 0; flex: 1; }
.nav-group-label {
  font-size: .68rem; font-weight: 600; letter-spacing: 1.2px;
  text-transform: uppercase; opacity: .4;
  padding: 16px 20px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: .88rem;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}
.nav-link:hover, .nav-link.active {
  color: var(--white);
  background: rgba(255,255,255,.08);
  border-left-color: var(--gold);
}
.nav-link i { width: 18px; text-align: center; font-size: .9rem; }

.sidebar-footer {
  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-footer-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: .85rem;
  transition: color var(--transition);
}
.sidebar-footer-link:hover   { color: var(--white); }
.sidebar-footer-link.logout-link:hover { color: #fca5a5; }

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin var(--transition);
}

.top-bar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.menu-toggle {
  display: none;
  background: none; border: none;
  font-size: 1.2rem; color: var(--navy); cursor: pointer;
  padding: 6px;
}
.page-title { font-size: 1rem; font-weight: 600; color: var(--navy); flex: 1; }
.top-bar-actions { display: flex; align-items: center; gap: 10px; }

.content-area { padding: 24px; flex: 1; max-width: 1400px; }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.card-title { font-size: .95rem; font-weight: 600; color: var(--navy); }
.card-body  { padding: 20px; }

/* ── Stat Cards ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
  border-left: 4px solid var(--navy);
}
.stat-card.gold   { border-left-color: var(--gold); }
.stat-card.green  { border-left-color: var(--success); }
.stat-card.red    { border-left-color: var(--danger); }
.stat-card.orange { border-left-color: var(--warning); }
.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  background: var(--cream); color: var(--navy);
  flex-shrink: 0;
}
.stat-card.gold   .stat-icon { background: #fef3c7; color: var(--warning); }
.stat-card.green  .stat-icon { background: #dcfce7; color: var(--success); }
.stat-card.red    .stat-icon { background: #fee2e2; color: var(--danger);  }
.stat-card.orange .stat-icon { background: #ffedd5; color: var(--warning); }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--navy); line-height: 1.2; }
.stat-label { font-size: .78rem; color: var(--gray-600); }

/* ── Table ─────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th {
  background: var(--navy);
  color: var(--white);
  font-weight: 600;
  font-size: .8rem;
  letter-spacing: .4px;
  padding: 11px 14px;
  text-align: left;
  white-space: nowrap;
}
th:first-child { border-radius: 8px 0 0 0; }
th:last-child  { border-radius: 0 8px 0 0; }
td { padding: 10px 14px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f0f4ff; }

.table-img {
  width: 44px; height: 44px;
  border-radius: 6px; object-fit: cover;
  border: 1px solid var(--gray-200);
}
.table-img-placeholder {
  width: 44px; height: 44px;
  border-radius: 6px;
  background: var(--gray-100);
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-400); font-size: .9rem;
}
.code-cell { font-family: 'IBM Plex Mono', monospace; font-size: .82rem; color: var(--navy); }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-success   { background: #dcfce7; color: #15803d; }
.badge-danger    { background: #fee2e2; color: #b91c1c; }
.badge-warning   { background: #fef3c7; color: #92400e; }
.badge-info      { background: #dbeafe; color: #1d4ed8; }
.badge-secondary { background: var(--gray-100); color: var(--gray-600); }

/* ── Qty indicator ─────────────────────────────────────── */
.qty-ok  { color: var(--success); font-weight: 600; }
.qty-low { color: var(--warning); font-weight: 600; }
.qty-out { color: var(--danger);  font-weight: 600; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 18px;
  border-radius: 8px;
  border: none; cursor: pointer;
  font-family: inherit; font-size: .88rem; font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--navy-light); }
.btn-gold    { background: var(--gold); color: var(--navy-dark); }
.btn-gold:hover { background: var(--gold-light); }
.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger  { background: var(--danger); color: var(--white); }
.btn-danger:hover  { filter: brightness(1.1); }
.btn-warning { background: var(--warning); color: var(--white); }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--gray-200);
  color: var(--gray-600);
}
.btn-outline:hover { border-color: var(--navy); color: var(--navy); }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-icon { padding: 7px; border-radius: 7px; }

/* ── Forms ─────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: .85rem; font-weight: 600; color: var(--gray-800); margin-bottom: 6px; }
.form-label .req { color: var(--danger); margin-left: 2px; }

.form-control, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-family: inherit; font-size: .9rem;
  background: var(--white); color: var(--gray-800);
  transition: border var(--transition), box-shadow var(--transition);
  appearance: none;
}
.form-control:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(26,58,92,.12);
}
.form-textarea { min-height: 90px; resize: vertical; }
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%234b5563' d='M6 8L0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.form-hint { font-size: .78rem; color: var(--gray-400); margin-top: 4px; }
.form-error { font-size: .78rem; color: var(--danger); margin-top: 4px; }

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

/* Rich text hint */
.rich-textarea-wrapper { position: relative; }
.rich-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 6px 8px;
  background: var(--gray-50);
  border: 1.5px solid var(--gray-200);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}
.rich-toolbar button {
  padding: 4px 8px; border: none; background: none; cursor: pointer;
  border-radius: 4px; font-size: .8rem; color: var(--gray-600);
}
.rich-toolbar button:hover { background: var(--gray-200); }
.rich-content {
  min-height: 120px;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: var(--white);
  font-family: inherit; font-size: .9rem; line-height: 1.6;
  outline: none;
}
.rich-content:focus { box-shadow: 0 0 0 3px rgba(26,58,92,.12); }

/* Image upload */
.img-upload-area {
  border: 2px dashed var(--gray-200);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border var(--transition), background var(--transition);
}
.img-upload-area:hover { border-color: var(--navy); background: #f0f4ff; }
.img-upload-area.dragover { border-color: var(--gold); background: #fffbeb; }
.img-preview { max-width: 140px; max-height: 140px; border-radius: 8px; object-fit: cover; }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: .9rem;
  position: relative;
}
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.alert-danger   { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-warning  { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info     { background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; }
.alert-close {
  margin-left: auto; background: none; border: none; cursor: pointer;
  font-size: 1.2rem; line-height: 1; opacity: .5; padding: 0 4px;
}
.alert-close:hover { opacity: 1; }

/* ── Modal ─────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 500;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: 14px;
  width: 100%; max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--navy); }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.3rem; color: var(--gray-400); padding: 4px;
  border-radius: 6px; transition: color var(--transition);
}
.modal-close:hover { color: var(--danger); }
.modal-body   { padding: 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--gray-100); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Pagination ─────────────────────────────────────────── */
.pagination { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.page-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; padding: 0 10px;
  border-radius: 8px; border: 1.5px solid var(--gray-200);
  background: var(--white); color: var(--gray-600);
  text-decoration: none; font-size: .85rem; font-weight: 500;
  transition: all var(--transition);
}
.page-btn:hover { border-color: var(--navy); color: var(--navy); }
.page-btn.active { background: var(--navy); color: var(--white); border-color: var(--navy); }
.page-btn.disabled { opacity: .4; pointer-events: none; }

/* ── Search & filter bar ─────────────────────────────────── */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  margin-bottom: 18px;
}
.filter-bar .form-control,
.filter-bar .form-select { max-width: 220px; }
.search-box { position: relative; }
.search-box input { padding-left: 36px; }
.search-box .search-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--gray-400); font-size: .85rem;
}

/* ── Login page ─────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy) 60%, #2d5a8e 100%);
  padding: 20px;
}
.login-card {
  background: var(--white);
  border-radius: 18px;
  padding: 40px 36px;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  text-align: center; margin-bottom: 28px;
}
.login-logo-icon {
  width: 64px; height: 64px;
  background: var(--navy); color: var(--gold);
  border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.8rem; margin-bottom: 14px;
}
.login-title { font-size: 1.25rem; font-weight: 700; color: var(--navy); }
.login-sub   { font-size: .85rem; color: var(--gray-400); }

/* ── Utilities ─────────────────────────────────────────── */
.flex         { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--gray-400); font-size: .85rem; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.fw-bold { font-weight: 700; }
.w-full { width: 100%; }
.d-none { display: none !important; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open { display: block; }
  .main-content { margin-left: 0; }
  .menu-toggle  { display: block; }
  .content-area { padding: 16px; }
  .stats-grid   { grid-template-columns: 1fr 1fr; gap: 12px; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .filter-bar .form-control,
  .filter-bar .form-select { max-width: 100%; }
  .top-bar { padding: 0 16px; }
  th, td { padding: 9px 10px; }
}

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
  .login-card { padding: 28px 20px; }
}

/* ── Print ─────────────────────────────────────────────── */
@media print {
  .sidebar, .top-bar, .menu-toggle,
  .btn, .filter-bar, .pagination { display: none !important; }
  .main-content { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
