/* =================================================================
   BASE & LAYOUT SETUP
================================================================= */
html {
    height: 100%;
}
body {
    height: 100%;
    margin: 0;
    font-family: 'Inter', sans-serif; 
    background: #000000;
    /* FIX: Set body as the main flex container with top padding for the nav */
    display: flex;
    flex-direction: column;
    padding-top: 0; /* This is the height of the nav, pushing all content down */
    box-sizing: border-box;
}

/* =================================================================
   NAVIGATION
================================================================= */
nav {
    position: fixed; /* FIX: Nav is fixed to the top of the viewport */
    top: 0;
    left: 0;
    width: 100%;
    z-index: 50;
    transform: translateY(0);
    transition: transform 0.3s ease-in-out;
}
nav:not(.visible) {
    transform: translateY(-100%);
}

.nav-btn {
    background-color: #1f2937;
    color: #d1d5db;
    transition: all 0.2s ease-in-out;
}
.nav-btn.active {
    background-color: #facc15;
    color: #111827;
    font-weight: bold;
}

/* =================================================================
   MAIN CONTENT WRAPPER & VIEWS
================================================================= */
/* FIX: This wrapper now just holds the views and grows to fill the space */
#main-content-wrapper {
    flex-grow: 1;
    display: flex;
    min-height: 0;
}

.view {
    display: none;
    width: 100%;
    animation: fadeIn 0.5s;
}

.view.active {
    display: flex; 
    flex-direction: column;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* =================================================================
   DASHBOARD (NON-SCROLLING)
================================================================= */
#view-dashboard.active {
    height: 100%;
    overflow: hidden; /* This view should NEVER scroll */
}

.dashboard-background {
    background-size: cover;
    background-position: center;
    position: relative;
}

.dashboard-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5); 
}

.dashboard-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.dashboard-ui-elements {
    flex-shrink: 0;
}

/* This new wrapper is the key to correct padding and flex behavior */
.dashboard-main-area {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0; /* Allows this area to shrink */
}

#view-dashboard main {
    flex-grow: 1;
    display: flex;
    position: relative;
    min-height: 0;
}

#dashboard-graph-content {
    flex-grow: 1;
    position: relative;
    width: 100%;
    height: 100%;
}

/* =================================================================
   OTHER VIEWS (SCROLLING)
================================================================= */
/* FIX: These views will now scroll naturally within the main wrapper */
#view-graph, #view-settings, #view-status {
    height: auto;
}

.status-light {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: #4b5563;
    transition: background-color 0.3s;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.4);
}
.status-light.active {
    background-color: #4ade80;
    box-shadow: 0 0 10px #4ade80, inset 0 0 5px rgba(255,255,255,0.4);
}

.settings-input, select.settings-input { 
    width: 100%;
    background-color: #e5e7eb;
    border: 1px solid #d1d5db;
    color: #111827;
    font-size: 0.875rem;
    border-radius: 0.5rem;
    padding: 0.625rem;
}
.settings-input:focus, select.settings-input:focus {
     outline: none !important;
     border-color: #4f46e5 !important;
     box-shadow: 0 0 0 1px #4f46e5 !important;
}
.settings-footer {
    padding: 1rem 2rem;
    background-color: rgba(243, 244, 246, 0.95);
    border-top: 1px solid #e5e7eb;
    backdrop-filter: blur(8px);
    flex-shrink: 0;
}

#brush-chart-container {
    position: relative;
    height: 100px;
    cursor: default;
}
#brush {
    position: absolute;
    top: 0;
    height: 100%;
    background-color: rgba(100, 150, 255, 0.3);
    border-left: 2px solid #6495ED;
    border-right: 2px solid #6495ED;
    cursor: move;
    z-index: 10;
}
.brush-handle {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 40px;
    background-color: #6495ED;
    border: 1px solid #fff;
    border-radius: 3px;
}
.brush-handle.left {
    left: -5px;
    cursor: ew-resize;
}
.brush-handle.right {
    right: -5px;
    cursor: ew-resize;
}

.tooltip-trigger {
    position: relative;
    display: inline-block;
    margin-left: 8px;
}
.tooltip-trigger .tooltip-content {
    visibility: hidden;
    width: 320px;
    background-color: #334155;
    color: #fff;
    text-align: left;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 50;
    bottom: 130%;
    left: 50%;
    margin-left: -160px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.8rem;
    line-height: 1.4;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    pointer-events: none; 
}
.tooltip-trigger .tooltip-content::after {
    content: "";
    position: absolute;
    top: 100%; 
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #334155 transparent transparent transparent;
}
.tooltip-trigger:hover .tooltip-content {
    visibility: visible;
    opacity: 1;
}

.drag-handle {
    cursor: grab;
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    padding: 1rem;
}
.drag-handle:hover {
    color: #4b5563;
}
.parameter-row, .rotation-row {
    padding-left: 48px !important;
}
.parameter-row.dragging, .rotation-row.dragging {
    opacity: 0.5;
    background: #e0e7ff;
}

#pin-input {
    letter-spacing: 16px;
    text-align: center;
    caret-color: #4f46e5;
    -webkit-text-security: disc;
    -moz-text-security: disc;
    text-security: disc;
    padding-left: 20px;
}
.keypad-btn:active {
    background-color: #9ca3af;
}

.image-picker-tabs button {
    padding: 8px 12px;
    border-bottom: 2px solid transparent;
    color: #6b7280;
}
.image-picker-tabs button.active {
    color: #4f46e5;
    border-bottom-color: #4f46e5;
    font-weight: 600;
}
.image-picker-content {
    display: none;
}
.image-picker-content.active {
    display: block;
}

.dashboard-main-content {
    display: none;
}
.dashboard-main-content.active {
    display: block;
    animation: fadeIn 0.5s;
    width: 100%;
    height: 100%;
}
#dashboard-video, #dashboard-image, #dashboard-youtube-iframe {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ad-mode .dashboard-ui-elements {
    display: none;
}
.ad-mode .dashboard-main-content.active {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100;
    background: #000;
}

#app-version-btn {
    position: absolute;
    top: 4rem; /* เปลี่ยนจาก 1rem เป็น 4rem เพื่อให้ต่ำกว่า nav */
    right: 1rem;
    z-index: 100; /* เพิ่ม z-index ให้สูงขึ้น */
    color: #9ca3af !important; /* เปลี่ยนสีให้เห็นชัดขึ้น */
    font-size: 0.75rem;
    text-decoration: underline;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s ease;
}

#app-version-btn:hover {
    color: #4b5563 !important; /* สีเมื่อ hover */
}

#app-version-btn:focus {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

/* ตรวจสอบให้แน่ใจว่า settings-form-container มี position relative */
#settings-form-container {
    position: relative;
}

/* ปรับให้ส่วนหัวของ Settings ไม่บังปุ่ม */
#settings-form-container .p-8.pb-4 {
    position: relative;
    /* เพิ่ม padding-top เพื่อให้พื้นที่สำหรับปุ่ม */
    padding-top: 3rem;
}

/* หรือวางปุ่มใน container ที่ไม่ถูกบังโดย nav */
@media (max-width: 640px) {
    #app-version-btn {
        top: 5rem; /* ในหน้าจอเล็กให้เลื่อนลงมาเพิ่ม */
        right: 0.5rem;
        font-size: 0.7rem;
    }
}