/* ==========================================================================
   css/map.css - Enterprise GPS Fleet Tracker (Clean Architecture - Master)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Prompt:wght@300;400;500;600&display=swap');

:root {
    --bg-glass: rgba(15, 23, 42, 0.88);
    --bg-card: rgba(30, 41, 59, 0.75);
    --border-glass: rgba(255, 255, 255, 0.12);
    --accent-blue: #38bdf8;
    --accent-emerald: #10b981;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --radius-main: 16px;
    --console-width: 360px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Prompt', 'Inter', -apple-system, sans-serif;
    background-color: #0f172a;
    color: var(--text-main);
}

/* ================= 1. MAP CONTAINER ================= */
#map-container {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    will-change: width;
    transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* แผนที่จะหดความกว้างลง "เฉพาะตอนที่ตรึงและแผงเปิ7ดอยู่เท่านั้น" */
body.sidebar-pinned:not(.sidebar-collapsed) #map-container {
    width: calc(100% - var(--console-width));
}

/* ================= 2. FLOATING EXPAND BUTTON (ปุ่มลอยกลม) ================= */
.floating-expand-btn {
    position: fixed;
    top: max(20px, env(safe-area-inset-top, 20px));
    right: max(20px, env(safe-area-inset-right, 20px));
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5), 0 0 15px rgba(56, 189, 248, 0.3);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9999;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.floating-expand-btn:active {
    transform: scale(0.92);
}

body.sidebar-collapsed .floating-expand-btn {
    display: flex !important;
}

/* ================= 3. RIGHT CONSOLE (แผงควบคุมฝั่งขวา) ================= */
.right-console {
    position: absolute;
    top: 16px;
    right: 16px;
    bottom: 16px;
    width: var(--console-width);
    max-width: calc(100vw - 32px);
    z-index: 25;
    display: flex;
    flex-direction: column;
    pointer-events: none;
    will-change: transform, opacity;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.25s ease,
                top 0.25s ease,
                right 0.25s ease,
                bottom 0.25s ease;
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

/* เมื่อกด "ตรึงขอบ" (Pinned Mode): ชิดขอบบน-ล่าง-ขวา */
body.sidebar-pinned .right-console {
    top: 0;
    right: 0;
    bottom: 0;
    border-radius: 0;
}

body.sidebar-pinned .sidebar-top-bar {
    border-radius: 0;
    margin-bottom: 8px;
}

/* เมื่อกด "ซ่อน" (Collapsed): ดีดหลุดจอ 100% */
/* เมื่ออยู่ในโหมดซ่อน (Collapsed Mode): ปิดการแสดงผล 100% เด็ดขาด */
body.sidebar-collapsed .right-console {
    display: none !important;
    transform: translateX(100vw) !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* แถบเครื่องมือหัวแผง */
.sidebar-top-bar {
    pointer-events: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-main);
    padding: 8px 14px;
    margin-bottom: 10px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.action-icon-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px 12px;
    color: var(--text-main);
    font-size: 11px;
    font-family: inherit;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
}

.action-icon-btn:hover {
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.4);
    color: var(--accent-blue);
}

/* พื้นที่เลื่อนเนื้อหาภายในการ์ด */
.console-scroll-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 2px;
}

.console-scroll-content::-webkit-scrollbar { width: 3px; }
.console-scroll-content::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 3px; }

.console-card {
    pointer-events: auto;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-main);
    padding: 14px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

/* ================= 4. UI COMPONENTS ================= */
.hud-status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.hud-status-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.speed-badge {
    font-family: 'Inter', sans-serif;
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-blue);
}

.speed-badge small {
    font-size: 10px;
    color: var(--text-muted);
}

