/* History Modal Styles - Updated with Server-side Filtering Support */
.history-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.history-modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.history-modal {
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 10px;
    width: 92vw;
    max-width: 1500px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

.history-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid #333;
    background: #0f0f0f;
    border-radius: 10px 10px 0 0;
}

.history-modal-header h2 {
    margin: 0;
    color: #00cc66;
    font-size: 18px;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 10px;
}

.history-close-btn {
    background: transparent;
    border: 1px solid #444;
    color: #888;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-close-btn:hover {
    background: #333;
    color: #fff;
    border-color: #666;
}

/* Filters */
.history-filters {
    padding: 14px 24px;
    background: #151515;
    border-bottom: 1px solid #333;
}

.filter-row {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 140px;
}

.filter-group label {
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Custom dropdown overrides for history modal */
.history-dropdown {
    min-width: 150px;
}

.history-dropdown .dropdown-toggle {
    padding: 8px 12px;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 5px;
    font-size: 13px;
}

.history-dropdown .dropdown-toggle:hover {
    border-color: #666;
    background: #222;
}

.history-dropdown .dropdown-toggle.active {
    border-color: #00cc66;
}

.history-dropdown .dropdown-menu {
    background: #1a1a1a;
    border-color: #00cc66;
    max-height: 300px;
    overflow-y: auto;
    z-index: 10001;
}

/* Message dropdown needs more width */
#filter-message {
    min-width: 180px;
}

#filter-message .dropdown-menu {
    min-width: 250px;
    max-height: 350px;
}

#filter-message .dropdown-item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Dropdown scrollbar */
.history-dropdown .dropdown-menu::-webkit-scrollbar {
    width: 6px;
}

.history-dropdown .dropdown-menu::-webkit-scrollbar-track {
    background: #1a1a1a;
    border-radius: 3px;
}

.history-dropdown .dropdown-menu::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

.history-dropdown .dropdown-menu::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.history-dropdown .dropdown-item {
    padding: 10px 12px;
    font-size: 13px;
    border-bottom-color: #2a2a2a;
}

.history-dropdown .dropdown-item:hover {
    background: #2a2a2a;
}

.history-dropdown .dropdown-item.selected {
    background: #003322;
    color: #00cc66;
}

.filter-actions {
    flex-direction: row;
    margin-left: auto;
    min-width: auto;
}

/* Custom time range controls */
.custom-time-group {
    min-width: 180px;
}

.custom-time-input {
    padding: 8px 12px;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 5px;
    color: #e0e0e0;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s;
    color-scheme: dark;
}

.custom-time-input:hover {
    border-color: #666;
}

.custom-time-input:focus {
    outline: none;
    border-color: #00cc66;
}

.custom-time-input::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s, filter 0.2s;
    /* Force white: make black first, then invert to white */
    filter: brightness(0) saturate(100%) invert(1);
}

.custom-time-input::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
    filter: brightness(0) saturate(100%) invert(1) brightness(1.2);
}

.custom-time-input::-webkit-datetime-edit {
    color: #e0e0e0;
}

.custom-time-input::-webkit-datetime-edit-fields-wrapper {
    color: #e0e0e0;
}

.custom-time-input::-webkit-datetime-edit-text {
    color: #666;
}

.custom-time-input::-webkit-datetime-edit-month-field,
.custom-time-input::-webkit-datetime-edit-day-field,
.custom-time-input::-webkit-datetime-edit-year-field,
.custom-time-input::-webkit-datetime-edit-hour-field,
.custom-time-input::-webkit-datetime-edit-minute-field,
.custom-time-input::-webkit-datetime-edit-ampm-field {
    color: #e0e0e0;
}

.custom-time-input::-webkit-datetime-edit-month-field:focus,
.custom-time-input::-webkit-datetime-edit-day-field:focus,
.custom-time-input::-webkit-datetime-edit-year-field:focus,
.custom-time-input::-webkit-datetime-edit-hour-field:focus,
.custom-time-input::-webkit-datetime-edit-minute-field:focus,
.custom-time-input::-webkit-datetime-edit-ampm-field:focus {
    background: #00cc66;
    color: #000;
}

