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

body {
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    background: #0a0a0a;
    color: #e0e0e0;
    overflow: hidden;
    touch-action: none;
}

#canvas {
    display: block;
    width: 100vw;
    height: 100vh;
}

/* ===== Header ===== */
#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, rgba(20,20,20,0.95) 0%, rgba(10,10,10,0.9) 100%);
    border-bottom: 1px solid #333;
    display: flex;
    align-items: center;
    padding: 0 12px;
    z-index: 1000;
    gap: 8px;
    height: 48px;
}

#header h1 {
    font-size: 14px;
    color: #00ff88;
    white-space: nowrap;
}

@media (max-width: 600px) {
    #header {
        height: auto;
        padding: 8px 10px;
        gap: 6px;
    }
    #header h1 {
        font-size: 13px;
    }
}

/* ===== Loading overlay ===== */
#loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #00ff88;
    border-radius: 8px;
    padding: 24px 32px;
    text-align: center;
    z-index: 2000;
    max-width: 90vw;
}

#loading.hidden { display: none; }

#loading h2 {
    color: #00ff88;
    margin-bottom: 12px;
    font-size: 16px;
}

#progress-bar {
    width: 260px;
    max-width: 100%;
    height: 6px;
    background: #333;
    border-radius: 3px;
    overflow: hidden;
    margin: 12px 0;
}

#progress-fill {
    height: 100%;
    background: #00ff88;
    width: 0%;
    transition: width 0.2s;
}

#progress-text {
    color: #888;
    font-size: 12px;
}

/* ===== Floating FPS badge ===== */
#fps-badge {
    position: fixed;
    top: 56px;
    left: 8px;
    background: rgba(0,0,0,0.7);
    border: 1px solid #333;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    z-index: 100;
    color: #00ff88;
    font-weight: bold;
    pointer-events: none;
}

@media (max-width: 600px) {
    #fps-badge { top: auto; bottom: 68px; left: 8px; }
}

/* ===== Drawer ===== */
#drawer-toggle {
    position: fixed;
    bottom: 12px;
    right: 12px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #00ff88;
    color: #000;
    border: none;
    font-size: 22px;
    cursor: pointer;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0,255,136,0.3);
    transition: transform 0.2s;
}

#drawer-toggle:hover {
    transform: scale(1.1);
}

#drawer-toggle.open {
    background: #444;
    color: #fff;
    box-shadow: none;
}

#drawer-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1050;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

#drawer-scrim.visible {
    opacity: 1;
    pointer-events: auto;
}

#drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 70vh;
    background: rgba(15,15,15,0.98);
    border-top: 1px solid #444;
    border-radius: 12px 12px 0 0;
    z-index: 1060;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

#drawer.open {
    transform: translateY(0);
}

/* Drawer handle */
#drawer-handle {
    width: 36px;
    height: 4px;
    background: #555;
    border-radius: 2px;
    margin: 8px auto 4px;
    flex-shrink: 0;
}

/* Tab bar */
#tab-bar {
    display: flex;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    flex: 1;
    min-width: 0;
    padding: 10px 6px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: #888;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    text-align: center;
    transition: color 0.15s, border-color 0.15s;
}

.tab-btn.active {
    color: #00ff88;
    border-bottom-color: #00ff88;
}

.tab-btn:not(.active):hover {
    color: #ccc;
}

/* Tab panels */
#tab-panels {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

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

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

/* ===== Panel: Files (Hierarchical Tree) ===== */
.tree-item {
    padding: 6px 8px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(34, 34, 34, 0.5);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.1s;
}

