@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  /* โทนสีสไตล์มินิมอล/ทันสมัย แบบแรก */
  --bg-body: #f8fafc;
  --bg-sidebar: #ffffff;
  --bg-topbar: #ffffff;
  --bg-card: #ffffff;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-soft: #ecfdf5;
  
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --radius: 12px;
}

/* ธีมสีดำ (Dark Mode) */
body.dark {
  --bg-body: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-topbar: #1e293b;
  --bg-card: #1e293b;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  
  --primary: #10b981;
  --primary-soft: rgba(16, 185, 129, 0.15);
  
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
}

/* ตั้งค่าเริ่มต้นให้สวยงาม */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', 'Sarabun', sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  display: flex;
  height: 100vh;
  overflow: hidden;
  transition: background-color 0.3s, color 0.3s;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }
button { font-family: inherit; cursor: pointer; }

/* ========================================= */
/* SIDEBAR (แถบด้านข้าง)                       */
/* ========================================= */
#sidebar-placeholder {
  width: 280px;
  flex-shrink: 0;
  transition: width 0.3s ease;
}
#sidebar-placeholder.collapsed { width: 80px; }

.sidebar {
  width: 280px;
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, background-color 0.3s;
  z-index: 100;
}
.sidebar.collapsed { width: 80px; }

.sidebar-top { padding: 24px 20px 16px 20px; }

.brand {
  display: flex; align-items: center; gap: 12px; margin-bottom: 24px;
}
.brand-logo {
  min-width: 36px; height: 36px;
  background: var(--primary); color: #fff;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 18px;
  box-shadow: var(--shadow-sm);
}
.brand-name {
  font-size: 22px; font-weight: 700; color: var(--text-main);
  white-space: nowrap; flex: 1; transition: opacity 0.2s;
}
.btn-collapse {
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-muted);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  min-width: 32px;
}
.btn-collapse:hover { background: var(--bg-body); color: var(--text-main); }

/* ช่องค้นหา */
.search-box {
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
}
.search-box i { color: var(--text-muted); width: 18px; height: 18px; }
.search-input {
  border: none; background: transparent; outline: none;
  font-family: inherit; font-size: 14px; color: var(--text-main);
  width: 100%;
}
.search-kbd {
  font-size: 11px; color: var(--text-muted);
  background: var(--bg-sidebar); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 4px;
}

/* ส่วนเมนู */
.sidebar-nav {
  flex: 1; overflow-y: auto; padding: 0 12px;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.nav-section-title {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  padding: 20px 12px 10px 12px; letter-spacing: 0.05em; white-space: nowrap;
}
.nav-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; margin-bottom: 4px;
  color: var(--text-muted); border-radius: 10px;
  transition: all 0.2s ease; white-space: nowrap; cursor: pointer;
}
.nav-item i { width: 22px; height: 22px; min-width: 22px; }
.nav-item:hover { background: var(--bg-body); color: var(--text-main); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.active i { color: var(--primary); }

.nav-label { font-size: 15px; font-weight: 500; flex: 1; transition: opacity 0.2s; }
.nav-label small { display: block; font-size: 11.5px; color: var(--text-muted); font-weight: 400; margin-top: 3px; }

/* Submenu / Accordion แบบสมูทๆ */
.submenu-indicator { width: 16px; height: 16px; transition: transform 0.3s ease; }
.nav-group.open .submenu-indicator { transform: rotate(180deg); color: var(--text-main); }
.nav-group.open > .nav-item { color: var(--text-main); }

.submenu-content {
  max-height: 0; overflow: hidden; transition: max-height 0.3s ease-in-out;
}
.nav-group.open .submenu-content { max-height: 300px; }
.submenu-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px 10px 42px;
  font-size: 14px; color: var(--text-muted); font-weight: 500;
  border-radius: 8px; transition: all 0.2s; white-space: normal;
  line-height: 1.3;
}
.submenu-item i, .submenu-item svg {
  width: 16px; height: 16px; min-width: 16px; margin-top: 2px; opacity: 0.7;
}
.submenu-item .text-col {
  display: flex; flex-direction: column; gap: 2px;
}
.submenu-item span {
  color: var(--text-main); font-weight: 500;
}
.submenu-item small { 
  display: block; font-size: 11.5px; opacity: 0.8; font-weight: 400; color: var(--text-muted);
}
.submenu-item:hover { background: var(--bg-body); }
.submenu-item.active { background: var(--primary-soft); }
.submenu-item.active span, .submenu-item.active i, .submenu-item.active svg { color: var(--primary); font-weight: 600; opacity: 1; }

/* แถบด้านล่างของ Sidebar */
.sidebar-bottom { padding: 16px; border-top: 1px solid var(--border); }
.theme-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; color: var(--text-muted); font-size: 14px; cursor: pointer;
  border-radius: 10px;
}
.theme-toggle:hover { background: var(--bg-body); color: var(--text-main); }
.theme-toggle i { width: 20px; height: 20px; min-width: 20px; }

