/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-green: #00ff88;
    --accent-green-dim: #00aa55;
    --accent-green-glow: rgba(0, 255, 136, 0.3);
    --accent-blue: #00ccff;
    --accent-blue-dim: #0088aa;
    --accent-blue-glow: rgba(0, 204, 255, 0.3);
    --accent-red: #ff6464;
    --accent-red-dim: #cc4444;
    --accent-red-glow: rgba(255, 100, 100, 0.3);
    --border-color: #2a2a35;
    --btn-primary: #00cc6a;
    --btn-primary-hover: #00ff88;
    --btn-secondary: #333340;
    --btn-secondary-hover: #444455;
    --btn-danger: #cc3333;
    --btn-danger-hover: #ff4444;
    --grid-cell-size: 40px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-size: 2.5rem;
    color: var(--accent-green);
    text-shadow: 0 0 20px var(--accent-green-glow);
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Main layout - 3 columns */
main {
    display: grid;
    grid-template-columns: auto 280px 320px;
    gap: 25px;
}

.grid-section {
    grid-column: 1;
}

.priority-section {
    grid-column: 2;
    display: flex;
    flex-direction: column;
}

.components-section {
    grid-column: 3;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 180px);
}

/* Section styling */
h2 {
    font-size: 1.3rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.instructions {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 12px;
}

/* Grid with Side Selectors Layout */
.grid-with-selectors {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

/* Power Selectors Container */
.power-selectors {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 200px;
}

/* Power Category Accordion */
.power-category {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 10px 8px;
    background-color: var(--bg-tertiary);
    border-radius: 4px;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: all 0.15s ease;
    user-select: none;
}

.power-category:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.power-category.has-selection {
    border-left: 3px solid var(--accent-green);
}

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

.power-category.disabled:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.power-category-toggle {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.power-category.expanded .power-category-toggle {
    transform: rotate(90deg);
}

.power-category-name {
    flex: 1;
    font-size: 0.7rem;
}

.power-category-selection {
    font-size: 0.6rem;
    color: var(--accent-green);
    font-weight: 400;
    text-transform: none;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.power-category.disabled .power-category-selection {
    color: var(--text-secondary);
    font-style: italic;
}

/* Power Category Content */
.power-category-content {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 6px 0 6px 8px;
    max-height: 200px;
    overflow-y: auto;
}

.power-category.expanded + .power-category-content {
    display: flex;
}

/* Power Option Items */
.power-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background-color: var(--bg-secondary);
    border-radius: 4px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.15s ease;
}

.power-option:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--accent-green-dim);
}

.power-option.selected {
    background-color: var(--accent-green-glow);
    border-color: var(--accent-green);
}

.power-option-preview {
    display: inline-grid;
    gap: 1px;
    background-color: var(--border-color);
    padding: 1px;
    border-radius: 2px;
    flex-shrink: 0;
}

.power-option-preview-cell {
    width: 6px;
    height: 6px;
    border-radius: 1px;
}

.power-option-preview-cell.powered {
    background-color: var(--accent-green-dim);
}

.power-option-preview-cell.protected {
    background-color: var(--accent-blue-dim);
}

.power-option-preview-cell.empty {
    background-color: transparent;
}

.power-option-info {
    flex: 1;
    min-width: 0;
}

.power-option-name {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.2;
}

.power-option-stats {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

/* Legacy selector styles (keeping for reference) */
.reactor-selector {
    display: none;
    padding-left: 4px;
}

.reactor-selector .custom-dropdown {
    height: 100%;
}

.reactor-selector .dropdown-selected {
    height: 100%;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    padding: 10px 6px;
    border-color: var(--accent-blue-dim);
    flex-direction: column;
}

.reactor-selector .dropdown-arrow {
    margin-left: 0;
    margin-top: 6px;
}

/* Aux selectors span 2 rows each (2 * 42px = 84px) */
.aux1-selector,
.aux2-selector {
    height: 84px;
    background: linear-gradient(to bottom, var(--bg-secondary) 0%, transparent 100%);
    border-radius: 4px 0 0 4px;
    padding-left: 4px;
}

.aux1-selector .custom-dropdown,
.aux2-selector .custom-dropdown {
    height: 100%;
}

.aux1-selector .dropdown-selected,
.aux2-selector .dropdown-selected {
    height: 100%;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    padding: 8px 6px;
    border-color: var(--accent-green-dim);
    flex-direction: column;
}

.aux1-selector .dropdown-arrow,
.aux2-selector .dropdown-arrow {
    margin-left: 0;
    margin-top: 6px;
}

/* Grid Stats */
.grid-stats {
    margin-top: 15px;
    padding: 10px 15px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.grid-stats .stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

.grid-stats .stat strong {
    color: var(--text-primary);
}

.grid-stats .stat.protected strong {
    color: var(--accent-blue);
}

.grid-stats .stat.unprotected strong {
    color: var(--accent-green);
}

/* Grid */
#grid-container {
    display: inline-grid;
    grid-template-columns: repeat(8, var(--grid-cell-size));
    grid-template-rows: repeat(8, var(--grid-cell-size));
    gap: 2px;
    background-color: var(--border-color);
    padding: 2px;
    border-radius: 4px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    position: relative;
}

.grid-cell {
    width: var(--grid-cell-size);
    height: var(--grid-cell-size);
    background-color: var(--bg-secondary);
    border-radius: 2px;
    transition: all 0.15s ease;
    position: relative;
}

.grid-cell.powered {
    background-color: var(--accent-green-dim);
    box-shadow: inset 0 0 10px var(--accent-green-glow),
                0 0 5px var(--accent-green-glow);
}

/* Protected cells (light blue) */
.grid-cell.protected {
    background-color: var(--accent-blue-dim);
    box-shadow: inset 0 0 10px var(--accent-blue-glow),
                0 0 5px var(--accent-blue-glow);
}

/* Component overlay on grid cells - semi-transparent black */
.grid-cell.has-piece {
    position: relative;
}

.grid-cell .piece-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.5);
    transition: all 0.15s ease;
    cursor: pointer;
}

