@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;600;700&display=swap');

:root {
    --bg-main: #0b0f19;
    --bg-card: rgba(22, 28, 45, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --border-glass: rgba(255, 255, 255, 0.1);
    
    --primary-gradient: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
    --danger-gradient: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%);
    --success-gradient: linear-gradient(135deg, #00b09b 0%, #96c93d 100%);
    
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --accent-cyan: #00f2fe;
    --accent-blue: #4facfe;
    --accent-red: #ff416c;

    --shadow-glow: 0 0 20px rgba(79, 172, 254, 0.3);
    --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 10% 20%, rgba(79, 172, 254, 0.15) 0px, transparent 50%),
        radial-gradient(at 90% 80%, rgba(150, 40, 255, 0.15) 0px, transparent 50%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

a {
    color: var(--accent-cyan);
    text-decoration: none;
    transition: all 0.3s ease;
}

a:hover {
    color: var(--accent-blue);
    text-shadow: 0 0 8px rgba(0, 242, 254, 0.5);
}

/* Layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

header {
    background: rgba(11, 15, 25, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-glass);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 1rem 0;
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-glass);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border-glass);
    font-size: 0.9rem;
}

.content {
    flex: 1;
    padding: 3rem 0;
}

footer {
    background: rgba(11, 15, 25, 0.9);
    border-top: 1px solid var(--border-glass);
    color: var(--text-muted);
    text-align: center;
    padding: 1.5rem 0;
    font-size: 0.875rem;
}

/* Glass Cards */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-card);
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.glass-card:hover {
    border-color: rgba(79, 172, 254, 0.4);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-gradient);
    color: #0b0f19;
    box-shadow: 0 4px 15px rgba(0, 242, 254, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 242, 254, 0.4);
    color: #0b0f19;
}

.btn-danger {
    background: var(--danger-gradient);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(255, 65, 108, 0.2);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 65, 108, 0.4);
    color: #ffffff;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-glass);
    border-color: var(--accent-blue);
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    background: rgba(11, 15, 25, 0.6);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(0, 242, 254, 0.15);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-cols: 1;
    gap: 2rem;
}

@media (min-width: 992px) {
    .dashboard-grid {
        grid-template-columns: 350px 1fr;
    }
}

.device-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 500px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.device-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.device-item:hover, .device-item.active {
    background: rgba(79, 172, 254, 0.1);
    border-color: var(--accent-blue);
    transform: translateX(4px);
}

.device-info h4 {
    margin-bottom: 0.25rem;
    font-size: 1.1rem;
}

.device-info span {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: monospace;
}

/* Map Container */
.map-card {
    height: 600px;
    display: flex;
    flex-direction: column;
}

#map {
    flex: 1;
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-glass);
    background: #1a1d24;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-main);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    padding: 2rem;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

/* Toast Notification */
#toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    background: rgba(22, 28, 45, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    padding: 1rem 1.5rem;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 280px;
    animation: slideIn 0.3s ease forwards;
}

.toast.success { border-left: 4px solid #00b09b; }
.toast.error { border-left: 4px solid #ff416c; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-glass);
    margin-bottom: 1.5rem;
}

.tab-btn {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.3s ease;
}

.tab-btn.active {
    color: var(--accent-cyan);
    border-bottom-color: var(--accent-cyan);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Timeline Timeline Items */
.timeline-item {
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.timeline-item:hover {
    background: rgba(79, 172, 254, 0.05);
    border-color: var(--accent-blue);
}

.timeline-item.active {
    background: rgba(79, 172, 254, 0.15);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.15);
}

/* Sidebar & Flex Layout */
.dashboard-grid {
    display: flex;
    gap: 1.5rem;
    align-items: stretch;
    transition: all 0.3s ease;
}

.sidebar-container {
    width: 320px;
    flex-shrink: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.sidebar-container.collapsed {
    width: 0;
    margin-right: -1.5rem;
    opacity: 0;
    pointer-events: none;
}

.map-card-container {
    flex: 1;
    min-width: 0;
}

/* 手機與平板適應 */
@media (max-width: 992px) {
    .dashboard-grid {
        flex-direction: column;
    }
    .sidebar-container {
        width: 100%;
        height: auto;
    }
    .sidebar-container.collapsed {
        display: none;
    }
}

@media (max-width: 768px) {
    .map-card-body {
        flex-direction: column !important;
        height: auto;
    }
    #map {
        min-height: 350px !important;
        height: 350px !important;
    }
    #timeline-box {
        width: 100% !important;
        height: 350px !important;
    }
    .content {
        padding: 1.5rem 0;
    }
    .glass-card {
        padding: 1.25rem;
    }
}

@media (max-width: 576px) {
    .user-badge span {
        display: none;
    }
    .user-badge {
        padding: 0;
        border: none;
        background: none;
        gap: 0;
    }
    .logo {
        font-size: 1.2rem;
    }
}