/* Enhanced Real-time Dashboard Styles */

:root {
    --primary: #3b82f6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #1a1a2e;
    --darker: #16213e;
    --light: #f8fafc;
    --gray: #6b7280;
    --border: #374151;
}

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

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: radial-gradient(circle at top left, #1e2748 0%, #181d35 45%, #111427 100%);
    color: var(--light);
    overflow-x: hidden;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* Auth Screen */
.auth-screen {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 24, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    padding: 1.5rem;
}

.auth-screen.active {
    display: flex;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--darker);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 2rem;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
    display: grid;
    gap: 1rem;
}

.auth-card h2 {
    margin-bottom: 0.25rem;
}

.auth-form {
    display: grid;
    gap: 0.75rem;
}

.auth-form label {
    display: grid;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--gray);
}

.auth-form input {
    background: var(--dark);
    border: 1px solid var(--border);
    color: var(--light);
    padding: 0.75rem;
    border-radius: 0.5rem;
}

.link-btn {
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
    text-align: left;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    inset: 0;
    background: var(--dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Header */
.header {
    background: var(--darker);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray);
}

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

.status-dot.connected {
    background: var(--success);
}

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

.header-right {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.user-pill {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.4);
    color: var(--primary);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.view-toggle, .notification-btn {
    background: var(--dark);
    border: 1px solid var(--border);
    color: var(--light);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.view-toggle:hover, .notification-btn:hover {
    background: var(--border);
}

.notification-btn {
    position: relative;
    padding: 0.5rem 0.75rem;
}

.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: white;
    font-size: 0.75rem;
    padding: 0.125rem 0.375rem;
    border-radius: 1rem;
    font-weight: 600;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.stat-card {
    background: var(--darker);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-icon {
    font-size: 2rem;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.5rem;
    background: rgba(59, 130, 246, 0.1);
}

.stat-delivered .stat-icon { background: rgba(16, 185, 129, 0.1); }
.stat-transit .stat-icon { background: rgba(59, 130, 246, 0.1); }
.stat-pending .stat-icon { background: rgba(245, 158, 11, 0.1); }
.stat-active .stat-icon { background: rgba(139, 92, 246, 0.1); }

.stat-content {
    flex: 1;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray);
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--light);
}

/* Map Container */
.map-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem 1.5rem;
}

.map-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.map-header h2 {
    font-size: 1.25rem;
}

.map-controls {
    display: flex;
    gap: 0.5rem;
}

.map-btn {
    background: var(--darker);
    border: 1px solid var(--border);
    color: var(--light);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.map-btn:hover {
    background: var(--border);
}

.map {
    height: 500px;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--border);
}

.map-legend {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    padding: 1rem;
    background: var(--darker);
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.legend-marker {
    width: 32px;
    height: 32px;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* Deliveries Section */
.deliveries-section {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem 2rem;
}

/* Admin Panel */
.admin-panel {
    max-width: 1400px;
    margin: 0 auto 2rem;
    padding: 0 1.5rem;
    display: none;
}

/* Reporting */
.reporting-section {
    max-width: 1400px;
    margin: 0 auto 2rem;
    padding: 0 1.5rem;
}

.report-summary {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    margin-bottom: 1rem;
}

.reporting-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.reporting-filters input,
.reporting-filters select {
    background: var(--dark);
    border: 1px solid var(--border);
    color: var(--light);
    padding: 0.45rem 0.6rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
}

.report-table {
    background: var(--darker);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow: hidden;
}

.report-row {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr)) 1.2fr;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

@media (max-width: 720px) {
    .report-row {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
    .report-row span:nth-child(n + 6) {
        display: none;
    }
}

.report-row:last-child {
    border-bottom: none;
}

.report-row.report-header {
    background: rgba(59, 130, 246, 0.15);
    font-weight: 600;
}

.admin-panel.active {
    display: block;
}

.admin-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.admin-users h3 {
    margin-bottom: 0.75rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1.25rem;
}

.filter-tabs {
    display: flex;
    gap: 0.5rem;
    background: var(--darker);
    padding: 0.25rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}

.filter-tab {
    background: transparent;
    border: none;
    color: var(--gray);
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.filter-tab:hover {
    color: var(--light);
}

.filter-tab.active {
    background: var(--primary);
    color: white;
}

.deliveries-list {
    display: grid;
    gap: 1rem;
}

.delivery-card {
    background: var(--darker);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
    transition: transform 0.2s;
}

.delivery-card:hover {
    transform: translateX(4px);
}

.delivery-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 1rem;
}

.delivery-info h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

.delivery-person {
    color: var(--gray);
    font-size: 0.875rem;
}

.status-badge {
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.status-delivered { background: rgba(16, 185, 129, 0.2); color: #10b981; }
.status-in_transit { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.status-picked_up { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.status-pending { background: rgba(107, 114, 128, 0.2); color: #9ca3af; }
.status-failed { background: rgba(239, 68, 68, 0.2); color: #ef4444; }

.delivery-details {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.detail-row {
    display: flex;
    align-items: start;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.detail-icon {
    color: var(--gray);
    margin-top: 0.125rem;
}

.detail-text {
    flex: 1;
    color: var(--gray);
}

.delivery-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    gap: 0.75rem;
    flex-wrap: wrap;
}

.delivery-time {
    color: var(--gray);
    font-size: 0.875rem;
}

.delivery-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.action-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--light);
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.action-btn:hover {
    background: var(--border);
}

/* Delivery Form */
.delivery-form-container {
    max-width: 800px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.delivery-form-container h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

.delivery-form {
    background: var(--darker);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    background: var(--dark);
    border: 1px solid var(--border);
    color: var(--light);
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.location-btn {
    margin-top: 0.5rem;
    background: var(--primary);
    border: none;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: opacity 0.2s;
}

.location-btn:hover {
    opacity: 0.9;
}

.location-info {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    color: var(--success);
    display: none;
}

.location-info.active {
    display: block;
}

.submit-btn {
    width: 100%;
    background: var(--primary);
    border: none;
    color: white;
    padding: 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: opacity 0.2s;
}

.submit-btn:hover:not(:disabled) {
    opacity: 0.9;
}

.submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* My Deliveries */
.my-deliveries-section {
    margin-top: 2rem;
}

.my-deliveries-section h3 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

.my-deliveries-list {
    display: grid;
    gap: 1rem;
}

/* Notification Panel */
.notification-panel {
    position: fixed;
    right: -400px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: var(--darker);
    border-left: 1px solid var(--border);
    z-index: 1000;
    transition: right 0.3s;
    display: flex;
    flex-direction: column;
}

.notification-panel.active {
    right: 0;
}

.notification-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notification-header h3 {
    font-size: 1.25rem;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--gray);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.close-btn:hover {
    color: var(--light);
}

.notifications-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.notification-item {
    padding: 1rem;
    background: var(--dark);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
}

.notification-item.unread {
    border-color: var(--primary);
}

.notification-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.notification-message {
    color: var(--gray);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.notification-time {
    color: var(--gray);
    font-size: 0.75rem;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--darker);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem 1.5rem;
    min-width: 300px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease-out;
}

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

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

/* Responsive */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .map {
        height: 400px;
    }

    .filter-tabs {
        flex-wrap: wrap;
    }

    .notification-panel {
        width: 100%;
        right: -100%;
    }

    .header-left,
    .header-right {
        width: 100%;
        justify-content: space-between;
    }

    .view-toggle,
    .notification-btn {
        flex: 1 1 auto;
        justify-content: center;
    }

    .delivery-form {
        padding: 1.5rem;
    }

    .auth-card {
        padding: 1.5rem;
    }
}

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

    .header-content {
        padding: 0.75rem 1rem;
    }

    .map {
        height: 320px;
    }

    .deliveries-section,
    .map-container,
    .delivery-form-container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .delivery-footer {
        flex-direction: column;
        align-items: flex-start;
    }
}
