:root {
    --bg-color: #050608;
    --panel-bg: rgba(12, 14, 20, 0.98);
    --border-color: rgba(0, 180, 255, 0.25);
    --text-main: #f0f0f0;
    --text-dim: #6a7a8a;
    --accent-blue: #00d4ff;
    --accent-purple: #9b59b6;
    --accent-red: #ff4d4d;
    --accent-orange: #ff9f1c;
    --accent-green: #2ecc71;
    --glow-blue: rgba(0, 212, 255, 0.5);
}

/* Scoped to mesh-section to prevent global pollution */
#mesh-section {
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 50% 10%, rgba(0, 180, 255, 0.1) 0%, transparent 60%),
        linear-gradient(rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.85)),
        url('https://www.transparenttextures.com/patterns/carbon-fibre.png');
    color: var(--text-main);
}

#mesh-section * {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

#mesh-section .app-container {
    width: 100%;
    max-width: 100% !important;
    margin: 0 !important;
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    flex: 1;
    padding: 20px;
}

@media (max-width: 1200px) {
    #mesh-section .app-container {
        grid-template-columns: 280px 1fr;
    }
}

@media (max-width: 1024px) {
    #mesh-section .app-container {
        grid-template-columns: 1fr;
        padding: 10px;
    }

    /* 手機版將地圖/指令層優先置頂，避免被側邊欄擋住 (Prioritize terminal/map on mobile) */
    #mesh-section aside {
        order: 2;
    }
    #mesh-section .terminal-panel {
        order: 1;
        margin-bottom: 20px !important;
    }
}

#mesh-section .module-box {
    background: rgba(20, 22, 30, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

#mesh-section .module-title {
    font-size: 0.9rem;
    font-weight: bold;
    color: #fff;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-left: 3px solid var(--accent-blue);
    padding-left: 10px;
}

#mesh-section .hw-tag {
    font-family: 'JetBrains Mono';
    font-size: 0.6rem;
    background: #ffd700;
    color: #000;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 900;
}

#mesh-section .btn {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 12px;
}

#mesh-section .btn:hover {
    background: rgba(0, 212, 255, 0.1);
    border-color: var(--accent-blue);
}

#mesh-section .btn-primary {
    background: var(--accent-blue);
    color: #000;
    border: none;
}

#mesh-section .btn-primary:hover {
    background: #00b4d8;
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.3);
}

#mesh-section .btn-bt {
    border-color: #3d5afe;
    color: #3d5afe;
}

#mesh-section .btn-bt:hover {
    background: rgba(61, 90, 254, 0.1);
}

#mesh-section .btn-wifi {
    border-color: var(--accent-orange);
    color: var(--accent-orange);
}

#mesh-section .btn-wifi:hover {
    background: rgba(255, 159, 28, 0.1);
}

#mesh-section .btn-mobile-ble {
    border-color: #9b59b6;
    color: #9b59b6;
}

#mesh-section .btn-mobile-ble:hover {
    background: rgba(155, 89, 182, 0.1);
}

#mesh-section .btn-share {
    grid-column: span 2;
    border-color: #f1c40f;
    color: #f1c40f;
}

#mesh-section .btn-share:hover {
    background: rgba(241, 196, 15, 0.1);
}

#mesh-section .terminal-panel {
    background: #000;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 600px;
    flex: 1;
    margin: 0 !important;
    width: 100%;
    max-width: none !important;
}

@media (max-width: 768px) {
    #mesh-section .terminal-panel {
        min-height: 70vh;
    }
}

#mesh-section .console-out {
    flex: 1;
    padding: 25px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    color: #2ecc71;
    overflow-y: auto;
    line-height: 1.5;
}

#mesh-section .indicator-bulb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #444;
    margin-right: 15px;
    transition: 0.3s;
}

#mesh-section .bulb-active {
    background: var(--accent-green);
    box-shadow: 0 0 10px var(--accent-green);
}

#mesh-section .bulb-blue {
    background: var(--accent-blue);
    box-shadow: 0 0 10px var(--accent-blue);
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

#mesh-section .online-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 6, 8, 0.95);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
}

#mesh-section .online-input {
    background: #111;
    border: 1px solid var(--accent-blue);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    margin-top: 20px;
    width: 100%;
    max-width: 300px;
    text-align: center;
    font-size: 1.1rem;
}

#mesh-section .feature-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

#mesh-section .f-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: 0.3s;
}

#mesh-section .f-card:hover {
    border-color: #2ecc71;
    background: rgba(46, 204, 113, 0.05);
}

#mesh-section .f-card.active,
#mesh-section .f-card.is-enabled {
    border: 1px solid #2ecc71 !important;
    background: rgba(46, 204, 113, 0.15) !important;
    box-shadow: 0 0 15px rgba(46, 204, 113, 0.3);
}

#mesh-section .f-card.active .f-icon,
#mesh-section .f-card.is-enabled .f-icon {
    transform: scale(1.1);
    filter: drop-shadow(0 0 5px #2ecc71);
}

#mesh-section .f-card.active .f-label,
#mesh-section .f-card.is-enabled .f-label {
    color: #2ecc71;
    font-weight: bold;
}

#mesh-section .f-icon {
    font-size: 1.2rem;
    margin-bottom: 5px;
    display: block;
    transition: 0.3s;
}

#mesh-section .f-label {
    font-size: 0.85rem;
    color: var(--text-dim);
    white-space: nowrap;
    display: block;
    margin-top: 4px;
}

#mesh-section .btn {
    width: 100%;
    padding: 12px 6px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#mesh-section .lora-tab-content {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

#mesh-section .lora-tab-content.active {
    display: flex;
}

#mesh-section .toast-container {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

#mesh-section .toast-msg {
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    border: 1px solid var(--accent-blue);
    backdrop-filter: blur(10px);
    animation: toastIn 0.3s forwards;
}

@keyframes toastIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

#mesh-section .dash-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

#mesh-section .dash-table th {
    text-align: left;
    padding: 12px;
    color: var(--text-dim);
    border-bottom: 1px solid #222;
}

#mesh-section .dash-table td {
    padding: 12px;
    border-bottom: 1px solid #111;
}

#mesh-section .chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #050a10;
}

#mesh-section .chat-bubble {
    max-width: 85%;
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.4;
    position: relative;
}

#mesh-section .bubble-received {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#mesh-section .bubble-sent {
    align-self: flex-end;
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid var(--accent-blue);
}

#mesh-section .chat-input-area {
    display: flex;
    padding: 10px;
    background: #000;
    gap: 10px;
    border-top: 1px solid #222;
}

#mesh-section .chat-input {
    flex: 1;
    background: #111;
    border: 1px solid #333;
    color: #fff;
    padding: 10px 15px;
    border-radius: 20px;
    outline: none;
}

#mesh-section .btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-blue);
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
}

#mesh-section .nav-locked .f-card:not(#lora-standalone-lock-card) {
    pointer-events: none !important;
    opacity: 0.5 !important;
    filter: grayscale(0.5);
    cursor: not-allowed !important;
}

#mesh-section .nav-locked .btn:not(.btn-send) {
    pointer-events: none !important;
    opacity: 0.5 !important;
    cursor: not-allowed !important;
}