.tree-item:hover { background: #222; }

.tree-item.selected {
    background: #1a3a1a;
    border-left: 3px solid #00ff88;
}

/* Directory items */
.tree-dir {
    color: #ccc;
    font-weight: 500;
}

.tree-dir:hover {
    background: #1a2030;
}

.tree-dir.collapsed {
    opacity: 0.8;
}

/* Chevron toggle */
.tree-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    font-size: 9px;
    color: #888;
    flex-shrink: 0;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.tree-chevron:hover {
    color: #00ff88;
    background: rgba(0, 255, 136, 0.1);
}

/* File items */
.tree-file {
    color: #aaa;
}

.tree-file:hover {
    color: #ddd;
}

/* Icons */
.tree-icon {
    width: 14px;
    flex-shrink: 0;
    opacity: 0.6;
    font-size: 11px;
}

.tree-icon-dir { opacity: 0.8; }
.tree-icon-file { opacity: 0.5; }

/* Name */
.tree-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* File/child count badge */
.tree-count {
    color: #555;
    font-size: 10px;
    flex-shrink: 0;
    min-width: 18px;
    text-align: right;
}

.tree-size { color: #666; font-size: 10px; }

/* Children container */
.tree-children {
    /* no extra styling needed - indentation is per-item via paddingLeft */
}

.tree-children.hidden {
    display: none;
}

.tree-empty {
    color: #666;
    text-align: center;
    padding: 24px;
    font-size: 12px;
}

/* ===== Panel: Settings ===== */
.setting-group {
    margin-bottom: 16px;
}

.setting-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    color: #aaa;
    font-size: 12px;
}

.setting-value {
    color: #ffaa00;
    font-weight: bold;
}

.setting-slider {
    width: 100%;
    height: 24px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    outline: none;
}

.setting-slider::-webkit-slider-runnable-track {
    height: 6px;
    background: #333;
    border-radius: 3px;
}

.setting-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    background: #ffaa00;
    border-radius: 50%;
    cursor: pointer;
    margin-top: -8px;
}

.setting-slider::-moz-range-track {
    height: 6px;
    background: #333;
    border-radius: 3px;
    border: none;
}

.setting-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    background: #ffaa00;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.setting-btn {
    width: 100%;
    padding: 12px;
    background: #222;
    color: #fff;
    border: 1px solid #444;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    margin-top: 6px;
    -webkit-tap-highlight-color: transparent;
}

