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

:root {
    --primary: #3498db;
    --primary-dark: #2980b9;
    --success: #27ae60;
    --danger: #e74c3c;
    --warning: #f39c12;
    --dark: #2c3e50;
    --light: #ecf0f1;
    --gray: #95a5a6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--light);
    color: var(--dark);
    line-height: 1.6;
}

/* ============================================
   LOGIN
   ============================================ */

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 5px;
}

.login-box .subtitle {
    text-align: center;
    color: var(--gray);
    margin-bottom: 30px;
}

/* ============================================
   FORMS
   ============================================ */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

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

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

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

.error-message {
    background: #fce4e4;
    color: var(--danger);
    padding: 10px;
    border-radius: 4px;
    margin-top: 15px;
    text-align: center;
}

/* ============================================
   DASHBOARD LAYOUT
   ============================================ */

.dashboard {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--dark);
    color: white;
    padding: 20px;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar h2 {
    font-size: 20px;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar nav a {
    display: block;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    padding: 10px 15px;
    border-radius: 4px;
    margin-bottom: 5px;
    transition: all 0.2s;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background: rgba(255,255,255,0.1);
    color: white;
}

.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 20px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #ddd;
}

.header h1 {
    font-size: 24px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* ============================================
   CARDS & STATS
   ============================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.stat-card h3 {
    font-size: 14px;
    color: var(--gray);
    margin-bottom: 10px;
}

.stat-card .value {
    font-size: 32px;
    font-weight: bold;
}

.stat-card.online .value {
    color: var(--success);
}

.stat-card.offline .value {
    color: var(--danger);
}

/* ============================================
   DEVICE LIST
   ============================================ */

.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.device-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
}

.device-card .device-header {
    padding: 15px 20px;
    background: var(--dark);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.device-card .device-header h3 {
    font-size: 16px;
}

.device-card .status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
}

.device-card .status.online {
    background: var(--success);
}

.device-card .device-body {
    padding: 20px;
}

.device-card .device-info {
    font-size: 13px;
    color: var(--gray);
    margin-bottom: 15px;
}

.device-card .device-info p {
    margin-bottom: 5px;
}

.badge-model {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.device-card .device-sensors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 15px;
}

.device-card .sensor {
    background: var(--light);
    padding: 10px;
    border-radius: 4px;
    text-align: center;
}

.device-card .sensor .label {
    font-size: 11px;
    color: var(--gray);
}

.device-card .sensor .value {
    font-size: 18px;
    font-weight: bold;
}

.device-card .sensor-group {
    grid-column: 1 / -1;
    background: var(--light);
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 5px;
}

.device-card .sensor-group .sensor-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 8px;
    padding-bottom: 5px;
    border-bottom: 1px solid #ddd;
}

.device-card .sensor-group .sensor-values {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.device-card .sensor-group .sensor {
    background: white;
    padding: 8px;
    border-radius: 4px;
    text-align: center;
}

.device-card .sensor-group .sensor .value {
    font-size: 16px;
}

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

.device-card .device-actions .btn {
    flex: 1;
}

/* ============================================
   MODAL
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ============================================
   TABLES
   ============================================ */

.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
}

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

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

th {
    background: var(--light);
    font-weight: 600;
}

tr:hover {
    background: #f8f9fa;
}

/* ============================================
   TABS
   ============================================ */

.tabs {
    display: flex;
    border-bottom: 2px solid #ddd;
    margin-bottom: 20px;
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

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

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============================================
   UTILITIES
   ============================================ */

.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-gray { color: var(--gray); }

.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }

.hidden { display: none; }

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .main-content {
        margin-left: 0;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .device-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   DETECTION STATS PANEL
   ============================================ */

.detection-stats-panel {
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.stats-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    min-width: 80px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    transition: all 0.3s;
}

.stat-card.active {
    background: rgba(231, 76, 60, 0.2);
    border: 1px solid #e74c3c;
}

.stat-icon {
    font-size: 20px;
    display: block;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 11px;
    color: #888;
    display: block;
}

.stat-value {
    font-size: 16px;
    font-weight: bold;
    color: #00ff88;
}

.stat-value.on {
    color: #e74c3c;
    animation: pulse 1s infinite;
}

.stat-value.off {
    color: #888;
}

.detection-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    margin-bottom: 15px;
    transition: all 0.3s;
}

