:root {
    --bg-color: #2e004f;
    --text-color: #e0b3ff;
    --input-bg: #4b0082;
    --input-border: #d1a3ff;
    --input-hover: #6a0dad;
    --plot-bg: #1c1c1c;
    --heading-color: #d1a3ff;
}

/* Theme Definitions */
[data-theme="purple"] {
    --bg-color: #2e004f;
    --text-color: #e0b3ff;
    --input-bg: #4b0082;
    --input-border: #d1a3ff;
    --input-hover: #6a0dad;
    --plot-bg: #1c1c1c;
    --heading-color: #d1a3ff;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
    --input-bg: #333333;
    --input-border: #4d4d4d;
    --input-hover: #404040;
    --plot-bg: #262626;
    --heading-color: #ffffff;
}

[data-theme="light"] {
    --bg-color: #f5f5f5;
    --text-color: #333333;
    --input-bg: #ffffff;
    --input-border: #cccccc;
    --input-hover: #e6e6e6;
    --plot-bg: #ffffff;
    --heading-color: #333333;
}

/* Update existing styles to use variables */
body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

.app-container {
    max-width: none;
    /* Remove max-width limitation */
    margin: 0 auto;
    padding: 10px 40px;
    /* Reduced top/bottom padding */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    box-sizing: border-box;
}

h1 {
    color: var(--heading-color);
}

button,
select,
input {
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
}

button:hover,
select:hover,
input:hover {
    background-color: var(--input-hover);
}

#plot {
    background-color: var(--plot-bg);
    flex-grow: 1;
    min-height: 300px;
    width: 100%;
    margin: 10px 0;
    /* Reduced margins */
    height: calc(100vh - 800px);
    /* Adjust plot height for larger fixed-container */
    transition: height 0.2s;
    /* Smooth transition for height changes */
}

.box {
    flex: 1;
    /* Make both boxes take equal space */
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    padding: 15px;
    margin: 0;
    overflow-y: auto;
    resize: none;
    /* Disable resizing */
    box-sizing: border-box;
    /* Include padding in width calculation */
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    width: 50%;
    /* Set explicit width with margin */
    height: calc(100% - 20px);
    /* Set explicit height with margin */
}

#keyValueDisplay {
    margin-top: 20px;
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    padding: 10px;
}

#stopChartUpdates {
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    padding: 10px;
    margin: 5px 0;
    border-radius: 5px;
}

#stopChartUpdates:hover {
    background-color: var(--input-hover);
}

#clearChart {
    background-color: var (--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    padding: 10px;
    margin: 5px 0;
    border-radius: 5px;
}

#clearChart:hover {
    background-color: var(--input-hover);
}

.container {
    display: flex;
    justify-content: space-between;
    margin: 10px 0;
    min-height: 150px;
    /* Reduced minimum height */
    height: 15vh;
    /* Reduced height of text areas */
    width: 100%;
    gap: 20px;
    padding: 0;
    /* Remove any padding */
    max-width: none;
    /* Remove max-width limitation */
}

.box {
    flex: 1;
    /* Make both boxes take equal space */
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    padding: 15px;
    margin: 0;
    overflow-y: auto;
    resize: vertical;
    box-sizing: border-box;
    /* Include padding in width calculation */
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    width: 100%;
    /* Set explicit width */
    margin: 0;
    padding: 10px;
}

.key-value-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.key-value-section,
.non-json-section {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    padding: 10px;
}

.form-group {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    /* Allow wrapping to prevent overlap */
    justify-content: flex-start;
    width: 355px;
    /* Increased from 295px to accommodate wider input */
}

.form-group label {
    display: inline-block;
    width: 100px;
}

.form-group input[type="text"],
.form-group input[type="number"] {
    width: calc(100% - 110px);
}

.form-group input[type="checkbox"] {
    margin-left: 10px;
}

.form-group button {
    width: auto;
}

