        :root {
            --accent: #10b981;
        }

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

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
            background: #f8f9fa;
            color: #1a1a1a;
            min-height: 100vh;
            overflow-x: hidden;
        }

        /* Top Bar */
        .top-bar {
            position: sticky;
            top: 0;
            z-index: 100;
            background: rgba(255, 255, 255, 0.75);
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
            color: #1a1a1a;
            padding: 12px 24px;
            display: flex;
            align-items: center;
            flex-wrap: nowrap;
            gap: 10px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
        }

        .top-bar h1 {
            font-size: 16px;
            font-weight: 700;
            letter-spacing: -0.02em;
            margin-right: 8px;
        }

        /* Top bar button groups */
        .top-bar-group {
            display: flex;
            align-items: center;
            gap: 4px;
            padding: 2px;
            background: rgba(0, 0, 0, 0.04);
            border-radius: 10px;
        }

        .top-bar-divider {
            width: 1px;
            height: 24px;
            background: rgba(0, 0, 0, 0.08);
            margin: 0 8px;
        }

        .save-btn {
            background: transparent;
            color: #374151;
            border: 1px solid transparent;
            padding: 6px 14px;
            font-size: 12px;
            font-weight: 500;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.15s ease;
            white-space: nowrap;
            flex-shrink: 0;
        }

        .save-btn:hover {
            background: rgba(0, 0, 0, 0.06);
            color: #1a1a1a;
        }

        .save-btn:active {
            background: rgba(0, 0, 0, 0.1);
        }

        .action-bar {
            display: flex;
            gap: 6px;
            padding: 6px 16px;
            background: #111827;
            border-bottom: 1px solid #1f2937;
        }

        .top-bar-action-btn {
            background: transparent;
            color: #9ca3af;
            border: 1px solid #374151;
            padding: 5px 12px;
            font-size: 11px;
            font-weight: 500;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.15s ease;
            white-space: nowrap;
        }
        .top-bar-action-btn:hover {
            background: #1f2937;
            color: #e5e7eb;
            border-color: #4b5563;
        }
        body.dark-mode .top-bar-action-btn {
            color: #9ca3af;
            border-color: #374151;
        }
        body.dark-mode .top-bar-action-btn:hover {
            background: #1f2937;
            color: #e5e7eb;
            border-color: #4b5563;
        }

        .top-bar-text-btn,
        body.dark-mode .top-bar-text-btn,
        button.top-bar-text-btn,
        body.dark-mode button.top-bar-text-btn,
        a.top-bar-text-btn,
        body.dark-mode a.top-bar-text-btn {
            background: none !important;
            border: none !important;
            color: #6b7280 !important;
            font-size: 12px !important;
            font-weight: 400 !important;
            -webkit-font-smoothing: antialiased;
            padding: 6px 10px;
            cursor: pointer;
            border-radius: 6px;
            transition: color 0.15s ease, background 0.15s ease;
            white-space: nowrap;
        }
        .top-bar-text-btn:hover,
        body.dark-mode .top-bar-text-btn:hover,
        button.top-bar-text-btn:hover,
        body.dark-mode button.top-bar-text-btn:hover {
            color: #e5e7eb !important;
            background: rgba(255, 255, 255, 0.08) !important;
        }

        /* Main Layout */
        .container {
            display: grid;
            grid-template-columns: 300px 1fr;
            gap: 15px;
            padding: 15px;
            height: calc(100vh - 92px);
        }

        /* Hide keyboard grid by default */
        #keyboardRemapGrid {
            display: none;
        }

        .panel {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.05);
            overflow: auto;
            border: 1px solid #e5e7eb;
        }

        .panel-title {
            font-size: 11px;
            font-weight: 700;
            margin-bottom: 18px;
            text-transform: uppercase;
            letter-spacing: 0.1em;
            color: #9ca3af;
        }

        /* Macros Panel */
        .macro-list {
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            max-height: 400px;
            overflow-y: auto;
            margin-bottom: 20px;
        }

        .macro-item {
            padding: 14px 16px;
            border-bottom: 1px solid #f3f4f6;
            cursor: pointer;
            transition: all 0.15s ease;
            font-size: 14px;
            font-weight: 500;
        }

        .macro-item:hover {
            background: #f9fafb;
        }

        .macro-item.selected {
            background: #eff6ff;
            color: #1e40af;
            border-left: 3px solid #3b82f6;
        }

        .macro-item:last-child {
            border-bottom: none;
        }

        /* Device Buttons */
        .device-tabs {
            display: flex;
            gap: 8px;
            margin-bottom: 20px;
            padding: 4px;
            background: #f3f4f6;
            border-radius: 10px;
        }

        .tab-btn {
            flex: 1 1 0;
            padding: 10px 16px;
            max-width: 220px;
            background: transparent;
            color: #6b7280;
            border: none;
            font-size: 13px;
            font-weight: 500;
            border-radius: 7px;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .tab-btn.active {
            background: white;
            color: #1a1a1a;
            box-shadow: 0 1px 2px rgba(0,0,0,0.05);
        }

        .button-grid {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            grid-template-rows: repeat(8, auto);
            gap: 6px;
            margin-top: 20px;
        }

        .device-button {
            background: white;
            color: #1a1a1a;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            font-size: 11px;
            font-weight: 500;
            cursor: pointer;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            text-align: center;
            padding: 6px 4px;
            line-height: 1.4;
            min-width: 0;
            overflow: hidden;
            box-shadow: 0 1px 2px rgba(0,0,0,0.05);
            position: relative; /* For absolute positioning of button ID */
            min-height: 50px;
            /* overflow: hidden already set above */
        }

        .keyboard-grid .device-button {
            min-height: 42px;
            border-radius: 6px;
            padding: 4px 2px;
            font-size: 10px;
            margin: 1px;
            background: #f3f4f6;
            border-color: #d1d5db;
            color: #374151;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            line-height: 1.2;
        }

        .keyboard-grid .device-button.mapped {
            font-weight: 600;
        }

        .device-button-empty {
            opacity: 0.4 !important;
            color: #9ca3af !important;
            transition: none !important;
            box-shadow: none !important;
        }

        body.dark-mode .device-button-empty {
            color: #6b7280 !important;
            background: #111 !important;
            border-color: #222 !important;
        }

        .device-button:hover {
            border-color: #d1d5db;
            box-shadow: 0 2px 4px rgba(0,0,0,0.08);
            transition: border-color 0.15s ease, box-shadow 0.15s ease;
        }

        .device-button.mapped {
            background: var(--accent);
            color: white;
            border-color: var(--accent);
        }

        .device-button.has-other-mapping {
            background: #fbbf24;
            color: #1a1a1a;
            border-color: #fbbf24;
        }

        .device-button.selected {
            border-width: 2px;
            border-color: #1a1a1a;
            box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
        }

        /* Right Panel */
        .status-card {
            background: #f9fafb;
            color: #1a1a1a;
            padding: 16px;
            border-radius: 8px;
            margin-bottom: 24px;
            border: 1px solid #e5e7eb;
        }

        .status-label {
            font-size: 11px;
            color: #6b7280;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            margin-bottom: 6px;
        }

        .status-value {
            font-size: 16px;
            font-weight: 600;
        }

        .modifiers {
            margin: 20px 0;
        }

        .modifier-label {
            font-size: 13px;
            font-weight: bold;
            margin-bottom: 10px;
        }

        .checkbox-group {
            display: flex;
            gap: 15px;
        }

        .checkbox-label {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 13px;
            font-weight: bold;
            cursor: pointer;
        }

        .checkbox-label input {
            width: 18px;
            height: 18px;
            cursor: pointer;
        }

        .action-btn {
            width: 100%;
            padding: 12px 16px;
            font-size: 14px;
            font-weight: 500;
            border: 1px solid;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.15s ease;
            margin-bottom: 10px;
        }

        .action-btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }

        .map-btn {
            background: var(--accent);
            color: white;
            border-color: var(--accent);
        }

        .map-btn:hover:not(:disabled) {
            filter: brightness(0.85);
        }

        .clear-btn {
            background: white;
            color: #1a1a1a;
            border-color: #e5e7eb;
        }

        .clear-btn:hover {
            background: #f9fafb;
            border-color: #d1d5db;
        }

        /* Instructions */
        .instructions {
            font-size: 12px;
            color: #6b7280;
            line-height: 1.6;
        }

        .instructions li {
            margin-bottom: 5px;
        }

        /* Keyboard Keys */
        .keyboard-grid {
            display: grid;
            gap: 3px;
            min-width: 800px;
            overflow-x: auto;
        }

        .keyboard-row {
            display: flex;
            gap: 6px;
            justify-content: center;
        }

        .keyboard-key {
            background: white;
            border: 2px solid #e5e7eb;
            border-radius: 8px;
            padding: 8px;
            min-width: 52px;
            height: 52px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.15s ease;
            color: #1a1a1a;
            position: relative;
            box-shadow: 0 2px 4px rgba(0,0,0,0.08);
        }

        .keyboard-key:hover {
            border-color: #cbd5e1;
            box-shadow: 0 4px 8px rgba(0,0,0,0.12);
            transform: translateY(-1px);
        }

        .keyboard-key.selected {
            background: #1a1a1a;
            color: white;
            border-color: #1a1a1a;
            box-shadow: 0 0 0 4px rgba(26, 26, 26, 0.15);
        }

        .keyboard-key.remapped {
            background: var(--accent);
            color: white;
            border-color: var(--accent);
            flex-direction: column;
            padding: 6px;
            line-height: 1.3;
        }

        .keyboard-key.remapped:hover {
            background: linear-gradient(135deg, #059669 0%, #047857 100%);
            border-color: #047857;
            transform: translateY(-1px);
        }

        .keyboard-key.wide {
            min-width: 90px;
        }

        .keyboard-key.extra-wide {
            min-width: 140px;
        }

        .key-remap-input {
            margin-top: 16px;
            padding: 16px;
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
        }

        textarea {
            resize: none;
        }

        /* Light Mode Enhancements */
        input,
        select,
        textarea {
            background: white;
            color: #1a1a1a;
            border: 1px solid #d1d5db;
            padding: 10px 14px;
            border-radius: 8px;
            font-size: 13px;
            transition: all 0.2s ease;
        }

        input::placeholder,
        textarea::placeholder {
            color: #9ca3af;
        }

        input:focus,
        select:focus,
        textarea:focus {
            border-color: #60a5fa;
            outline: none;
            box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
        }

        label {
            font-size: 12px;
            font-weight: 600;
            color: #6b7280;
            margin-bottom: 6px;
            display: block;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }

        /* Ensure inline-styled elements work in light mode */
        div[style*="background: white"] {
            color: #1a1a1a;
        }

        div[style*="color: #1a1a1a"] {
            color: #1a1a1a;
        }

        /* Light mode button text visibility */
        button {
            font-family: inherit;
            font-weight: inherit;
        }

        /* Create Macro boxes */
        .create-macro-box,
        .ai-macro-box {
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
        }

        .create-macro-title,
        .ai-macro-title {
            color: #1a1a1a;
            font-weight: 600;
            margin-bottom: 16px;
        }

        /* Help text and tips */
        .help-text {
            font-size: 12px;
            color: #6b7280;
            margin-top: 6px;
        }

        /* Info boxes */
        .info-box {
            background: #f0f9ff;
            border: 1px solid #bfdbfe;
            border-radius: 8px;
            padding: 12px;
            color: #0369a1;
        }

        /* Recording status */
        #recordingStatus {
            background: rgba(239, 68, 68, 0.1);
            color: #dc2626;
            padding: 8px 12px;
            border-radius: 6px;
            font-size: 12px;
            font-weight: 500;
        }

        /* Keys help */
        #keysHelp {
            background: #f9fafb;
            color: #6b7280;
            padding: 8px;
            border-radius: 6px;
            font-size: 11px;
        }

        /* Horizontal rule */
        hr {
            border: none;
            border-top: 1px solid #e5e7eb;
            margin: 20px 0;
        }

        /* Scrollbar for light mode */
        ::-webkit-scrollbar {
            width: 10px;
            height: 10px;
        }

        ::-webkit-scrollbar-track {
            background: #f9fafb;
        }

        ::-webkit-scrollbar-thumb {
            background: #d1d5db;
            border-radius: 5px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: #9ca3af;
        }

        /* Bulk actions styling */
        #bulkActions {
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 16px;
            margin-bottom: 16px;
        }

        #bulkActions button {
            margin-right: 8px;
            margin-bottom: 8px;
        }

        /* Modal styling enhancements */
        .modal h2 {
            color: #1a1a1a;
            font-size: 20px;
            font-weight: 600;
            margin-bottom: 16px;
        }

        .modal p {
            color: #6b7280;
            line-height: 1.6;
        }

        /* Button close icon in modals */
        .modal button[style*="font-size: 24px"] {
            color: #6b7280;
            background: transparent;
            border: none;
            cursor: pointer;
            transition: color 0.15s ease;
        }

        .modal button[style*="font-size: 24px"]:hover {
            color: #1a1a1a;
        }

        /* Select dropdown options */
        select option {
            background: white;
            color: #1a1a1a;
        }

        /* Ensure proper contrast for all buttons */
        button:not(.device-button):not(.keyboard-key):not(.tab-btn):not(.macro-item) {
            font-weight: 500;
        }

        /* Tooltip light mode */
        .tooltip {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        }

        /* Macro Preview Box */
        #macroPreview {
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 20px;
            margin-top: 20px;
        }

        #macroPreview div[style*="font-weight: 600"] {
            color: #1a1a1a;
        }

        #macroPreview div[style*="font-size: 12px"],
        #macroPreview strong {
            color: #6b7280;
        }

        #macroPreview #previewName,
        #macroPreview #previewType {
            color: #1a1a1a;
        }

        #previewContent {
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 6px;
            padding: 12px;
            color: #374151;
            font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
            font-size: 13px;
            line-height: 1.5;
            white-space: pre-wrap;
            word-wrap: break-word;
        }

        /* Edit, Duplicate, and Delete buttons in preview */
        button[onclick="editMacro()"] {
            background: white;
            color: #3b82f6;
            border: 1px solid #3b82f6;
        }

        button[onclick="editMacro()"]:hover {
            background: #eff6ff;
        }

        button[onclick="duplicateMacro()"] {
            background: white;
            color: #1a1a1a;
            border: 1px solid #e5e7eb;
        }

        button[onclick="duplicateMacro()"]:hover {
            background: #f9fafb;
            border-color: #d1d5db;
        }

        button[onclick="deleteMacro()"] {
            background: white;
            color: #dc2626;
            border: 1px solid #dc2626;
        }

        button[onclick="deleteMacro()"]:hover {
            background: #fef2f2;
        }

        /* Record button */
        #recordBtn {
            background: #dc2626;
            color: white;
            border: 1px solid #dc2626;
        }

        #recordBtn:hover {
            background: #b91c1c;
        }

        /* Clear keys button */
        button[onclick="clearKeysInput()"] {
            background: #6b7280;
            color: white;
            border: 1px solid #6b7280;
        }

        button[onclick="clearKeysInput()"]:hover {
            background: #4b5563;
        }

        /* Browse Templates button */
        button[onclick="showTemplates()"] {
            background: white;
            color: #1a1a1a;
            border: 1px solid #e5e7eb;
        }

        button[onclick="showTemplates()"]:hover {
            background: #f9fafb;
            border-color: #d1d5db;
        }

        /* Create/Generate Macro buttons */
        button[onclick="createMacro()"],
        button[onclick="generateAIMacro()"] {
            background: #1a1a1a;
            color: white;
            border: 1px solid #1a1a1a;
        }

        button[onclick="createMacro()"]:hover,
        button[onclick="generateAIMacro()"]:hover {
            background: #333;
        }

        /* Dark Mode */
        body.dark-mode {
            background: #0a0a0a;
            color: #e5e7eb;
        }

        body.dark-mode .top-bar {
            background: rgba(17, 17, 17, 0.8);
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
            color: #e5e7eb;
        }

        body.dark-mode .top-bar-group {
            background: rgba(255, 255, 255, 0.06);
        }

        body.dark-mode .top-bar-divider {
            background: rgba(255, 255, 255, 0.1);
        }

        body.dark-mode .top-bar h1 {
            color: #fff;
        }

        body.dark-mode .save-btn {
            background: transparent;
            color: #d1d5db;
            border-color: transparent;
        }

        body.dark-mode .save-btn:hover {
            background: rgba(255, 255, 255, 0.08);
            color: #f3f4f6;
        }

        /* Dropdown menu items */
        .dropdown-item {
            display: block;
            width: 100%;
            padding: 10px 16px;
            text-align: left;
            background: transparent;
            border: none;
            color: #e5e7eb;
            font-size: 13px;
            font-weight: 500;
            cursor: pointer;
            transition: background 0.1s ease;
        }
        .dropdown-item:hover {
            background: #374151;
        }

        /* Profile selector dark mode */
        body.dark-mode #profileSelector {
            background: #0a0a0a !important;
            color: #e5e7eb !important;
            border-color: #333 !important;
        }

        body.dark-mode .panel {
            background: #0f0f0f;
            border-color: #374151;
        }

        body.dark-mode .panel-title {
            color: #9ca3af;
        }

        body.dark-mode .macro-list {
            border-color: #374151;
            background: #0a0a0a;
        }

        body.dark-mode .macro-item {
            border-bottom-color: #1f1f1f;
            color: #e5e7eb;
        }

        body.dark-mode .macro-item:hover {
            background: #1a1a1a;
        }

        body.dark-mode .macro-item.selected {
            background: #1e3a8a;
            color: #93c5fd;
            border-left-color: #60a5fa;
        }

        body.dark-mode .device-button {
            background: #1a1a1a;
            color: #e5e7eb;
            border-color: #333;
        }

        body.dark-mode .keyboard-grid .device-button {
            background: #252525;
            border-color: #3a3a3a;
            color: #9ca3af;
        }

        body.dark-mode .device-button:hover {
            background: #222;
            border-color: #444;
        }

        body.dark-mode .device-button.mapped {
            background: var(--accent);
            color: white;
            border-color: var(--accent);
            filter: brightness(0.8);
        }

        body.dark-mode .device-button.has-other-mapping {
            background: #78350f;
            color: #fef3c7;
            border-color: #92400e;
        }

        body.dark-mode .device-button.selected {
            border-color: #60a5fa;
            box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
        }

        /* Dark mode - button ID numbers */
        body.dark-mode .device-button div[style*="rgba(0,0,0,0.5)"],
        body.dark-mode .device-button div[style*="rgba(0,0,0,0.4)"] {
            color: rgba(255,255,255,0.4) !important;
        }

        body.dark-mode .status-card {
            background: #1a1a1a;
            border-color: #333;
            color: #e5e7eb;
        }

        body.dark-mode .status-label {
            color: #9ca3af;
        }

        body.dark-mode .status-value {
            color: #fff;
        }

        body.dark-mode input,
        body.dark-mode select,
        body.dark-mode textarea {
            background: #0a0a0a;
            color: #e5e7eb;
            border-color: #2a2a2a;
        }

        body.dark-mode input::placeholder,
        body.dark-mode textarea::placeholder {
            color: #6b7280;
        }

        body.dark-mode input:focus,
        body.dark-mode select:focus,
        body.dark-mode textarea:focus {
            border-color: #3b82f6;
            outline: none;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
            background: #111;
        }

        body.dark-mode .keyboard-key {
            background: #1f2937;
            color: #e5e7eb;
            border-color: #374151;
        }

        body.dark-mode .keyboard-key:hover {
            background: #374151;
            border-color: #4b5563;
            transform: translateY(-1px);
        }

        body.dark-mode .keyboard-key.selected {
            background: #60a5fa;
            color: #111;
            border-color: #60a5fa;
            box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.2);
        }

        body.dark-mode .keyboard-key.remapped {
            background: var(--accent);
            color: white;
            border-color: var(--accent);
            filter: brightness(0.8);
        }

        body.dark-mode .keyboard-key.remapped:hover {
            filter: brightness(0.7);
            transform: translateY(-1px);
        }

        body.dark-mode .tab-btn {
            color: #9ca3af;
        }

        body.dark-mode .tab-btn.active {
            background: #333;
            color: #fff;
        }

        .tab-btn:focus-visible {
            outline: none;
        }

        body.dark-mode .device-tabs {
            background: #1a1a1a;
        }

        /* Keyboard mode toggle dark mode */
        body.dark-mode #keyboardModeToggle {
            background: #1a1a1a !important;
        }

        body.dark-mode .kb-mode-btn.active {
            background: #333 !important;
            color: #fff !important;
        }

        body.dark-mode .kb-mode-btn:not(.active) {
            color: #9ca3af !important;
        }

        body.dark-mode .action-btn {
            background: #1a1a1a;
            color: #e5e7eb;
            border-color: #333;
        }

        body.dark-mode .map-btn {
            background: var(--accent);
            color: white;
            border-color: var(--accent);
            filter: brightness(0.8);
        }

        body.dark-mode .map-btn:hover:not(:disabled) {
            filter: brightness(0.7);
        }

        body.dark-mode .clear-btn:hover {
            background: #222;
            border-color: #444;
        }

        body.dark-mode .key-remap-input {
            background: #1a1a1a;
            border-color: #333;
        }

        body.dark-mode button {
            color: #e5e7eb;
        }

        body.dark-mode .instructions {
            color: #9ca3af;
        }

        body.dark-mode .modifier-label {
            color: #e5e7eb;
        }

        body.dark-mode .checkbox-label {
            color: #e5e7eb;
        }

        body.dark-mode #macroPreview {
            background: #1a1a1a;
            border-color: #333;
        }

        body.dark-mode #previewContent {
            background: #0a0a0a;
            border-color: #333;
            color: #e5e7eb;
        }

        /* Modal */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.7);
            z-index: 1000;
            align-items: center;
            justify-content: center;
        }

        .modal.show {
            display: flex;
        }

        .modal-content {
            background: white;
            border-radius: 12px;
            padding: 32px;
            max-width: 600px;
            width: 90%;
            max-height: 80vh;
            overflow-y: auto;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
        }

        body.dark-mode .modal-content {
            background: #111;
            color: #e5e7eb;
        }

        .template-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 12px;
            margin-top: 20px;
        }

        .template-item {
            padding: 16px;
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.15s ease;
        }

        .template-item:hover {
            background: #f3f4f6;
            border-color: #d1d5db;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        }

        body.dark-mode .template-item {
            background: #1a1a1a;
            border-color: #333;
        }

        body.dark-mode .template-item:hover {
            background: #222;
            border-color: #444;
        }

        body.dark-mode #bulkActions {
            background: #1a1a1a;
            border-color: #333;
        }

        body.dark-mode #recordingStatus {
            background: rgba(239, 68, 68, 0.2);
            color: #fca5a5;
        }

        body.dark-mode #keysHelp {
            background: #1a1a1a;
            color: #9ca3af;
        }

        body.dark-mode hr {
            border-top-color: #333;
        }

        /* Dark mode specific button overrides */
        body.dark-mode button[style*="background: #1a1a1a"],
        body.dark-mode button[style*="background: white"] {
            background: #1a1a1a !important;
            color: #e5e7eb !important;
            border-color: #333 !important;
        }

        body.dark-mode button[style*="background: #ef4444"] {
            background: #991b1b !important;
            color: #fecaca !important;
            border-color: #991b1b !important;
        }

        body.dark-mode button[style*="background: #10b981"],
        body.dark-mode button[style*="background: linear-gradient(135deg, #10b981"] {
            background: #065f46 !important;
            color: #d1fae5 !important;
            border-color: #047857 !important;
        }

        body.dark-mode button[style*="background: #6b7280"] {
            background: #374151 !important;
            color: #e5e7eb !important;
            border-color: #4b5563 !important;
        }

        body.dark-mode .modal {
            background: rgba(0,0,0,0.85);
        }

        body.dark-mode .tooltip {
            background: #333;
            color: #e5e7eb;
        }

        /* Modal dark mode headers and text */
        body.dark-mode .modal-content h2 {
            color: #e5e7eb;
        }

        body.dark-mode .modal-content p {
            color: #9ca3af;
        }

        body.dark-mode .modal-content button[style*="font-size: 24px"] {
            color: #9ca3af !important;
        }

        body.dark-mode .modal-content button[style*="font-size: 24px"]:hover {
            color: #e5e7eb !important;
        }

        /* Scrollbar for dark mode */
        body.dark-mode ::-webkit-scrollbar {
            width: 10px;
            height: 10px;
        }

        body.dark-mode ::-webkit-scrollbar-track {
            background: #1a1a1a;
        }

        body.dark-mode ::-webkit-scrollbar-thumb {
            background: #333;
            border-radius: 5px;
        }

        body.dark-mode ::-webkit-scrollbar-thumb:hover {
            background: #444;
        }

        /* Dark mode for Create Macro boxes */
        body.dark-mode .create-macro-box {
            background: #0f0f0f !important;
            border-color: #2a2a2a !important;
        }

        body.dark-mode .create-macro-title {
            color: #f3f4f6 !important;
        }

        body.dark-mode .ai-macro-box {
            background: #0f0f0f !important;
            border-color: #2a2a2a !important;
        }

        body.dark-mode .ai-macro-title {
            color: #f3f4f6 !important;
        }

        /* Dark mode for labels */
        body.dark-mode label {
            color: #9ca3af !important;
        }

        body.dark-mode label[style*="color: #6b7280"] {
            color: #9ca3af !important;
        }

        /* Dark mode for help text and tips */
        body.dark-mode div[style*="color: #1a1a1a"] {
            color: #e5e7eb !important;
        }

        body.dark-mode div[style*="color: #64748b"] {
            color: #9ca3af !important;
        }

        /* Dark mode for inline-styled backgrounds */
        body.dark-mode div[style*="background: #f9fafb"] {
            background: #1a1a1a !important;
        }

        body.dark-mode textarea[style*="background: white"] {
            background: #1a1a1a !important;
        }

        /* Dark mode for Browse Templates button */
        body.dark-mode button[onclick="showTemplates()"] {
            background: #1a1a1a !important;
            color: #e5e7eb !important;
            border-color: #333 !important;
        }

        body.dark-mode button[onclick="showTemplates()"]:hover {
            background: #222 !important;
            border-color: #444 !important;
        }

        /* Dark mode for all white boxes - aggressive overrides */
        body.dark-mode div[style*="background: white"],
        body.dark-mode div[style*="background:white"] {
            background: #1a1a1a !important;
            border-color: #333 !important;
        }

        body.dark-mode div[style*="color: #1a1a1a"] {
            color: #e5e7eb !important;
        }

        /* Dark mode for specific elements in Create Macro box */
        body.dark-mode #newMacroName,
        body.dark-mode #newMacroCategory,
        body.dark-mode #newMacroActionType,
        body.dark-mode #newMacroText,
        body.dark-mode #newMacroKeys,
        body.dark-mode #aiPrompt,
        body.dark-mode #macroSearch,
        body.dark-mode #categoryFilter,
        body.dark-mode #sortOrder {
            background: #0a0a0a !important;
            color: #e5e7eb !important;
            border-color: #2a2a2a !important;
        }

        body.dark-mode #newMacroName::placeholder,
        body.dark-mode #newMacroText::placeholder,
        body.dark-mode #newMacroKeys::placeholder,
        body.dark-mode #aiPrompt::placeholder,
        body.dark-mode #macroSearch::placeholder {
            color: #6b7280 !important;
        }

        /* Dark mode for Create Macro button */
        body.dark-mode button[onclick="createMacro()"] {
            background: #333 !important;
            color: #e5e7eb !important;
            border-color: #444 !important;
        }

        body.dark-mode button[onclick="createMacro()"]:hover {
            background: #444 !important;
        }

        /* Dark mode for Generate Macro button */
        body.dark-mode button[onclick="generateAIMacro()"] {
            background: #333 !important;
            color: #e5e7eb !important;
            border-color: #444 !important;
        }

        body.dark-mode button[onclick="generateAIMacro()"]:hover {
            background: #444 !important;
        }

        /* Dark mode for Record button */
        body.dark-mode #recordBtn {
            background: #7f1d1d !important;
            color: #fecaca !important;
        }

        body.dark-mode #recordBtn:hover {
            background: #991b1b !important;
        }

        /* Dark mode for Clear button in keys input */
        body.dark-mode button[onclick="clearKeysInput()"] {
            background: #374151 !important;
            color: #e5e7eb !important;
        }

        /* Dark mode for all select dropdowns */
        body.dark-mode select option {
            background: #1a1a1a;
            color: #e5e7eb;
        }

        /* Dark mode for info boxes with background colors */
        body.dark-mode div[style*="background: #f0f9ff"] {
            background: #172554 !important;
            border-color: #1e40af !important;
        }

        body.dark-mode div[style*="color: #0369a1"] {
            color: #93c5fd !important;
        }

        body.dark-mode div[style*="color: #075985"] {
            color: #bfdbfe !important;
        }

        /* Dark mode for Macro Preview box */
        body.dark-mode #macroPreview {
            background: #1a1a1a !important;
            border-color: #333 !important;
        }

        body.dark-mode #macroPreview div[style*="font-weight: 600"] {
            color: #e5e7eb !important;
        }

        body.dark-mode #macroPreview div[style*="font-size: 12px"],
        body.dark-mode #macroPreview strong {
            color: #9ca3af !important;
        }

        body.dark-mode #macroPreview #previewName,
        body.dark-mode #macroPreview #previewType {
            color: #e5e7eb !important;
        }

        /* Dark mode for Edit, Duplicate and Delete buttons in preview */
        body.dark-mode button[onclick="editMacro()"] {
            background: #1a1a1a !important;
            color: #3b82f6 !important;
            border-color: #3b82f6 !important;
        }

        body.dark-mode button[onclick="duplicateMacro()"] {
            background: #1a1a1a !important;
            color: #e5e7eb !important;
            border-color: #333 !important;
        }

        body.dark-mode button[onclick="duplicateMacro()"]:hover {
            background: #222 !important;
            border-color: #444 !important;
        }

        body.dark-mode button[onclick="deleteMacro()"] {
            background: #1a1a1a !important;
            color: #ef4444 !important;
            border-color: #7f1d1d !important;
        }

        body.dark-mode button[onclick="deleteMacro()"]:hover {
            background: #7f1d1d !important;
            color: #fecaca !important;
        }

        /* Contextual Bar */
        .context-bar {
            display: none;
            align-items: center;
            gap: 10px;
            padding: 8px 14px;
            background: #f3f4f6;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            margin-top: 12px;
            animation: contextBarSlideUp 0.2s ease;
            flex-wrap: nowrap;
            min-height: 0;
        }

        .context-bar.visible {
            display: flex;
        }

        .context-bar .cb-value {
            font-size: 13px;
            font-weight: 700;
            color: #1a1a1a;
            white-space: nowrap;
            flex-shrink: 0;
        }

        .context-bar .cb-mapping {
            font-size: 12px;
            color: #6b7280;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 200px;
        }

        .context-bar .cb-separator {
            width: 1px;
            height: 20px;
            background: #d1d5db;
            flex-shrink: 0;
        }

        .context-bar .cb-actions {
            display: flex;
            gap: 6px;
            margin-left: auto;
            flex-shrink: 0;
        }

        .context-bar .cb-actions button {
            padding: 5px 12px;
            border-radius: 5px;
            font-size: 11px;
            font-weight: 600;
            cursor: pointer;
            border: 1px solid;
            transition: all 0.15s ease;
            white-space: nowrap;
        }

        body.dark-mode .context-bar {
            background: #1a1a1a;
            border-color: #333;
        }

        body.dark-mode .context-bar .cb-value {
            color: #e5e7eb;
        }

        body.dark-mode .context-bar .cb-mapping {
            color: #9ca3af;
        }

        body.dark-mode .context-bar .cb-separator {
            background: #374151;
        }

        @keyframes contextBarSlideUp {
            from { opacity: 0; transform: translateY(8px); }
            to { opacity: 1; transform: translateY(0); }
        }

        /* Deploy button in header */
        .deploy-header-btn {
            background: #10b981;
            color: white;
            border: 1px solid #10b981;
            padding: 5px 14px;
            font-size: 11px;
            font-weight: 600;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.15s ease;
            white-space: nowrap;
        }

        .deploy-header-btn:hover {
            background: #059669;
            border-color: #059669;
        }

        /* Animations */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .macro-item,
        .device-button {
            animation: fadeIn 0.2s ease;
        }

        /* Bulk selection */
        .macro-item.bulk-selected {
            background: #dbeafe !important;
            border-left: 3px solid #3b82f6 !important;
        }

        body.dark-mode .macro-item.bulk-selected {
            background: #1e3a5f !important;
        }

        /* Tooltip */
        .tooltip {
            position: absolute;
            background: #1a1a1a;
            color: white;
            padding: 8px 12px;
            border-radius: 6px;
            font-size: 12px;
            z-index: 1000;
            pointer-events: none;
            white-space: nowrap;
            max-width: 300px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        }

        /* ============================================ */
        /* NEW UI ENHANCEMENTS */
        /* ============================================ */

        /* Toast Notifications */
        .toast-container {
            position: fixed;
            top: 80px;
            right: 20px;
            z-index: 10000;
            display: flex;
            flex-direction: column;
            gap: 10px;
            pointer-events: none;
        }

        .toast {
            background: white;
            color: #1a1a1a;
            padding: 16px 20px;
            border-radius: 8px;
            box-shadow: 0 4px 16px rgba(0,0,0,0.15);
            border-left: 4px solid #10b981;
            display: flex;
            align-items: center;
            gap: 12px;
            min-width: 300px;
            max-width: 400px;
            pointer-events: auto;
            animation: toastSlideIn 0.3s ease;
            transition: all 0.3s ease;
        }

        .toast.success {
            border-left-color: #10b981;
        }

        .toast.error {
            border-left-color: #ef4444;
        }

        .toast.info {
            border-left-color: #3b82f6;
        }

        .toast.warning {
            border-left-color: #f59e0b;
        }

        .toast-icon {
            font-size: 20px;
            flex-shrink: 0;
        }

        .toast-content {
            flex: 1;
        }

        .toast-title {
            font-weight: 600;
            font-size: 14px;
            margin-bottom: 2px;
        }

        .toast-message {
            font-size: 13px;
            color: #6b7280;
        }

        .toast-close {
            background: none;
            border: none;
            color: #9ca3af;
            cursor: pointer;
            font-size: 18px;
            padding: 0;
            width: 20px;
            height: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 4px;
            transition: all 0.15s ease;
        }

        .toast-close:hover {
            background: #f3f4f6;
            color: #1a1a1a;
        }

        @keyframes toastSlideIn {
            from {
                transform: translateX(400px);
                opacity: 0;
            }
            to {
                transform: translateX(0);
                opacity: 1;
            }
        }

        @keyframes toastSlideOut {
            from {
                transform: translateX(0);
                opacity: 1;
            }
            to {
                transform: translateX(400px);
                opacity: 0;
            }
        }

        .toast.removing {
            animation: toastSlideOut 0.3s ease forwards;
        }

        body.dark-mode .toast {
            background: #1a1a1a;
            color: #e5e7eb;
            border-left-width: 4px;
        }

        body.dark-mode .toast-message {
            color: #9ca3af;
        }

        body.dark-mode .toast-close:hover {
            background: #333;
            color: #fff;
        }

        /* Loading Spinner */
        .loading-spinner {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid rgba(59, 130, 246, 0.3);
            border-top-color: #3b82f6;
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }

        .loading-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 9999;
        }

        .loading-content {
            background: white;
            padding: 32px;
            border-radius: 12px;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 16px;
        }

        .loading-content .loading-spinner {
            width: 40px;
            height: 40px;
            border-width: 4px;
        }

        .loading-text {
            font-size: 14px;
            font-weight: 500;
            color: #1a1a1a;
        }

        body.dark-mode .loading-content {
            background: #1a1a1a;
        }

        body.dark-mode .loading-text {
            color: #e5e7eb;
        }

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

        /* Empty States */
        .empty-state {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 60px 20px;
            text-align: center;
        }

        .empty-state-icon {
            font-size: 64px;
            margin-bottom: 16px;
            opacity: 0.5;
        }

        .empty-state-title {
            font-size: 18px;
            font-weight: 600;
            color: #1a1a1a;
            margin-bottom: 8px;
        }

        .empty-state-message {
            font-size: 14px;
            color: #6b7280;
            max-width: 300px;
            line-height: 1.6;
        }

        body.dark-mode .empty-state-title {
            color: #e5e7eb;
        }

        body.dark-mode .empty-state-message {
            color: #9ca3af;
        }

        /* Category Badges */
        .category-badge {
            display: inline-block;
            padding: 3px 8px;
            border-radius: 4px;
            font-size: 10px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            margin-left: 8px;
        }

        /* Usage Indicator */
        .usage-indicator {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            font-size: 10px;
            color: #9ca3af;
            margin-left: 8px;
        }

        .usage-count {
            font-weight: 600;
        }

        /* Favorite Star */
        .favorite-star {
            cursor: pointer;
            font-size: 16px;
            opacity: 0.3;
            transition: all 0.2s ease;
            margin-left: 8px;
        }

        .favorite-star:hover {
            opacity: 0.6;
            transform: scale(1.2);
        }

        .favorite-star.active {
            opacity: 1;
            color: #fbbf24;
        }

        /* Button Hover Enhancements */
        button:not(.device-button):not(.keyboard-key):not(.tab-btn):not(.macro-item):not(.toast-close) {
            transition: all 0.2s ease;
        }

        button:not(.device-button):not(.keyboard-key):not(.tab-btn):not(.macro-item):not(.toast-close):hover:not(:disabled) {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        }

        button:not(.device-button):not(.keyboard-key):not(.tab-btn):not(.macro-item):not(.toast-close):active:not(:disabled) {
            transform: translateY(0);
        }

        /* Smooth Scrolling */
        * {
            scroll-behavior: smooth;
        }

        /* Enhanced Drag Feedback */
        .dragging {
            opacity: 0.5;
            cursor: grabbing !important;
        }

        .drag-over {
            background: #eff6ff !important;
            border-color: #3b82f6 !important;
            transform: scale(1.02);
        }

        body.dark-mode .drag-over {
            background: #1e3a8a !important;
            border-color: #60a5fa !important;
        }

        /* Keyboard Shortcuts Display */
        .keyboard-shortcut {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 4px 8px;
            background: #f3f4f6;
            border: 1px solid #d1d5db;
            border-radius: 4px;
            font-size: 11px;
            font-weight: 600;
            font-family: 'Monaco', 'Menlo', monospace;
            color: #374151;
        }

        body.dark-mode .keyboard-shortcut {
            background: #2a2a2a;
            border-color: #3a3a3a;
            color: #9ca3af;
        }

        /* Enhanced Tooltips */
        .has-tooltip {
            position: relative;
        }

        .has-tooltip::after {
            content: attr(data-tooltip);
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%) translateY(-8px);
            background: #1a1a1a;
            color: white;
            padding: 6px 10px;
            border-radius: 6px;
            font-size: 12px;
            white-space: nowrap;
            opacity: 0;
            pointer-events: none;
            transition: all 0.2s ease;
            z-index: 10001;
        }

        .has-tooltip:hover::after {
            opacity: 1;
            transform: translateX(-50%) translateY(-4px);
        }

        body.dark-mode .has-tooltip::after {
            background: #333;
        }

        /* Better Focus Indicators */
        *:focus-visible {
            outline: 2px solid #3b82f6;
            outline-offset: 2px;
        }

        body.dark-mode *:focus-visible {
            outline-color: #60a5fa;
        }

        /* Recent Macros Section */
        .recent-section {
            margin-bottom: 20px;
            padding: 12px;
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
        }

        .recent-title {
            font-size: 11px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.1em;
            color: #9ca3af;
            margin-bottom: 8px;
        }

        body.dark-mode .recent-section {
            background: #0f0f0f;
            border-color: #2a2a2a;
        }

        /* Pulse Animation for New Items */
        @keyframes pulse {
            0%, 100% {
                opacity: 1;
            }
            50% {
                opacity: 0.7;
            }
        }

        .pulse {
            animation: pulse 2s ease-in-out;
        }

        /* Keyboard Shortcuts Display */
        .keyboard-shortcut-display {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .key-badge {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-width: 32px;
            height: 32px;
            padding: 0 10px;
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 6px;
            font-size: 13px;
            font-weight: 600;
            color: #1a1a1a;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.05);
        }

        body.dark-mode .key-badge {
            background: #1a1a1a;
            color: white;
            border-color: #333;
        }

        body.dark-mode #keyboardShortcutsModal .modal-content {
            background: #0a0a0a;
            border-color: #2a2a2a;
        }

        body.dark-mode #keyboardShortcutsModal .modal-content > div > div {
            background: #0f0f0f !important;
            border-color: #2a2a2a !important;
        }

        /* Custom Device Tab - Add Button */
        .device-tab-add {
            flex: 0 0 auto !important;
            min-width: 36px;
            max-width: 36px;
            padding: 10px 0 !important;
            font-size: 18px !important;
            font-weight: 600;
            color: #6b7280 !important;
            border: 2px dashed #d1d5db !important;
            background: transparent !important;
        }

        .device-tab-add:hover {
            color: #10b981 !important;
            border-color: #10b981 !important;
            background: rgba(16, 185, 129, 0.05) !important;
        }

        body.dark-mode .device-tab-add {
            border-color: #374151 !important;
            color: #6b7280 !important;
        }

        body.dark-mode .device-tab-add:hover {
            color: #10b981 !important;
            border-color: #10b981 !important;
            background: rgba(16, 185, 129, 0.1) !important;
        }

        /* AHK Builder Styles */
        .ahk-palette-block:hover {
            opacity: 0.85;
        }

        .ahk-sequence-block input:focus {
            border-color: #3b82f6 !important;
            outline: none;
        }

        /* Dark mode for AHK Builder button */
        body.dark-mode button[onclick="openAHKBuilder()"] {
            background: #1a1a1a !important;
            color: #e5e7eb !important;
            border-color: #333 !important;
        }

        body.dark-mode button[onclick="openAHKBuilder()"]:hover {
            background: #222 !important;
            border-color: #444 !important;
        }

        /* Dark mode for template filter controls */
        body.dark-mode #templateSearch,
        body.dark-mode #templateCategoryFilter,
        body.dark-mode #templateSort {
            background: #0a0a0a !important;
            color: #e5e7eb !important;
            border-color: #2a2a2a !important;
        }

        /* Dark mode for Feedback button */
        body.dark-mode button[onclick="openFeedbackModal()"] {
            background: transparent !important;
            color: #9ca3af !important;
            border-color: #374151 !important;
        }

        /* Dark mode for feedback modal inputs */
        body.dark-mode #feedbackType,
        body.dark-mode #feedbackTitle,
        body.dark-mode #feedbackDescription,
        body.dark-mode #feedbackEmail {
            background: #0a0a0a !important;
            color: #e5e7eb !important;
            border-color: #2a2a2a !important;
        }

        /* Dark mode for AHK builder inputs */
        body.dark-mode #ahkBuilderName {
            background: #0a0a0a !important;
            color: #e5e7eb !important;
            border-color: #2a2a2a !important;
        }

        /* Dark mode for AHK export warning */
        body.dark-mode #ahkExportWarning {
            background: #78350f !important;
            border-color: #92400e !important;
            color: #fef3c7 !important;
        }

        /* Grid Editor Styles */
        .grid-edit-btn:hover {
            box-shadow: 0 0 0 2px rgba(59,130,246,0.5);
        }

        .grid-edit-btn:active {
            cursor: grabbing;
        }

        .grid-edit-empty:hover {
            border-color: #3b82f6 !important;
            color: #3b82f6 !important;
            background: rgba(59,130,246,0.05);
        }

        /* Grid Edit Controls Bar */
        .grid-edit-controls {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 10px;
        }

        .grid-edit-toggle {
            padding: 7px 14px;
            background: #6366f1;
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            white-space: nowrap;
        }

        .grid-edit-quickmap {
            padding: 7px 14px;
            background: transparent;
            color: #6b7280;
            border: 1px solid #d1d5db;
            border-radius: 6px;
            font-size: 12px;
            font-weight: 500;
            cursor: pointer;
            white-space: nowrap;
        }

        .grid-edit-quickmap:hover {
            color: #1a1a1a;
            border-color: #9ca3af;
        }

        body.dark-mode .grid-edit-quickmap {
            color: #9ca3af;
            border-color: #374151;
        }

        body.dark-mode .grid-edit-quickmap:hover {
            color: #e5e7eb;
            border-color: #6b7280;
        }

        .grid-edit-toolbar {
            display: none;
            align-items: center;
            gap: 2px;
            margin-left: 8px;
            background: #f3f4f6;
            border-radius: 8px;
            padding: 4px 10px;
        }

        body.dark-mode .grid-edit-toolbar {
            background: #1a1a1a;
        }

        .grid-edit-toolbar-group {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .grid-edit-toolbar-label {
            font-size: 10px;
            font-weight: 600;
            color: #9ca3af;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            margin-right: 2px;
        }

        .grid-edit-adj-btn {
            width: 26px;
            height: 26px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: white;
            color: #374151;
            border: 1px solid #d1d5db;
            border-radius: 5px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            padding: 0;
            line-height: 1;
        }

        .grid-edit-adj-btn:hover {
            background: #e5e7eb;
            border-color: #9ca3af;
        }

        body.dark-mode .grid-edit-adj-btn {
            background: #374151;
            color: #e5e7eb;
            border-color: #4b5563;
        }

        body.dark-mode .grid-edit-adj-btn:hover {
            background: #4b5563;
            border-color: #6b7280;
        }

        .grid-edit-counter {
            font-size: 13px;
            font-weight: 700;
            min-width: 18px;
            text-align: center;
            color: #1a1a1a;
        }

        body.dark-mode .grid-edit-counter {
            color: #e5e7eb;
        }

        .grid-edit-toolbar-divider {
            width: 1px;
            height: 20px;
            background: #d1d5db;
            margin: 0 8px;
        }

        body.dark-mode .grid-edit-toolbar-divider {
            background: #374151;
        }

        /* Modifier checkbox group - improved layout */
        .checkbox-group {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }

        .checkbox-label {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 13px;
            font-weight: 600;
            cursor: pointer;
            padding: 6px 10px;
            border-radius: 6px;
            border: 1px solid #e5e7eb;
            background: #f9fafb;
            transition: all 0.15s ease;
        }

        .checkbox-label:hover {
            background: #f3f4f6;
            border-color: #d1d5db;
        }

        body.dark-mode .checkbox-label {
            border-color: #333;
            background: #1a1a1a;
        }

        body.dark-mode .checkbox-label:hover {
            background: #222;
            border-color: #444;
        }

        /* Account Avatar Button */
        .account-btn {
            width: 34px;
            height: 34px;
            border-radius: 50%;
            background: linear-gradient(135deg, #6366f1, #8b5cf6);
            color: white;
            border: none;
            font-size: 13px;
            font-weight: 700;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s ease;
            flex-shrink: 0;
        }

        .account-btn:hover {
            transform: scale(1.08);
            box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
        }

        /* Profile selector compact */
        .profile-compact {
            display: flex;
            align-items: center;
            gap: 4px;
            padding: 3px 8px;
            background: rgba(0, 0, 0, 0.04);
            border-radius: 8px;
            border: 1px solid rgba(0, 0, 0, 0.06);
        }

        body.dark-mode .profile-compact {
            background: rgba(255, 255, 255, 0.06);
            border-color: rgba(255, 255, 255, 0.08);
        }

        .profile-compact select {
            padding: 4px 8px;
            border-radius: 6px;
            border: none;
            font-size: 12px;
            font-weight: 600;
            min-width: 120px;
            background: transparent;
            color: inherit;
        }

        .profile-compact .profile-action-btn {
            padding: 2px 7px;
            border: none;
            border-radius: 5px;
            font-size: 13px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.15s ease;
            background: transparent;
            color: inherit;
            opacity: 0.5;
            line-height: 1;
        }

        .profile-compact .profile-action-btn:hover {
            opacity: 1;
            background: rgba(0, 0, 0, 0.06);
        }

        body.dark-mode .profile-compact .profile-action-btn:hover {
            background: rgba(255, 255, 255, 0.1);
        }

        .profile-compact .profile-delete-btn:hover {
            color: #ef4444;
        }

        /* Settings Page */
        .settings-container {
            max-width: 720px;
            margin: 0 auto;
            padding: 40px 24px;
        }

        .settings-section {
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 12px;
            padding: 24px;
            margin-bottom: 20px;
        }

        body.dark-mode .settings-section {
            background: #0f0f0f;
            border-color: #2a2a2a;
        }

        .settings-section h3 {
            font-size: 15px;
            font-weight: 600;
            margin-bottom: 16px;
            color: inherit;
        }

        .settings-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid #f3f4f6;
        }

        body.dark-mode .settings-row {
            border-bottom-color: #1f1f1f;
        }

        .settings-row:last-child {
            border-bottom: none;
        }

        .settings-label {
            font-size: 13px;
            font-weight: 500;
            color: #374151;
        }

        body.dark-mode .settings-label {
            color: #d1d5db;
        }

        .settings-value {
            font-size: 13px;
            color: #6b7280;
        }

        body.dark-mode .settings-value {
            color: #9ca3af;
        }

        /* Dark mode for smart import modal */
        body.dark-mode #smartImportMacros,
        body.dark-mode #smartImportMappings {
            background: #0a0a0a;
            border-color: #2a2a2a !important;
        }

        /* Profile Tab Bar */
        .profile-tab-bar {
            display: flex;
            align-items: center;
            gap: 2px;
            padding: 6px 24px;
            background: #f3f4f6;
            border-bottom: 1px solid #e5e7eb;
            overflow-x: auto;
            flex-wrap: nowrap;
        }

        body.dark-mode .profile-tab-bar {
            background: #111;
            border-bottom-color: #2a2a2a;
        }

        .profile-tab {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 6px 16px;
            border: none;
            border-bottom: 2px solid transparent;
            background: transparent;
            color: #6b7280;
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            white-space: nowrap;
            transition: all 0.15s ease;
        }

        .profile-tab:hover {
            color: #1a1a1a;
        }

        .profile-tab-action {
            background: none;
            border: none;
            font-size: 13px;
            cursor: pointer;
            padding: 0 2px;
            color: #93c5fd;
            opacity: 0.7;
            transition: opacity 0.15s;
            line-height: 1;
        }

        .profile-tab-action:hover {
            opacity: 1;
        }

        .profile-tab-delete:hover {
            color: #f87171;
        }

        body.dark-mode .profile-tab-action {
            color: #93c5fd;
        }

        body.dark-mode .profile-tab-delete:hover {
            color: #f87171;
        }

        body.dark-mode .profile-tab:hover {
            color: #e5e7eb;
        }

        .profile-tab.active {
            color: #1d4ed8;
            background: #dbeafe;
            border-bottom-color: #3b82f6;
            border-radius: 6px 6px 0 0;
            padding: 6px 12px;
        }

        body.dark-mode .profile-tab.active {
            color: #93c5fd;
            background: #1e3a8a;
            border-bottom-color: #60a5fa;
        }

        .profile-tab-add-btn {
            padding: 6px 12px;
            font-size: 16px;
            font-weight: 700;
            color: #9ca3af;
            opacity: 0.6;
        }

        .profile-tab-add-btn:hover {
            opacity: 1;
            color: #10b981;
        }

        /* ============================================ */
        /* DARK MODE CONTRAST FIXES (WCAG AA)           */
        /* ============================================ */

        /* Improve muted text contrast: #6b7280 on #0a0a0a = 4.2:1, bump to #9ca3af = 6.5:1 */
        body.dark-mode .help-text,
        body.dark-mode .toast-message,
        body.dark-mode .instructions {
            color: #a1a1aa;
        }

        /* Borders: #2a2a2a on #0a0a0a = 1.4:1, bump to #4b5563 = 2.7:1+ for key UI borders */
        body.dark-mode .status-card {
            border-color: #4b5563;
        }

        body.dark-mode .create-macro-box,
        body.dark-mode .ai-macro-box {
            border-color: #374151 !important;
        }

        body.dark-mode input,
        body.dark-mode select,
        body.dark-mode textarea {
            border-color: #4b5563;
        }

        /* Interactive element glow on hover */
        body.dark-mode .device-button:hover {
            box-shadow: 0 0 8px rgba(96, 165, 250, 0.15);
        }

        body.dark-mode .macro-item:hover {
            box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.1);
        }

        body.dark-mode .map-btn:hover:not(:disabled) {
            box-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
        }

        /* Focus ring visibility in dark mode */
        body.dark-mode *:focus-visible {
            outline: 2px solid #60a5fa;
            outline-offset: 2px;
            box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.15);
        }

        /* Disabled state - slightly higher contrast */
        body.dark-mode .action-btn:disabled {
            opacity: 0.45;
            color: #6b7280;
        }

        /* ============================================ */
        /* RICH MACRO CARDS                             */
        /* ============================================ */

        .macro-action-icon {
            font-size: 14px;
            flex-shrink: 0;
            opacity: 0.6;
            width: 20px;
            text-align: center;
        }

        .category-badge {
            cursor: pointer;
            transition: opacity 0.15s ease;
        }

        .category-badge:hover {
            opacity: 0.8;
        }

        /* ============================================ */
        /* RESIZE HANDLES                               */
        /* ============================================ */

        /* Grid button right-edge resize handle */
        .grid-resize-handle {
            position: absolute;
            top: 0;
            right: 0;
            width: 4px;
            height: 100%;
            cursor: ew-resize;
            background: transparent;
            transition: background 0.15s ease;
            z-index: 2;
        }

        .device-button:hover .grid-resize-handle {
            background: rgba(59, 130, 246, 0.3);
        }

        .grid-resize-handle:hover {
            background: rgba(59, 130, 246, 0.6) !important;
        }

        body.dark-mode .device-button:hover .grid-resize-handle {
            background: rgba(96, 165, 250, 0.3);
        }

        body.dark-mode .grid-resize-handle:hover {
            background: rgba(96, 165, 250, 0.6) !important;
        }

        /* SVG resize handle indicator - shown via JS on hover */
        .svg-resize-handle {
            cursor: nwse-resize;
        }

        /* ============================================
           RESPONSIVE - TABLET (≤1024px)
           ============================================ */
        @media (max-width: 1024px) {
            .container {
                grid-template-columns: 1fr 1fr;
                grid-template-rows: auto auto;
                height: auto;
                min-height: calc(100vh - 92px);
            }
            .container > .panel:nth-child(3) {
                grid-column: 1 / -1;
            }
            .panel {
                padding: 16px;
            }
            .macro-list {
                max-height: 300px;
            }
        }

        /* ============================================
           RESPONSIVE - PHONE (≤640px)
           ============================================ */
        @media (max-width: 640px) {
            .header {
                flex-wrap: wrap;
                gap: 8px;
                padding: 10px 12px;
            }
            .header h1 {
                font-size: 16px;
            }
            .container {
                grid-template-columns: 1fr;
                gap: 10px;
                padding: 10px;
                height: auto;
            }
            .container > .panel:nth-child(3) {
                grid-column: auto;
            }
            .panel {
                padding: 12px;
                border-radius: 8px;
            }
            .macro-list {
                max-height: 250px;
            }
            /* Larger touch targets */
            .macro-item {
                min-height: 44px;
                padding: 10px 12px;
            }
            .device-button {
                min-width: 44px;
                min-height: 44px;
            }
            button, .btn, select, input[type="text"], input[type="search"] {
                min-height: 44px;
                font-size: 14px;
            }
            /* Stack device button grid tighter */
            .button-grid {
                gap: 4px;
            }
            /* Collapsible panels via details/summary pattern */
            .panel-title {
                cursor: pointer;
                user-select: none;
            }
            /* Device tabs stack */
            .device-tabs {
                flex-wrap: wrap;
                gap: 4px;
            }
            .device-tabs button {
                flex: 1 1 auto;
                min-width: 80px;
            }
        }

        /* Action Cards */
        .action-cards-grid {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            margin-bottom: 8px;
        }
        .action-card {
            padding: 6px 12px;
            border: 1px solid #333;
            border-radius: 6px;
            cursor: pointer;
            font-size: 12px;
            color: #9ca3af;
            background: #111;
            transition: all 0.15s;
            user-select: none;
        }
        .action-card:hover {
            border-color: #555;
            color: #e5e7eb;
        }
        .action-card.selected {
            border-color: #7c3aed;
            color: white;
            background: #2d1b69;
        }
        .action-card-sm {
            font-size: 10px;
            padding: 4px 10px;
            color: #6b7280;
            border-color: #282828;
        }
