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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
    transition: direction 0.3s ease;
}

/* RTL Support */
body[dir="rtl"] {
    direction: rtl;
}

body[dir="ltr"] {
    direction: ltr;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    background: white;
    padding: 20px 30px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

header h1 {
    color: #667eea;
    font-size: 2em;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1em;
}

.port-name {
    color: #667eea;
    font-weight: bold;
    font-size: 0.9em;
}

.stats-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    text-decoration: none;
}

.stats-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(59, 130, 246, 0.4);
}

.stats-btn svg {
    width: 18px;
    height: 18px;
}

.disconnect-btn {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.disconnect-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(239, 68, 68, 0.4);
}

.disconnect-btn svg {
    width: 18px;
    height: 18px;
}

/* Language Toggle Button */
.language-toggle-btn {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(139, 92, 246, 0.3);
}

.language-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(139, 92, 246, 0.4);
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
}

.language-toggle-btn:active {
    transform: translateY(0);
}

.language-toggle-btn svg {
    width: 18px;
    height: 18px;
}

#languageToggleText {
    font-weight: 700;
    letter-spacing: 0.5px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background-color: #10b981;
}

.status-dot.disconnected {
    background-color: #ef4444;
    animation: none;
}

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

.dashboard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

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

.card {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.card h2 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 1.5em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.card h3 {
    color: #764ba2;
    margin-bottom: 15px;
    font-size: 1.2em;
}

/* Motor Display Styles */
.motor-display {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

@media (max-width: 768px) {
    .motor-display {
        grid-template-columns: 1fr;
    }
}

.servo-section {
    text-align: center;
    padding: 15px;
    background: #f9fafb;
    border-radius: 8px;
}

.angle-display {
    font-size: 2.5em;
    font-weight: bold;
    color: #667eea;
    margin: 15px 0;
}

.direction-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin: 20px 0;
}

.direction-indicator.vertical {
    flex-direction: column;
}

.arrow {
    font-size: 2em;
    color: #d1d5db;
    transition: all 0.3s ease;
}

.arrow.active {
    color: #667eea;
    transform: scale(1.3);
    text-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}

.center-dot {
    font-size: 1.5em;
    color: #d1d5db;
    transition: all 0.3s ease;
}

.center-dot.active {
    color: #10b981;
    transform: scale(1.5);
}

.direction-label {
    font-size: 1.2em;
    font-weight: bold;
    color: #764ba2;
    margin-top: 10px;
}

/* Position Visualizer */
.position-visualizer {
    margin-top: 20px;
}

.position-grid {
    width: 100%;
    max-width: 300px;
    height: 300px;
    margin: 20px auto;
    background: linear-gradient(to right, #f3f4f6 1px, transparent 1px),
                linear-gradient(to bottom, #f3f4f6 1px, transparent 1px);
    background-size: 30px 30px;
    border: 2px solid #667eea;
    border-radius: 8px;
    position: relative;
}

.position-marker {
    width: 20px;
    height: 20px;
    background: #667eea;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.5s ease;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.6);
}

.grid-labels {
    position: absolute;
    width: 100%;
    height: 100%;
}

.grid-labels span {
    position: absolute;
    font-weight: bold;
    color: #764ba2;
}

.label-top { top: -25px; left: 50%; transform: translateX(-50%); }
.label-bottom { bottom: -25px; left: 50%; transform: translateX(-50%); }
.label-left { left: -40px; top: 50%; transform: translateY(-50%); }
.label-right { right: -45px; top: 50%; transform: translateY(-50%); }

/* Light Sensors Styles */
.light-readings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.light-sensor {
    background: #f9fafb;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.light-sensor.average {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.sensor-label {
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 0.9em;
    text-transform: uppercase;
}

.sensor-value {
    font-size: 1.8em;
    font-weight: bold;
    margin-bottom: 10px;
}

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

.light-sensor.average .sensor-bar {
    background: rgba(255, 255, 255, 0.3);
}

.sensor-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
    border-radius: 4px;
}

.light-sensor.average .sensor-bar-fill {
    background: white;
}

/* Chart Container */
.chart-container {
    margin-top: 20px;
    padding: 20px;
    background: #f9fafb;
    border-radius: 8px;
}

#lightChart {
    max-height: 300px;
}

/* Footer */
footer {
    background: white;
    padding: 15px 30px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 20px;
}

footer p {
    margin: 5px 0;
    color: #6b7280;
}

footer span {
    font-weight: bold;
    color: #667eea;
}

/* ============================================
   PORT SELECTOR PANEL STYLES
   ============================================ */

.port-selector-panel {
    background: white;
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    direction: rtl;
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
}

.port-selector-header {
    text-align: center;
    margin-bottom: 30px;
    position: relative;
}

.port-selector-header h2 {
    color: #667eea;
    font-size: 1.8em;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.port-selector-header h2 svg {
    width: 32px;
    height: 32px;
}

.port-selector-header p {
    color: #6b7280;
    font-size: 1.1em;
    margin-bottom: 20px;
}

.refresh-ports-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.refresh-ports-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.refresh-ports-btn svg {
    width: 18px;
    height: 18px;
}

.ports-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
}

.port-item {
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.port-item:hover {
    border-color: #667eea;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.2);
    transform: translateY(-2px);
}

.port-item.arduino-port {
    border-color: #10b981;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(5, 150, 105, 0.05) 100%);
}

.port-info {
    flex: 1;
}

.port-path {
    font-size: 1.2em;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.arduino-badge {
    background: #10b981;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.7em;
    font-weight: 600;
}

.port-details {
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: #6b7280;
    font-size: 0.9em;
}

.connect-port-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.connect-port-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.connect-port-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.port-item.arduino-port .connect-port-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.port-item.arduino-port .connect-port-btn:hover {
    box-shadow: 0 5px 15px rgba(16, 185, 129, 0.4);
}

.loading-ports,
.no-ports,
.error-ports {
    text-align: center;
    padding: 40px;
    color: #6b7280;
    font-size: 1.1em;
}

.no-ports svg,
.error-ports svg {
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
    color: #9ca3af;
}

.no-ports p,
.error-ports p {
    margin-bottom: 20px;
    font-size: 1.2em;
}

.refresh-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
}

.refresh-btn:hover {
    background: #5568d3;
    transform: translateY(-2px);
}

/* Notification styles */
.notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: white;
    padding: 15px 30px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    font-weight: 600;
    font-size: 1.1em;
}

.notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.notification-success {
    border-right: 5px solid #10b981;
    color: #059669;
}

.notification-error {
    border-right: 5px solid #ef4444;
    color: #dc2626;
}

.notification-info {
    border-right: 5px solid #3b82f6;
    color: #2563eb;
}

/* ============================================
   DATA TABLE STYLES
   ============================================ */

.data-table-card {
    margin-top: 20px;
}

.data-table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 15px;
}