.filter-btn.refresh,
.filter-btn.export {
    padding: 7px 14px;
    background: transparent;
    border: 1px solid #444;
    color: #888;
    border-radius: 5px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.filter-btn.refresh:hover,
.filter-btn.export:hover {
    background: rgba(0, 204, 102, 0.1);
    border-color: #00cc66;
    color: #00cc66;
}

.filter-btn.export:disabled,
.filter-btn.refresh:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

/* Stats bar with metadata */
.history-stats {
    padding: 8px 24px;
    background: #121212;
    border-bottom: 1px solid #333;
    font-size: 12px;
    color: #888;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

#log-count {
    min-width: 100px;
}

.log-metadata {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
    font-size: 11px;
}

.log-metadata i {
    color: #00cc66;
}

.log-metadata strong {
    color: #00cc66;
}

/* Content */
.history-content {
    flex: 1;
    overflow: auto;
    position: relative;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 15, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    color: #00cc66;
}

.loading-spinner i {
    font-size: 48px;
    animation: spin 1s linear infinite;
}

.loading-spinner span {
    font-size: 14px;
    color: #888;
}

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

/* Disabled filters state */
.history-filters.disabled {
    pointer-events: none;
    opacity: 0.5;
}

.history-filters.disabled .dropdown-toggle,
.history-filters.disabled .filter-btn {
    cursor: not-allowed;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.history-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.history-table th {
    background: #0f0f0f;
    color: #888;
    font-weight: 500;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid #333;
    text-transform: uppercase;
    font-size: 11px;
}

.history-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #252525;
    vertical-align: middle;
}

.history-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.history-table tr.log-error {
    background: rgba(255, 68, 68, 0.08);
}

.history-table tr.log-warn {
    background: rgba(255, 170, 0, 0.06);
}

.history-table tr.log-debug {
    background: rgba(100, 100, 100, 0.06);
}

/* Level Badge */
.log-level-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.log-level-badge.info {
    background: rgba(0, 204, 102, 0.15);
    color: #00cc66;
}

.log-level-badge.warn {
    background: rgba(255, 170, 0, 0.15);
    color: #ffaa00;
}

.log-level-badge.error {
    background: rgba(255, 68, 68, 0.15);
    color: #ff4444;
}

.log-level-badge.debug {
    background: rgba(136, 136, 136, 0.15);
    color: #999;
}

.log-timestamp {
    font-family: 'Consolas', 'Monaco', monospace;
    color: #777;
    font-size: 12px;
    white-space: nowrap;
}

.log-category {
    color: #0088ff;
    font-weight: 500;
    font-size: 12px;
}

.log-message {
    color: #e0e0e0;
}

/* Smart Data Formatting */
.log-data {
    font-size: 12px;
}

.data-empty {
    color: #444;
}

.data-formatted {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.data-formatted.generic {
    gap: 8px;
}

/* Data Tags */
.data-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

.data-tag i {
    font-size: 10px;
    opacity: 0.8;
}

.data-tag.node {
    background: rgba(0, 136, 255, 0.15);
    color: #4da6ff;
    border: 1px solid rgba(0, 136, 255, 0.3);
}

.data-tag.user {
    background: rgba(156, 39, 176, 0.15);
    color: #ce93d8;
    border: 1px solid rgba(156, 39, 176, 0.3);
}

.data-tag.method {
    background: rgba(255, 255, 255, 0.08);
    color: #bbb;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.data-tag.method.start {
    background: rgba(0, 204, 102, 0.15);
    color: #00ff88;
    border: 1px solid rgba(0, 204, 102, 0.3);
}

.data-tag.method.stop {
    background: rgba(255, 68, 68, 0.15);
    color: #ff6b6b;
    border: 1px solid rgba(255, 68, 68, 0.3);
}

.data-tag.method.config {
    background: rgba(255, 170, 0, 0.15);
    color: #ffcc00;
    border: 1px solid rgba(255, 170, 0, 0.3);
}

.data-tag.state {
    background: rgba(255, 255, 255, 0.08);
    color: #aaa;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.data-tag.state.active {
    background: rgba(0, 204, 102, 0.2);
    color: #00ff88;
    border: 1px solid rgba(0, 204, 102, 0.4);
}

.data-tag.state.stopped {
    background: rgba(136, 136, 136, 0.15);
    color: #aaa;
    border: 1px solid rgba(136, 136, 136, 0.3);
}

.data-tag.state.transition {
    background: rgba(255, 170, 0, 0.15);
    color: #ffcc00;
    border: 1px solid rgba(255, 170, 0, 0.3);
}

.data-tag.error {
    background: rgba(255, 68, 68, 0.15);
    color: #ff6b6b;
    border: 1px solid rgba(255, 68, 68, 0.3);
}

.data-tag.info {
    background: rgba(100, 100, 100, 0.15);
    color: #aaa;
    border: 1px solid rgba(100, 100, 100, 0.3);
}

.data-tag.detection {
    background: rgba(255, 68, 68, 0.15);
    color: #ff8888;
    border: 1px solid rgba(255, 68, 68, 0.3);
}

.data-tag.freq {
    background: rgba(255, 68, 68, 0.1);
    color: #ffaaaa;
    font-family: 'Consolas', 'Monaco', monospace;
    border: 1px solid rgba(255, 68, 68, 0.2);
}

/* Drone summary styles */
.data-tag.drone {
    background: rgba(0, 170, 255, 0.15);
    color: #00ccff;
    border: 1px solid rgba(0, 170, 255, 0.3);
}

.data-tag.drone.active {
    background: rgba(0, 204, 102, 0.2);
    color: #00ff88;
    border: 1px solid rgba(0, 204, 102, 0.4);
}

.data-tag.drone.warn {
    background: rgba(255, 170, 0, 0.15);
    color: #ffcc00;
    border: 1px solid rgba(255, 170, 0, 0.3);
}

.data-tag.node-small {
    background: rgba(0, 136, 255, 0.1);
    color: #66b3ff;
    border: 1px solid rgba(0, 136, 255, 0.2);
    font-size: 10px;
    padding: 2px 6px;
}

.data-tag.location {
    background: rgba(100, 100, 100, 0.1);
    color: #999;
    border: 1px solid rgba(100, 100, 100, 0.2);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 10px;
}

.data-formatted.drone-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    row-gap: 6px;
}

.data-value {
    color: #888;
    font-size: 11px;
}

.data-value.name {
    color: #aaa;
    font-weight: 500;
}

.data-value.from {
    color: #666;
    font-style: italic;
}

.data-value.ip {
    font-family: 'Consolas', 'Monaco', monospace;
    color: #888;
}

.data-params {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
}

.param-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    font-size: 11px;
    color: #999;
}

