/* ==============================================
   PGRBuilder - Build Panel Styles
   ============================================== */

/* ==============================================
   Right Panel - Configurations
   ============================================== */
.right-panel {
    display: flex;
    flex-direction: column;
}

/* 
   Section Headers 
   ----------------------------------------------
   Titles for each build section (e.g., "Build 1", "Build 2")
*/
.section-header {
    font-family: var(--font-header);
    font-weight: 700;
    color: #fff;
    font-size: 1.5rem;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid #1a1a1a;
    padding-bottom: 10px;
}

.section-header span {
    color: var(--accent-red);
    font-size: 1rem;
}

/* 
   Build Row Layout
   ----------------------------------------------
   Definitions for the main grid that holds the memory slots,
   harmony slots, and resonance columns for a single build.
*/
.build-row {
    /* Local variables for grid sizing */
    --slot-size: 100px;
    --mem-gap: 10px;
    --mem-col-width: calc(var(--slot-size) * 3 + var(--mem-gap) * 2);

    margin-bottom: 10px;
    display: grid;
    /* Grid Columns: Memories | Harmony | Weapon Res | Res | Controls */
    grid-template-columns: var(--mem-col-width) var(--slot-size) 220px 1fr 30px;
    gap: 10px;
    border-bottom: 1px solid #111;
    padding-bottom: 10px;
    position: relative;
}

/* Lift build-row above others when dropdown is open */
.build-row:has(.custom-res-select.open) {
    z-index: 10000;
}

.build-title {
    grid-column: 1 / -1;
    /* Title spans full width */
    font-family: var(--font-tech);
    color: var(--accent-red);
    font-size: 1.1rem;
    margin-bottom: 0px;
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.build-title input {
    background: transparent;
    border: none;
    color: var(--accent-red);
    font-family: inherit;
    font-size: inherit;
    width: 300px;
    text-transform: uppercase;
    line-height: 1.4;
}

/* 
   Memories Grid 
   ----------------------------------------------
   2x3 Grid for the 6 memory slots.
*/
.mem-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, auto);
    gap: var(--mem-gap);
    align-self: start;
}

.mem-cell {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Individual Memory Slot */
.mem-box {
    width: 100%;
    aspect-ratio: 1;
    /* Keep square */
    background: #080808;
    border: 1px solid #222;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.mem-box img {
    width: 90%;
    height: 90%;
    object-fit: cover;
}

.mem-box:hover {
    border-color: #444;
}

/* Memory Level Input */
.mem-input {
    width: 100%;
    text-align: center;
    background: transparent;
    border: 1px solid transparent;
    color: #666;
    font-family: var(--font-tech);
    font-size: 0.7rem;
    height: 20px;
    line-height: 20px;
    display: block;
    transition: all 0.2s;
}

.mem-input:hover,
.mem-input:focus {
    background: #111;
    border: 1px solid #333;
    color: #fff;
    outline: none;
}

/* Remove Button (Red 'X') */
.mem-remove-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #b30000;
    border: 1px solid #000;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    font-size: 16px;
    line-height: 1;
    font-family: Arial, sans-serif;
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /** Fun bouncy animation */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    /* Prevent clicks when hidden */
}

/* 
   Empty State Visuals (Double Frame)
   ----------------------------------------------
   Creates a "frame within a frame" look for empty slots.
*/
/* 1. Hide the empty image so no broken icon appears */
.mem-cell:not(.has-item) img,
.harm-col:not(.has-item) img {
    display: none !important;
}

/* 2. Create the "Inner Frame" using ::after pseudo-element */
.mem-cell:not(.has-item) .mem-box::after,
.harm-col:not(.has-item) .harm-slot::after {
    content: "";
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    /* Inset for double frame look */
    border: 1px solid #ccc;
    /* Light grey inner frame */
    pointer-events: none;
}

.mem-cell.has-item:hover .mem-remove-btn,
.harm-col.has-item:hover .mem-remove-btn {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    pointer-events: auto;
}

.mem-remove-btn:hover {
    background: #ff3333;
    transform: scale(1.15) rotate(90deg);
}

.mem-remove-btn:active {
    transform: scale(0.95) rotate(90deg);
}

/* 
   Harmonization Slots 
   ----------------------------------------------
   Vertical column for the two harmony slots.
*/
.harm-col {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-self: start;
    position: relative;
}

.harm-slot {
    width: 100%;
    aspect-ratio: 1;
    background: #0a0505;
    border: 1px solid var(--accent-dim);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin-bottom: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.harm-slot:hover {
    border-color: #ff4d4d;
    background: #1a1a1a;
    box-shadow: 0 0 8px rgba(255, 50, 50, 0.4);
}

.harm-slot img {
    width: 90%;
    height: 90%;
    object-fit: cover;
}

.harm-input {
    width: 100%;
    text-align: center;
    background: transparent;
    border: 1px solid transparent;
    /* Prepare for border highlight */
    color: var(--accent-red);
    font-family: var(--font-tech);
    font-size: 0.7rem;
    height: 20px;
    line-height: 20px;
    display: block;
    transition: all 0.2s;
    /* Smooth transition */
}

.harm-input:hover,
.harm-input:focus {
    background: #111;
    border: 1px solid #333;
    color: #fff;
    outline: none;
}

/* 
   Resonance & Skills 
   ----------------------------------------------
   Logic for resonance skill selection dropdowns.
*/
.res-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-self: start;
    padding-top: 0;
}

.res-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: #080808;
    border: 1px solid #1a1a1a;
    padding: 10px;
    border-left: 2px solid #333;
    overflow: visible;
}