.form-group input[type="number"] {
    width: 120px;
    /* Double from 60px */
    margin-left: 5px;
}

.command-group {
    display: flex;
    align-items: flex-end;
    /* Align items to bottom */
    margin-top: 10px;
    padding: 5px 0;
    /* Reduced padding */
}

.command-group input[type="text"] {
    flex: 1;
    margin-right: 10px;
}

.checkbox-container {
    display: flex;
    flex-direction: row;
    /* Change to row for horizontal layout */
    align-items: center;
    margin-left: 20px;
    gap: 15px;
    /* Add gap between checkbox groups */
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 5px;
    /* Space between label and checkbox */
}

.checkbox-container label {
    margin: 0;
    /* Remove margin as we're using gap */
    font-size: 14px;
}

.box-container {
    flex: 1;
    /* Make each container take up 50% of the space */
    margin-top: 5px;
    display: flex;
    flex-direction: column;
    width: 50%;
    /* Set explicit width for side by side */
    min-width: 0;
    /* Allow container to shrink */
    transition: width 0.2s;
    /* Add smooth transition for width changes */
}

.box {
    flex: 1;
    /* Fill the remaining space in the container */
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    padding: 15px;
    margin: 0;
    overflow-y: auto;
    resize: none;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    width: 100%;
    /* Take full width of the container */
    height: 100%;
    /* Take full height of the container */
}

.box-label {
    color: var(--heading-color);
    font-weight: bold;
    margin-bottom: 5px;
    margin-right: auto;
}

.form-group button {
    width: auto;
    margin-right: 10px;
    /* Add space between buttons */
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    padding: 8px 15px;
    /* Reduced padding */
    border-radius: 5px;
}

.form-group button:last-child {
    margin-right: 0;
    /* Remove margin from last button */
}

.form-group button:hover {
    background-color: var(--input-hover);
}

.button-group {
    display: flex;
    gap: 15px;
    /* Slightly increase gap between buttons */
    margin: 5px 0;
    /* Reduced margins */
    align-items: center;
    /* Align buttons vertically */
    width: 295px;
    /* Explicit width for button group */
}

.button-group button {
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    padding: 8px 15px;
    /* Reduced padding */
    border-radius: 5px;
    width: 140px;
    /* Set fixed width instead of min-width */
    font-size: 14px;
    text-align: center;
    /* Ensure text is centered */
    white-space: nowrap;
    /* Prevent text wrapping */
    margin-right: 5px; /* Add spacing between buttons */
}

#downloadJson, #downloadCli {
    min-width: 120px;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    /* Reduced margin */
}

.theme-select {
    width: 140px;
    padding: 5px;
    border-radius: 5px;
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
}

.controls-section {
    display: flex;
    gap: 15px;
    /* Slightly reduced gap */
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
    /* Reduced margin */
}

