@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;500;600;700&display=swap');

:root {
    --bg-page: #f3f5f8;
    --card-bg: #ffffff;
    --subcard-bg: #f8f9fb;
    --border-light: #eceef2;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --brand-primary: #10b981;
    --brand-emerald: #10b981;
    --brand-orange: #10b981;
    --brand-amber: #f59e0b;
    --brand-green: #22c55e;
}

html, body {
    font-family: 'Noto Sans Thai', sans-serif;
    background-color: var(--bg-page);
    color: var(--text-primary);
    height: 100%;
    margin: 0;
}

/* การ์ดหลักสีขาวคลีน ขอบมน สไตล์ Vigillix */
.vx-card {
    background: var(--card-bg);
    border-radius: 22px;
    border: 1px solid var(--border-light);
    box-shadow: 0 4px 20px -6px rgba(17, 24, 39, 0.04);
}

/* การ์ดย่อยสีเทาอ่อนคลีน */
.vx-subcard {
    background: var(--subcard-bg);
    border-radius: 14px;
    border: 1px solid #eef0f4;
    transition: all 0.2s ease;
}

.vx-subcard:hover {
    border-color: #e2e6ee;
    background: #f4f6f9;
}

/* แถบเมนูตรงกลางด้านบน (Segmented Pill Nav) */
.vx-nav-shell {
    background: #eceef2;
    padding: 4px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.vx-nav-item {
    padding: 6px 15px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 500;
    color: #6b7280;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.vx-nav-item:hover {
    color: #111827;
}

.vx-nav-item.active {
    background: #ffffff;
    color: #111827;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(17, 24, 39, 0.06);
}

/* ปุ่มกระจกใสและป้ายสถานะบนจอภาพกล้อง (Dark Frosted Glass เหมือนการ์ดตอนขยาย มองเห็นชัดแม้ภาพสว่าง) */
.vx-glass-pill {
    background: rgba(22, 27, 34, 0.78);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: all 0.2s ease;
}

.vx-glass-pill:hover {
    background: rgba(30, 38, 48, 0.88);
    border-color: rgba(255, 255, 255, 0.25);
}

.vx-glass-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: rgba(22, 27, 34, 0.78);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: all 0.2s ease;
}

.vx-glass-btn:hover {
    background: rgba(30, 38, 48, 0.88);
}

/* กล่อง Live Camera Info มุมซ้ายล่างของภาพ (Dark Frosted Glass โทนสีเดียวกัน) */
.vx-cam-info {
    background: rgba(22, 27, 34, 0.78);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 16px;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Scrollbar แบบบางเรียบหรู สำหรับรายการคลาสบนจอกล้อง */
.vx-cam-scroll::-webkit-scrollbar {
    width: 3px;
}
.vx-cam-scroll::-webkit-scrollbar-track {
    background: transparent;
}
.vx-cam-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.28);
    border-radius: 9999px;
}
.vx-cam-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Scrollbar เรียบหรูสำหรับ Light Theme (เลื่อนดูรายการคลาสที่ส่งมาไม่จำกัด) */
.vx-light-scroll::-webkit-scrollbar {
    width: 4px;
}
.vx-light-scroll::-webkit-scrollbar-track {
    background: transparent;
}
.vx-light-scroll::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 9999px;
}
.vx-light-scroll::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Sidebar ด้านซ้าย ย่อ-ขยายได้ */
#app-sidebar {
    transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1), padding 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

#app-sidebar.collapsed {
    width: 68px !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
}

#app-sidebar.collapsed .sidebar-text {
    display: none !important;
}

#app-sidebar.collapsed .sidebar-item {
    justify-content: center !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

#app-sidebar.collapsed .sidebar-brand {
    justify-content: center !important;
}

#card-camera.cam-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 100;
    width: 100vw;
    height: 100vh;
    border: 0;
    border-radius: 0;
}

