/* Root Variables */
:root {
    --primary-color: #4F46E5; /* soft indigo */
    --secondary-color: #7C3AED; /* periwinkle purple */
    --success-color: #16A185; /* muted green */
    --danger-color: #EF5F6B;  /* soft red */
    --warning-color: #F59E0B;
    --info-color: #3B82F6;
    --dark-color: #1F2937;
    --light-color: #F9FAFB;
    --border-color: #E5E7EB;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --sidebar-width: 260px;
    --transition-speed: 0.3s;
}

/* Reset and Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Poppins', 'Segoe UI', sans-serif;
    background:
        radial-gradient(circle at top left, rgba(79, 70, 229, 0.08), transparent 58%),
        radial-gradient(circle at bottom right, rgba(129, 140, 248, 0.10), transparent 60%),
        #F6F7FB;
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: #ffffff;
    color: #0f172a;
    padding: 20px;
    overflow-y: auto;
    z-index: 1000;
    transition: transform var(--transition-speed);
    box-shadow: 4px 0 18px rgba(15, 23, 42, 0.06);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
    padding-bottom: 10px;
}

.sidebar-header .logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #111827;
}

.nav-menu {
    list-style: none;
}

.nav-menu li {
    margin-bottom: 5px;
}

.nav-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: rgba(15, 23, 42, 0.70);
    text-decoration: none;
    border-radius: 10px;
    transition: all var(--transition-speed);
}

.nav-menu a:hover {
    background: rgba(129, 140, 248, 0.10);
    color: #111827;
    transform: translateX(4px);
}

.nav-menu li.active a {
    color: #ffffff;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    box-shadow: 0 10px 28px rgba(79, 70, 229, 0.35);
}

.sidebar-footer {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-bottom: 10px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.user-details {
    flex: 1;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.user-role {
    font-size: 0.75rem;
    opacity: 0.8;
}

.btn-logout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--transition-speed);
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.8);
    color: rgba(239, 68, 68, 0.95);
}

.btn-collector-portal {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    color: var(--primary-color);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all var(--transition-speed);
}

.btn-collector-portal:hover {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border-color: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 32px 32px 40px;
    min-height: 100vh;
    background:
        radial-gradient(circle at top, rgba(148, 163, 184, 0.16), transparent 60%),
        linear-gradient(to bottom right, #F7F8FC, #EFF3FF);
    box-shadow: none;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    position: static;
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin-top: 20px;
    margin-left: 20px;
    margin-bottom: 20px;
    margin-right: 20px;
}

.mobile-menu-toggle span {
    width: 20px;
    height: 2px;
    background: white;
    transition: all var(--transition-speed);
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

.mobile-menu-close {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: var(--danger-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: white;
    font-size: 24px;
    font-weight: bold;
    align-items: center;
    justify-content: center;
    z-index: 1002;
    transition: all var(--transition-speed);
}

.mobile-menu-close.active {
    display: flex;
}

.mobile-menu-close:hover {
    background: #dc2626;
    transform: scale(1.05);
}

/* Connection Status */
.connection-status {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 10px 20px;
    background: var(--success-color);
    color: white;
    border-radius: 8px;
    font-size: 0.85rem;
    display: none;
    align-items: center;
    gap: 8px;
    z-index: 999;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    user-select: none;
}

.connection-status:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.connection-status.connected {
    display: flex;
    background: var(--success-color);
}

.connection-status.disconnected {
    display: flex;
    background: var(--danger-color);
}

.connection-status .status-dot {
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s infinite;
}

.connection-status .retry-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    border-radius: 4px;
    padding: 2px 8px;
    margin-left: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s;
}

.connection-status .retry-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(180deg);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.9); }
}

/* Cards */
.card {
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    margin-bottom: 22px;
    border: none;
    overflow: hidden;
}

/* Keep non-KPI cards white on hover */
.card:hover {
    background: #ffffff;
}

.card-header {
    padding: 16px 22px;
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
}

.card-body {
    padding: 18px 22px 20px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all var(--transition-speed);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #4338CA;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

.btn-secondary {
    background: var(--text-secondary);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #4B5563;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #059669;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #DC2626;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--primary-color);
    color: white;
}

.badge-primary {
    background: var(--primary-color);
}

.badge-success {
    background: var(--success-color);
}

.badge-info {
    background: #3B82F6 !important;
    color: #ffffff !important;
}

.badge-warning {
    background: #FBBF24 !important;
    color: #1F2937 !important;
}

.badge-danger {
    background: var(--danger-color);
}

.badge-secondary {
    background: var(--text-secondary);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    max-height: 380px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: #ffffff;
}

.data-table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid rgba(229, 231, 235, 0.8);
    font-size: 0.9rem;
}

.data-table tbody tr:nth-child(even) {
    background: #f9fafb;
}

.data-table tbody tr:hover {
    background: #eef2ff;
}

.cell-truncate {
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loading-row td {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: all var(--transition-speed);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

/* Messages */
.message {
    padding: 12px;
    border-radius: 8px;
    margin: 15px 0;
    font-size: 0.9rem;
}

.message.success {
    background: #D1FAE5;
    color: #065F46;
    border: 1px solid #34D399;
}

.message.error {
    background: #FEE2E2;
    color: #991B1B;
    border: 1px solid #F87171;
}

.message.warning {
    background: #FEF3C7;
    color: #92400E;
    border: 1px solid #FCD34D;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-secondary); }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