/* Remove internal borders for adjacent cells in same component */
.grid-cell .piece-overlay.no-border-top {
    border-top-color: transparent;
}

.grid-cell .piece-overlay.no-border-bottom {
    border-bottom-color: transparent;
}

.grid-cell .piece-overlay.no-border-left {
    border-left-color: transparent;
}

.grid-cell .piece-overlay.no-border-right {
    border-right-color: transparent;
}

.grid-cell .piece-overlay.highlighted {
    border-color: #ffdd00;
    border-width: 3px;
    box-shadow: 0 0 12px rgba(255, 221, 0, 0.6);
}

/* Restore internal transparent borders when highlighted */
.grid-cell .piece-overlay.highlighted.no-border-top {
    border-top-color: transparent;
}

.grid-cell .piece-overlay.highlighted.no-border-bottom {
    border-bottom-color: transparent;
}

.grid-cell .piece-overlay.highlighted.no-border-left {
    border-left-color: transparent;
}

.grid-cell .piece-overlay.highlighted.no-border-right {
    border-right-color: transparent;
}

/* Protected component overlays - blue border */
.grid-cell .piece-overlay.protected-component {
    border-color: var(--accent-blue);
}

.grid-cell .piece-overlay.protected-component.no-border-top {
    border-top-color: transparent;
}

.grid-cell .piece-overlay.protected-component.no-border-bottom {
    border-bottom-color: transparent;
}

.grid-cell .piece-overlay.protected-component.no-border-left {
    border-left-color: transparent;
}

.grid-cell .piece-overlay.protected-component.no-border-right {
    border-right-color: transparent;
}

