* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #1a1a2e;
    color: #eee;
    min-height: 100vh;
}

.container {
    display: flex;
    height: 100vh;
}

/* 左側面板 */
.sidebar {
    width: 300px;
    background: #16213e;
    padding: 20px;
    overflow-y: auto;
    border-right: 1px solid #0f3460;
}

.sidebar h1 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: #e94560;
}

.panel {
    background: #1a1a2e;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
}

.panel h2 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: #0f3460;
    border-bottom: 1px solid #0f3460;
    padding-bottom: 5px;
}

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 5px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #0f3460;
    border-radius: 4px;
    background: #16213e;
    color: #eee;
    font-size: 0.9rem;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #e94560;
}

.btn {
    background: #e94560;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    width: 100%;
    transition: background 0.2s;
}

.btn:hover {
    background: #ff6b6b;
}

.btn-small {
    padding: 6px 12px;
    width: auto;
    font-size: 0.8rem;
}

.quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* 設備列表 */
.device-list {
    margin-top: 10px;
}

.device-item {
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.device-item:hover {
    border-color: #e94560;
}

.device-item.selected {
    border-color: #e94560;
    background: #0f3460;
}

.device-item .name {
    font-weight: bold;
    margin-bottom: 4px;
}

.device-item .address {
    font-size: 0.8rem;
    color: #888;
}

.hint {
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
}

/* 主畫面區 */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #0f0f1a;
    padding: 20px;
}

.screen-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

#device-name {
    font-size: 1.1rem;
    font-weight: bold;
}

.status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
}

.status.connected {
    background: #00b894;
    color: white;
}

.status.disconnected {
    background: #636e72;
    color: white;
}

.status.connecting {
    background: #fdcb6e;
    color: #2d3436;
}

.screen-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}

#screen-canvas {
    max-width: 100%;
    max-height: 100%;
    cursor: crosshair;
}

#click-indicator {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 2px solid #e94560;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
    transition: opacity 0.3s, transform 0.3s;
}

#click-indicator.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* 右側元素資訊 */
.info-panel {
    width: 280px;
    background: #16213e;
    padding: 20px;
    overflow-y: auto;
    border-left: 1px solid #0f3460;
}

.info-panel h2 {
    font-size: 1rem;
    margin-bottom: 15px;
    color: #e94560;
}

#element-info {
    margin-top: 15px;
}

.info-row {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #0f3460;
}

.info-row .label {
    display: block;
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 3px;
}

.info-row span:last-child {
    font-size: 0.9rem;
    word-break: break-all;
}

/* RWD */
@media (max-width: 1200px) {
    .info-panel {
        display: none;
    }
}

@media (max-width: 800px) {
    .container {
        flex-direction: column;
        height: 100vh;
        height: 100dvh; /* 動態視口高度，避免瀏覽器 UI 問題 */
        overflow: hidden;
    }

    .sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 100;
        overflow-y: auto;
        border-right: none;
        padding-bottom: 80px;
    }

    .sidebar.open {
        display: block;
    }

    .main {
        flex: 1;
        padding: 0;
        display: flex;
        flex-direction: column;
        /* 不使用 height，讓 flex 處理 */
        min-height: 0;
        margin-bottom: 50px; /* 預留底部工具列空間 */
    }

    .screen-header {
        font-size: 0.8rem;
        padding: 5px 10px;
        background: #16213e;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;
        height: 30px;
    }

    .screen-header.hidden {
        display: none;
    }

    .screen-container {
        flex: 1;
        border-radius: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
        background: #000;
        /* 確保不會超出 */
        min-height: 0;
    }

    #screen-canvas {
        display: block;
        max-width: 100%;
        max-height: 100%;
    }

    /* 全螢幕模式 */
    .fullscreen .screen-header {
        display: none !important;
    }

    .fullscreen .main {
        margin-bottom: 50px;
    }

    .fullscreen .mobile-toolbar {
        opacity: 0.4;
        transition: opacity 0.3s;
        background: rgba(22, 33, 62, 0.9);
    }

    .fullscreen .mobile-toolbar:active {
        opacity: 1;
    }

    /* 手機版底部工具列 */
    .mobile-toolbar {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #16213e;
        padding: 8px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        gap: 5px;
        border-top: 1px solid #0f3460;
        z-index: 99;
        height: 50px;
        box-sizing: border-box;
    }

    .mobile-toolbar button {
        flex: 1;
        padding: 10px 5px;
        font-size: 0.75rem;
        border-radius: 4px;
        border: none;
        background: #0f3460;
        color: white;
        cursor: pointer;
    }

    .mobile-toolbar button.active {
        background: #e94560;
    }

    /* 手機版元素資訊彈出層 */
    .info-panel.mobile-open {
        display: block;
        position: fixed;
        bottom: 60px;
        left: 10px;
        right: 10px;
        top: auto;
        height: auto;
        max-height: 40vh;
        border-radius: 8px;
        z-index: 98;
        overflow-y: auto;
        border: 1px solid #0f3460;
    }

    /* 手機版訊息輸入 */
    .mobile-message {
        position: fixed;
        bottom: 60px;
        left: 10px;
        right: 10px;
        background: #16213e;
        padding: 15px;
        border-radius: 8px;
        z-index: 98;
        border: 1px solid #0f3460;
    }

    .mobile-message textarea {
        width: 100%;
        padding: 10px;
        border: 1px solid #0f3460;
        border-radius: 4px;
        background: #1a1a2e;
        color: #eee;
        font-size: 16px;
        margin-bottom: 10px;
        resize: none;
    }

    .mobile-message .btn-row {
        display: flex;
        gap: 8px;
    }

    .mobile-message button {
        flex: 1;
        padding: 12px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        font-size: 0.9rem;
    }

    .mobile-message .btn-send {
        background: #e94560;
        color: white;
    }

    .mobile-message .btn-cancel {
        background: #636e72;
        color: white;
    }
}

/* 手機版預設隱藏 */
.mobile-toolbar {
    display: none;
}

.mobile-message {
    display: none;
}

/* 關閉按鈕 */
.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #e94560;
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
}
