/* CSS Custom Properties */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-tertiary: #2d2d2d;
    --bg-hover: #363636;
    --bg-selected: #3a3a3a;

    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-muted: #707070;

    --border-color: #404040;
    --border-light: #505050;

    --accent-primary: #4a9eff;
    --accent-hover: #3d8ae6;
    --accent-success: #4caf50;
    --accent-warning: #ff9800;
    --accent-error: #f44336;

    --header-height: 50px;
    --tabs-height: 36px;
    --status-height: 28px;

    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.4;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.firmware-note {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: help;
}

.connection-status {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 12px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.connection-status.connected {
    background: rgba(76, 175, 80, 0.2);
    color: var(--accent-success);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.separator {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 8px;
}

/* Buttons */
.btn {
    font-family: inherit;
    font-size: 12px;
    padding: 6px 14px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

/* Split Button with Dropdown */
.btn-split {
    position: relative;
    display: inline-flex;
}

.btn-split-main {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.btn-split-arrow {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    padding: 6px 8px;
    min-width: 28px;
}

.btn-split-arrow:hover:not(:disabled) {
    background: var(--bg-hover);
}

.btn-split-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 100;
    min-width: 140px;
}

.btn-split-menu.show {
    display: block;
}

.btn-split-menu button {
    display: block;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
    transition: background 0.1s ease;
}

.btn-split-menu button:hover {
    background: var(--bg-hover);
}

.btn-split-menu button:first-child {
    border-radius: 3px 3px 0 0;
}

.btn-split-menu button:last-child {
    border-radius: 0 0 3px 3px;
}

/* Tabs */
.tabs {
    height: var(--tabs-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    padding: 0 16px;
    flex-shrink: 0;
}

.tab {
    font-family: inherit;
    font-size: 13px;
    padding: 0 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    transition: color 0.15s ease;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--accent-primary);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-primary);
}

.tab.hidden {
    display: none;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel {
    display: none;
    flex: 1;
    overflow: hidden;
    flex-direction: column;
}

.panel.active {
    display: flex;
}

/* Grid Toolbar */
.grid-toolbar {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.grid-info {
    font-size: 11px;
    color: var(--text-muted);
}

/* Channel Grid */
.grid-container {
    flex: 1;
    overflow: auto;
    padding: 0;
}

.channel-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    font-family: var(--font-mono);
}

.channel-grid thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.channel-grid th {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-weight: 500;
    padding: 8px 6px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    user-select: none;
}

.channel-grid td {
    padding: 0;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    height: 28px;
    background: var(--bg-primary);
}

.channel-grid td:first-child {
    border-left: 1px solid var(--border-color);
}

.channel-grid tr:hover td {
    background: var(--bg-secondary);
}

.channel-grid tr.selected td {
    background: var(--bg-selected);
}

/* Empty channel rows */
.channel-grid tr.empty-channel td {
    opacity: 0.5;
}

.channel-grid tr.empty-channel:hover td {
    opacity: 1;
}

/* Disabled cells in empty channels */
.cell.disabled {
    background: transparent;
    cursor: not-allowed;
    color: var(--text-muted);
}

.cell.disabled:hover {
    background: transparent;
}

/* Column widths */
.col-ch { width: 45px; text-align: center; }
.col-rxfreq, .col-txfreq { width: 95px; }
.col-hop, .col-power, .col-bw, .col-mod, .col-busy, .col-pttid, .col-scan, .col-scramble { width: 55px; }
.col-decode, .col-encode { width: 100px; }
.col-name { width: 90px; }

/* Grid Cells */
.cell {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 6px;
    cursor: default;
}

.cell.readonly {
    color: var(--text-muted);
    justify-content: center;
}

.cell.editable {
    cursor: pointer;
}

.cell.editable:hover {
    background: var(--bg-hover);
}

.cell.focused {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
    background: var(--bg-tertiary);
}

.cell.editing {
    padding: 0;
}

/* Cell Inputs */
.cell input,
.cell select {
    width: 100%;
    height: 100%;
    padding: 0 6px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    outline: none;
}

.cell input:focus,
.cell select:focus {
    background: var(--bg-hover);
}

.cell select {
    cursor: pointer;
}

/* Panel disabled state - shared by grid, settings, debug */
.panel-disabled-message {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 16;
    background: var(--bg-primary);
    padding: 20px 32px;
    border-radius: 8px;
    border: 2px solid var(--accent-primary);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.disabled .panel-disabled-message {
    display: block;
}

/* Grid disabled state */
.grid-container.disabled {
    position: relative;
    pointer-events: none;
    overflow: hidden;
}

.grid-container.disabled::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 15;
}

.grid-container.disabled table {
    opacity: 0.4;
}

/* Settings disabled state */
.settings-container.disabled {
    position: relative;
    pointer-events: none;
    overflow: hidden;
}

.settings-container.disabled::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 15;
}

.settings-container.disabled > *:not(.panel-disabled-message) {
    opacity: 0.4;
}

/* Debug disabled state */
.debug-container.disabled {
    position: relative;
    pointer-events: none;
    overflow: hidden;
}

.debug-container.disabled::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 15;
}

.debug-container.disabled > *:not(.panel-disabled-message) {
    opacity: 0.4;
}

/* Settings Panel */
.settings-container {
    flex: 1;
    overflow: auto;
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    align-content: start;
}

.settings-group {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 16px;
}

.settings-group h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    gap: 12px;
}

