/* ===== MAX3D Theme ===== */

/* ฟอนต์ Sukhumvit Set (self-host) — วางไฟล์ฟอนต์จริงใน assets/fonts/sukhumvit/
   ถ้าไม่มีไฟล์ จะ fallback เป็น Noto Sans Thai อัตโนมัติ */
@font-face {
  font-family: 'Sukhumvit Set';
  src: url('../fonts/sukhumvit/SukhumvitSet-Text.woff2') format('woff2'),
       url('../fonts/sukhumvit/SukhumvitSet-Text.ttf') format('truetype');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Sukhumvit Set';
  src: url('../fonts/sukhumvit/SukhumvitSet-Medium.woff2') format('woff2'),
       url('../fonts/sukhumvit/SukhumvitSet-Medium.ttf') format('truetype');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: 'Sukhumvit Set';
  src: url('../fonts/sukhumvit/SukhumvitSet-SemiBold.woff2') format('woff2'),
       url('../fonts/sukhumvit/SukhumvitSet-SemiBold.ttf') format('truetype');
  font-weight: 600; font-display: swap;
}
@font-face {
  font-family: 'Sukhumvit Set';
  src: url('../fonts/sukhumvit/SukhumvitSet-Bold.woff2') format('woff2'),
       url('../fonts/sukhumvit/SukhumvitSet-Bold.ttf') format('truetype');
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: 'Noto Sans Thai';
  src: url('../fonts/NotoSansThai-Variable.ttf') format('truetype');
  font-weight: 100 900; font-display: swap;
}
/* Material Symbols — ไอคอนโมเดิร์นทั้งระบบ (self-host) */
@font-face {
  font-family: 'Material Symbols Outlined';
  font-style: normal;
  font-weight: 100 700;
  src: url('../fonts/material-symbols/material-symbols-outlined.woff2') format('woff2');
  font-display: block;
}
.ms {
  font-family: 'Material Symbols Outlined' !important;
  font-weight: normal; font-style: normal;
  font-size: 20px; line-height: 1;
  letter-spacing: normal; text-transform: none;
  display: inline-block; white-space: nowrap; word-wrap: normal;
  direction: ltr; vertical-align: middle;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  -webkit-font-smoothing: antialiased; user-select: none;
}
.ms.fill { font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24; }
.ms-sm { font-size: 16px; } .ms-lg { font-size: 26px; } .ms-xl { font-size: 34px; }

:root {
  --bg: #F4F6FA;
  --card: #ffffff;
  --text: #1e293b;
  --text-dim: #64748b;
  --border: #e2e8f0;
  --primary: #3B5BDB;
  --primary-dark: #2f4ab8;
  --primary-soft: #e8edfb;
  --sidebar-bg: #101532;
  --sidebar-text: #aab2d5;
  --sidebar-active: #3B5BDB;
  --shadow: 0 1px 3px rgba(16,21,50,.07), 0 4px 14px rgba(16,21,50,.05);
}
html.dark {
  --bg: #0f1420;
  --card: #1a2130;
  --text: #e2e8f0;
  --text-dim: #8b98b3;
  --border: #2b3550;
  --primary: #5c7cfa;
  --primary-dark: #4263eb;
  --primary-soft: #232f52;
  --sidebar-bg: #0b0f1d;
  --sidebar-text: #8b98b3;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

* { font-family: 'Sukhumvit Set', 'Noto Sans Thai', 'Leelawadee UI', Tahoma, sans-serif; }
body { background: var(--bg); color: var(--text); }

/* ---- Layout ---- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; background: var(--sidebar-bg); color: var(--sidebar-text);
  position: fixed; inset: 0 auto 0 0; z-index: 40; overflow-y: auto;
  transition: transform .2s ease;
}
.sidebar .nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 18px; margin: 2px 10px;
  border-radius: 10px; font-size: 14.5px; color: var(--sidebar-text); white-space: nowrap;
}
.sidebar .nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.sidebar .nav-group { padding: 16px 22px 5px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .55; }
.main-area { flex: 1; margin-left: 250px; min-width: 0; display: flex; flex-direction: column; }
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .main-area { margin-left: 0; }
}
.topbar {
  height: 60px; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 30;
}

/* ---- Page container: ทุกหน้าสมส่วนกัน ---- */
.page-wrap { max-width: 1440px; margin-inline: auto; width: 100%; }
.page-wrap.narrow { max-width: 880px; }
.page-wrap.mid { max-width: 1140px; }
@media (min-width: 1800px) { .page-wrap { max-width: 1600px; } }

/* ---- Density (ตั้งค่ารายบุคคล) ---- */
html.density-compact table.tbl th { padding: 7px 11px; }
html.density-compact table.tbl td { padding: 7px 11px; }
html.density-compact .card-pad { padding: 14px; }
html.density-compact .btn { padding: 6px 12px; font-size: 13.5px; }
html.density-compact main { padding: 16px !important; }

/* ---- EDC-style filter field: input พร้อมไอคอนซ้าย ---- */
.flt-field { position: relative; }
.flt-field .flt-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 17px; color: var(--text-dim); pointer-events: none;
}
.flt-field .input { padding-left: 34px; }

/* ---- Log viewer ---- */
.log-chip { display:inline-flex; align-items:center; gap:5px; padding:3px 10px; border-radius:99px; font-size:12px; font-weight:600; cursor:pointer; border:1.5px solid var(--border); background:var(--card); transition:all .12s; }
.log-chip.active, .log-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.avatar-sm { width:30px; height:30px; border-radius:99px; background:var(--primary-soft); color:var(--primary); display:inline-flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; flex-shrink:0; overflow:hidden; }
.avatar-sm img { width:100%; height:100%; object-fit:cover; }

