/* =================================================================
   myStage - Stage Plot Builder Styles
   -----------------------------------------------------------------
   Layout:
     - .topbar       : sticky top bar with global actions
     - .layout       : 3-column flex (palette | stage | input list)
     - .stage        : the absolute-positioned drop target
     - .canvas-item  : a placed instrument/element on the stage
     - .item-toolbar : floating context bar for the selected item
   ================================================================= */

/* -------- CSS RESET / BASELINE -------- */
* {
    box-sizing: border-box;
}
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    color: #1f2937;
    background: #f3f4f6;
    overflow: hidden; /* main layout manages its own scrolling */
}

h1, h2, h3, p {
    margin: 0;
}

button {
    font-family: inherit;
}

/* -------- TOP BAR -------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
    color: #f9fafb;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    z-index: 100;
    position: relative;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand i {
    color: #f59e0b;
    font-size: 22px;
}
.brand h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.brand .tagline {
    font-size: 12px;
    color: #9ca3af;
    margin-left: 4px;
}

/* -------- PLOT TITLE (in topbar) -------- */
.plot-title-wrap {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 0 16px;
    min-width: 0;
}
.plot-title {
    width: 100%;
    max-width: 520px;
    background: transparent;
    border: 1px solid transparent;
    color: #f9fafb;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    padding: 6px 10px;
    border-radius: 6px;
    text-align: center;
    transition: background 0.15s, border-color 0.15s;
    /* Truncate when unfocused */
    text-overflow: ellipsis;
}
.plot-title::placeholder {
    color: #9ca3af;
    font-weight: 400;
    font-style: italic;
}
.plot-title:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: #374151;
}
.plot-title:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.1);
    border-color: #f59e0b;
    text-align: left;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* -------- BUTTONS -------- */
.btn {
    background: #374151;
    color: #f9fafb;
    border: 1px solid #4b5563;
    padding: 7px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s ease, transform 0.05s;
    user-select: none;
}
.btn:hover {
    background: #4b5563;
}
.btn:active {
    transform: translateY(1px);
}
.btn-danger {
    background: #991b1b;
    border-color: #b91c1c;
}
.btn-danger:hover {
    background: #b91c1c;
}

/* -------- MAIN LAYOUT (3 columns) -------- */
.layout {
    display: grid;
    grid-template-columns: 260px 1fr 340px;
    height: calc(100vh - 56px); /* full viewport minus topbar */
    width: 100%;
}

/* -------- PALETTE (left sidebar) -------- */
.palette {
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    overflow-y: auto;
    padding: 14px;
}
.palette h2 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6b7280;
    margin-bottom: 4px;
}
.hint {
    font-size: 12px;
    color: #9ca3af;
    margin-bottom: 12px;
}

