/* Variables - Thème Clair */
:root {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f0f2f5;
    --border-color: #e1e5eb;
    --text-primary: #1a1a2e;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --accent-blue: #3b82f6;
    --accent-green: #22c55e;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.1);
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* App Layout */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 600;
    color: var(--accent-blue);
    text-decoration: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    border-radius: 20px;
    font-size: 14px;
    color: #166534;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Main */
.main {
    flex: 1;
    padding: 24px;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.stat-icon.devices { background: #dbeafe; color: var(--accent-blue); }
.stat-icon.positions { background: #dcfce7; color: var(--accent-green); }
.stat-icon.logs { background: #fef3c7; color: var(--accent-orange); }
.stat-icon.online { background: #ede9fe; color: var(--accent-purple); }

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Content Grid */
.content-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

@media (max-width: 1024px) {
    .content-grid {
        grid-template-columns: 1fr;
    }
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.card:last-child {
    margin-bottom: 0;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 20px;
}

.card-actions {
    display: flex;
    gap: 8px;
}

/* Map */
.map-card {
    margin-bottom: 0;
}

.map-card .card-body {
    padding: 0;
    height: 400px;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
}

/* Devices List */
.devices-card {
    margin-bottom: 0;
}

.devices-card .card-body {
    padding: 0;
    max-height: 400px;
    overflow-y: auto;
}

.devices-list {
    display: flex;
    flex-direction: column;
}

.device-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.device-item:hover {
    background: var(--bg-hover);
}

.device-item:last-child {
    border-bottom: none;
}

.device-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #dbeafe;
    color: var(--accent-blue);
    border-radius: var(--radius-sm);
}

.device-info {
    flex: 1;
}

.device-imei {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.device-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.device-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #cbd5e1;
}

.device-status.online {
    background: var(--accent-green);
    box-shadow: 0 0 0 3px #dcfce7;
}

/* Table */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: var(--bg-primary);
}

.table td {
    font-size: 14px;
    color: var(--text-primary);
}

.table tr:hover td {
    background: var(--bg-hover);
}

.table .imei {
    font-family: monospace;
    font-weight: 600;
    color: var(--accent-blue);
}

.table .coords {
    font-family: monospace;
    font-size: 12px;
    color: var(--text-secondary);
}

.table .speed {
    color: var(--accent-green);
    font-weight: 500;
}

.table .battery {
    display: flex;
    align-items: center;
    gap: 6px;
}

.battery-bar {
    width: 40px;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.battery-fill {
    height: 100%;
    background: var(--accent-green);
    border-radius: 4px;
}

.battery-fill.low {
    background: var(--accent-red);
}

.battery-fill.medium {
    background: var(--accent-orange);
}

/* Logs */
.logs-container {
    max-height: 300px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 13px;
}

.log-entry {
    display: flex;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
}

.log-entry:hover {
    background: var(--bg-hover);
}

.log-time {
    color: var(--text-muted);
    flex-shrink: 0;
}

.log-imei {
    color: var(--accent-blue);
    flex-shrink: 0;
    width: 140px;
    font-weight: 500;
}

.log-protocol {
    color: var(--accent-purple);
    flex-shrink: 0;
    width: 80px;
}

.log-path {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Server Logs */
.server-logs-container {
    max-height: 400px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 12px;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    padding: 12px;
    border: 1px solid var(--border-color);
}

.server-log-entry {
    display: flex;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid #e2e8f0;
}

.server-log-entry:last-child {
    border-bottom: none;
}

.server-log-time {
    color: var(--text-muted);
    flex-shrink: 0;
    font-size: 11px;
}

.server-log-message {
    color: var(--text-primary);
    word-break: break-all;
}

.server-log-message.connection {
    color: var(--accent-blue);
}

.server-log-message.position {
    color: var(--accent-green);
}

.server-log-message.error {
    color: var(--accent-red);
}

.server-log-message.imei {
    color: var(--accent-purple);
}

.server-log-message.codec {
    color: var(--accent-orange);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    color: var(--text-secondary);
}

.btn-icon:hover {
    color: var(--accent-blue);
    background: #dbeafe;
    border-color: #93c5fd;
}

.btn-primary {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

/* Select */
.select {
    padding: 8px 12px;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.select:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px #dbeafe;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Leaflet Overrides */
.leaflet-container {
    background: var(--bg-primary);
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-hover) !important;
}

.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.leaflet-popup-tip {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.leaflet-popup-content {
    margin: 12px 16px;
}

.popup-title {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--accent-blue);
}

.popup-info {
    font-size: 12px;
    color: var(--text-secondary);
}

.popup-info div {
    margin-bottom: 4px;
}