.hud-details-row {
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.coord-text {
    font-family: 'Inter', monospace;
    font-size: 11px;
    color: var(--text-muted);
}

.device-name-tag {
    font-size: 12px;
    color: var(--accent-blue);
    margin-top: 4px;
    cursor: pointer;
    text-decoration: underline dotted;
}

.hud-actions-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.hud-action-btn {
    padding: 8px 4px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: #f1f5f9;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    transition: 0.2s;
    white-space: nowrap;
}

.hud-action-btn:hover {
    background: rgba(56, 189, 248, 0.18);
    border-color: rgba(56, 189, 248, 0.4);
    color: var(--accent-blue);
}

.badge-pill {
    background: #0284c7;
    color: #fff;
    padding: 1px 5px;
    border-radius: 999px;
    font-size: 9px;
}

/* Playback Card */
.playback-card {
    border-color: rgba(56, 189, 248, 0.3);
    background: rgba(15, 23, 42, 0.95);
}

.playback-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.playback-stat-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.playback-stat-badge {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 8px;
    border-radius: 6px;
    font-family: 'Inter', monospace;
    font-size: 11px;
    font-weight: 600;
}

.playback-slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-play-sm {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #0284c7, #0ea5e9);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close-sm {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}

/* Modals & Pins */
.map-marker-label {
    background: rgba(15, 23, 42, 0.95) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid var(--accent-blue) !important;
    border-radius: 999px !important;
    padding: 3px 12px !important;
    font-size: 12px !important;
    font-weight: 700 !important;
    color: var(--text-main) !important;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6) !important;
    white-space: nowrap !important;
    transform: translateY(-8px);
}

.radar-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-emerald);
    border-radius: 50%;
    position: relative;
}

.radar-dot::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(16, 185, 129, 0.4);
    animation: radar-pulse 2s infinite ease-out;
}

@keyframes radar-pulse {
    0% { transform: scale(0.5); opacity: 1; }
    100% { transform: scale(2.2); opacity: 0; }
}

#btn-recenter {
    position: absolute;
    bottom: 24px;
    left: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 15;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.rename-card {
    width: 100%;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-main);
    padding: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.6);
}

.avatar-box {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    background: #1e293b;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.35);
}

.premium-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    color: #fff;
    outline: none;
}

.btn-primary {
    flex: 1;
    padding: 10px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #0284c7, #0ea5e9);
    color: #fff;
    cursor: pointer;
}

.btn-secondary {
    flex: 1;
    padding: 10px;
    font-size: 13px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    cursor: pointer;
}

.btn-close {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: var(--text-muted);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
}

input[type="range"] {
    flex: 1;
    height: 5px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #0284c7;
    cursor: pointer;
}

/* ================= 5. RESPONSIVE ADAPTIVE LAYOUT ================= */
@media (max-width: 640px) {
    :root {
        --console-width: 100vw;
    }
    body.sidebar-pinned:not(.sidebar-collapsed) #map-container {
        width: 100% !important;
    }
    .right-console {
        top: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
    }
    /* ป้องกันการ Scroll ล้นแนวนอนบนหน้าจอมือถือเมื่อแผงถูกซ่อน */
    body.sidebar-collapsed .right-console {
    display: none !important;
    transform: translateX(100vw) !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
   }
}

/* ==========================================================================
   ENTERPRISE TOAST NOTIFICATION (ธีมเข้าชุด Glassmorphism)
   ========================================================================== */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999; /* อยู่เหนือทุกเลเยอร์ */
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none; /* เพื่อให้คลิกทะลุแผนที่ได้ถ้าไม่ได้แตะโดนตัวการ์ด */
    width: 90%;
    max-width: 380px;
}

.app-toast-card {
    pointer-events: auto;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(56, 189, 248, 0.4);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 15px rgba(56, 189, 248, 0.25);
    border-radius: 14px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #f8fafc;
    font-family: 'Prompt', sans-serif;
    animation: toastSlideDown 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transition: all 0.3s ease;
}

.app-toast-card.hide {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
}

.toast-icon-wrap {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(56, 189, 248, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.toast-body {
    flex: 1;
}

.toast-title {
    font-size: 13px;
    font-weight: 600;
    color: #38bdf8;
    margin-bottom: 2px;
}

.toast-desc {
    font-size: 11px;
    color: #cbd5e1;
    line-height: 1.3;
}

.toast-btn-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    touch-action: manipulation;
}

.toast-btn-close:hover {
    color: #ffffff;
}

@keyframes toastSlideDown {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