.data-table-header h2 {
    color: #667eea;
    font-size: 1.5em;
    margin: 0;
}

.export-csv-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.export-csv-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(16, 185, 129, 0.4);
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

.export-csv-btn:active {
    transform: translateY(0);
}

.export-csv-btn svg {
    width: 20px;
    height: 20px;
}

.data-table-info {
    display: flex;
    gap: 30px;
    margin-bottom: 15px;
    padding: 12px 15px;
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    border-radius: 8px;
    font-size: 0.95em;
    color: #4b5563;
}

.data-table-info strong {
    color: #667eea;
    font-weight: 700;
}

.data-table-container {
    max-height: 500px;
    overflow-y: auto;
    overflow-x: auto;
    border-radius: 8px;
    border: 2px solid #e5e7eb;
    background: white;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.data-table thead th {
    padding: 15px 12px;
    text-align: center;
    font-weight: 600;
    font-size: 0.95em;
    border-bottom: 3px solid #5a67d8;
    white-space: nowrap;
}

.data-table tbody tr {
    transition: all 0.2s ease;
    border-bottom: 1px solid #e5e7eb;
}

.data-table tbody tr:hover {
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
}

.data-table tbody tr.new-row {
    animation: highlightRow 1s ease;
}

@keyframes highlightRow {
    0% {
        background: #dbeafe;
    }
    100% {
        background: transparent;
    }
}

.data-table tbody td {
    padding: 12px;
    text-align: center;
    color: #374151;
    border-right: 1px solid #f3f4f6;
}

.data-table tbody td:first-child {
    font-weight: 600;
    color: #667eea;
    white-space: nowrap;
}

.data-table tbody td:last-child {
    border-right: none;
}

.data-table .no-data-row td {
    padding: 40px;
    text-align: center;
    color: #9ca3af;
    font-style: italic;
    font-size: 1.1em;
}

/* Scrollbar styling for data table */
.data-table-container::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.data-table-container::-webkit-scrollbar-track {
    background: #f3f4f6;
    border-radius: 5px;
}

.data-table-container::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 5px;
}

.data-table-container::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46a0 100%);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .port-item {
        flex-direction: column;
        gap: 15px;
    }

    .connect-port-btn {
        width: 100%;
    }

    .port-selector-header h2 {
        font-size: 1.4em;
    }

    .data-table-header {
        flex-direction: column;
        align-items: stretch;
    }

    .export-csv-btn {
        width: 100%;
        justify-content: center;
    }

    .data-table-info {
        flex-direction: column;
        gap: 10px;
    }

    .data-table {
        font-size: 0.85em;
    }

    .data-table thead th,
    .data-table tbody td {
        padding: 10px 8px;
    }

    .data-table-container {
        max-height: 400px;
    }
}
