:root {
    /* MCHOSE like Modern Tech Colors */
    --md-primary: #0066ff;
    --md-primary-container: #e6f0ff;
    --md-on-primary: #ffffff;
    --md-on-primary-container: #003380;

    --md-secondary: #8e8e93;
    --md-secondary-container: #e5e5ea;
    --md-on-secondary: #ffffff;
    --md-on-secondary-container: #1d1d1f;

    --md-error: #ff3b30;
    --md-error-container: #ffe5e5;
    --md-on-error: #ffffff;

    --md-background: #f4f5f7;
    --md-on-background: #111111;

    --md-surface: #ffffff;
    --md-surface-variant: #f9fafb;
    --md-on-surface: #111111;
    --md-on-surface-variant: #666666;

    --md-outline: rgba(0, 0, 0, 0.08);
    /* Softer outline */
    --md-outline-variant: rgba(0, 0, 0, 0.04);
    /* Almost invisible outline */

    /* Flat tech diffuse shadows */
    --md-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.02);
    --md-shadow-md: 0 4px 16px rgba(0, 0, 0, 0.03);

    --primary-color: #007aff;
    /* Keep primary blue but ensure flat use */
    --primary-hover: #0062cc;
    --primary-pressed: #004fb0;
    --danger-color: var(--md-error);
    --border-color: var(--md-outline-variant);
    --bg-color: var(--md-background);
    --text-color: var(--md-on-background);
    --disabled-bg: #e5e5ea;
    --disabled-text: #86868b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    background: var(--md-background);
    /* Flat bg instead of gradient */
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    transition: all 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    background: var(--md-surface);
    padding: 24px 32px;
    border-radius: 16px;
    /* slightly rounder */
    box-shadow: var(--md-shadow-sm);
    /* Softer shadow */
    border: none;
    /* remove borders for cleaner look */
}

.header h1 {
    background: var(--md-primary);
    -webkit-background-clip: text;
    color: var(--md-on-surface);
    background-clip: text;
    font-size: 2rem;
    font-weight: 600;
    margin: 0;
}

.main-layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 24px;
    align-items: start;
}

.group-box {
    background: var(--md-surface);
    border: none;
    /* No border */
    border-radius: 16px;
    /* Softer radius */
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--md-shadow-sm);
    /* Just a soft shadow */
    transition: box-shadow 0.2s ease;
}

.group-box:hover {
    border-color: var(--md-outline);
    box-shadow: var(--md-shadow-md);
}

.group-box h3 {
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--md-on-surface);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

button {
    background: var(--md-primary);
    border: none;
    color: var(--md-on-primary);
    padding: 8px 16px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    width: 100%;
    margin-bottom: 12px;
}

button:hover {
    background: var(--primary-hover);
}

button:active {
    background: var(--primary-pressed);
}

button:disabled {
    background: var(--disabled-bg);
    color: var(--disabled-text);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

button.danger {
    background: var(--md-error);
    color: var(--md-on-error);
}

button.danger:hover {
    background: #d32f2f;
}

input[type="text"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--md-outline);
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 12px;
    background: var(--md-surface);
    color: var(--md-on-surface);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

input[type="text"]:hover,
input[type="number"]:hover,
select:hover,
textarea:hover {
    border-color: var(--md-on-surface-variant);
}

textarea {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    resize: vertical;
    min-height: 150px;
}

.steps-editor {
    position: relative;
    border: 1px solid var(--md-outline);
    border-radius: 12px;
    background: var(--md-surface-container-low);
    margin-bottom: 12px;
    display: flex;
    width: 100%;
    overflow: hidden;
    transition: all 0.2s ease;
}

.steps-editor:focus-within {
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.line-numbers {
    width: 50px;
    background: var(--md-surface-variant);
    border-right: 1px solid var(--md-outline-variant);
    color: var(--md-on-surface-variant);
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    font-size: 12px;
    line-height: 20px;
    padding: 12px 8px 12px 0;
    text-align: right;
    overflow-y: auto;
    overflow-x: hidden;
    user-select: none;
    white-space: pre;
    flex-shrink: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.line-numbers::-webkit-scrollbar {
    display: none;
}

#stepsInput {
    flex: 1;
    padding: 12px;
    border: none;
    min-height: 300px;
    line-height: 20px;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    resize: vertical;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre;
    background: transparent;
    color: var(--md-on-surface);
    outline: none;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.input-group label {
    min-width: 60px;
    font-weight: 500;
    color: var(--md-on-surface);
}

#logText {
    background: var(--md-surface-container-low);
    min-height: 200px;
    max-height: 200px;
    overflow-y: auto;
    padding: 16px;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    font-size: 12px;
    border-radius: 12px;
    border: 1px solid var(--md-outline-variant);
    color: var(--md-on-surface);
}

#sequenceDetails {
    background: var(--md-surface-container-low);
    min-height: 120px;
    max-height: 120px;
    overflow-y: auto;
    border-radius: 12px;
    border: 1px solid var(--md-outline-variant);
    color: var(--md-on-surface);
}

#sequenceList {
    list-style: none;
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--md-outline-variant);
    border-radius: 12px;
    background: var(--md-surface-container-low);
}

#sequenceList li {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--md-outline-variant);
    transition: all 0.2s ease;
    color: var(--md-on-surface);
}

