/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    line-height: 1.5;
    color: #e4e6ea;
    background: #1a1d23;
    min-height: 100vh;
    margin: 0;
    padding: 0;
}

.dashboard {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: #0a0e1a;
}

/* Header Styles */
.header {
    background: #242932;
    color: white;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #2f3349;
    grid-column: 1 / -1;
}

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

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

.logo {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    background: white;
    padding: 8px;
}

.header-text h1 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #ffffff;
}

.header-text p {
    font-size: 0.9rem;
    color: #9ca3af;
    font-weight: 400;
    margin: 0;
}

.header-right .powered-by {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    opacity: 0.8;
}

.neuron-logo {
    width: 80px;
    height: 20px;
}

/* Connection Status */
.connection-status {
    padding: 0.5rem 1rem;
    font-weight: 500;
    font-size: 0.85rem;
    grid-column: 1 / -1;
}

.connection-status.success {
    background: #10b981;
    color: #ffffff;
}

.connection-status.error {
    background: #ef4444;
    color: #ffffff;
}

/* Main Dashboard */
.main-dashboard {
    flex: 1;
    padding: 1.5rem;
    background: #0a0e1a;
}

/* KPI Header */
.kpi-header {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.kpi-module {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.3s ease;
}

.kpi-module:hover {
    border-color: #3b82f6;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.15);
}

.kpi-icon {
    font-size: 1.8rem;
    width: 50px;
    text-align: center;
}

.kpi-content {
    flex: 1;
}

.kpi-title {
    color: #e2e8f0;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.kpi-details {
    color: #64748b;
    font-size: 0.75rem;
    cursor: pointer;
}

.kpi-counts {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.kpi-count {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.count-value {
    color: #ffffff;
    font-weight: 700;
    font-size: 1.2rem;
    line-height: 1;
}

.count-label {
    color: #64748b;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-count.overdue .count-value {
    color: #ef4444;
}



.filters {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.filter-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #2f3349;
    border-radius: 4px;
    background: #1a1d23;
    color: #e4e6ea;
    font-size: 0.85rem;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: #3b82f6;
}

/* System Monitoring */
.system-monitoring {
    max-width: 1400px;
}

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

.system-header h2 {
    color: #ffffff;
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0;
}

.system-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.time-filter {
    padding: 0.5rem 1rem;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 0.85rem;
    cursor: pointer;
}

.export-btn {
    padding: 0.5rem 1rem;
    background: #3b82f6;
    border: none;
    border-radius: 6px;
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease;
}

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

/* Metrics Row */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.system-metric-card {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 1.5rem;
    transition: all 0.3s ease;
}

.system-metric-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.15);
}

.system-metric-card.blue {
    border-left: 4px solid #3b82f6;
}

.system-metric-card.green {
    border-left: 4px solid #10b981;
}

.system-metric-card.yellow {
    border-left: 4px solid #f59e0b;
}

.system-metric-card.teal {
    border-left: 4px solid #06b6d4;
}

.metric-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.metric-icon {
    font-size: 1.5rem;
}

.metric-title {
    color: #94a3b8;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-main {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.metric-value {
    color: #ffffff;
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1;
}

.metric-trend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.trend-icon {
    font-size: 1rem;
}

.trend-text {
    color: #64748b;
    font-size: 0.8rem;
}

/* Monitoring Grid */
.monitoring-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.analysis-panel {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border: 1px solid #334155;
    border-radius: 8px;
    overflow: hidden;
}

.panel-header {
    background: #0f172a;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #334155;
}

.panel-header h3 {
    color: #e2e8f0;
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.panel-content {
    padding: 1.5rem;
}

/* Permit List */
.permit-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 200px;
    overflow-y: auto;
}

.permit-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: #0a0e1a;
    border: 1px solid #1e293b;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.permit-item:hover {
    border-color: #3b82f6;
    background: #1e293b;
}

.permit-id {
    color: #64748b;
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 60px;
}

.permit-details {
    flex: 1;
}

.permit-workspace {
    color: #e2e8f0;
    font-size: 0.85rem;
    font-weight: 500;
}

