/* ==============================
   全局設定（Global Styles）
============================== */
:root {
    --bg-color: #f9fafb;
    --card-color: #ffffff;
    --primary-color: #4f46e5;
    --secondary-color: #6366f1;
    --text-color: #111827;
    --subtext-color: #6b7280;
    --border-color: #e5e7eb;
    --radius: 16px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    --transition: all 0.25s ease;
}

body {
    font-family: "Noto Sans TC", "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: row;
    min-height: 100vh;
}

/* ==============================
   側邊欄（桌機）
============================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    background-color: var(--card-color);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    z-index: 10;
}

.sidebar-header {
    text-align: center;
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 20px 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    margin-top: 20px;
}

.nav-link {
    text-decoration: none;
    color: var(--subtext-color);
    padding: 12px 24px;
    font-size: 1rem;
    transition: var(--transition);
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary-color);
    background-color: #f3f4f6;
    border-left: 4px solid var(--primary-color);
}

/* ==============================
   主內容區
============================== */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 40px;
}

/* 標題 */
h2 {
    font-size: 1.6rem;
    color: var(--primary-color);
    border-left: 6px solid var(--primary-color);
    padding-left: 10px;
    margin-bottom: 10px;
}
h3 {
    color: var(--text-color);
    margin-bottom: 8px;
}

/* ==============================
   Dashboard Cards
============================== */
.sensor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
}
.sensor-card {
    background: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    text-align: center;
    padding: 20px;
    transition: var(--transition);
}
.sensor-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}
.sensor-card .value {
    font-size: 2rem;
    font-weight: bold;
    display: block;
}

/* ==============================
   警告設定
============================== */
#alert-settings {
    background: var(--card-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.setting-card {
    border-bottom: 1px solid var(--border-color);
    padding: 20px 0;
}
.setting-card:last-child {
    border-bottom: none;
}
.threshold-input {
    width: 80px;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    outline: none;
    font-size: 0.9rem;
    transition: var(--transition);
}
.threshold-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(79,70,229,0.15);
}

/* Switch 開關 */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    background-color: #ccc;
    border-radius: 34px;
    top: 0; left: 0; right: 0; bottom: 0;
    transition: var(--transition);
}
.slider::before {
    position: absolute;
    content: "";
    height: 20px; width: 20px;
    left: 3px; bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: var(--transition);
}
input:checked + .slider {
    background-color: var(--primary-color);
}
input:checked + .slider::before {
    transform: translateX(20px);
}

/* ==============================
   設備控制
============================== */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-top: 15px;
}
.device-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    text-align: center;
    padding: 20px;
    transition: var(--transition);
}
.device-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

/* ==============================
   安裝按鈕
============================== */
#installBtn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 14px 26px;
    font-size: 1rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
}
#installBtn:hover {
    background-color: var(--secondary-color);
    transform: translateY(-2px);
}

/* ==============================
   響應式手機版
============================== */
@media (max-width: 900px) {
    body {
        flex-direction: column;
    }

    /* 側邊欄改為頂部橫條 */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 60px;
        width: 100%;
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        z-index: 1000;
    }
    .sidebar-header {
        display: none;
    }
    .sidebar-nav {
        flex-direction: row;
        margin: 0;
        width: 100%;
        justify-content: space-around;
    }
    .nav-link {
        padding: 10px;
        font-size: 0.9rem;
        border-left: none !important;
    }
    .nav-link.active {
        border-bottom: 3px solid var(--primary-color);
        background: none;
    }

    /* 主內容 */
    .main-content {
        margin: 80px 0 60px 0;
        padding: 20px;
        gap: 20px;
    }

    /* 卡片單欄 */
    .sensor-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    .device-grid {
        grid-template-columns: 1fr;
    }

    /* 表單欄位自動展開 */
    .threshold-input {
        width: 100%;
        max-width: 200px;
        display: inline-block;
    }

    /* 安裝按鈕縮小 */
    #installBtn {
        bottom: 15px;
        right: 15px;
        padding: 10px 18px;
        font-size: 0.9rem;
    }
}

/* 更小手機（小於600px） */
@media (max-width: 600px) {
    h2 {
        font-size: 1.3rem;
    }
    h3 {
        font-size: 1.1rem;
    }

    .sensor-card .value {
        font-size: 1.6rem;
    }

    .main-content {
        padding: 15px;
    }

    /* canvas圖表縮放 */
    #historyChart {
        width: 100%;
        height: 260px !important;
    }

    select#dataSelect {
        width: 100%;
        padding: 6px;
        font-size: 0.9rem;
        border-radius: 8px;
        margin-bottom: 10px;
    }
}

/* ========= 手機版圖表放大可滑動 ========= */
#history {
    overflow-x: auto;              /* 啟用橫向滾動 */
    -webkit-overflow-scrolling: touch;
}

.chart-container {
    width: 1200px;                 /* 讓圖表比手機螢幕寬，便於滑動 */
    max-width: none;
    margin-bottom: 20px;
}

#historyChart {
    width: 100%;
    height: 400px !important;      /* 放大高度 */
}

/* 桌機保持一般大小 */
@media (min-width: 901px) {
    #history {
        overflow-x: visible;
    }
    .chart-container {
        width: 100%;
    }
    #historyChart {
        height: 500px !important;
    }
}