.res-label {
    font-family: var(--font-tech);
    color: var(--accent-red);
    font-size: 0.65rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.res-row {
    display: flex;
    gap: 5px;
    align-items: center;
    width: 100%;
}

.res-slot-select {
    /* Hidden input styling mostly irrelevant, but keep consistent */
    display: none;
}

/* 
   Custom Dropdown Component 
   ----------------------------------------------
   Replaces specific native <select> elements for better styling.
*/
.custom-res-select {
    position: relative;
    width: 20px;
    min-width: 20px;
    /* Micro size */
    height: 24px;
    font-family: var(--font-tech);
    font-size: 0.8rem;
    /* Smaller Font */
    cursor: pointer;
    user-select: none;
    z-index: 10;
    flex-shrink: 0;
}

/* Open State High Z-Index */
.custom-res-select.open {
    z-index: 10001 !important;
    position: relative;
    /* Force on top when open */
}

/* Ensure parent containers don't clip open dropdown */
.res-group:has(.custom-res-select.open) {
    z-index: 10000;
    position: relative;
}

.res-col:has(.custom-res-select.open) {
    z-index: 10000;
}

.res-select-trigger {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--accent-red);
    background-color: var(--input-bg);
    border: 1px solid transparent;
    transition: all 0.2s;
    font-weight: 700;
    /* Bolder for visibility */
}

.custom-res-select:hover .res-select-trigger,
.custom-res-select.open .res-select-trigger {
    background: #000;
    border-color: #333;
}

.res-select-options {
    position: absolute;
    top: 100%;
    left: 0;
    width: auto;
    min-width: 35px;
    background: #000;
    border: 1px solid #333;
    display: none;
    flex-direction: column;
    z-index: 100000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
}

.custom-res-select.open .res-select-options {
    display: flex;
}

.res-select-option {
    padding: 3px 4px;
    text-align: center;
    color: #888;
    transition: background 0.2s, color 0.2s;
    font-size: 0.75rem;
    cursor: pointer;
}

.res-select-option:hover {
    background: #222;
    color: #fff;
    cursor: pointer;
}

.res-select-option.selected {
    color: var(--accent-red);
}

/* 
   Weapon Resonance Input 
   ----------------------------------------------
   Small input field for the specific skill ID or Value.
*/
.res-skill-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid #333;
    padding: 2px 5px;
    color: var(--text-color);
    font-family: var(--font-body);
    font-size: 0.8rem;
    height: 24px;
    flex: 1;
    /* Stretch to fill space */
    min-width: 0;
    width: 0;
    box-sizing: border-box;
    outline: none;
}

.res-skill-input:focus {
    border-bottom-color: var(--accent-red);
    color: #fff;
}

/* ==============================================
   Weapon Resonance UI
   ============================================== */
.weapon-res-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: #080808;
    border: 1px solid #1a1a1a;
    padding: 10px;
    border-left: 2px solid #333;
}

.weapon-res-row {
    display: flex;
    gap: 5px;
    justify-content: flex-start;
}

.weapon-res-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Slot for Weapon Resonance Icon */
.weapon-res-box {
    width: 40px;
    height: 40px;
    background: #0a0505;
    border: 1px solid var(--accent-dim);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.weapon-res-box:hover {
    border-color: #ff4d4d;
    background: #1a1a1a;
    box-shadow: 0 0 8px rgba(255, 50, 50, 0.4);
}

.weapon-res-box img {
    width: 90%;
    height: 90%;
    object-fit: cover;
}

/* ==============================================
   Tactical Analysis (Notes) Section
   ============================================== */
.tac-box {
    position: relative;
    height: 100%;
    padding: 15px;
    border: 1px solid #1a1a1a;
    background: rgba(255, 255, 255, 0.01);
    overflow: hidden;
    max-width: 100%;
}

/* Corner Brackets for Tech Look */
.corner-bracket {
    position: absolute;
    width: 15px;
    height: 15px;
    pointer-events: none;
    border-color: #444;
    border-style: solid;
}

.cb-tl {
    top: -1px;
    left: -1px;
    border-width: 2px 0 0 2px;
}

.cb-br {
    bottom: -1px;
    right: -1px;
    border-width: 0 2px 2px 0;
}

.tac-header {
    font-family: var(--font-header);
    font-weight: 700;
    color: #fff;
    font-size: 0.8rem;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.7;
}

.tac-header::before {
    content: '';
    width: 3px;
    height: 12px;
    background: var(--accent-red);
}

/* Add Build Wide Button */
.add-build-area {
    margin-top: 10px;
    padding-bottom: 20px;
}

.add-build-wide-btn {
    width: 100%;
    background: transparent;
    border: 1px dashed #333;
    color: #555;
    font-family: var(--font-tech);
    font-size: 0.9rem;
    padding: 15px;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.2s;
    letter-spacing: 1px;
}

.add-build-wide-btn:hover {
    border-color: var(--accent-red);
    color: #fff;
    background: rgba(255, 255, 255, 0.02);
}

/* 
   Build Row Animations 
   ----------------------------------------------
   Transitions for adding/removing builds.
*/
.build-row {
    transition: max-height 0.3s ease-out, margin 0.3s ease-out, padding 0.3s ease-out, opacity 0.3s ease-out;
    max-height: 800px;
    /* Allow growth but defined for transition */
    overflow: hidden;
    /* Required for height animation */
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }

    to {
        opacity: 0;
        transform: scale(0.95);
    }
}

.build-row.adding {
    animation: slideDown 0.3s ease-out forwards;
}

.build-row.removing {
    animation: fadeOut 0.3s ease-in forwards;
    pointer-events: none;

    /* Collapsing transition */
    max-height: 0;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom-width: 0;
    opacity: 0;
}