/* ============================================================
   MIDI Matrix Editor - Stylesheet
   Dark theme ispirato a Max/MSP
   ============================================================ */

:root {
    --bg:           #1a1a1a;
    --bg2:          #242424;
    --bg3:          #2e2e2e;
    --border:       #3a3a3a;
    --border-hi:    #555;
    --text:         #d0d0d0;
    --text-dim:     #777;
    --accent:       #e8a020;    /* arancio Max/MSP */
    --accent2:      #4a9eff;    /* blu per porte IN */
    --node-active:  #e8a020;
    --node-empty:   #2e2e2e;
    --node-hover:   #404040;
    --header-h:     40px;
    --footer-h:     22px;
    --info-w:       360px;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'SF Mono', 'Fira Mono', monospace;
    font-size: 12px;
    height: 100vh;
    overflow: hidden;
}

/* ===== TOOLBAR ===== */
#toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 0 12px;
    gap: 16px;
}

#toolbar-left, #toolbar-right { display: flex; align-items: center; gap: 8px; }
#toolbar-center { display: flex; align-items: center; }

.app-title {
    color: var(--accent);
    font-weight: bold;
    font-size: 13px;
    margin-right: 8px;
    letter-spacing: 1px;
}

button {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 3px 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    border-radius: 2px;
    transition: background 0.1s;
}
button:hover { background: var(--border-hi); }
button:disabled { opacity: 0.4; cursor: default; }
button.active { background: var(--accent); color: #111; border-color: var(--accent); }

#filename-label { color: var(--text-dim); font-size: 11px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Separatore visivo nella toolbar */
.toolbar-sep { color: var(--border-hi); font-size: 14px; user-select: none; }

/* Bottoni .gph — colore leggermente diverso dal .bin per distinguerli */
#btn-open-gph, #btn-save-gph {
    color: #9eddff;
    border-color: #2a5a7a;
}
#btn-save-gph:not(:disabled) { color: #9eddff; }

/* View tabs */
#view-tabs { display: flex; gap: 2px; }
.tab-btn { border-radius: 2px; }
.tab-btn.active { background: var(--accent); color: #111; border-color: var(--accent); }

/* Subsong tabs */
#subsong-tabs { display: flex; gap: 2px; }
.subsong-btn { min-width: 28px; text-align: center; }
.subsong-btn.active { background: var(--accent2); color: #fff; border-color: var(--accent2); }
#btn-sub-add { min-width: 24px; padding: 2px 6px; color: #6f6; }
#btn-sub-del { min-width: 24px; padding: 2px 6px; color: #f66; }
#btn-new     { color: var(--accent); }

/* ===== MAIN AREA ===== */
#main-area {
    display: flex;
    height: calc(100vh - var(--header-h) - var(--footer-h));
    overflow: hidden;
}

.view { display: none; width: 100%; height: 100%; }
.view.active { display: flex; }

/* ===== MATRIX VIEW ===== */
#view-matrix {
    flex-direction: row;
}

#matrix-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background: var(--bg);
    padding: 24px;
    position: relative;
}

#matrix-toolbar {
    position: absolute;
    bottom: 8px;
    right: 12px;
    display: flex;
    gap: 6px;
}

#matrix-canvas {
    image-rendering: pixelated;
    cursor: pointer;
}

/* ===== NODE DETAIL PANEL ===== */
#matrix-info {
    width: var(--info-w);
    background: var(--bg2);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#node-detail {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

#node-detail h3 {
    font-size: 11px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

#node-detail-content {
    color: var(--text-dim);
    font-size: 11px;
    line-height: 1.6;
}

.detail-action {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 6px 8px;
    margin-bottom: 6px;
}

.detail-action-header {
    color: var(--accent);
    font-weight: bold;
    margin-bottom: 4px;
    font-size: 11px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    color: var(--text-dim);
    font-size: 10px;
    line-height: 1.5;
}

.detail-row span:last-child { color: var(--text); }

.detail-cc-bar {
    margin-top: 8px;
    padding: 6px 8px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 3px;
}

.detail-cc-title {
    color: var(--accent2);
    font-size: 10px;
    margin-bottom: 4px;
}

.cc-mini-grid {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 1px;
}

.cc-mini-cell {
    width: 100%;
    aspect-ratio: 1;
    background: var(--bg);
    border-radius: 1px;
}
.cc-mini-cell.on { background: var(--accent2); }