.setting-btn:hover { background: #333; border-color: #ffaa00; }
.setting-btn:active { background: #444; }

/* ===== Panel: Stats ===== */
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid #1a1a1a;
    font-size: 12px;
}

.stat-label { color: #888; }
.stat-value { color: #00ff88; font-weight: bold; }

/* ===== Panel: Controls ===== */
.controls-section h4 {
    color: #00ff88;
    font-size: 12px;
    margin-bottom: 8px;
    margin-top: 12px;
}

.controls-section h4:first-child { margin-top: 0; }

.control-row {
    display: flex;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
    line-height: 1.8;
}

.key {
    display: inline-block;
    background: #333;
    padding: 2px 8px;
    border-radius: 3px;
    min-width: 24px;
    text-align: center;
    margin-right: 10px;
    font-size: 11px;
}

/* ===== Panel: Repo ===== */
.repo-section {
    margin-bottom: 16px;
}

.repo-label {
    display: block;
    color: #aaa;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.repo-input {
    width: 100%;
    padding: 10px 10px;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 4px;
    color: #fff;
    font-family: inherit;
    font-size: 13px;
}

.repo-input:focus {
    outline: none;
    border-color: #00ff88;
}

.repo-input::placeholder {
    color: #666;
}

.branch-input-row {
    display: flex;
    gap: 6px;
}

.branch-input-row .repo-input {
    flex: 1;
    min-width: 0;
}

.repo-btn {
    width: 100%;
    padding: 12px;
    background: #00ff88;
    color: #000;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    font-size: 14px;
}

.repo-btn:hover {
    background: #00cc66;
}

.repo-btn:disabled {
    background: #444;
    color: #888;
    cursor: not-allowed;
}

.repo-btn-sm {
    padding: 8px 12px;
    background: #333;
    color: #00ff88;
    border: 1px solid #555;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 16px;
    flex-shrink: 0;
    line-height: 1;
}

.repo-btn-sm:hover {
    background: #444;
    border-color: #00ff88;
}

.repo-btn-sm:disabled {
    color: #666;
    cursor: not-allowed;
}

.branch-list {
    margin-top: 8px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #333;
    border-radius: 4px;
    background: #111;
}

.branch-list.hidden {
    display: none;
}

.branch-item {
    padding: 8px 10px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid #222;
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.branch-item:hover {
    background: #1a2a1a;
}

.branch-item.selected {
    background: #1a3a1a;
    color: #00ff88;
}

.branch-item .branch-default-badge {
    font-size: 9px;
    background: #00ff88;
    color: #000;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: bold;
}

.branch-status {
    font-size: 11px;
    color: #666;
    margin-top: 4px;
    min-height: 16px;
}

#header-repo-label {
    color: #888;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.bmc-link {
    color: #ffdd00;
    text-decoration: none;
    font-size: 12px;
    opacity: 0.7;
    transition: opacity 0.2s;
    white-space: nowrap;
}

.bmc-link:hover {
    opacity: 1;
}

/* ===== Panel: Log Capture ===== */
.log-capture-controls {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.log-capture-btn {
    padding: 8px 14px;
    border-radius: 4px;
    border: 1px solid #444;
    background: #222;
    color: #e0e0e0;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.log-capture-btn:hover {
    background: #333;
    border-color: #666;
}

.log-capture-btn.active {
    background: #1a3a1a;
    border-color: #00ff88;
    color: #00ff88;
}

.log-capture-btn.download {
    background: #00ff88;
    color: #000;
    border-color: #00ff88;
    font-weight: bold;
}

.log-capture-btn.download:hover {
    background: #00cc66;
}

.log-capture-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.log-capture-status {
    font-size: 11px;
    color: #888;
    margin-bottom: 8px;
}

.log-capture-status .count {
    color: #00ff88;
    font-weight: bold;
}

.log-capture-status .recording {
    color: #ff4444;
    font-weight: bold;
}

.log-capture-preview {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #333;
    border-radius: 4px;
    background: #111;
    font-size: 10px;
    line-height: 1.6;
}

.log-capture-preview .log-line {
    padding: 2px 8px;
    border-bottom: 1px solid #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.log-capture-preview .log-line.DEBUG { color: #888; }
.log-capture-preview .log-line.INFO  { color: #0f0; }
.log-capture-preview .log-line.WARN  { color: #ff0; }
.log-capture-preview .log-line.ERROR { color: #f44; }
.log-capture-preview .log-line.METRIC { color: #4af; }

/* ===== Toast ===== */
#toast {
    position: fixed;
    bottom: 72px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 10px 20px;
    border-radius: 4px;
    z-index: 3000;
    transition: opacity 0.3s;
    font-size: 12px;
    max-width: 90vw;
    text-align: center;
}

#toast.hidden { opacity: 0; pointer-events: none; }
#toast.error { background: #a33; border: 1px solid #f44; }
#toast.success { background: #2a5; border: 1px solid #4f8; }

/* ===== Diff Panel ===== */
.diff-status { font-size: 11px; padding: 4px 8px; color: #aaa; }
.diff-status.success { color: #4f8; }
.diff-status.error { color: #f44; }

.diff-summary { padding: 8px; border-bottom: 1px solid #333; }
.diff-pr-title { font-size: 13px; font-weight: 600; color: #eee; margin-bottom: 4px; }
.diff-pr-meta { font-size: 11px; color: #999; margin-bottom: 4px; }
.diff-pr-author { margin-right: 8px; }
.diff-pr-state { padding: 1px 6px; border-radius: 3px; font-size: 10px; text-transform: uppercase; }
.diff-pr-state.open { background: #238636; color: #fff; }
.diff-pr-state.closed { background: #da3633; color: #fff; }
.diff-pr-state.merged { background: #8957e5; color: #fff; }
.diff-pr-stats { font-size: 12px; display: flex; gap: 8px; }
.diff-stat-add { color: #4f8; }
.diff-stat-remove { color: #f44; }
.diff-stat-files { color: #aaa; }

.diff-file-list { overflow-y: auto; max-height: 400px; }
.diff-file-item {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 8px; cursor: pointer; font-size: 11px;
    border-bottom: 1px solid #222;
}
.diff-file-item:hover { background: #2a2a2a; }
.diff-file-item.selected { background: #1a3a1a; }
.diff-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #ccc; }
.diff-file-stats { display: flex; gap: 6px; font-size: 10px; flex-shrink: 0; }
.diff-file-status { flex-shrink: 0; }

.badge {
    display: inline-block; width: 16px; height: 16px; line-height: 16px;
    text-align: center; border-radius: 3px; font-size: 10px; font-weight: 700;
    background: #444; color: #ccc;
}
.badge-added { background: #238636; color: #fff; }
.badge-removed { background: #da3633; color: #fff; }
.badge-modified { background: #d29922; color: #fff; }
.badge-renamed { background: #8957e5; color: #fff; }

/* ===== Desktop: side drawer ===== */
@media (min-width: 769px) {
    #drawer {
        top: 48px;
        bottom: 0;
        left: auto;
        right: 0;
        width: 320px;
        max-height: none;
        border-radius: 0;
        border-top: none;
        border-left: 1px solid #444;
        transform: translateX(100%);
    }
    #drawer.open { transform: translateX(0); }
    #drawer-handle { display: none; }
    #drawer-toggle { bottom: 12px; right: 12px; }
    #fps-badge { top: 56px; bottom: auto; left: 8px; }
}