.permit-date {
    color: #64748b;
    font-size: 0.75rem;
}

.permit-status {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.permit-status.active, .permit-status.completed, .permit-status.工作中 {
    background: #10b981;
    color: #ffffff;
}

.permit-status.expired, .permit-status.已拒絕申請 {
    background: #ef4444;
    color: #ffffff;
}

.permit-status.已完工 {
    background: #3b82f6;
    color: #ffffff;
}

.permit-status.註銷准許證, .permit-status.確認拒絕 {
    background: #f59e0b;
    color: #ffffff;
}

.permit-status.unknown {
    background: #6b7280;
    color: #ffffff;
}

/* Tab Content (Dark Theme) */
.tab-content {
    background: #1e293b;
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid #334155;
    text-align: center;
    font-size: 1rem;
    color: #9ca3af;
}

/* Loading and Error States (Updated) */
.loading, .error, .chart-loading {
    background: transparent;
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    font-size: 0.9rem;
    color: #9ca3af;
}

.chart-loading {
    padding: 2rem;
    color: #9ca3af;
    font-size: 0.9rem;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

.loading {
    color: #9ca3af;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 8px;
    border: 2px solid #64748b;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

.error {
    color: #ef4444;
}

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

/* Permits Analysis Styles */
.permits-analysis {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.permits-filters {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    border: 1px solid #f0f0f0;
}

.permits-filters h3 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1.2rem;
}

.filter-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.permits-table-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    border: 1px solid #f0f0f0;
    overflow: hidden;
}

.permits-table-container h3 {
    padding: 1.5rem;
    margin: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
}

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

.permits-table th {
    background: #f8f9fa;
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.permits-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e0e0e0;
    color: #666;
}

.permits-table tr:hover {
    background: #f8f9fa;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.active { background: #e8f5e8; color: #2e7d2e; }
.status-badge.completed { background: #e3f2fd; color: #1976d2; }
.status-badge.expired { background: #ffeaea; color: #c62828; }
.status-badge.unknown { background: #f5f5f5; color: #666; }

/* Safety Analytics Styles */
.safety-analytics {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.safety-overview {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    border: 1px solid #f0f0f0;
}

.safety-overview h3 {
    margin-bottom: 2rem;
    color: #333;
    font-size: 1.3rem;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.5rem;
}

.safety-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.safety-metric {
    background: #f8f9fa;
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
}

.safety-metric h4 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1.1rem;
}

.safety-metric .metric-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 0.5rem;
}

.safety-metric .metric-subtitle {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 1rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 4px;
}

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

.permits-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.permits-table th {
    background: #1a1d23;
    padding: 0.75rem 0.5rem;
    text-align: left;
    font-weight: 600;
    color: #9ca3af;
    border-bottom: 1px solid #2f3349;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.permits-table td {
    padding: 0.5rem;
    border-bottom: 1px solid #2f3349;
    color: #e4e6ea;
}

.permits-table tr:hover {
    background: #2f3349;
}

.status-badge {
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.active, .status-badge.completed, .status-badge.工作中 {
    background: #10b981;
    color: #ffffff;
}

.status-badge.expired, .status-badge.已拒絕申請 {
    background: #ef4444;
    color: #ffffff;
}

.status-badge.已完工 {
    background: #3b82f6;
    color: #ffffff;
}

.status-badge.註銷准許證, .status-badge.確認拒絕 {
    background: #f59e0b;
    color: #ffffff;
}

.status-badge.unknown {
    background: #6b7280;
    color: #ffffff;
}

/* Loading States */
.loading, .error {
    color: #9ca3af;
    padding: 1rem;
    text-align: center;
    font-size: 0.9rem;
}

.error {
    color: #ef4444;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .dashboard {
        grid-template-columns: 250px 1fr;
    }
    
    .content-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .dashboard {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
    }
    
    .sidebar {
        order: 2;
        padding: 1rem;
    }
    
    .main-content {
        order: 3;
        padding: 1rem;
    }
    
    .header {
        order: 1;
        padding: 1rem;
    }
    
    .metric-value {
        font-size: 1.5rem;
    }
}