/* Yellow takes priority on hover for protected components */
.grid-cell .piece-overlay.protected-component.highlighted {
    border-color: #ffdd00;
}

.grid-cell .piece-overlay.protected-component.highlighted.no-border-top {
    border-top-color: transparent;
}

.grid-cell .piece-overlay.protected-component.highlighted.no-border-bottom {
    border-bottom-color: transparent;
}

.grid-cell .piece-overlay.protected-component.highlighted.no-border-left {
    border-left-color: transparent;
}

.grid-cell .piece-overlay.protected-component.highlighted.no-border-right {
    border-right-color: transparent;
}

/* Drag-and-drop highlighting for grid cells */
.grid-cell.drag-valid {
    background-color: var(--accent-green) !important;
    box-shadow: inset 0 0 15px var(--accent-green-glow),
                0 0 10px var(--accent-green-glow) !important;
}

.grid-cell.drag-protected {
    background-color: var(--accent-blue) !important;
    box-shadow: inset 0 0 15px var(--accent-blue-glow),
                0 0 10px var(--accent-blue-glow) !important;
}

.grid-cell.drag-invalid {
    background-color: var(--accent-red) !important;
    box-shadow: inset 0 0 15px var(--accent-red-glow),
                0 0 10px var(--accent-red-glow) !important;
}

/* Flash animation for invalid drop */
@keyframes flash-invalid {
    0%, 100% { background-color: var(--accent-red); }
    50% { background-color: var(--accent-red-dim); }
}

.grid-cell.flash-invalid {
    animation: flash-invalid 0.15s ease 3;
}

/* Invalid placement overlay (red border, stays visible) */
.grid-cell .piece-overlay.invalid-placement {
    border-color: var(--accent-red) !important;
    box-shadow: 0 0 8px var(--accent-red-glow);
}

.grid-cell .piece-overlay.invalid-placement.no-border-top {
    border-top-color: transparent !important;
}

.grid-cell .piece-overlay.invalid-placement.no-border-bottom {
    border-bottom-color: transparent !important;
}

.grid-cell .piece-overlay.invalid-placement.no-border-left {
    border-left-color: transparent !important;
}

.grid-cell .piece-overlay.invalid-placement.no-border-right {
    border-right-color: transparent !important;
}

/* Piece labels on grid */
.piece-label {
    position: absolute;
    font-size: 0.5rem;
    font-weight: 600;
    color: white;
    text-shadow: 0 0 2px black, 0 0 2px black, 0 0 4px black;
    pointer-events: none;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2px;
    box-sizing: border-box;
    overflow: hidden;
    word-break: break-word;
    line-height: 1.1;
}

/* Grid controls */
.grid-controls {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* Solution dropdown */
.solution-select-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.solution-select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    min-width: 180px;
}

.solution-select:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 5px var(--accent-green-glow);
}

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

.solution-select option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

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

.btn-primary:hover {
    background-color: var(--btn-primary-hover);
    box-shadow: 0 0 15px var(--accent-green-glow);
}

.btn-secondary {
    background-color: var(--btn-secondary);
    color: var(--text-primary);
}

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

.btn-danger {
    background-color: var(--btn-danger);
    color: var(--text-primary);
}

.btn-danger:hover {
    background-color: var(--btn-danger-hover);
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.4);
}

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

/* Priority Section */
#priority-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 8px;
    min-height: 200px;
    max-height: calc(100vh - 400px);
    border: 2px dashed transparent;
    border-radius: 4px;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

#priority-list.drop-target {
    border-color: var(--accent-green);
    background-color: rgba(0, 255, 136, 0.05);
}

.priority-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: grab;
    transition: all 0.15s ease;
}

.priority-item:hover {
    border-color: var(--accent-green-dim);
}

.priority-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.priority-item.drag-over {
    border-color: var(--accent-green);
    box-shadow: 0 0 10px var(--accent-green-glow);
}