.control-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.form-group {
    min-width: auto;
    /* Remove fixed width */
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.form-group input[type="number"] {
    width: 120px;
    /* Double from 60px */
    margin-left: 5px;
}

.button-group {
    display: flex;
    gap: 10px;
    align-items: center;
    width: auto;
    /* Remove fixed width */
}

.button-group button {
    width: auto;
    /* Allow buttons to size to content */
    min-width: 100px;
    /* Set minimum width */
    padding: 8px 12px;
}

.connection-group {
    display: flex;
    align-items: center;
    gap: 10px;
    width: auto;
    min-width: auto;
}

.connection-group input[type="number"] {
    width: 100px;
    margin: 0;
    height: 24px;
    padding: 2px 8px;
    font-size: 12px;
}

.connection-group button {
    margin: 0;
    height: 24px;
    padding: 2px 8px;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
}

@media (max-width: 768px) {
    .app-container {
        padding: 10px 20px;
    }
}

@media (min-width: 1920px) {
    .app-container {
        padding: 10px 60px;
        /* Adjust padding for larger screens */
    }
}

@media only screen and (max-width: 480px) {
    .app-container {
        padding: 5px 10px;
    }
    h1 {
        font-size: 20px;
    }
    .theme-select {
        width: 100px;
        padding: 3px;
    }
    .command-group input[type="text"],
    .command-group button {
        font-size: 14px;
    }
    .controls-section,
    .fixed-container {
        padding: 5px;
    }
}

.btn {
    color: var(--text-color) !important;
    border: 1px solid var(--input-border) !important;
}

.btn-success {
    background-color: #198754 !important;
}

.btn-danger {
    background-color: #dc3545 !important;
}

.btn-warning {
    background-color: #ffc107 !important;
    color: #000 !important;
}

.btn-secondary {
    background-color: #6c757d !important;
}

.btn-primary {
    background-color: #0d6efd !important;
}

.btn:hover {
    opacity: 0.9;
}

.form-control {
    background-color: var(--input-bg) !important;
    color: var(--text-color) !important;
    border-color: var(--input-border) !important;
}

.form-control:focus {
    background-color: var(--input-bg) !important;
    color: var(--text-color) !important;
    border-color: var(--input-border) !important;
    box-shadow: 0 0 0 0.2rem rgba(209, 163, 255, 0.25) !important;
}

.sent-command {
    color: #00ff00;
    /* Bright green for sent commands */
    font-style: italic;
}

.received-data {
    color: var (--text-color);
    /* Default color for received data */
}

.command-prefix {
    font-weight: bold;
    margin-right: 5px;
}

.ad-container {
    width: 100%;
    margin: 10px 0;
    text-align: center;
    background: rgba(0, 0, 0, 0.1);
    padding: 10px;
    border-radius: 5px;
}

.draggable {
    position: absolute;
    cursor: move;
}

.resizable {
    resize: both;
    overflow: auto;
}

.fixed-container {
    display: flex;
    flex-direction: row;
    height: 30vh; /* Initial height */
    border: 1px solid var(--input-border);
    margin-top: 20px;
    padding: 10px;
    overflow: hidden;
    gap: 20px;
    position: relative; /* Required for the resize handle */
}

.resize-handle {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 10px;
    cursor: ns-resize;
    background-color: rgba(255, 255, 255, 0.2);
    z-index: 10;
}

.resize-handle:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

.box {
    flex: 1;
    resize: none;
    overflow-y: auto;
    height: calc(100% - 20px); /* Adjust height dynamically */
}

.collapsible-container {
    width: 100%;
    margin-top: 10px;
}

.collapsible-header {
    background-color: var(--input-bg);
    color: var(--text-color);
    padding: 10px;
    cursor: pointer;
    border: 1px solid var(--input-border);
    border-radius: 5px;
}

.collapsible-content {
    display: none;
    overflow: hidden;
    transition: max-height 0.2s ease-out;
}

.collapsible-content.show {
    display: block;
}

.serial-output-box {
    width: 100%;
    height: 200px;
    /* Set a fixed height for the serial output box */
    margin-top: 10px;
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    padding: 15px;
    overflow-y: auto;
    resize: none;
    /* Disable resizing */
    box-sizing: border-box;
    /* Include padding in width calculation */
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}

.controls-section .button-group {
    gap: 5px;
    /* Reduce gap between buttons */
}

.controls-section .button-group button {
    padding: 4px 8px;
    /* Reduce padding */
    min-width: 60px;
    /* Smaller minimum width */
    font-size: 12px;
    /* Smaller font */
}

.controls-section .form-group {
    margin-left: 5px;
    /* Reduce margin */
}

.controls-section .form-group input[type="number"] {
    width: 120px;
    /* Double from 60px */
    padding: 4px;
    font-size: 12px;
}

.controls-section .form-group label {
    font-size: 12px;
    /* Match other text sizes */
}

.box-container.collapsed {
    width: 30px;
    min-width: 30px;
    flex: 0;
    position: relative; /* Add this */
    margin-right: 20px; /* Add this */
}

.box-container.collapsed .box-header {
    position: absolute;
    transform: rotate(-90deg);
    transform-origin: left;
    white-space: nowrap;
    width: 24px; /* Add fixed width */
    left: 15px;
    top: 50%;
}

.box-container.collapsed .download-btn,
.box-container.collapsed .box-label {
    display: none;
}

.collapse-btn {
    cursor: pointer;
    padding: 2px 6px;
    margin-left: 10px;
    border-radius: 3px;
    font-size: 10px;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-color);
    position: relative; /* Add this */
    z-index: 1; /* Add this */
    opacity: 1;  /* Changed from 0 to 1 */
}