.param-key {
    color: #666;
}

.data-kv {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #888;
}

.data-key {
    color: #666;
}

.no-logs {
    text-align: center;
    color: #666;
    padding: 40px 20px !important;
    font-style: italic;
}

/* Scrollbar */
.history-content::-webkit-scrollbar {
    width: 8px;
}

.history-content::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.history-content::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

/* Responsive */
@media (max-width: 1200px) {
    .history-modal { width: 95vw; height: 90vh; }
    .filter-row { gap: 10px; }
    .filter-group { min-width: 120px; }
    .history-dropdown { min-width: 120px; }
    .custom-time-group { min-width: 160px; }
    .filter-actions { margin-left: auto; }
}

@media (max-width: 900px) {
    .filter-actions { margin-left: 0; width: 100%; margin-top: 10px; }
    .history-stats { flex-direction: column; gap: 8px; align-items: flex-start; }
}

/* ============================================
   Light Mode Theme Support
   ============================================ */

body.light-mode .history-modal-overlay {
    background: rgba(200, 200, 200, 0.75);
}

body.light-mode .history-modal {
    background: #ffffff;
    border: 1px solid #d0d0d0;
}

body.light-mode .history-modal-header {
    background: #f5f5f5;
    border-bottom: 1px solid #d0d0d0;
}

body.light-mode .history-modal-header h2 {
    color: #00aa55;
}

body.light-mode .history-close-btn {
    border-color: #c0c0c0;
    color: #666;
}

body.light-mode .history-close-btn:hover {
    background: #e8e8e8;
    color: #333;
    border-color: #999;
}

body.light-mode .history-filters {
    background: #fafafa;
    border-bottom: 1px solid #d0d0d0;
}

body.light-mode .filter-group label {
    color: #666;
}

body.light-mode .history-input,
body.light-mode .history-dropdown {
    background: #ffffff;
    border-color: #c0c0c0;
    color: #2a2a2a;
}

body.light-mode .history-input:focus,
body.light-mode .history-dropdown:focus {
    border-color: #00aa55;
}

body.light-mode .history-dropdown-menu {
    background: #ffffff;
    border-color: #00aa55;
}

body.light-mode .history-dropdown-item {
    color: #2a2a2a;
    border-bottom-color: #e8e8e8;
}

body.light-mode .history-dropdown-item:hover {
    background: #f0f0f0;
}

body.light-mode .history-dropdown-item.selected {
    background: #e8f5e9;
    color: #00aa55;
}

body.light-mode .history-apply-btn {
    background: #00aa55;
    border-color: #00aa55;
}

body.light-mode .history-apply-btn:hover {
    background: #008844;
    border-color: #008844;
}

body.light-mode .history-reset-btn {
    background: transparent;
    border-color: #c0c0c0;
    color: #666;
}

body.light-mode .history-reset-btn:hover {
    background: #f0f0f0;
    border-color: #999;
}

body.light-mode .history-body {
    background: #ffffff;
}

body.light-mode .history-content {
    background: #fafafa;
}

body.light-mode .history-table {
    background: #ffffff;
}