.priority-item.highlighted {
    background-color: rgba(255, 221, 0, 0.15);
    border-color: #ffdd00;
}

.priority-item.not-placed {
    border-color: var(--accent-red);
    background-color: rgba(255, 100, 100, 0.1);
}

.priority-item.placed {
    border-color: var(--accent-green-dim);
}

.priority-item.protected-placed {
    border-color: var(--accent-blue);
    box-shadow: 0 0 6px rgba(0, 150, 255, 0.4);
}

.priority-drag-handle {
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: grab;
    user-select: none;
}

.priority-preview {
    display: inline-grid;
    gap: 1px;
    background-color: var(--border-color);
    padding: 1px;
    border-radius: 2px;
    flex-shrink: 0;
}

.priority-preview-cell {
    width: 8px;
    height: 8px;
    border-radius: 1px;
}

.priority-preview-cell.filled {
    background-color: var(--accent-green-dim);
}

.priority-preview-cell.empty {
    background-color: transparent;
}

.priority-info {
    flex: 1;
    min-width: 0;
}

.priority-name {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.2;
}

.priority-tier {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.priority-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.priority-checkbox {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 0.65rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.priority-checkbox input {
    width: 12px;
    height: 12px;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

/* Priority item action buttons */
.priority-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

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

.priority-rotate:hover:not(:disabled) {
    color: var(--accent-blue);
    background-color: var(--accent-blue-glow);
}

.priority-unplace:hover:not(:disabled) {
    color: var(--accent-yellow);
    background-color: rgba(255, 193, 7, 0.15);
}

.priority-remove:hover:not(:disabled) {
    color: var(--accent-red);
    background-color: var(--accent-red-glow);
}

.priority-empty {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
    padding: 40px 20px;
    border: 1px dashed var(--border-color);
    border-radius: 4px;
}

/* Solve section inside priority */
.priority-section .solve-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

#solve-btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
}

.solve-status {
    margin-top: 10px;
    padding: 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    min-height: 36px;
}

.solve-status.success {
    background-color: rgba(0, 255, 136, 0.1);
    color: var(--accent-green);
    border: 1px solid var(--accent-green-dim);
}

.solve-status.error {
    background-color: rgba(255, 100, 100, 0.1);
    color: #ff6464;
    border: 1px solid #ff6464;
}

.solve-status.info {
    background-color: rgba(100, 150, 255, 0.1);
    color: #6496ff;
    border: 1px solid #6496ff;
}

/* Component Filters Fieldset */
.component-filters-wrapper {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 12px;
}

.component-filters-wrapper legend {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.component-filters {
    display: flex;
    gap: 8px;
}

.filter-input {
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.8rem;
}

.filter-input:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 5px var(--accent-green-glow);
}

.filter-input::placeholder {
    color: var(--text-secondary);
}

#filter-name {
    width: 110px;
    flex: none;
}

#filter-blocks {
    width: 75px;
    flex: none;
}

/* Tier Checkboxes */
.tier-checkboxes {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tier-checkbox {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

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

.tier-checkbox input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--accent-green);
}

/* Components section */
#components-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    padding-right: 8px;
}

/* Collapsible Category Headers */
.component-category {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 10px 8px;
    margin-top: 8px;
    background-color: var(--bg-tertiary);
    border-radius: 4px;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: all 0.15s ease;
    user-select: none;
}

.component-category:first-child {
    margin-top: 0;
}