/* ---- Floor editor ---- */
.fl-toolbar { display:flex; gap:6px; flex-wrap:wrap; align-items:center; }
.fl-tool { display:inline-flex; align-items:center; justify-content:center; width:38px; height:38px; border-radius:10px; border:1.5px solid var(--border); background:var(--card); cursor:pointer; color:var(--text); transition:all .12s; }
.fl-tool:hover { border-color: var(--primary); color: var(--primary); }
.fl-tool.active { background: var(--primary); color:#fff; border-color: var(--primary); }
#fl-svg { cursor: default; touch-action: none; }
#fl-svg.tool-pan { cursor: grab; }
#fl-svg.panning { cursor: grabbing; }
#fl-svg.tool-draw { cursor: crosshair; }
.fl-handle { fill:#fff; stroke:#3B5BDB; stroke-width:1.5; cursor:nwse-resize; }
.fl-selected-outline { fill:none; stroke:#3B5BDB; stroke-width:1.2; stroke-dasharray:5 4; pointer-events:none; }

/* ---- Components ---- */
.card { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-pad { padding: 20px; }
.page-title { font-size: 22px; font-weight: 700; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid transparent;
  transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { border-color: var(--border); color: var(--text); background: var(--card); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: #e03131; color: #fff; }
.btn-danger:hover { background: #c92a2a; }
.btn-success { background: #2f9e44; color: #fff; }
.btn-success:hover { background: #2b8a3e; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.input, select.input, textarea.input {
  width: 100%; padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--card); color: var(--text); font-size: 14px; outline: none; transition: border .15s;
}
.input:focus { border-color: var(--primary); }
.input.error { border-color: #e03131 !important; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text-dim); }
.err-msg { color: #e03131; font-size: 12px; margin-top: 3px; }

.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-gray   { background: #e9ecef; color: #495057; }
.badge-green  { background: #d3f9d8; color: #2b8a3e; }
.badge-blue   { background: #d0ebff; color: #1971c2; }
.badge-indigo { background: #dbe4ff; color: #3b5bdb; }
.badge-yellow { background: #fff3bf; color: #b08800; }
.badge-orange { background: #ffe8cc; color: #d9480f; }
.badge-red    { background: #ffe3e3; color: #c92a2a; }
.badge-purple { background: #eebefa33; color: #9c36b5; background: #f3d9fa; }
html.dark .badge-gray   { background: #343a46; color: #ced4da; }
html.dark .badge-green  { background: #14331c; color: #69db7c; }
html.dark .badge-blue   { background: #14293d; color: #4dabf7; }
html.dark .badge-indigo { background: #1a2350; color: #91a7ff; }
html.dark .badge-yellow { background: #3d3311; color: #ffd43b; }
html.dark .badge-orange { background: #3d2411; color: #ffa94d; }
html.dark .badge-red    { background: #3d1515; color: #ff8787; }
html.dark .badge-purple { background: #331a3d; color: #e599f7; }

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th { text-align: left; padding: 10px 14px; font-size: 12.5px; color: var(--text-dim); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--primary-soft); }
table.tbl tbody tr:last-child td { border-bottom: none; }

/* KPI card */
.kpi { display: flex; align-items: center; gap: 14px; padding: 18px; }
.kpi .kpi-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.kpi .kpi-num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi .kpi-label { font-size: 13px; color: var(--text-dim); }

/* Upload dropzone */
.dropzone {
  border: 2px dashed var(--border); border-radius: 14px; padding: 26px; text-align: center;
  color: var(--text-dim); cursor: pointer; transition: all .15s; background: var(--card);
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.file-chip { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; background: var(--card); }

/* Timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item::before { content: ''; position: absolute; left: -22px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2.5px solid var(--card); }

/* Machine card บน monitor */
.machine-card {
  position: absolute; width: 190px; border-radius: 14px; background: var(--card);
  box-shadow: var(--shadow); border: 2px solid var(--border); padding: 12px; cursor: pointer;
  transition: transform .15s;
}
.machine-card:hover { transform: scale(1.04); z-index: 5; }
.machine-card.st-idle { border-color: #2f9e44; }
.machine-card.st-printing { border-color: #1971c2; }
.machine-card.st-maintenance { border-color: #f59f00; }
.machine-card.st-error { border-color: #e03131; animation: blink 1s infinite; }
.machine-card.st-offline { opacity: .55; }
@keyframes blink { 50% { box-shadow: 0 0 0 5px rgba(224,49,49,.25); } }
.progress-bar { height: 7px; border-radius: 99px; background: var(--border); overflow: hidden; }
.progress-bar > div { height: 100%; border-radius: 99px; background: var(--primary); transition: width .5s; }

/* Kanban */
.kanban-col { min-width: 270px; width: 270px; flex-shrink: 0; }

/* flatpickr ปรับธีม */
.flatpickr-calendar { font-family: 'Sukhumvit Set', 'Noto Sans Thai', sans-serif !important; }
html.dark .flatpickr-calendar { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
html.dark .flatpickr-day { color: var(--text); }
html.dark .flatpickr-day.selected { background: var(--primary); border-color: var(--primary); }
html.dark .flatpickr-months, html.dark .flatpickr-weekdays { color: var(--text); }

/* print */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
}

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10,14,30,.55); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--card); border-radius: 16px; max-width: 640px; width: 100%; max-height: 92vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