.palette-category {
    margin-bottom: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
}
.palette-category-header {
    background: #f9fafb;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}
.palette-category-header i.chev {
    transition: transform 0.2s;
    font-size: 10px;
    color: #9ca3af;
}
.palette-category.collapsed .palette-category-header i.chev {
    transform: rotate(-90deg);
}
.palette-category.collapsed .palette-category-items {
    display: none;
}
.palette-category-items {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 6px;
    background: #fff;
}

.palette-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fafafa;
    cursor: grab;
    transition: all 0.15s ease;
    text-align: center;
}
.palette-item:hover {
    background: #fef3c7;
    border-color: #f59e0b;
    transform: translateY(-1px);
}
.palette-item:active {
    cursor: grabbing;
}
.palette-item .palette-item-icon {
    width: 32px;
    height: 32px;
    color: #1f2937;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.palette-item .palette-item-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}
.palette-item span {
    font-size: 10px;
    line-height: 1.2;
    color: #4b5563;
}

/* -------- STAGE -------- */
.stage-wrap {
    display: flex;
    flex-direction: column;
    padding: 14px;
    background: #e5e7eb;
    overflow: auto;
}

.stage-toolbar {
    text-align: center;
    padding: 6px;
}
.stage-label-back,
.stage-label-front {
    font-size: 11px;
    font-weight: 700;
    color: #6b7280;
    letter-spacing: 2px;
}

.stage {
    flex: 1;
    position: relative;
    background: #fafaf9;
    border: 3px solid #1f2937;
    border-radius: 8px;
    overflow: hidden;
    min-height: 500px;
    /* Wood-floor inspired gradient + grid */
    background-image:
        linear-gradient(180deg, rgba(120, 53, 15, 0.04), rgba(120, 53, 15, 0.08));
}

/* Subtle dot grid drawn as a separate layer so it doesn't disturb items. */
.stage-grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: radial-gradient(circle, #d1d5db 1px, transparent 1px);
    background-size: 25px 25px;
    opacity: 0.5;
}

.stage.drag-over {
    background-color: #fef3c7;
    border-color: #f59e0b;
}

/* -------- CANVAS ITEMS (instruments on the stage) -------- */
.canvas-item {
    position: absolute;
    /* Default footprint of a placed item. Anchored from its center via transform. */
    width: 70px;
    height: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: grab;
    user-select: none;
    /* The transform contains translation + rotation; both are set per item via JS. */
    transition: box-shadow 0.15s;
    /* A 1px transparent border so the selection ring doesn't shift layout */
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(2px);
}
.canvas-item:hover {
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.4);
}
.canvas-item.selected {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
    z-index: 9999; /* selected items pop to front visually */
}
.canvas-item.dragging {
    opacity: 0.7;
    cursor: grabbing;
}
.canvas-item .icon {
    width: 48px;
    height: 48px;
    color: #1f2937;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.canvas-item .icon svg {
    width: 100%;
    height: 100%;
    display: block;
}
.canvas-item .label {
    font-size: 10px;
    font-weight: 600;
    color: #1f2937;
    margin-top: 3px;
    text-align: center;
    line-height: 1.1;
    max-width: 90px;
    word-wrap: break-word;
    /* The text content stays upright relative to the item; rotation is on the parent. */
}
.canvas-item .ch-badge {
    position: absolute;
    top: -6px;
    left: -6px;
    background: #f59e0b;
    color: #1f2937;
    font-size: 10px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Text labels (the "Text" palette tool) use a different look. */
.canvas-item.type-text {
    width: auto;
    min-width: 60px;
    height: auto;
    background: rgba(255, 255, 255, 0.85);
    border: 1px dashed #6b7280;
}
.canvas-item.type-text .icon {
    display: none;
}
.canvas-item.type-text .ch-badge {
    display: none;
}
.canvas-item.type-text .label {
    font-size: 14px;
    margin-top: 0;
    padding: 4px 8px;
}

/* -------- INPUT LIST (right sidebar) -------- */
.inputs {
    background: #ffffff;
    border-left: 1px solid #e5e7eb;
    overflow-y: auto;
    padding: 14px;
}
.inputs h2 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6b7280;
    margin-bottom: 4px;
}

.input-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.input-table th {
    text-align: left;
    padding: 6px 4px;
    border-bottom: 2px solid #e5e7eb;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.5px;
}
.input-table td {
    padding: 4px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}
.input-table .ch-num {
    text-align: center;
    font-weight: 700;
    color: #f59e0b;
    background: #fffbeb;
    border-radius: 4px;
}
.input-table .ch-name {
    font-weight: 500;
    color: #1f2937;
}
.input-table .row-icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    vertical-align: middle;
    color: #6b7280;
    margin-right: 4px;
}
.input-table .row-icon svg {
    width: 100%;
    height: 100%;
}
.input-table input.notes-field {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
    background: #fafafa;
}
.input-table input.notes-field:focus {
    outline: none;
    border-color: #f59e0b;
    background: #fff;
}
.input-table tr.row-selected td.ch-name {
    color: #b45309;
}

.empty-hint {
    color: #9ca3af;
    font-size: 12px;
    text-align: center;
    margin-top: 20px;
    font-style: italic;
}

/* -------- FLOATING ITEM TOOLBAR -------- */
.item-toolbar {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: #1f2937;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    color: #f9fafb;
}
.item-toolbar button {
    background: transparent;
    color: #f9fafb;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.item-toolbar button:hover {
    background: #4b5563;
}
.item-toolbar button.danger:hover {
    background: #b91c1c;
}
.item-toolbar #rotate-slider {
    width: 100px;
    cursor: pointer;
}

/* -------- RESPONSIVE ADJUSTMENTS -------- */
@media (max-width: 1000px) {
    .layout {
        grid-template-columns: 220px 1fr 280px;
    }
}
@media (max-width: 800px) {
    .layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        height: auto;
    }
    .palette, .inputs {
        max-height: 250px;
    }
    html, body {
        overflow: auto;
    }
}

/* -------- SCROLLBAR POLISH (webkit) -------- */
.palette::-webkit-scrollbar,
.inputs::-webkit-scrollbar,
.stage-wrap::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.palette::-webkit-scrollbar-thumb,
.inputs::-webkit-scrollbar-thumb,
.stage-wrap::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}
.palette::-webkit-scrollbar-thumb:hover,
.inputs::-webkit-scrollbar-thumb:hover,
.stage-wrap::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}