.detection-badge.detected {
    background: rgba(231, 76, 60, 0.2);
    border: 2px solid #e74c3c;
}

.detection-badge.idle {
    border: 2px solid transparent;
}

.badge-icon {
    font-size: 32px;
}

.badge-text {
    font-size: 18px;
    font-weight: bold;
    color: #fff;
}

.counters {
    justify-content: center;
}

.counter-card {
    background: rgba(0, 255, 136, 0.1);
    border-radius: 8px;
    padding: 15px 20px;
    text-align: center;
    min-width: 70px;
}

.counter-card.mouse {
    background: rgba(52, 152, 219, 0.1);
}

.counter-card.cat {
    background: rgba(155, 89, 182, 0.1);
}

.counter-icon {
    font-size: 20px;
    display: block;
}

.counter-value {
    font-size: 28px;
    font-weight: bold;
    color: #00ff88;
    display: block;
}

.counter-card.mouse .counter-value {
    color: #3498db;
}

.counter-card.cat .counter-value {
    color: #9b59b6;
}

.counter-label {
    font-size: 11px;
    color: #888;
}

.last-detection {
    text-align: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    font-size: 13px;
    color: #888;
}

.last-detection .value {
    color: #00ff88;
    font-weight: bold;
}

.last-detection .animal {
    font-size: 18px;
    margin-left: 5px;
}

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

/* Panel Control Stats */
.panel-gpio-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    margin-bottom: 12px;
    color: #888;
}

.panel-gpio-status.active {
    background: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
    animation: pulse 1s infinite;
}

.panel-gpio-status .status-icon {
    font-size: 18px;
}

.panel-metrics {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.panel-metrics .metric {
    flex: 1;
    text-align: center;
    background: rgba(0, 255, 136, 0.1);
    padding: 10px;
    border-radius: 6px;
}

.panel-metrics .metric-value {
    font-size: 24px;
    font-weight: bold;
    color: #00ff88;
}

.panel-metrics .metric-unit {
    font-size: 12px;
    color: #888;
}

.panel-metrics .metric-label {
    display: block;
    font-size: 10px;
    color: #888;
    margin-top: 3px;
}

.panel-detection-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    margin-bottom: 12px;
}

.panel-detection-status.detected {
    background: rgba(231, 76, 60, 0.2);
    border: 1px solid #e74c3c;
}

.panel-detection-status .detection-icon {
    font-size: 24px;
}

.panel-detection-status .detection-text {
    font-weight: bold;
    color: #fff;
}

.panel-counters {
    display: flex;
    justify-content: center;
    gap: 15px;
    font-size: 13px;
    color: #888;
}

.panel-counters strong {
    color: #00ff88;
}

/* Ultrasonic Card */
.ultrasonic-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
}