/* ===== GRAPH PLACEHOLDER ===== */
#graph-placeholder, #split-graph {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 14px;
    width: 100%;
    height: 100%;
    background: var(--bg);
    border: 1px dashed var(--border);
}

/* ===== SPLIT VIEW ===== */
#view-split {
    flex-direction: row;
}
#split-matrix {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-right: 1px solid var(--border);
}
#split-graph { flex: 1; }

/* ===== STATUS BAR ===== */
#statusbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--footer-h);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    padding: 0 12px;
    font-size: 10px;
    color: var(--text-dim);
}

#status-msg { color: var(--text); }

/* ===== PANNELLO EDIT ===== */

.panel-toolbar {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.panel-empty {
    color: var(--text-dim);
    font-size: 11px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 4px 0;
}

.btn-sm {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 2px;
}

.btn-add { border-color: var(--accent); color: var(--accent); }
.btn-add:hover { background: var(--accent); color: #111; }
.btn-del { border-color: #c04040; color: #c04040; }
.btn-del:hover { background: #c04040; color: #fff; }

/* Action card */
.actions-list { display: flex; flex-direction: column; gap: 6px; }

.action-card {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 3px;
    overflow: hidden;
    cursor: default;
    transition: border-color 0.1s;
}
.action-card:hover { border-color: var(--border-hi); }
.action-card.dragging { opacity: 0.4; border-color: var(--accent); }

.action-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
}

.drag-handle {
    color: var(--text-dim);
    cursor: grab;
    font-size: 13px;
    line-height: 1;
    user-select: none;
}
.drag-handle:active { cursor: grabbing; }

.action-label { flex: 1; font-size: 10px; color: var(--text-dim); }

.action-card-btns { display: flex; gap: 3px; }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 1px 4px;
    font-size: 11px;
    cursor: pointer;
    border-radius: 2px;
}
.btn-icon:hover { background: var(--border); color: var(--text); }
.btn-icon.btn-del:hover { background: #c04040; color: #fff; }

/* Campi azione */
.action-fields { padding: 6px; display: flex; flex-direction: column; gap: 4px; }

.field-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
}

.field-row label {
    color: var(--text-dim);
    min-width: 40px;
    flex-shrink: 0;
}

.field-row input[type="number"],
.field-row select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 2px 4px;
    font-family: inherit;
    font-size: 10px;
    border-radius: 2px;
    width: 48px;
    flex-shrink: 0;
}
.field-row input[type="number"]:focus,
.field-row select:focus {
    outline: none;
    border-color: var(--accent);
}

.field-row select { width: auto; flex: 1; }

.field-row span { color: var(--text-dim); }

/* CC editor */
.cc-port-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-bottom: 8px;
}

.cc-port-btn {
    font-size: 9px;
    padding: 2px 5px;
    min-width: 36px;
    text-align: center;
    line-height: 1.3;
}
.cc-port-btn.active { background: var(--accent2); color: #fff; border-color: var(--accent2); }
.cc-cnt { font-size: 8px; color: inherit; opacity: 0.8; }

.cc-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 2px;
}

.cc-cell {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 2px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.08s;
}
.cc-cell span { font-size: 7px; color: var(--text-dim); pointer-events: none; }
.cc-cell:hover { background: var(--border-hi); }
.cc-cell.on { background: var(--accent2); border-color: var(--accent2); }
.cc-cell.on span { color: #fff; }

/* ===== GRAPH VIEW ===== */
#view-graph {
    flex-direction: row;
    position: relative;
}

#graph-canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg);
}

#graph-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: default;
}

#graph-toolbar {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 4px 8px;
    pointer-events: all;
}

#lbl-use-split {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
    padding: 0 4px;
    border-left: 1px solid var(--border);
    margin-left: 2px;
}
#lbl-use-split:hover { color: var(--text); }
#chk-use-split { margin: 0; cursor: pointer; accent-color: var(--accent); }

#graph-sidebar {
    width: var(--info-w);
    background: var(--bg2);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#graph-params {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

#graph-params h3 {
    font-size: 11px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

#graph-params-content {
    font-size: 11px;
    color: var(--text-dim);
}

/* Palette context menu */
#graph-palette {
    position: fixed;
    z-index: 1000;
    background: var(--bg2);
    border: 1px solid var(--border-hi);
    border-radius: 4px;
    padding: 4px 0;
    min-width: 140px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.6);
}

.gp-cat-label {
    font-size: 9px;
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 6px 10px 2px;
    opacity: 0.8;
}

.gp-palette-item {
    padding: 5px 10px 5px 12px;
    font-size: 11px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s;
}
.gp-palette-item:hover { background: var(--border-hi); }

