/* Reset and Base Styles */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css');

:root {
    --primary-color: #4a69bd;
    --secondary-color: #6a89cc;
    --text-color: #f0f4f8;
    --bg-color: #1a1a2e;
    --card-bg-color: rgba(255, 255, 255, 0.1);
    --card-border-color: rgba(255, 255, 255, 0.2);
    --shadow-color: rgba(0, 0, 0, 0.3);
    --success-color: #2ecc71;
    --error-color: #e74c3c;
    --font-family: 'Poppins', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    color: var(--text-color);
    background: var(--bg-color);
    background-image: url('https://images.unsplash.com/photo-1617469723732-1201a3a374b8?q=80&w=2070&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

body.login-page {
    background-image: url('https://images.unsplash.com/photo-1555215695-3004980ad54e?q=80&w=2070&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

body:not(.login-page) {
    background-image: url('https://images.unsplash.com/photo-1492144534655-ae79c964c9d7?q=80&w=2083&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(74, 105, 189, 0.7); }
    70% { box-shadow: 0 0 0 20px rgba(74, 105, 189, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 105, 189, 0); }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

/* Glassmorphism Card Base */
.glass-card {
    background: var(--card-bg-color);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--card-border-color);
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 var(--shadow-color);
    animation: fadeIn 0.8s ease-out forwards;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 450px;
}

.login-card {
    padding: clamp(30px, 5vw, 50px);
    text-align: center;
    background: rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 25px;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.2);
}

.logo {
    margin-bottom: 30px;
    animation: float 4s ease-in-out infinite;
}

.logo h1 {
    font-size: clamp(2rem, 6vw, 2.8rem);
    font-weight: 700;
    color: var(--text-color);
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

.logo p {
    color: var(--text-color);
    opacity: 0.8;
    font-size: clamp(0.8rem, 2vw, 1rem);
}

.form-group {
    margin-bottom: 25px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    color: #4a90e2;
    opacity: 0.9;
}

.form-group input {
    width: 100%;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--card-border-color);
    border-radius: 10px;
    font-size: 1rem;
    color: #4a90e2 !important;
    font-weight: 600;
    transition: all 0.3s ease;
}

.form-group input::placeholder {
    color: rgba(74, 144, 226, 0.5);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(74, 105, 189, 0.5);
}

.form-group input:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(74, 105, 189, 0.3),
                inset 0 -3px 0 rgba(74, 105, 189, 0.5),
                inset 0 3px 0 rgba(255, 255, 255, 0.1);
    border-color: var(--secondary-color);
    background: rgba(0, 0, 0, 0.4);
}

.btn-primary {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 15px 35px rgba(74, 105, 189, 0.5),
                inset 0 -4px 0 rgba(0, 0, 0, 0.3),
                inset 0 4px 0 rgba(255, 255, 255, 0.2);
    background: linear-gradient(135deg, #5a79cd, #7a99dc);
}

.btn-primary:active {
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 8px 20px rgba(74, 105, 189, 0.4);
}

.error-msg {
    color: var(--error-color);
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid var(--error-color);
    padding: 10px;
    border-radius: 8px;
    margin-top: 15px;
    display: none; /* Initially hidden */
}

/* Navbar */
.navbar {
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    animation: fadeIn 0.5s ease-out;
}

.nav-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar h1 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    color: var(--text-color);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.btn {
    padding: 10px 25px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    text-transform: uppercase;
    font-size: 0.9rem;
}

.btn-logout {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    padding: 12px 28px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.4);
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.btn-logout:hover {
    background: linear-gradient(135deg, #ff6b6b, #ee5a6f);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(231, 76, 60, 0.6),
                inset 0 -3px 0 rgba(0, 0, 0, 0.2),
                inset 0 3px 0 rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.btn-back {
    background: var(--primary-color);
    color: white;
}

.btn-back:hover {
    background: var(--secondary-color);
    transform: scale(1.05);
}

/* Main Container */
.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 30px;
    flex-grow: 1;
}

/* Page Header */
.page-header {
    padding: 30px;
    margin-bottom: 30px;
    text-align: center;
}

.page-header h2 {
    font-size: clamp(2rem, 5vw, 2.5rem);
    color: var(--text-color);
    margin-bottom: 10px;
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

.stats {
    color: var(--text-color);
    opacity: 0.8;
    font-size: 1.1rem;
}

/* Devices Grid */
.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 30px;
}

.device-card {
    padding: 25px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.device-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 15px 40px var(--shadow-color);
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--card-border-color);
    padding-bottom: 15px;
}

.device-header h3 {
    font-size: 1.4rem;
    color: var(--text-color);
}

.status-badge {
    padding: 8px 15px;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-online {
    background: rgba(46, 204, 113, 0.2);
    color: #2ecc71;
    border: 1px solid #2ecc71;
}

.status-offline {
    background: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
    border: 1px solid #e74c3c;
}

.device-info p {
    margin-bottom: 12px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.device-info p i {
    color: var(--primary-color);
    width: 20px;
    text-align: center;
}

.device-info strong {
    font-weight: 600;
    color: var(--text-color);
    opacity: 0.9;
}

.device-card a {
    text-decoration: none;
    color: inherit;
}

/* --- Device Page Specifics --- */
.device-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-content {
    flex-grow: 1;
    padding: 30px;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

.device-title-main {
    text-align: center;
    flex-grow: 1;
}

.tab-btn {
    padding: 12px 25px;
    cursor: pointer;
    border-radius: 10px;
    font-weight: 600;
    transition: all 0.3s ease;
    background: var(--card-bg-color);
    border: 1px solid var(--card-border-color);
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
}

.tab-btn.active,
.tab-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(74, 105, 189, 0.4);
}

.tab-content {
    padding-top: 30px;
}

/* Live Location Grid */
.live-location-grid {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 30px;
    align-items: flex-start;
}

.location-details {
    position: sticky;
    top: 100px; /* Adjust based on navbar height */
}

.detail-item {
    background: rgba(0,0,0,0.2);
    padding: 25px;
    border-radius: 15px;
}

.detail-item h3 {
    font-size: 1.5rem;
    margin-bottom: 15px;
}

.coord-display {
    font-size: 1.2rem;
    font-weight: 300;
    margin-bottom: 10px;
    word-wrap: break-word;
}

.last-update {
    font-size: 0.9rem;
    opacity: 0.7;
    margin-bottom: 25px;
}

.location-actions {
    display: flex;
    gap: 15px;
}

.btn-tertiary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--card-border-color);
    color: var(--text-color);
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-tertiary:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.map-container {
    height: 80vh; /* Taller map */
    width: 100%;
    border-radius: 15px;
    border: 1px solid var(--card-border-color);
    overflow: hidden;
    animation: fadeIn 1s ease-out;
}

/* History and Logs Tables */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h3 {
    font-size: 1.8rem;
}

.table-container {
    overflow-x: auto;
    max-height: 60vh;
    overflow-y: auto;
}

.history-list, .logs-list {
    width: 100%;
    min-width: 600px;
}

.history-item, .log-item {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    padding: 15px;
    border-bottom: 1px solid var(--card-border-color);
    transition: background 0.3s;
}
.log-item {
    grid-template-columns: 1fr 2fr;
}

.history-item:hover, .log-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.history-item p, .log-item p {
    margin: 0;
}

/* Analytics Tab */
.analytics-form {
    padding: 30px;
    margin-bottom: 30px;
}

.date-range-picker {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.analytics-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.analytics-card {
    background: rgba(0,0,0,0.2);
    padding: 20px;
    border-radius: 15px;
    animation: fadeIn 0.5s ease-out forwards;
}

.analytics-card h4 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 10px;
    opacity: 0.8;
}

.analytics-card p {
    font-size: 1.2rem;
    font-weight: 600;
}

/* Loading Spinner for tables */
.loading-spinner {
    display: block;
    margin: 50px auto;
    width: 50px;
    height: 50px;
    border: 4px solid var(--card-border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Icon Font Placeholders */
[class^="icon-"]::before {
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    margin-right: 8px;
}
.icon-back::before { content: "\f060"; }
.icon-logout::before { content: "\f2f5"; }
.icon-live::before { content: "\f3c5"; }
.icon-history::before { content: "\f1da"; }
.icon-logs::before { content: "\f0f6"; }
.icon-analytics::before { content: "\f201"; }
.icon-copy::before { content: "\f0c5"; }
.icon-map::before { content: "\f5a0"; }
.icon-download::before { content: "\f019"; }

/* Device Details Page */
.device-details-header {
    padding: 30px;
    margin-bottom: 30px;
    text-align: left;
}


.device-details-header h2 {
    font-size: clamp(2rem, 5vw, 3rem);
    color: var(--text-color);
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.tab-button {
    padding: 12px 25px;
    cursor: pointer;
    border-radius: 10px;
    font-weight: 600;
    transition: all 0.3s ease;
    background: var(--card-bg-color);
    border: 1px solid var(--card-border-color);
    color: var(--text-color);
}

.tab-button.active,
.tab-button:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.5s;
}

#map, #history-map {
    height: 500px;
    width: 100%;
    border-radius: 15px;
    border: 1px solid var(--card-border-color);
    margin-bottom: 20px;
}

.leaflet-tile-pane {
    filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.data-table th, .data-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--card-border-color);
}

.data-table th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.9rem;
}

.data-table tbody tr {
    background: transparent;
    transition: background 0.3s;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn-download {
    margin-top: 20px;
    background: var(--success-color);
    color: white;
}
.btn-download:hover {
    background: #27ae60;
}

/* Loading Spinner */
#loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    border: 5px solid var(--card-border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 2000;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .nav-container, .container {
        padding: 15px;
    }

    .devices-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .tabs {
        justify-content: center;
    }

    .tab-button {
        flex-grow: 1;
        text-align: center;
    }

    .device-details-header h2 {
        text-align: center;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 20px;
        border: none;
        background: transparent;
        box-shadow: none;
    }

    .navbar h1 {
        font-size: 1.2rem;
    }

    .btn {
        padding: 8px 15px;
        font-size: 0.8rem;
    }
}