.ultrasonic-header {
    padding: 15px 20px;
    background: var(--dark);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ultrasonic-header h4 {
    margin: 0;
    font-size: 14px;
}

.ultrasonic-config {
    padding: 15px 20px;
}

.ultrasonic-config .config-row {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.ultrasonic-config .config-row label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.ultrasonic-config .config-row input[type="number"],
.ultrasonic-config .config-row select {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.ultrasonic-config .config-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.ultrasonic-config .config-section h5 {
    margin: 0 0 10px 0;
    font-size: 13px;
    color: var(--gray);
    text-transform: uppercase;
}

/* Animal Detection Icons */
.animal-icon {
    font-size: 24px;
    margin-right: 10px;
}

.animal-cat::before { content: "🐱"; }
.animal-mouse::before { content: "🐭"; }
.animal-unknown::before { content: "❓"; }

/* ============================================
   CONTROL PANEL
   ============================================ */

.control-panel-overlay {
    background: rgba(0, 0, 0, 0.8);
}

.control-panel-modal {
    background: #1a1a2e;
    border-radius: 12px;
    width: 95%;
    max-width: 1000px;
    max-height: 95vh;
    overflow-y: auto;
    color: #fff;
}

.control-panel-modal .modal-header {
    background: #16213e;
    border-bottom: 1px solid #0f3460;
    padding: 15px 20px;
}

.control-panel-modal .modal-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--danger);
    display: inline-block;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

.control-panel-body {
    padding: 20px;
}

.control-panel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.panel-section {
    background: #16213e;
    border-radius: 8px;
    padding: 20px;
}

.panel-section h3 {
    font-size: 14px;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #0f3460;
}

/* Radar in Panel */
.radar-section .radar-display {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
}

.radar-section #controlRadarCanvas {
    border-radius: 50%;
    background: radial-gradient(circle, #0f3460 0%, #1a1a2e 100%);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.2);
}

.radar-stats {
    display: flex;
    justify-content: space-around;
    text-align: center;
}

.radar-stats .stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.radar-stats .stat-label {
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
}

.radar-stats .stat-value {
    font-size: 18px;
    font-weight: bold;
    color: #00ff88;
    font-family: 'Courier New', monospace;
}

.detection-badge {
    padding: 4px 12px;
    border-radius: 12px;
    background: rgba(39, 174, 96, 0.2);
    color: #27ae60 !important;
    font-size: 12px !important;
}

.detection-badge.detected {
    background: rgba(231, 76, 60, 0.3);
    color: #e74c3c !important;
    animation: pulse 1s infinite;
}

/* Sensor Cards */
.sensor-cards {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.sensor-card-large {
    background: #0f3460;
    border-radius: 8px;
    padding: 15px;
}

.sensor-card-name {
    font-size: 12px;
    color: #888;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.sensor-card-values {
    display: flex;
    justify-content: space-around;
}

.sensor-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sensor-icon {
    font-size: 28px;
}

.sensor-data {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.sensor-value {
    font-size: 32px;
    font-weight: bold;
    color: #fff;
}

.sensor-unit {
    font-size: 16px;
    color: #888;
}

/* GPIO Controls Grid */
.gpio-controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
}

.gpio-control-card {
    background: #0f3460;
    border-radius: 8px;
    overflow: hidden;
}

.gpio-control-card.gpio-input {
    opacity: 0.8;
}

.gpio-control-header {
    background: #16213e;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gpio-name {
    font-weight: 600;
    font-size: 14px;
}

.gpio-pin {
    font-size: 11px;
    color: #888;
}

.gpio-control-body {
    padding: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60px;
}

/* Toggle Switch */
.switch-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #2c3e50;
    transition: .3s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .3s;
}

input:checked + .slider {
    background-color: var(--success);
    box-shadow: 0 0 15px var(--success);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.switch-label {
    font-size: 14px;
    font-weight: bold;
    color: var(--danger);
}

.switch-label.on {
    color: var(--success);
}

/* PWM Slider */
.pwm-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pwm-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: #2c3e50;
    outline: none;
}

.pwm-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 0 10px var(--primary);
}

.pwm-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

.pwm-value {
    text-align: center;
    font-family: 'Courier New', monospace;
}

.pwm-value span:first-child {
    font-size: 24px;
    font-weight: bold;
}

.pwm-percent {
    font-size: 12px;
    color: #888;
    margin-left: 5px;
}

/* Input Display */
.input-display {
    width: 100%;
}

.analog-display {
    width: 100%;
}

.analog-bar {
    width: 100%;
    height: 10px;
    background: #2c3e50;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 8px;
}

.analog-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    transition: width 0.3s;
}

.analog-value {
    display: block;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 18px;
}

.digital-display {
    padding: 10px 25px;
    border-radius: 4px;
    background: rgba(231, 76, 60, 0.2);
    color: var(--danger);
    font-weight: bold;
    font-size: 14px;
}

.digital-display.high {
    background: rgba(39, 174, 96, 0.2);
    color: var(--success);
}

/* Empty State */
.panel-empty {
    text-align: center;
    padding: 40px;
    color: #888;
}

.panel-empty p {
    margin-bottom: 20px;
}

/* Responsive */
@media (max-width: 768px) {
    .control-panel-grid {
        grid-template-columns: 1fr;
    }

    .gpio-controls-grid {
        grid-template-columns: 1fr;
    }
}