#sequenceList li:last-child {
    border-bottom: none;
}

#sequenceList li:hover {
    background: var(--md-surface-container);
}

#sequenceList li.selected {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
    font-weight: 600;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
}

.status-connected {
    color: var(--md-on-tertiary-container);
    background: var(--md-tertiary-container);
}

.status-disconnected {
    color: var(--md-on-error-container);
    background: var(--md-error-container);
}

.active-sequence-display {
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: var(--md-on-primary-container);
    padding: 20px;
    background: var(--md-primary-container);
    border-radius: 12px;
    margin-bottom: 16px;
    border: 1px solid var(--md-outline-variant);
}

.step-info {
    text-align: right;
    color: var(--md-on-surface-variant);
    font-size: 12px;
    margin-top: 8px;
}

.button-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.right-panel {
    min-width: 650px;
}

@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 350px 1fr;
    }
}

@media (max-width: 768px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .button-group {
        grid-template-columns: 1fr;
    }

    .right-panel {
        min-width: auto;
    }

    .steps-editor {
        min-width: auto;
        overflow-x: auto;
    }

    .container {
        padding: 16px;
    }

    .debug-input-container {
        flex-direction: column;
    }

    .debug-input-container button {
        width: 100%;
    }
}

.current-line-highlight {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}

.debug-output {
    background: var(--md-surface-container-lowest);
    color: var(--md-on-surface);
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    font-size: 12px;
    min-height: 500px;
    max-height: 500px;
    overflow-y: auto;
    padding: 16px;
    border: 1px solid var(--md-outline-variant);
    border-radius: 12px;
    margin-bottom: 16px;
    white-space: pre-wrap;
    word-break: break-all;
}

.debug-input-container {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    width: 100%;
    box-sizing: border-box;
}

.debug-input-container input {
    flex: 1;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    font-size: 12px;
    margin-bottom: 0;
    min-width: 0;
}

.debug-input-container button {
    flex-shrink: 0;
    width: auto;
    padding: 8px 16px;
    font-size: 12px;
}

.debug-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.debug-buttons button {
    font-size: 12px;
    padding: 8px 16px;
}

.debug-sent {
    color: var(--md-primary);
}

.debug-received {
    color: var(--md-tertiary);
}

.debug-error {
    color: var(--md-error);
}

.debug-info {
    color: var(--md-on-surface-variant);
}

.sequence-name-valid {
    border-color: var(--md-tertiary) !important;
    background-color: var(--md-tertiary-container) !important;
}

.sequence-name-invalid {
    border-color: var(--md-error) !important;
    background-color: var(--md-error-container) !important;
}

/* Custom scrollbar styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--md-surface-variant);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--md-outline);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--md-on-surface-variant);
}

.validation-message {
    font-size: 12px;
    margin-top: 5px;
    padding: 5px;
    border-radius: 3px;
}

.validation-success {
    color: #4CAF50;
    background-color: #f0fff0;
    border: 1px solid #4CAF50;
}

.validation-error {
    color: #f44336;
    background-color: #fff0f0;
    border: 1px solid #f44336;
}

#fkeyTable table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

#fkeyTable th,
#fkeyTable td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: center;
}

#fkeyTable th {
    background-color: #f5f5f5;
    font-weight: bold;
}

#fkeyTable select {
    width: 100%;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
}

#fkeyTable button {
    padding: 4px 8px;
    margin: 2px;
    font-size: 11px;
    border-radius: 3px;
    min-width: 40px;
}

.fkey-bind-btn {
    background-color: #2196F3;
}

.fkey-bind-btn:hover {
    background-color: #1976D2;
}

.fkey-unbind-btn {
    background-color: #ff9800;
}

.fkey-unbind-btn:hover {
    background-color: #f57c00;
}

#numkeyTable table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

#numkeyTable th,
#numkeyTable td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: center;
}

#numkeyTable th {
    background-color: #f5f5f5;
    font-weight: bold;
}

#numkeyTable select {
    width: 100%;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
}

#numkeyTable button {
    padding: 4px 8px;
    margin: 2px;
    font-size: 11px;
    border-radius: 3px;
    min-width: 40px;
}

.numkey-set-btn {
    background-color: #4CAF50;
}

.numkey-set-btn:hover {
    background-color: #45a049;
}

.numkey-clear-btn {
    background-color: #ff9800;
}

.numkey-clear-btn:hover {
    background-color: #f57c00;
}

#sidekeyTable table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

#sidekeyTable th,
#sidekeyTable td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: center;
}

#sidekeyTable th {
    background-color: #f5f5f5;
    font-weight: bold;
}

#sidekeyTable select {
    width: 100%;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
}

#sidekeyTable button {
    padding: 4px 8px;
    margin: 2px;
    font-size: 11px;
    border-radius: 3px;
    min-width: 40px;
}

.sidekey-bind-btn {
    background-color: #4CAF50;
}

.sidekey-bind-btn:hover {
    background-color: #45a049;
}

.sidekey-unbind-btn {
    background-color: #ff9800;
}

.sidekey-unbind-btn:hover {
    background-color: #f57c00;
}

.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: white;
    margin: 15% auto;
    padding: 20px;
    border-radius: 10px;
    width: 80%;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    margin: 0;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #000;
}