/* โครงร่างกำลังโหลด (skeleton loader) ดู public/js/skeleton.js */
.sk-bar {
    display: block;
    height: 10px;
    max-width: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, #eceef2 25%, #f7f8fa 37%, #eceef2 63%);
    background-size: 400% 100%;
    animation: sk-shimmer 1.4s ease-in-out infinite;
}
.sk-row td { border: 0; }
.sk-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid #eef0f4;
    background: var(--subcard-bg);
}
.sk-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 0;
}
.sk-fill { width: 100%; height: auto !important; flex: 1; min-height: 120px; border-radius: 14px; }
@keyframes sk-shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}
@media (prefers-reduced-motion: reduce) {
    .sk-bar { animation: none; }
}

/* โครงร่างทั้งหน้า ทับเนื้อหาระหว่างเปิดหน้า/สลับเมนู */
#page-skeleton {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--bg-page);
    opacity: 1;
    transition: opacity 0.2s ease;
    overflow: hidden;
}
#page-skeleton.hidden { display: none; }
#page-skeleton.sk-page-out { opacity: 0; pointer-events: none; }
@media (min-width: 1024px) {
    #page-skeleton { flex-direction: row; }
}
.sk-page-card { display: flex; flex-direction: column; gap: 10px; padding: 16px; min-height: 0; }
.sk-page-col { display: flex; flex-direction: column; gap: 14px; min-height: 0; min-width: 0; }
.sk-page-split { display: flex; gap: 14px; min-height: 0; }
.sk-page-rows { display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }
.sk-page-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; }
.sk-page-nav { flex-shrink: 0; }
.sk-page-nav-item { padding: 8px 4px; }
.sk-grow { flex: 1; }
.sk-flex-1 { flex: 1 1 0; }
.sk-w-8 { flex: 8 1 0; }
.sk-w-7 { flex: 7 1 0; }
.sk-w-5 { flex: 5 1 0; }
.sk-w-4 { flex: 4 1 0; }
@media (min-width: 1024px) {
    .sk-page-nav { width: 220px; }
}
@media (max-width: 1023px) {
    .sk-page-split { flex-direction: column; }
    .sk-page-col, .sk-page-card { flex: none; }
    .sk-fill { min-height: 80px; }
}

/* ===== จอแท็บเล็ต / มือถือแนวนอน =====
   >= 1280 x 600 : แบบเดิมของจอคอม (พอดีหนึ่งจอ ไม่เลื่อน)
   1024–1279     : iPad แนวนอน · แถบเมนูย่อเป็นไอคอนเอง ช่องว่างแคบลง ยังพอดีหนึ่งจอ
   640–1023      : มือถือแนวนอน / iPad แนวตั้ง · การ์ดเรียงลงล่าง เลื่อนหน้าขึ้นลงได้
   < 640 กว้าง หรือ < 360 สูง : มือถือแนวตั้ง -> หน้าแจ้งให้หมุนจอ (#screen-gate) */
@media (max-width: 1279px) {
    #app-sidebar {
        width: 68px !important;
        padding-left: 10px !important;
        padding-right: 10px !important;
    }
    #app-sidebar .sidebar-text { display: none !important; }
    #app-sidebar .sidebar-item { justify-content: center !important; padding-left: 0 !important; padding-right: 0 !important; }
    #app-sidebar .sidebar-brand { justify-content: center !important; }
    #sidebar-toggle-btn { display: none !important; }               /* ย่ออยู่แล้ว ปุ่มย่อ-ขยายไม่มีผล */
    #slot-dash-system { width: 220px !important; }
    #slot-dash-sensor { width: 172px !important; }
    #slot-dash-camera { width: calc(220px + 172px + 0.875rem) !important; }
}
@media (max-width: 1023px) {
    body { padding: 8px !important; }
    /* กรอบหน้าไม่ล็อกความสูงเท่าจอแล้ว ให้สูงตามเนื้อหาแล้วเลื่อนทั้งหน้า · แถบเมนูติดขอบบนตอนเลื่อน */
    body > div.max-w-\[1800px\] { height: auto !important; flex: none !important; align-items: flex-start; gap: 8px !important; }
    body > div.max-w-\[1800px\] > main { height: auto !important; }
    #app-sidebar { position: sticky; top: 8px; height: calc(100vh - 16px) !important; }
    #view-dashboard { height: auto !important; gap: 10px !important; flex: none !important; }
    #view-dashboard > div { height: auto !important; min-height: 0 !important; }
    #view-dashboard .flex-\[53\] { flex: none !important; flex-wrap: wrap; min-height: 0 !important; gap: 10px !important; }
    #view-dashboard .flex-\[47\] { flex: none !important; flex-direction: column !important; gap: 10px !important; }
    #slot-dash-system, #slot-dash-sensor { width: calc(50% - 5px) !important; height: auto !important; }
    #slot-dash-class { flex: 1 1 100% !important; height: auto !important; min-height: 230px; }
    #slot-dash-camera { width: 100% !important; height: auto !important; aspect-ratio: 16 / 9; max-height: 80vh; }
    #slot-dash-summary { height: auto !important; }
    #slot-dash-summary > .grid { min-height: 260px; }
    #slot-dash-edit, #card-sack-edit { height: auto !important; overflow: visible !important; }
    /* หน้าจัดการล็อต: กราฟต้องมีความสูงของตัวเอง ไม่งั้นถูกบีบจนแบน */
    #slot-sacks-chart { flex: none !important; }
    #panel-chart-view { flex: none !important; height: 240px; }
}