.profile-min {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; margin-top: 8px; border-radius: 12px;
  background: var(--bg-body); cursor: pointer; transition: 0.2s;
}
.profile-min:hover { box-shadow: var(--shadow-sm); }
.profile-min img { width: 36px; height: 36px; border-radius: 50%; min-width: 36px;}
.profile-text { flex: 1; white-space: nowrap; overflow: hidden; }
.profile-name { font-size: 14px; font-weight: 600; color: var(--text-main); }
.profile-role { font-size: 11px; color: var(--text-muted); }

/* เมื่อ Sidebar หด (Collapsed) */
.sidebar.collapsed .brand-name,
.sidebar.collapsed .search-input,
.sidebar.collapsed .search-kbd,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .submenu-indicator,
.sidebar.collapsed .submenu-content,
.sidebar.collapsed .theme-label,
.sidebar.collapsed .profile-text,
.sidebar.collapsed .profile-icon {
  opacity: 0; display: none;
}
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px 0; }
.sidebar.collapsed .search-box { padding: 10px; justify-content: center; }
.sidebar.collapsed .theme-toggle { justify-content: center; }
.sidebar.collapsed .profile-min { padding: 8px; justify-content: center; background: transparent; }

/* ========================================= */
/* MAIN CONTENT                              */
/* ========================================= */
.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* แถบด้านบนเป๊ะๆ ตามต้นฉบับ */
.topbar {
  height: 72px; padding: 0 40px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-topbar); border-bottom: 1px solid var(--border);
  transition: background-color 0.3s; z-index: 10;
}
.page-title { font-size: 22px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 20px; }
.avatar-stack { display: flex; align-items: center; }
.avatar-stack img { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--bg-topbar); margin-left: -12px; object-fit: cover; }
.avatar-stack img:first-child { margin-left: 0; }
.avatar-more { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--bg-topbar); margin-left: -12px; background: #e2e8f0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: #475569; }
body.dark .avatar-more { background: #334155; color: #cbd5e1; }

.topbar-icons { display: flex; align-items: center; gap: 18px; color: var(--text-muted); cursor: pointer; }
.topbar-icons i { width: 22px; height: 22px; transition: 0.2s; }
.topbar-icons i:hover { color: var(--text-main); }

.topbar-divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.btn-manage {
  height: 40px; padding: 0 20px; background: transparent;
  border: 1px solid var(--border); border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: var(--text-main); transition: 0.2s;
}
.btn-manage:hover { background: var(--bg-body); }

/* ปุ่มสีหลัก (Primary) */
.btn-primary {
  height: 40px; padding: 0 20px; background: var(--primary);
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: #ffffff; 
  cursor: pointer; transition: 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-sm); }
.btn-primary i { width: 18px; height: 18px; }

/* แถบเครื่องมือ Filter & Action */
.page-toolbar {
  display: flex; justify-content: space-between; align-items: center; 
  margin-bottom: 24px; flex-wrap: wrap; gap: 16px;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 12px; }

.filter-select {
  padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-main);
  font-size: 14px; font-family: inherit; outline: none; cursor: pointer;
}