.component-category:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.component-category-toggle {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.component-category.expanded .component-category-toggle {
    transform: rotate(90deg);
}

.component-category-name {
    flex: 1;
}

.component-category-count {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 0.65rem;
}

/* Category content wrapper */
.category-content {
    display: none;
    flex-direction: column;
    gap: 6px;
    padding-left: 8px;
}

.component-category.expanded + .category-content {
    display: flex;
}

/* Component Accordion */
.component-accordion {
    background-color: var(--bg-secondary);
    border-radius: 4px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.component-accordion.has-selection {
    border-color: var(--accent-green);
    box-shadow: 0 0 10px var(--accent-green-glow);
}

.component-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.component-header:hover {
    background-color: var(--bg-tertiary);
}

.component-toggle {
    color: var(--text-secondary);
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.component-accordion.expanded .component-toggle {
    transform: rotate(90deg);
}

.component-name {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 500;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.2;
}

.component-badge {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 0.7rem;
}

.component-tiers {
    display: none;
    padding: 0 10px 10px 10px;
    border-top: 1px solid var(--border-color);
}

.component-accordion.expanded .component-tiers {
    display: block;
}

.tier-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
    cursor: grab;
    transition: background-color 0.15s ease;
}

.tier-item:hover {
    background-color: var(--bg-tertiary);
}

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

.tier-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.tier-drag-handle {
    color: var(--text-secondary);
    font-size: 0.75rem;
    opacity: 0.5;
    cursor: grab;
}

.tier-item:hover .tier-drag-handle {
    opacity: 1;
}

.tier-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
    min-width: 28px;
}

.tier-quantity {
    width: 40px;
    height: 24px;
    padding: 2px 4px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.8rem;
    text-align: center;
}

.tier-quantity:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 5px var(--accent-green-glow);
}

.tier-preview {
    display: inline-grid;
    gap: 1px;
    background-color: var(--border-color);
    padding: 1px;
    border-radius: 2px;
}

.tier-preview-cell {
    width: 8px;
    height: 8px;
    border-radius: 1px;
}

.tier-preview-cell.filled {
    background-color: var(--accent-green-dim);
}

.tier-preview-cell.empty {
    background-color: transparent;
}

.tier-blocks {
    color: var(--text-secondary);
    font-size: 0.7rem;
}

/* Footer */
footer {
    margin-top: 40px;
    padding: 20px;
    text-align: center;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
}

footer a {
    color: var(--accent-green);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Scrollbar styling */
#components-container::-webkit-scrollbar,
#priority-list::-webkit-scrollbar,
.dropdown-options::-webkit-scrollbar {
    width: 6px;
}

#components-container::-webkit-scrollbar-track,
#priority-list::-webkit-scrollbar-track,
.dropdown-options::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

#components-container::-webkit-scrollbar-thumb,
#priority-list::-webkit-scrollbar-thumb,
.dropdown-options::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

#components-container::-webkit-scrollbar-thumb:hover,
#priority-list::-webkit-scrollbar-thumb:hover,
.dropdown-options::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive */
@media (max-width: 1100px) {
    main {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }

    .grid-section {
        grid-column: 1 / 3;
        grid-row: 1;
    }

    .priority-section {
        grid-column: 1;
        grid-row: 2;
    }

    .components-section {
        grid-column: 2;
        grid-row: 2;
        max-height: none;
    }

    #priority-list {
        max-height: 400px;
    }

    #components-container {
        max-height: 400px;
    }

    .grid-with-selectors {
        justify-content: center;
    }
}