/* Node params panel */
.gp-node-title {
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 2px;
}

.gp-node-id {
    font-size: 9px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.gp-param-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    margin-bottom: 6px;
}

.gp-param-row label {
    color: var(--text-dim);
    min-width: 54px;
    flex-shrink: 0;
}

.gp-param-input {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 2px 4px;
    font-family: inherit;
    font-size: 10px;
    border-radius: 2px;
}
.gp-param-input:focus { outline: none; border-color: var(--accent); }

.gp-param-select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 2px 4px;
    font-family: inherit;
    font-size: 10px;
    border-radius: 2px;
    flex: 1;
}
.gp-param-select:focus { outline: none; border-color: var(--accent); }

.gp-param-label {
    font-size: 10px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

/* Thresholds editor (splitter zones) */
.gp-thresholds { margin-bottom: 4px; }

.gp-zone-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    margin-bottom: 3px;
}

.gp-zone-label {
    color: var(--text-dim);
    min-width: 42px;
    flex-shrink: 0;
}

.gp-zone-range {
    color: var(--text);
    min-width: 32px;
    flex-shrink: 0;
}

.gp-zone-input {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 2px 4px;
    font-family: inherit;
    font-size: 10px;
    border-radius: 2px;
    width: 44px;
}
.gp-zone-input:focus { outline: none; border-color: var(--accent); }

/* Bitmask CC grid nel pannello params */
.gp-bitmask-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 2px;
    margin-bottom: 8px;
}

.gp-bitmask-cell {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 2px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.08s;
}
.gp-bitmask-cell span { font-size: 7px; color: var(--text-dim); pointer-events: none; }
.gp-bitmask-cell:hover { background: var(--border-hi); }
.gp-bitmask-cell.on { background: var(--accent2); border-color: var(--accent2); }
.gp-bitmask-cell.on span { color: #fff; }

/* Ch-map grid nel pannello params */
.gp-chmap-grid {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 6px;
}

.gp-chmap-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-family: monospace;
}

.gp-chmap-label {
    color: var(--text-dim);
    min-width: 20px;
    text-align: right;
}

.gp-chmap-arrow {
    color: var(--border-hi);
    font-size: 9px;
}

.gp-chmap-select {
    width: 44px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 2px;
    font: 10px monospace;
    padding: 1px 2px;
    cursor: pointer;
    transition: background 0.1s;
}
.gp-chmap-select:focus { outline: none; border-color: var(--accent); }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }

/* ===== SD CARD FILE MANAGER ===== */

#view-sdcard {
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

#sd-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg);
}

#sd-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.sd-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.sd-dot-on  { background: #3ecf8e; box-shadow: 0 0 4px #3ecf8e88; }
.sd-dot-off { background: #555; }

#sd-status-label {
    font-size: 11px;
    color: var(--text-dim);
    min-width: 140px;
}

.sd-sep { color: var(--border-hi); padding: 0 2px; }

#sd-breadcrumb {
    font-family: monospace;
    font-size: 12px;
    color: var(--accent);
    flex: 1;
    min-width: 60px;
}

#sd-toolbar button {
    font-size: 11px;
    padding: 3px 8px;
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
}
#sd-toolbar button:hover:not(:disabled) { background: var(--border); }
#sd-toolbar button:disabled { opacity: 0.4; cursor: default; }

/* File list */
#sd-file-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.sd-placeholder {
    padding: 20px;
    color: var(--text-dim);
    font-size: 12px;
    text-align: center;
}
.sd-loading { font-style: italic; }
.sd-error   { color: #e74c3c; }

.sd-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    transition: background 0.1s;
}
.sd-row:hover { background: var(--bg2); }

.sd-icon { font-size: 14px; flex-shrink: 0; width: 20px; text-align: center; }

.sd-name {
    flex: 1;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sd-dir  .sd-name { color: var(--accent2); }
.sd-file .sd-name { color: var(--text); }

.sd-name[style*="cursor: pointer"]:hover { text-decoration: underline; }

.sd-size {
    color: var(--text-dim);
    font-size: 10px;
    font-family: monospace;
    min-width: 60px;
    text-align: right;
    flex-shrink: 0;
}

.sd-actions {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}
.sd-row:hover .sd-actions { opacity: 1; }

.sd-action-btn {
    font-size: 12px;
    padding: 2px 5px;
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
    line-height: 1;
}
.sd-action-btn:hover { background: var(--border-hi); }
