/* CK Daily Admin — desktop-first, responsive down to 360px */
:root {
  --bg: #f3f4f6; --surface: #ffffff; --text: #111827; --text-muted: #6b7280;
  --primary: #f97316; --primary-dark: #ea580c; --danger: #dc2626; --warning: #d97706; --info: #2563eb;
  --border: #e5e7eb; --radius: 12px; --shadow: 0 2px 10px rgba(0,0,0,.06); --sidebar-w: 240px;
}
:root[data-theme="dark"] { --bg: #0d0e11; --surface: #17181c; --text: #f2f2f5; --text-muted: #9aa0a6; --border: #2a2b31; --shadow: 0 2px 10px rgba(0,0,0,.5); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #0d0e11; --surface: #17181c; --text: #f2f2f5; --text-muted: #9aa0a6; --border: #2a2b31; } }

* { box-sizing: border-box; }
body { margin: 0; font-family: 'Sarabun', -apple-system, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }

.admin-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); flex: none; padding: 16px 0; position: fixed; top: 0; bottom: 0; overflow-y: auto; z-index: 50; transition: transform .2s; }
.sidebar .brand { padding: 10px 20px 20px; }
.sidebar .brand b { font-size: 16px; display: block; }
.sidebar .brand span { font-size: 11px; color: var(--text-muted); }
.sidebar .nav-item { display: flex; align-items: center; gap: 10px; padding: 11px 20px; font-size: 14px; color: var(--text-muted); cursor: pointer; border-left: 3px solid transparent; }
.sidebar .nav-item:hover { background: var(--bg); }
.sidebar .nav-item.active { color: var(--primary); border-left-color: var(--primary); background: var(--bg); font-weight: 600; }
.sidebar .nav-section { font-size: 11px; text-transform: uppercase; color: var(--text-muted); padding: 14px 20px 4px; letter-spacing: .04em; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 40; background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar h1 { font-size: 18px; margin: 0; }
.icon-btn-topbar { width: 38px; height: 38px; border-radius: 50%; background: var(--bg); color: var(--primary); display: flex; align-items: center; justify-content: center; flex: none; }
.hamburger { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text); }
.content { padding: 20px; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 20px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .hamburger { display: block; }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 45; display: none; }
  .sidebar-backdrop.show { display: block; }
}

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi-card .label { font-size: 12px; color: var(--text-muted); }
.kpi-card .value { font-size: 24px; font-weight: 800; margin-top: 4px; }
.kpi-card .sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 24px; }
.card canvas { display: block; margin: 0 auto; }
.card h3 { margin: 0 0 14px; font-size: 15px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }

.filters-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters-row .form-control, .filters-row select { width: auto; min-width: 130px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; }
.table-wrap { overflow-x: auto; }
tr:hover td { background: var(--bg); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: 9px; padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer; min-height: 36px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-approve { background: #d1fae5; color: #065f46; }
.btn-approve:hover { background: #a7f3d0; }
.btn-reject { background: #fee2e2; color: #991b1b; }
.btn-reject:hover { background: #fecaca; }
.btn-sm { padding: 6px 10px; font-size: 12px; min-height: 30px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.form-control { width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

.chip { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 700; display: inline-block; }
.chip.pending { background: #fef3c7; color: #92400e; }
.chip.in_progress { background: #dbeafe; color: #1e40af; }
.chip.completed { background: #d1fae5; color: #065f46; }
.chip.cancelled { background: #fee2e2; color: #991b1b; }
.chip.ok, .chip.active, .chip.paid, .chip.approved { background: #d1fae5; color: #065f46; }
.chip.low, .chip.pending_verify { background: #fef3c7; color: #92400e; }
.chip.out, .chip.unpaid, .chip.suspended, .chip.rejected { background: #fee2e2; color: #991b1b; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal h3 { margin-top: 0; }
.modal-close { float: right; background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }

.kanban-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; }
.kanban-col { flex: none; width: 250px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.kanban-col h4 { font-size: 13px; margin: 4px 6px 10px; display: flex; justify-content: space-between; }
.kanban-card { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 12px; cursor: grab; }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: .4; }
.kanban-col.dragover { outline: 2px dashed var(--primary); }

.tabs-row { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; cursor: pointer; }
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--primary); }

.loading-center { text-align: center; padding: 50px; color: var(--text-muted); }
.empty-state { text-align: center; padding: 40px; color: var(--text-muted); }
.badge-count { background: var(--danger); color: #fff; font-size: 10px; border-radius: 999px; padding: 1px 6px; margin-left: 6px; }

.checkbox-cell { width: 20px; }
.color-swatch { width: 26px; height: 26px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; box-shadow: 0 0 0 1px var(--border) inset; }
.color-swatch.selected { border-color: #111; }
.production-list { list-style: none; padding: 0; margin: 0; }
.production-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }

.print-only { display: none; }
#printScopeContainer { display: none; }

.print-doc-header { color: #000; }
.print-doc-head-row { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.print-doc-logo { width: 44px; height: 44px; border-radius: 10px; }
.print-doc-brand { line-height: 1.3; }
.print-doc-brand b { font-size: 17px; }
.print-doc-brand span { display: block; font-size: 11px; color: #555; }
.print-doc-title { font-size: 20px; margin: 10px 0 4px; }
.print-doc-meta { font-size: 12px; color: #333; margin-bottom: 6px; }
.print-doc-rule { border: none; border-top: 2px solid #111; margin: 10px 0 16px; }
.print-doc-footer { display: none; font-size: 11px; color: #333; }

@media print {
  /* พิมพ์เฉพาะเนื้อหาที่ UI.printWithHeader โคลนมาใส่ #printScopeContainer เท่านั้น ไม่พิมพ์ส่วนอื่นของหน้า */
  body > *:not(#printScopeContainer) { display: none !important; }
  body { background: #fff; }
  #printScopeContainer { display: block !important; padding: 0 20px; }
  .print-doc-footer { display: block; position: fixed; bottom: 8mm; left: 12mm; }
}