/* ป้ายสถานะแบบใหม่ (Badges) */
.badge {
  padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
}
.badge-vip { background: #fef3c7; color: #d97706; }
.badge-company { background: #e0e7ff; color: #4338ca; }
.badge-general { background: #f1f5f9; color: #475569; }
body.dark .badge-vip { background: rgba(217, 119, 6, 0.2); color: #fbbf24; }
body.dark .badge-company { background: rgba(67, 56, 202, 0.2); color: #818cf8; }
body.dark .badge-general { background: #334155; color: #cbd5e1; }

/* ปุ่มจัดการในตาราง (Table Actions) */
.table-actions {
  display: flex; gap: 8px; align-items: center;
}
.btn-icon {
  width: 32px; height: 32px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text-muted); cursor: pointer; transition: 0.2s;
}
.btn-icon:hover { color: var(--text-main); background: var(--bg-body); }
.btn-icon.edit:hover { color: #2563eb; border-color: #bfdbfe; background: #eff6ff; }
.btn-icon.delete:hover { color: #dc2626; border-color: #fecaca; background: #fef2f2; }
body.dark .btn-icon.edit:hover { background: rgba(37,99,235,0.2); border-color: #3b82f6; }
body.dark .btn-icon.delete:hover { background: rgba(220,38,38,0.2); border-color: #ef4444; }

/* Pagination (แบ่งหน้าตาราง) */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 16px; border-top: 1px solid var(--border); margin-top: 16px;
}
.page-info { font-size: 13px; color: var(--text-muted); }
.page-controls { display: flex; gap: 8px; }
.btn-page {
  padding: 6px 12px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-main);
  border-radius: 6px; cursor: pointer; transition: 0.2s;
}
.btn-page:hover { background: var(--bg-body); }
.btn-page.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ========================================= */
/* MODAL & FORMS (ป๊อปอัปและฟอร์ม)             */
/* ========================================= */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 999; opacity: 0; pointer-events: none; transition: 0.3s;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-container {
  background: var(--bg-card); border-radius: 16px;
  width: 90%; max-width: 800px; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
  transform: translateY(20px); transition: 0.3s;
  border: 1px solid var(--border);
}
.modal-overlay.active .modal-container { transform: translateY(0); }

.modal-header {
  padding: 24px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-title { font-size: 18px; font-weight: 700; color: var(--text-main); }
.btn-close {
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
.btn-close:hover { background: var(--bg-body); color: var(--text-main); }

.modal-body { padding: 0; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 20px 24px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 12px; background: var(--bg-body);
  border-radius: 0 0 16px 16px;
}

/* Tabs ใน Modal */
.modal-tabs {
  display: flex; gap: 24px; padding: 0 24px; border-bottom: 1px solid var(--border);
  background: var(--bg-card); position: sticky; top: 0; z-index: 10;
}
.tab-btn {
  padding: 16px 0; background: transparent; border: none;
  font-size: 14px; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent; cursor: pointer; transition: 0.2s;
}
.tab-btn:hover { color: var(--text-main); }
.tab-btn.active { color: var(--primary); border-color: var(--primary); }

.tab-content { display: none; padding: 24px; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Forms */
.form-section-title { font-size: 15px; font-weight: 700; color: var(--text-main); margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.form-grid.col-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.col-1 { grid-template-columns: 1fr; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-main); }
.form-label span.req { color: #ef4444; }
.form-input, .form-select, .form-textarea {
  padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-body); color: var(--text-main);
  font-size: 14px; font-family: inherit; transition: 0.2s; outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-textarea { resize: vertical; min-height: 80px; }

/* Checkboxes / Radios */
.check-group { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 4px; }
.check-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-main); cursor: pointer; }
.check-label input[type="checkbox"], .check-label input[type="radio"] {
  width: 16px; height: 16px; accent-color: var(--primary);
}

/* ========================================= */
/* JOB PRODUCTION BOARD (ใบสั่งผลิต)          */
/* ========================================= */
.status-job { padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.status-job.new { background: #f1f5f9; color: #475569; }
.status-job.design { background: #e0e7ff; color: #4338ca; }
.status-job.printing { background: #fef3c7; color: #d97706; }
.status-job.qc { background: #ffedd5; color: #ea580c; }
.status-job.ready { background: #dcfce7; color: #16a34a; }

body.dark .status-job.new { background: #334155; color: #cbd5e1; }
body.dark .status-job.design { background: rgba(67, 56, 202, 0.2); color: #818cf8; }
body.dark .status-job.printing { background: rgba(217, 119, 6, 0.2); color: #fbbf24; }
body.dark .status-job.qc { background: rgba(234, 88, 12, 0.2); color: #fb923c; }
body.dark .status-job.ready { background: rgba(22, 163, 74, 0.2); color: #4ade80; }

.progress-bar-container { width: 100%; height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress-bar { height: 100%; border-radius: 4px; transition: width 0.3s; }
.progress-bar.design { background: #4338ca; }
.progress-bar.printing { background: #d97706; }
.progress-bar.qc { background: #ea580c; }
.progress-bar.ready { background: #16a34a; }

.priority-high { color: #dc2626; font-weight: 700; display: flex; align-items: center; gap: 4px; }
body.dark .priority-high { color: #f87171; }

/* พื้นที่ใส่เนื้อหา */
.content-body { flex: 1; padding: 24px; overflow-y: auto; }

/* สร้างการ์ดสวยสดใสตาม Tailwind ดีไซน์ */
.dashboard-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; margin-bottom: 24px; }
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow-sm); transition: 0.3s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card p { color: var(--text-muted); font-size: 14px; font-weight: 500; margin-bottom: 12px; }
.card h2 { font-size: 32px; font-weight: 700; color: var(--text-main); }
.card h3 { font-size: 18px; font-weight: 600; margin-bottom: 20px; color: var(--text-main); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 16px; font-size: 13px; color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
td { padding: 16px; font-size: 14px; border-bottom: 1px solid var(--border); color: var(--text-main); }
tr:last-child td { border-bottom: none; }
tr:hover { background: var(--bg-body); }

.status { padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.status-printing { background: #dbeafe; color: #2563eb; }
.status-pending { background: #ffedd5; color: #ea580c; }
.status-completed { background: #dcfce7; color: #16a34a; }
body.dark .status-printing { background: rgba(37,99,235,0.2); color: #60a5fa; }
body.dark .status-pending { background: rgba(234,88,12,0.2); color: #fb923c; }

