:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --success: #3fb950;
    --warning: #d29922;
    --error: #f85149;
    --purple: #a371f7;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.4;
    min-height: 100vh;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.app-header h1 {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.status-bar {
    display: flex;
    gap: 12px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error);
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.status-dot.warning {
    background: var(--warning);
}

.tab-nav {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 10px 8px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    flex: 1;
    overflow-y: auto;
}

.tab-panel {
    display: none;
    padding: 12px;
}

.tab-panel.active {
    display: block;
}

.video-preview {
    position: relative;
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 16/9;
    margin-bottom: 12px;
}

.video-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-preview canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.gesture-indicators {
    position: absolute;
    top: 8px;
    right: 8px;
}

.gesture-display {
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 12px;
    border-radius: 6px;
    backdrop-filter: blur(4px);
}

.gesture-display .gesture-icon {
    font-size: 24px;
}

.gesture-display.detected {
    background: rgba(63, 185, 80, 0.8);
}

.section {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.section h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.mapping-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

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

.gesture-label {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.action-select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 6px 8px;
    font-size: 12px;
    min-width: 140px;
}

.action-select:focus {
    outline: none;
    border-color: var(--accent);
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
}

.toggle {
    position: relative;
    width: 40px;
    height: 22px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-tertiary);
    transition: 0.2s;
    border-radius: 22px;
    border: 1px solid var(--border);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    transition: 0.2s;
    border-radius: 50%;
}

.toggle input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle input:checked + .toggle-slider:before {
    transform: translateX(18px);
    background: white;
}

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

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

.description-box {
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 12px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    min-height: 60px;
}

.activity-feed {
    max-height: 200px;
    overflow-y: auto;
}

.activity-item {
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    margin-bottom: 6px;
    font-size: 12px;
    border-left: 3px solid var(--accent);
}

.activity-item.placeholder {
    color: var(--text-muted);
    border-left-color: var(--border);
    text-align: center;
}

.activity-item .timestamp {
    font-size: 10px;
    color: var(--text-muted);
    display: block;
    margin-top: 4px;
}

.rule-item {
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.rule-item.empty-state {
    color: var(--text-muted);
    justify-content: center;
    padding: 20px;
}

.rule-info {
    flex: 1;
}

.rule-keywords {
    font-weight: 500;
    color: var(--purple);
    font-size: 12px;
}

.rule-scene {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.rule-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.rule-toggle {
    transform: scale(0.8);
}

.delete-btn {
    background: transparent;
    border: none;
    color: var(--error);
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
}

.current-scene-display {
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 12px;
    text-align: center;
}

.scene-label {
    font-size: 10px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
}

.scene-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--success);
}

.last-trigger {
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 10px;
    font-size: 12px;
    color: var(--text-secondary);
}

.control-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #da3633;
}

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

.btn-full {
    width: 100%;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border);
}

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

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

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

.modal-body {
    padding: 16px;
}

.settings-section {
    margin-bottom: 20px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.input-group {
    margin-bottom: 12px;
}

.input-group:last-child {
    margin-bottom: 0;
}

.input-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.help-link {
    font-size: 11px;
    color: var(--accent);
    text-decoration: none;
    display: inline-block;
    margin-top: 4px;
}

.help-link:hover {
    text-decoration: underline;
}

.help-text {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