/* ดักขนาดจอ: จอแคบกว่า 640 หรือเตี้ยกว่า 360 (มือถือแนวตั้ง) เห็นหน้าแจ้งให้หมุนจอแทนหน้าเว็บ
   แก้ขนาดขั้นต่ำต้องแก้ตัวเลขใน media query นี้ และข้อความใน #screen-gate ของ index.html กับ login.html ให้ตรงกัน */
#screen-gate { display: none; }
@media (max-width: 639px), (max-height: 359px) {
    #screen-gate {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 2147483647;
        align-items: center;
        justify-content: center;
        padding: 24px;
        background: var(--bg-page);
        overflow-y: auto;
    }
    body:has(#screen-gate) { overflow: hidden !important; }
    /* ซ่อนแบบไม่กินพื้นที่ ไม่งั้นมือถือจะย่อหน้าตามความกว้างของแดชบอร์ดจนกล่องแจ้งเตือนหลุดจอ */
    body:has(#screen-gate) > :not(#screen-gate) { display: none !important; }
}
.screen-gate-box {
    max-width: 420px;
    margin: auto;
    text-align: center;
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: 22px;
    padding: 28px 24px;
    box-shadow: 0 4px 20px -6px rgba(17, 24, 39, 0.08);
}
.screen-gate-box img { width: 48px; height: 48px; margin: 0 auto 12px; display: block; }
.screen-gate-box h1 { font-size: 18px; font-weight: 700; margin: 0 0 8px; color: var(--text-primary); }
.screen-gate-box p { font-size: 13px; line-height: 1.6; margin: 0 0 8px; color: var(--text-secondary); }
.screen-gate-box .screen-gate-now {
    display: inline-block;
    margin: 4px 0 12px;
    padding: 4px 12px;
    border-radius: 999px;
    background: #fff1f2;
    border: 1px solid #fecdd3;
    color: #be123c;
    font-size: 12px;
    font-weight: 600;
}
.screen-gate-box .screen-gate-hint { font-size: 12px; color: #9ca3af; margin: 0; }

/* ===== หน้าสถานีอากาศ: ปุ่มแบ่งช่อง (segmented) ===== */
.wx-seg {
    padding: 5px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    color: #71717a;
    white-space: nowrap;
    transition: background-color .15s, color .15s;
}
.wx-seg:hover { color: #27272a; }
.wx-seg[aria-selected="true"] {
    background: #fff;
    color: #047857;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

/* ===== หน้าสถานีอากาศ: แผนที่ ===== */
#wx-map { background: #e5e7eb; }
.leaflet-container img { max-width: none !important; max-height: none !important; }   /* กัน Tailwind บีบรูปแผนที่ */
.leaflet-container { font-family: inherit; }
.wx-glass {
    background: rgba(255, 255, 255, .86);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, .7);
    border-radius: 14px;
    box-shadow: 0 6px 24px rgba(15, 23, 42, .14);
}
.wx-farm {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 8px; border-radius: 10px; text-align: left; width: 100%;
    border: 1px solid transparent; transition: background-color .15s, border-color .15s;
}
.wx-farm:hover { background: rgba(244, 244, 245, .9); }
.wx-farm[aria-selected="true"] { background: #fff; border-color: #a7f3d0; box-shadow: 0 1px 3px rgba(0, 0, 0, .06); }

/* หมุดไร่ */
.wx-pin { position: relative; width: 44px; height: 44px; }
.wx-pin-dot {
    position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; transform: translate(-50%, -50%);
    border-radius: 50%; border: 3px solid #fff; display: flex; align-items: center; justify-content: center;
    color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); transition: transform .2s;
}
.wx-pin-dot svg { width: 15px; height: 15px; }
.wx-pin.is-selected .wx-pin-dot { transform: translate(-50%, -50%) scale(1.22); }
.wx-pin.is-selected::after {
    content: ''; position: absolute; inset: -6px; border-radius: 50%;
    border: 2px solid #fff; box-shadow: 0 0 0 2px rgba(15, 23, 42, .25);
}
.wx-pin-ring {
    position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px;
    border-radius: 50%; animation: wx-pulse 2s ease-out infinite;
}
.wx-online .wx-pin-dot { background: #10b981; }
.wx-online .wx-pin-ring { background: rgba(16, 185, 129, .55); }
.wx-partial .wx-pin-dot { background: #f59e0b; }
.wx-partial .wx-pin-ring { background: rgba(245, 158, 11, .5); }
.wx-offline .wx-pin-dot { background: #f43f5e; }
.wx-offline .wx-pin-ring { display: none; }
@keyframes wx-pulse {
    0% { transform: scale(1); opacity: .9; }
    100% { transform: scale(2.6); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .wx-pin-ring { animation: none; opacity: 0; } }

/* หมุด Gateway */
.wx-gw {
    width: 30px; height: 30px; border-radius: 9px; background: #6366f1; color: #fff; border: 3px solid #fff;
    display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
.wx-gw svg { width: 15px; height: 15px; }

/* ป้ายชื่อใต้หมุด */
.leaflet-tooltip.wx-label {
    background: rgba(255, 255, 255, .95); border: 0; border-radius: 9px; padding: 3px 8px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .25); color: #18181b; font-size: 11px; font-weight: 700; line-height: 1.35;
    text-align: center;
}
.leaflet-tooltip.wx-label::before { display: none; }
.leaflet-tooltip.wx-label .wx-label-sub { display: block; font-size: 10px; font-weight: 600; color: #71717a; }

/* ===== Weather station: device cards + device window ===== */
.wx-node-card { transition: border-color .15s, box-shadow .15s, transform .15s; cursor: pointer; }
.wx-node-card:hover { border-color: #a7f3d0; box-shadow: 0 4px 14px rgba(16, 185, 129, .12); }
.wx-node-card:focus-visible { outline: 2px solid #10b981; outline-offset: 2px; }
.wx-node-more { opacity: .55; transition: opacity .15s; }
.wx-node-card:hover .wx-node-more { opacity: 1; }
.wxd-flash { animation: wxd-flash 1.2s ease-out; }
@keyframes wxd-flash {
    0% { background-color: #d1fae5; }
    100% { background-color: transparent; }
}
@media (prefers-reduced-motion: reduce) { .wxd-flash { animation: none; } }

/* ===== Sidebar: collapsible system groups ===== */
.nav-group-items { display: block; }
.nav-group.is-closed .nav-group-items { display: none; }
.nav-group-chevron { transition: transform .2s; }
.nav-group.is-closed .nav-group-chevron { transform: rotate(-90deg); }
.nav-group-divider { display: none; }
/* collapsed sidebar (icons only): group header becomes a thin divider, items always visible */
#app-sidebar.collapsed .nav-group-toggle { display: none; }
#app-sidebar.collapsed .nav-group-divider { display: block; height: 1px; background: #eceef2; margin: 4px 6px; }
#app-sidebar.collapsed .nav-group:first-child .nav-group-divider { display: none; }
#app-sidebar.collapsed .nav-group.is-closed .nav-group-items { display: block; }