body.light-mode .history-table th {
    background: #f5f5f5;
    color: #666;
    border-bottom-color: #d0d0d0;
}

body.light-mode .history-table td {
    color: #2a2a2a;
    border-bottom-color: #e8e8e8;
}

body.light-mode .history-table tbody tr:hover {
    background: #f9f9f9;
}

body.light-mode .level-badge {
    border-width: 1px;
    border-style: solid;
}

body.light-mode .level-badge.INFO {
    background: #e3f2fd;
    color: #1976d2;
    border-color: #90caf9;
}

body.light-mode .level-badge.WARN {
    background: #fff3e0;
    color: #f57c00;
    border-color: #ffb74d;
}

body.light-mode .level-badge.ERROR {
    background: #ffebee;
    color: #d32f2f;
    border-color: #ef5350;
}

body.light-mode .history-footer {
    background: #f5f5f5;
    border-top: 1px solid #d0d0d0;
}

body.light-mode .history-stats {
    background: #f5f5f5;
    border-bottom-color: #d0d0d0;
    color: #666;
}

body.light-mode .history-close-footer-btn {
    background: #e8e8e8;
    border-color: #c0c0c0;
    color: #2a2a2a;
}

body.light-mode .history-close-footer-btn:hover {
    background: #d0d0d0;
    border-color: #999;
}

body.light-mode .history-loading {
    color: #666;
}

body.light-mode .loading-overlay {
    background: rgba(255, 255, 255, 0.9);
}

body.light-mode .loading-spinner {
    color: #00aa55;
}

body.light-mode .loading-spinner span {
    color: #666;
}

body.light-mode .filter-btn.refresh,
body.light-mode .filter-btn.export {
    color: #666;
    border-color: #c0c0c0;
}

body.light-mode .filter-btn.refresh:hover,
body.light-mode .filter-btn.export:hover {
    background: rgba(0, 170, 85, 0.1);
    color: #00aa55;
    border-color: #00aa55;
}

/* Additional fixes for history modal */
body.light-mode .history-modal-header p,
body.light-mode .history-modal-header span {
    color: #666;
}

body.light-mode .history-dropdown-toggle {
    background: #ffffff;
    border-color: #c0c0c0;
    color: #2a2a2a;
}

body.light-mode .history-dropdown-toggle:hover {
    border-color: #999;
    background: #f9f9f9;
}

body.light-mode .history-dropdown-toggle.active {
    border-color: #00aa55;
    background: #ffffff;
}

body.light-mode .history-dropdown-arrow {
    color: #666;
}

body.light-mode .history-content::-webkit-scrollbar-track {
    background: #f5f5f5;
}

body.light-mode .history-content::-webkit-scrollbar-thumb {
    background: #c0c0c0;
}

body.light-mode .history-content::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Light mode custom time input */
body.light-mode .custom-time-input {
    background: #ffffff;
    border-color: #c0c0c0;
    color: #2a2a2a;
    color-scheme: light;
}

body.light-mode .custom-time-input:hover {
    border-color: #999;
    background: #f9f9f9;
}

body.light-mode .custom-time-input:focus {
    border-color: #00aa55;
    background: #ffffff;
}

body.light-mode .custom-time-input::-webkit-calendar-picker-indicator {
    filter: none;
    opacity: 0.7;
}

body.light-mode .custom-time-input::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

body.light-mode .custom-time-input::-webkit-datetime-edit,
body.light-mode .custom-time-input::-webkit-datetime-edit-fields-wrapper,
body.light-mode .custom-time-input::-webkit-datetime-edit-month-field,
body.light-mode .custom-time-input::-webkit-datetime-edit-day-field,
body.light-mode .custom-time-input::-webkit-datetime-edit-year-field,
body.light-mode .custom-time-input::-webkit-datetime-edit-hour-field,
body.light-mode .custom-time-input::-webkit-datetime-edit-minute-field,
body.light-mode .custom-time-input::-webkit-datetime-edit-ampm-field {
    color: #2a2a2a;
}

body.light-mode .custom-time-input::-webkit-datetime-edit-text {
    color: #888;
}

body.light-mode .custom-time-input::-webkit-datetime-edit-month-field:focus,
body.light-mode .custom-time-input::-webkit-datetime-edit-day-field:focus,
body.light-mode .custom-time-input::-webkit-datetime-edit-year-field:focus,
body.light-mode .custom-time-input::-webkit-datetime-edit-hour-field:focus,
body.light-mode .custom-time-input::-webkit-datetime-edit-minute-field:focus,
body.light-mode .custom-time-input::-webkit-datetime-edit-ampm-field:focus {
    background: #00aa55;
    color: #fff;
}