/* ==========================================================================
   ManuLink — Smart Manufacturing Design System (Light Theme)
   ธีม Industry 4.0 โทนสว่าง: พื้นขาว + กริด blueprint + accent ฟ้า cyan
   ========================================================================== */

:root {
    /* โทนมืออาชีพ: navy / steel blue — น่าเชื่อถือ ไม่ฉูดฉาด */
    --mfg-bg: #f5f7fa;
    --mfg-surface: rgba(255, 255, 255, 0.92);
    --mfg-surface-solid: #ffffff;
    --mfg-border: rgba(30, 41, 59, 0.11);
    --mfg-border-accent: rgba(44, 82, 130, 0.32);
    --mfg-cyan: #2c5282;        /* accent หลัก (steel blue) */
    --mfg-cyan-deep: #1e3a5f;   /* navy เข้ม */
    --mfg-blue: #2b4c7e;
    --mfg-violet: #4a5568;      /* เดิมม่วง → เปลี่ยนเป็น slate เทาน้ำเงิน */
    --mfg-emerald: #2f855a;
    --mfg-amber: #b7791f;
    --mfg-rose: #c53030;
    --mfg-text: #1a2433;
    --mfg-muted: #5f6b7a;
    --mfg-font-head: 'Chakra Petch', 'Prompt', sans-serif;
    --mfg-font-body: 'Prompt', sans-serif;
}

/* ---------- พื้นหลังหลัก: ขาวสะอาด + ไล่แสงจางๆ + เส้นกริดแบบ blueprint ---------- */
html { scroll-behavior: smooth; }

body {
    font-family: var(--mfg-font-body);
    color: var(--mfg-text);
    background:
        radial-gradient(1100px 560px at 8% -10%, rgba(44, 82, 130, 0.07), transparent 60%),
        radial-gradient(900px 520px at 95% 115%, rgba(74, 85, 104, 0.05), transparent 60%),
        var(--mfg-bg);
    background-attachment: fixed;
    min-height: 100vh;
    overflow-x: hidden; /* กัน scrollbar แนวนอนจาก hero แบบ full-bleed (100vw) */
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(15, 23, 42, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(15, 23, 42, 0.04) 1px, transparent 1px);
    background-size: 44px 44px;
    z-index: -1;   /* กริดอยู่ใต้เนื้อหา โดยไม่ต้องให้ main สร้าง stacking context
                      (ถ้า main มี z-index จะทำให้ modal-backdrop ของ Bootstrap สลับชั้นเพี้ยน) */
}

:root { --content-pad: 1.5rem; }
@media (max-width: 575.98px) { :root { --content-pad: 1rem; } }
/* ไม่ใส่ z-index ที่ main แล้ว — กัน stacking context ทับซ้อนกับ modal/backdrop */
main.app-main { flex: 1 0 auto; padding: var(--content-pad); }

/* บังคับ backdrop ของ modal ให้มืดชัดเจน (กันกรณี opacity ถูก reset เป็น 0) */
.modal-backdrop.show { opacity: .5 !important; }

h1, h2, h3, h4, h5, .navbar-brand, .btn, .stat-value, .step-num {
    font-family: var(--mfg-font-head);
}

