/* ============================================================
   CSS Styles - ESP32-C3 Radar Detection System
   ============================================================ */
:root {
    --bg-primary: #0f1923;
    --bg-secondary: #1a2a3a;
    --bg-card: #1e3040;
    --bg-input: #152535;
    --text-primary: #e0e8f0;
    --text-secondary: #8899aa;
    --text-muted: #5a6a7a;
    --accent-blue: #00b4d8;
    --accent-green: #00e676;
    --accent-red: #ff1744;
    --accent-yellow: #ffd600;
    --accent-orange: #ff9100;
    --border-color: #2a4050;
    --shadow: 0 4px 20px rgba(0,0,0,0.3);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================================================
   Header
   ============================================================ */
.header {
    background: linear-gradient(135deg, #0a1628 0%, #1a2a3a 100%);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 12px;
}

.header h1 {
    font-size: 20px;
    font-weight: 600;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header .subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    -webkit-text-fill-color: var(--text-secondary);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all 0.3s;
}

.status-dot.connected { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); }
.status-dot.disconnected { background: var(--text-muted); }
.status-dot.connecting { background: var(--accent-yellow); animation: pulse 1s infinite; }

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

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-blue);
    color: #000;
}
.btn-primary:hover { background: #00c8f0; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-danger {
    background: var(--accent-red);
    color: #fff;
}
.btn-danger:hover { background: #ff2d55; }

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: var(--bg-secondary); }

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* ============================================================
   Layout
   ============================================================ */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

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

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-header .badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.card-body {
    padding: 16px 18px;
}

/* ============================================================
   Radar Visualization
   ============================================================ */
.radar-viz {
    grid-column: 1 / -1;
}

.radar-container {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}

.radar-canvas-wrapper {
    position: relative;
    flex-shrink: 0;
}

#radarCanvas {
    width: 420px;
    height: 400px;
    border-radius: 12px;
    background: radial-gradient(ellipse at 50% 100%, #0d1a2a 0%, #070e16 100%);
    border: 1px solid var(--border-color);
}

.radar-legend {
    flex: 1;
    min-width: 200px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* ============================================================
   Target Table
   ============================================================ */
.target-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.target-table th {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.target-table td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(42, 64, 80, 0.5);
    font-variant-numeric: tabular-nums;
}

.target-table tr:last-child td { border-bottom: none; }

.target-table .target-id {
    font-weight: 600;
    color: var(--accent-blue);
}

.target-table .target-range { color: var(--accent-green); }
.target-table .target-angle { color: var(--accent-yellow); }
.target-table .target-speed { color: var(--accent-orange); }

/* ============================================================
   Alert Status
   ============================================================ */
.alert-indicators {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.alert-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    transition: all 0.3s;
    min-width: 120px;
}

.alert-indicator.active {
    border-color: var(--accent-red);
    background: rgba(255, 23, 68, 0.1);
}

.alert-indicator .led {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all 0.3s;
}

.alert-indicator .led.active {
    box-shadow: 0 0 12px currentColor;
}

.alert-indicator .led.left { color: var(--accent-yellow); }
.alert-indicator .led.left.active { background: var(--accent-yellow); }
.alert-indicator .led.right { color: var(--accent-orange); }
.alert-indicator .led.right.active { background: var(--accent-orange); }
.alert-indicator .led.buzzer { color: var(--accent-red); }
.alert-indicator .led.buzzer.active { background: var(--accent-red); }

.alert-indicator .label {
    font-size: 13px;
    font-weight: 500;
}

/* ============================================================
   Form Elements
   ============================================================ */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

input, select, textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    transition: border-color 0.2s;
    font-family: inherit;
}

input:focus, select:focus { outline: none; border-color: var(--accent-blue); }
input[type="range"] { padding: 0; }
input[type="checkbox"] { width: auto; }

/* ============================================================
   Tabs
   ============================================================ */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.tab {
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

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

/* ============================================================
   Rule List
   ============================================================ */
.rule-list {
    max-height: 400px;
    overflow-y: auto;
}

.rule-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: all 0.2s;
    cursor: pointer;
}

.rule-item:hover { border-color: var(--accent-blue); }
.rule-item .rule-info { flex: 1; }
.rule-item .rule-name { font-size: 14px; font-weight: 500; }
.rule-item .rule-desc { font-size: 12px; color: var(--text-secondary); }
.rule-item .rule-toggle { font-size: 20px; cursor: pointer; }

/* ============================================================
   Log Console
   ============================================================ */
.log-console {
    background: #0a0a0a;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    height: 150px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-muted);
}

.log-console .log-info { color: var(--accent-blue); }
.log-console .log-alert { color: var(--accent-red); }
.log-console .log-data { color: var(--accent-green); }
.log-console .log-warn { color: var(--accent-yellow); }

/* ============================================================
   Stats Bar
   ============================================================ */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.stat-item {
    text-align: center;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================================
   Toast / Notifications
   ============================================================ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 13px;
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast.info { border-left: 3px solid var(--accent-blue); }
.toast.success { border-left: 3px solid var(--accent-green); }
.toast.warning { border-left: 3px solid var(--accent-yellow); }
.toast.error { border-left: 3px solid var(--accent-red); }

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

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .header { padding: 12px; }
    .header h1 { font-size: 16px; }
    .container { padding: 8px; gap: 8px; }
    .form-row { grid-template-columns: 1fr; }
    #radarCanvas { width: 300px; height: 280px; }
    .radar-container { justify-content: center; }
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   Zone Config
   ============================================================ */
.zone-config {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

.zone-card {
    padding: 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.zone-card h3 {
    font-size: 14px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.zone-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

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

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.show { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

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

.modal-body { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}