@media (max-width: 700px) {
    main {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .grid-section,
    .priority-section,
    .components-section {
        grid-column: 1;
        grid-row: auto;
    }

    .grid-with-selectors {
        flex-direction: column;
        align-items: center;
    }

    .power-selectors {
        width: 100%;
        max-width: 320px;
    }
}

/* ============================================
   Dialog System
   ============================================ */

.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.dialog-overlay.hidden {
    display: none;
}

.dialog-box {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    min-width: 320px;
    max-width: 480px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: dialog-appear 0.2s ease-out;
}

@keyframes dialog-appear {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.dialog-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.dialog-icon {
    font-size: 1.5rem;
}

.dialog-title {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-primary);
}

.dialog-content {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.dialog-content ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.dialog-content li {
    margin: 0.25rem 0;
}

.dialog-input-section {
    margin-bottom: 1rem;
}

.dialog-input-section.hidden {
    display: none;
}

.dialog-input {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1rem;
    box-sizing: border-box;
}

.dialog-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px var(--accent-blue-glow);
}

.dialog-input-error {
    display: block;
    color: var(--accent-red);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    min-height: 1.2em;
}

.dialog-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.dialog-btn {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.dialog-btn-primary {
    background-color: var(--accent-green);
    color: var(--bg-primary);
}

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

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

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

.dialog-btn-danger {
    background-color: var(--accent-red);
    color: white;
}

.dialog-btn-danger:hover:not(:disabled) {
    background-color: var(--accent-red-dim);
}

/* ============================================
   Toast Notifications
   ============================================ */

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1001;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s ease;
}

.toast-show {
    transform: translateX(0);
    opacity: 1;
}

.toast-hide {
    transform: translateX(100%);
    opacity: 0;
}

.toast-icon {
    font-size: 1.1rem;
}

.toast-message {
    color: var(--text-primary);
    font-size: 0.9rem;
}

.toast-success {
    border-color: var(--accent-green);
}

.toast-error {
    border-color: var(--accent-red);
}

.toast-warning {
    border-color: var(--accent-yellow);
}

.toast-info {
    border-color: var(--accent-blue);
}

/* ============================================
   Build Header
   ============================================ */

.build-header {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    order: -1; /* Always first in grid */
}

.build-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.build-label {
    font-weight: 500;
    color: var(--text-secondary);
}

/* Custom Build Dropdown */
.build-dropdown {
    position: relative;
    min-width: 200px;
}

.build-dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.build-dropdown-toggle:hover {
    border-color: var(--accent-blue);
}

.build-dropdown-toggle:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.build-dropdown-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    text-align: left;
}

.build-dropdown-arrow {
    margin-left: 0.5rem;
    font-size: 0.7rem;
    transition: transform 0.15s ease;
}

.build-dropdown.open .build-dropdown-arrow {
    transform: rotate(180deg);
}

.build-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    max-height: 300px;
    overflow-y: auto;
}

.build-dropdown.open .build-dropdown-menu {
    display: block;
}

.build-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background-color 0.1s ease;
}

.build-dropdown-item:hover {
    background-color: var(--bg-tertiary);
}

.build-dropdown-item.selected {
    background-color: var(--accent-blue-glow);
}

.build-dropdown-item-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.build-dropdown-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.build-dropdown-item-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.build-dropdown-item-actions {
    display: flex;
    gap: 4px;
    margin-left: 8px;
}

.build-clone-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.build-clone-btn:hover {
    color: var(--accent-blue);
    background-color: var(--accent-blue-glow);
}

.build-dropdown-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 4px 0;
}

.save-indicator {
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.save-indicator.saved {
    color: var(--accent-green);
}

.save-indicator.unsaved {
    color: var(--accent-yellow);
}

.save-indicator.unnamed {
    color: var(--accent-red);
}

.build-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-small {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
}

.btn-success {
    background-color: var(--accent-green);
    color: var(--bg-primary);
}

.btn-success:hover:not(:disabled) {
    background-color: var(--accent-green-dim);
}

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

/* Unnamed Build Prompt */

.unnamed-build-prompt {
    grid-column: 1 / -1;
    background-color: var(--bg-secondary);
    border: 2px solid var(--accent-yellow);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.unnamed-build-prompt.hidden {
    display: none;
}

.unnamed-build-warning {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    color: var(--accent-yellow);
    font-weight: 500;
}

.warning-icon {
    font-size: 1.2rem;
}

.unnamed-build-form {
    margin-bottom: 1rem;
}

.build-name-input {
    width: 100%;
    max-width: 400px;
    padding: 0.6rem 0.75rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1rem;
}

.build-name-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px var(--accent-blue-glow);
}

.build-name-error {
    display: block;
    color: var(--accent-red);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    min-height: 1.2em;
}

.unnamed-build-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}