/* ---------- ตัวอักษรไล่สี / ป้ายหัวข้อ ---------- */
.text-grad {
    background: linear-gradient(90deg, var(--mfg-cyan-deep), var(--mfg-blue) 55%, var(--mfg-violet));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* ปรับ text-info ของ Bootstrap ให้เข้มพอสำหรับพื้นขาว (ใช้กับไอคอนทั่วระบบ) */
.text-info { color: var(--mfg-cyan-deep) !important; }

.section-chip {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-family: var(--mfg-font-head);
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: #1e3a5f;
    background: rgba(44, 82, 130, 0.08);
    border: 1px solid var(--mfg-border-accent);
    border-radius: 999px;
    padding: .35rem .9rem;
}

.section-title { font-weight: 700; margin-top: .6rem; }

/* ---------- Navbar ---------- */
.navbar-mfg {
    background: rgba(255, 255, 255, 0.85) !important;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(44, 82, 130, 0.18);
    box-shadow: 0 2px 16px rgba(15, 23, 42, 0.05);
}

.navbar-mfg .navbar-brand { color: var(--mfg-text); }
.navbar-mfg .nav-link { color: var(--mfg-muted); font-weight: 500; }
.navbar-mfg .nav-link:hover { color: var(--mfg-cyan-deep); }
.navbar-mfg .nav-link.text-warning { color: #8a5a1a !important; }
.navbar-mfg .nav-link.text-warning:hover { color: #6b4513 !important; }

.brand-badge {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--mfg-cyan), var(--mfg-blue));
    color: #ffffff;
    font-size: 1.15rem;
    box-shadow: 0 4px 14px rgba(44, 82, 130, 0.35);
}

/* ---------- Sidebar layout ---------- */
:root { --sidebar-w: 260px; --topbar-h: 56px; }

.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    z-index: 1045;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-right: 1px solid rgba(44, 82, 130, 0.18);
    box-shadow: 2px 0 18px rgba(15, 23, 42, 0.05);
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: .6rem;
    padding: 1rem 1.25rem;
    font-family: var(--mfg-font-head);
    font-size: 1.25rem; font-weight: 700;
    color: var(--mfg-text); text-decoration: none;
    border-bottom: 1px solid var(--mfg-border);
}
.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: .75rem .75rem 1.5rem; }
.sidebar-label {
    font-family: var(--mfg-font-head);
    font-size: .68rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase;
    color: var(--mfg-muted); padding: .9rem .75rem .35rem;
}
.sidebar-link {
    display: flex; align-items: center; gap: .7rem;
    padding: .6rem .75rem; margin-bottom: 2px;
    border-radius: 10px;
    color: #475569; text-decoration: none; font-weight: 500; font-size: .95rem;
    transition: background .15s, color .15s;
}
.sidebar-link i { font-size: 1.1rem; width: 20px; text-align: center; }
.sidebar-link:hover { background: rgba(44, 82, 130, 0.08); color: var(--mfg-cyan-deep); }
.sidebar-link.active {
    background: linear-gradient(135deg, rgba(44, 82, 130,.14), rgba(43, 76, 126,.12));
    color: var(--mfg-cyan-deep);
    box-shadow: inset 3px 0 0 var(--mfg-cyan);
}
.sidebar-link.admin { color: #8a5a1a; }
.sidebar-link.admin:hover, .sidebar-link.admin.active { color: #6b4513; background: rgba(183, 121, 31,.1); }
.sidebar-foot { border-top: 1px solid var(--mfg-border); padding: .75rem; }

/* topbar (มือถือ) — มีปุ่ม hamburger */
.topbar {
    position: sticky; top: 0; z-index: 1030;
    height: var(--topbar-h);
    display: none; align-items: center; gap: .6rem;
    padding: 0 1rem;
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--mfg-border);
}
.sidebar-toggle { background: none; border: 0; font-size: 1.5rem; color: var(--mfg-text); line-height: 1; }
.sidebar-backdrop {
    position: fixed; inset: 0; z-index: 1040;
    background: rgba(15,23,42,.4); opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

/* พื้นที่เนื้อหา — เว้นซ้ายให้ sidebar */
.content-area { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.content-area.full { margin-left: 0; }  /* หน้า public (ยังไม่ login) — ไม่มี sidebar */

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .content-area { margin-left: 0; }
    .topbar { display: flex; }
}

/* ---------- ปุ่ม (override Bootstrap ให้เป็นโทนโรงงานอัจฉริยะ) ---------- */
.btn { border-radius: 12px; font-weight: 600; letter-spacing: .02em; }

.btn-primary {
    background: linear-gradient(135deg, #2c5282, #2b4c7e);
    border: 0;
    box-shadow: 0 4px 18px rgba(44, 82, 130, 0.32);
}
.btn-primary:hover { background: linear-gradient(135deg, #1e3a5f, #233f6b); transform: translateY(-1px); }

.btn-success {
    background: linear-gradient(135deg, #2f855a, #276749);
    border: 0;
    box-shadow: 0 4px 18px rgba(47, 133, 90, 0.28);
}
.btn-success:hover { transform: translateY(-1px); }

.btn-warning { background: linear-gradient(135deg, #b7791f, #9c6215); border: 0; color: #fff; }
.btn-danger { background: linear-gradient(135deg, #c53030, #9b2c2c); border: 0; }
.btn-info {
    background: rgba(44, 82, 130, 0.1);
    border: 1px solid var(--mfg-border-accent);
    color: #1e3a5f;
}
.btn-info:hover { background: rgba(44, 82, 130, 0.18); color: #1a2f47; }

.btn-outline-secondary {
    border: 1px solid rgba(15, 23, 42, 0.2);
    color: #334155;
}
.btn-outline-secondary:hover { background: rgba(15, 23, 42, 0.05); color: var(--mfg-text); }

/* ปุ่มขอบขาว — ใช้เฉพาะบนพื้นมืด เช่น ใน hero */
.btn-outline-light { border: 1px solid rgba(255, 255, 255, 0.55); color: #f8fafc; }

/* ---------- การ์ด ---------- */
.card {
    background: var(--mfg-surface);
    border: 1px solid var(--mfg-border);
    border-radius: 18px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 30px rgba(15, 23, 42, 0.05);
}

.card .card-header {
    background: rgba(44, 82, 130, 0.06);
    border-bottom: 1px solid var(--mfg-border);
    font-family: var(--mfg-font-head);
}

.glass-hover { transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease; }
.glass-hover:hover {
    transform: translateY(-4px);
    border-color: var(--mfg-border-accent);
    box-shadow: 0 16px 44px rgba(44, 82, 130, 0.16);
}

/* มุม HUD แบบจอควบคุมเครื่องจักร */
.hud-corners { position: relative; }
.hud-corners::before, .hud-corners::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border: 0 solid var(--mfg-cyan);
    opacity: .75;
}
.hud-corners::before { top: 10px; left: 10px; border-top-width: 2px; border-left-width: 2px; }
.hud-corners::after { bottom: 10px; right: 10px; border-bottom-width: 2px; border-right-width: 2px; }

/* ---------- Hero (คงโทนมืดเป็นภาพโรงงาน ตัดกับพื้นขาว) ----------
   แบบ Full screen: กว้างเต็มจอ (ทะลุ container) สูงเต็ม viewport ลบความสูง navbar */
:root { --nav-h: 61px; }

.hero-mfg {
    position: relative;
    /* full-bleed ภายในพื้นที่เนื้อหา — ดันออกนอก padding ของ main ทั้งสองด้าน */
    width: calc(100% + 2 * var(--content-pad));
    margin-left: calc(-1 * var(--content-pad));
    margin-right: calc(-1 * var(--content-pad));
    margin-top: calc(-1 * var(--content-pad));
    min-height: calc(100vh - 2 * var(--content-pad));
    min-height: calc(100svh - 2 * var(--content-pad));
    overflow: hidden;
    border: 0;
    border-bottom: 1px solid rgba(44, 82, 130, 0.25);
    display: flex;
    align-items: center;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
}
@media (max-width: 991.98px) {
    .hero-mfg { min-height: calc(100vh - var(--topbar-h)); min-height: calc(100svh - var(--topbar-h)); }
}

.hero-mfg .hero-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.5) saturate(1.15);
}

.hero-mfg .hero-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg,
        rgba(6, 10, 19, 0.92) 20%,
        rgba(6, 10, 19, 0.6) 58%,
        rgba(91, 127, 166, 0.16) 100%);
}

/* ข้อความใน hero ต้องสว่างเสมอ (อยู่บนภาพมืด) */
.hero-mfg { color: #f1f5f9; }
.hero-mfg .text-secondary { color: #cbd5e1 !important; }
.hero-mfg .text-grad {
    background: linear-gradient(90deg, #5b7fa6, #6d8bb0 55%, #8592a6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.hero-mfg .section-chip {
    color: #9fb6cf;
    background: rgba(91, 127, 166, 0.1);
    border-color: rgba(91, 127, 166, 0.4);
}

/* เส้นสแกนกวาดลงแบบเซ็นเซอร์ */
.hero-mfg .hero-scanline {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(91, 127, 166, 0.55), transparent);
    animation: scan 7s linear infinite;
    opacity: .5;
}

@keyframes scan {
    0% { top: 0; }
    100% { top: 100%; }
}

.hero-content { position: relative; z-index: 2; padding: 4rem 0; }

.hero-title {
    font-size: clamp(2.1rem, 5.5vw, 4rem);
    font-weight: 700;
    line-height: 1.15;
}

/* ปุ่มเลื่อนลงด้านล่างของ hero */
.hero-scroll {
    position: absolute;
    left: 50%;
    bottom: 1.4rem;
    transform: translateX(-50%);
    z-index: 2;
    color: rgba(255, 255, 255, 0.75);
    font-size: 1.6rem;
    text-decoration: none;
    animation: bob 1.8s ease-in-out infinite;
}
.hero-scroll:hover { color: #5b7fa6; }

@keyframes bob {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(8px); }
}

/* ชิปคุณสมบัติลอยด้านขวาของ hero (บนภาพมืด) */
.telemetry-chip {
    display: flex;
    align-items: center;
    gap: .7rem;
    background: rgba(8, 14, 26, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 14px;
    padding: .7rem 1rem;
    color: #e2e8f0;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.telemetry-chip i { color: #5b7fa6; font-size: 1.2rem; }
.telemetry-chip small { color: #94a3b8; display: block; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; }

/* ---------- ไอคอนฟีเจอร์ ---------- */
.feature-icon {
    display: inline-grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    font-size: 1.5rem;
    background: rgba(44, 82, 130, 0.1);
    border: 1px solid var(--mfg-border-accent);
    color: var(--mfg-cyan-deep);
}
.feature-icon.violet { background: rgba(74, 85, 104, 0.08); border-color: rgba(74, 85, 104, 0.35); color: var(--mfg-violet); }
.feature-icon.emerald { background: rgba(5, 150, 105, 0.08); border-color: rgba(5, 150, 105, 0.35); color: var(--mfg-emerald); }

/* ---------- การ์ดขั้นตอน (timeline แนวนอน) ---------- */
.step-card {
    height: 100%;
    background: var(--mfg-surface);
    border: 1px solid var(--mfg-border);
    border-radius: 16px;
    padding: 1.25rem;
    position: relative;
    overflow: hidden;
    box-shadow: 0 6px 22px rgba(15, 23, 42, 0.05);
    transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease;
}
.step-card:hover {
    transform: translateY(-4px);
    border-color: var(--mfg-border-accent);
    box-shadow: 0 14px 36px rgba(44, 82, 130, 0.14);
}
.step-num {
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1;
    color: rgba(8, 145, 178, 0.25);
}
.step-card i { color: var(--mfg-cyan-deep); font-size: 1.35rem; }

/* ---------- ตาราง ---------- */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--mfg-text);
    border-color: var(--mfg-border);
}
.table thead th {
    font-family: var(--mfg-font-head);
    font-size: .8rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #1e3a5f;
    background: rgba(44, 82, 130, 0.07);
    border-bottom: 1px solid var(--mfg-border-accent) !important;
    white-space: nowrap;
}
.table tbody td { border-color: var(--mfg-border); vertical-align: middle; }
.table-hover tbody tr:hover { background: rgba(44, 82, 130, 0.045); }

/* ---------- ป้ายสถานะ + จุด pulse ---------- */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .35rem .8rem;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-status .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

.st-pending { background: rgba(183, 121, 31, 0.12); color: #8a5a1a; border: 1px solid rgba(183, 121, 31, 0.4); }
.st-pending .dot { background: #b7791f; animation: pulse-dot 1.6s ease-out infinite; }
.st-approved { background: rgba(47, 133, 90, 0.1); color: #047857; border: 1px solid rgba(47, 133, 90, 0.4); }
.st-approved .dot { background: #2f855a; }
.st-rejected { background: rgba(197, 48, 48, 0.08); color: #be123c; border: 1px solid rgba(197, 48, 48, 0.35); }
.st-rejected .dot { background: #c53030; }

@keyframes pulse-dot {
    0% { box-shadow: 0 0 0 0 rgba(183, 121, 31, 0.45); }
    75% { box-shadow: 0 0 0 7px rgba(183, 121, 31, 0); }
    100% { box-shadow: 0 0 0 0 rgba(183, 121, 31, 0); }
}

/* ---------- ตัวเลขสถิติ (คะแนนรวม) ---------- */
.stat-card { text-align: center; padding: 2rem 1.5rem; }
.stat-label {
    font-family: var(--mfg-font-head);
    letter-spacing: .18em;
    text-transform: uppercase;
    font-size: .75rem;
    color: var(--mfg-muted);
}
.stat-value {
    font-size: clamp(2.6rem, 6vw, 4rem);
    font-weight: 700;
    filter: drop-shadow(0 4px 14px rgba(44, 82, 130, 0.25));
}

/* ---------- ฟอร์ม ---------- */
.form-control, .form-select {
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.14);
    color: var(--mfg-text);
    border-radius: 12px;
    padding: .6rem .9rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--mfg-cyan);
    box-shadow: 0 0 0 .2rem rgba(44, 82, 130, 0.14);
    color: var(--mfg-text);
}
.form-control::placeholder { color: #94a3b8; }
.input-group-text {
    background: rgba(44, 82, 130, 0.08);
    border: 1px solid rgba(15, 23, 42, 0.14);
    color: var(--mfg-cyan-deep);
    border-radius: 12px 0 0 12px;
}
.form-check-input:checked { background-color: var(--mfg-cyan); border-color: var(--mfg-cyan); }

/* ---------- Alert / Flash ---------- */
.alert { border-radius: 14px; border-width: 1px; }

/* ---------- Modal ---------- */
.modal-content {
    background: var(--mfg-surface-solid);
    border: 1px solid var(--mfg-border-accent);
    border-radius: 18px;
}

/* ---------- Footer ---------- */
.footer-mfg {
    position: relative;
    z-index: 1;
    border-top: 1px solid rgba(44, 82, 130, 0.18);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    color: var(--mfg-muted);
    font-size: .85rem;
}
.footer-mfg .text-grad { font-weight: 600; }

/* ---------- Dashboard: stat tiles + bar chart ---------- */
.kpi-card {
    padding: 1.4rem 1.25rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: .3rem;
}
.kpi-icon {
    width: 42px; height: 42px;
    display: grid; place-items: center;
    border-radius: 12px;
    font-size: 1.3rem;
    background: rgba(44, 82, 130, 0.1);
    border: 1px solid var(--mfg-border-accent);
    color: var(--mfg-cyan-deep);
    margin-bottom: .4rem;
}
.kpi-value { font-family: var(--mfg-font-head); font-size: 2rem; font-weight: 700; line-height: 1; }
.kpi-label { color: var(--mfg-muted); font-size: .85rem; }

/* กราฟแท่งแนวนอนล้วน CSS */
.bar-row { display: flex; align-items: center; gap: .75rem; margin-bottom: .7rem; }
.bar-row .bar-label { flex: 0 0 88px; font-size: .85rem; color: var(--mfg-muted); text-align: right; }
.bar-track { flex: 1; height: 22px; background: rgba(15, 23, 42, 0.05); border-radius: 6px; overflow: hidden; }
.bar-fill {
    height: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--mfg-cyan), var(--mfg-blue));
    min-width: 2px;
    transition: width .6s ease;
}
.bar-fill.amber { background: linear-gradient(90deg, #d69e2e, #9c6215); }
.bar-fill.emerald { background: linear-gradient(90deg, #48a373, #276749); }
.bar-fill.rose { background: linear-gradient(90deg, #d16060, #9b2c2c); }
.bar-row .bar-num { flex: 0 0 42px; font-weight: 600; font-size: .85rem; }

/* ---------- อนิเมชันเข้า ---------- */
/* ใช้ fill-mode: backwards + base state = สถานะสุดท้าย (transform:none)
   เพื่อให้หลัง animation จบ element revert เป็น transform:none จริงๆ
   (ถ้าใช้ forwards จะค้าง identity matrix ไว้ → สร้าง containing block ทำให้
    modal ที่ position:fixed ข้างในเพี้ยน/ไม่เต็มจอ) */
.fade-up { opacity: 1; transform: none; animation: fadeUp .6s ease backwards; }
.fade-up.d1 { animation-delay: .08s; }
.fade-up.d2 { animation-delay: .16s; }
.fade-up.d3 { animation-delay: .24s; }
.fade-up.d4 { animation-delay: .32s; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
}

@media (prefers-reduced-motion: reduce) {
    .fade-up { animation: none; opacity: 1; transform: none; }
    .hero-mfg .hero-scanline { animation: none; display: none; }
    .st-pending .dot { animation: none; }
    .hero-scroll { animation: none; }
}