.box-header {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
    gap: 10px;
}

.box-container:not(.collapsed)+.box-container.collapsed~.box-container,
.box-container.collapsed+.box-container {
    width: calc(100% - 50px);
    /* Full width minus collapsed width and gap */
}

/* Modal Styles */
.info-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 15% auto;
    padding: 20px;
    border: 1px solid var(--input-border);
    border-radius: 5px;
    width: 70%;
    max-width: 700px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--input-border);
}

.modal-title {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--heading-color);
}

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

.close-modal:hover {
    color: var(--input-hover);
}

.info-icon {
    cursor: pointer;
    margin-left: 10px;
    color: var(--text-color);
    font-size: 1.2em;
    transition: color 0.2s;
}

.info-icon:hover {
    color: var(--input-hover);
}

.modal-code {
    background-color: var(--input-bg);
    padding: 15px;
    border-radius: 5px;
    margin: 10px 0;
    font-family: monospace;
    white-space: pre-wrap;
}

.guide-section {
    margin: 20px 0;
    padding: 15px;
    border: 1px solid var(--input-border);
    border-radius: 5px;
    background-color: var(--input-bg);
}

.guide-section h4 {
    color: var(--heading-color);
    margin-bottom: 15px;
}

.guide-section ul {
    list-style-type: none;
    padding-left: 20px;
}

.guide-section li {
    margin: 8px 0;
    position: relative;
}

.guide-section li:before {
    content: "→";
    position: absolute;
    left: -20px;
    color: var(--heading-color);
}

.guide-img {
    width: 100%;
    max-width: 400px;
    height: auto;
    margin: 10px 0;
    border-radius: 5px;
    display: block;
}

.modal-code {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 5px;
    margin: 10px 0;
    font-family: monospace;
    white-space: pre;
    overflow-x: auto;
}

.code-container {
    position: relative;
    margin: 15px 0;
}

.copy-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    padding: 5px 10px;
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    opacity: 0.8;
}

.copy-btn:hover {
    opacity: 1;
    background-color: var(--input-hover);
}

.code-block {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 5px;
    margin: 10px 0;
    font-family: 'Consolas', monospace;
    white-space: pre;
    overflow-x: auto;
    color: #e0b3ff;
    font-size: 14px;
    line-height: 1.4;
}

/* Syntax highlighting */
.code-block .keyword {
    color: #ff79c6;
}

.code-block .function {
    color: #50fa7b;
}

.code-block .string {
    color: #f1fa8c;
}

.code-block .number {
    color: #bd93f9;
}

.code-block .comment {
    color: #6272a4;
}

.download-btn {
    padding: 2px 8px;
    font-size: 12px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 1;  /* Changed from 0 to 1 */
}

/* Content Section Styles */
.content-section {
    margin: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    transition: all 0.3s ease;
    color: var(--text-color);
}

.content-section.collapsed .content-body {
    display: none;
}

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

.content-header h3 {
    margin: 0;
    font-size: 1.2em;
    color: var(--heading-color);
}

.toggle-icon {
    transition: transform 0.3s ease;
}

.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

/* Add new style for navbar links */
.navbar-nav {
    gap: 20px; /* Add space between nav items */
}

.nav-link {
    padding: 5px 10px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
}