.setting-row label {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.setting-row label[title] {
    cursor: help;
}

.setting-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 18px;
    padding: 0 4px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
}

.setting-row select,
.setting-row input[type="text"],
.setting-row input[type="number"] {
    width: 120px;
    min-width: 80px;
    flex-shrink: 1;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
}

.setting-row select:focus,
.setting-row input[type="text"]:focus,
.setting-row input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.setting-row .text-input {
    width: 140px;
    min-width: 80px;
    flex-shrink: 1;
    font-family: var(--font-mono);
}

.setting-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

/* Status Bar */
.status-bar {
    height: var(--status-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.progress-container {
    width: 200px;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent-primary);
    width: 0%;
    transition: width 0.2s ease;
}

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

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 5px;
    border: 2px solid var(--bg-primary);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

::-webkit-scrollbar-corner {
    background: var(--bg-primary);
}

/* Selection */
::selection {
    background: var(--accent-primary);
    color: white;
}

/* Key select wider */
.key-select {
    width: 140px !important;
}

/* Tooltips */
[title] {
    position: relative;
    cursor: help;
}

.channel-grid th[data-tip] {
    cursor: help;
    text-decoration: underline dotted var(--text-muted);
    text-underline-offset: 2px;
}

.channel-grid th[data-tip]:hover {
    color: var(--accent-primary);
}

/* Custom tooltip styling via CSS */
.channel-grid th[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: normal;
    white-space: normal;
    max-width: 300px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    pointer-events: none;
}

/* Debug Panel */
.debug-toolbar {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.debug-info {
    font-size: 11px;
    color: var(--text-muted);
}

.legend-known {
    display: inline-block;
    background: #aaff66;
    color: #1a1a1a;
    padding: 2px 8px;
    border-radius: 3px;
    margin-left: 12px;
    font-size: 10px;
}

.legend-unknown {
    display: inline-block;
    background: #ffaaaa;
    color: #1a1a1a;
    padding: 2px 8px;
    border-radius: 3px;
    margin-left: 6px;
    font-size: 10px;
}

.legend-empty {
    display: inline-block;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 3px;
    margin-left: 6px;
    font-size: 10px;
}

.debug-container {
    flex: 1;
    overflow: auto;
    padding: 0;
}

.hexdump {
    padding: 16px;
    min-height: 100%;
}

.hexdump-placeholder {
    color: var(--text-muted);
    text-align: center;
    padding: 60px 20px;
    font-size: 14px;
}

.hexdump-table {
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 12px;
    width: auto;
}

.hexdump-table th {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-weight: 500;
    padding: 6px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.hexdump-table td {
    padding: 4px 6px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.hex-offset {
    color: var(--text-muted);
    text-align: left !important;
    padding-right: 16px !important;
    font-weight: 500;
}

.hex-byte {
    cursor: help;
    border-radius: 2px;
    transition: transform 0.1s ease;
}

.hex-byte:hover {
    transform: scale(1.2);
    z-index: 5;
    position: relative;
}

/* Known/mapped bytes - light green */
.hex-known {
    background: #aaff66;
    color: #1a1a1a;
}

/* Unknown bytes that are NOT 0xFF - light red */
.hex-unknown {
    background: #ffaaaa;
    color: #1a1a1a;
}

/* Unknown bytes that are 0xFF - default/muted */
.hex-empty {
    color: var(--text-muted);
}

.hex-ascii {
    text-align: left !important;
    padding-left: 16px !important;
    color: var(--text-secondary);
    font-size: 11px;
    letter-spacing: 0;
    white-space: pre;
}

/* Instant tooltips (hex dump and settings) */
.hex-tooltip,
.settings-tooltip {
    display: none;
    position: fixed;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 4px;
    font-family: var(--font-sans);
    font-size: 11px;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    max-width: 320px;
    white-space: normal;
    line-height: 1.4;
}

.hex-tooltip {
    font-family: var(--font-mono);
}

.hex-tooltip .tip-line {
    display: block;
    padding: 1px 0;
}

.hex-tooltip .tip-line:first-child {
    color: var(--accent-primary);
    font-weight: 500;
    margin-bottom: 4px;
}

.hex-tooltip .tip-bitfield {
    display: block;
    padding-left: 8px;
    color: var(--text-secondary);
}
