:root {
    --bg-app: #0f0f0f;
    --bg-sidebar: #181818;
    --bg-panel: #202020;
    --bg-header: #252525;
    --border: #333333;
    --highlight: #2a2a2a;

    --text-main: #e0e0e0;
    --text-muted: #a0a0a0;
    --accent: #3b82f6;
    --accent-hover: #2563eb;

    --color-select: #fbbf24;
    --color-bundle: #34d399;
    --color-ref: #c084fc;
    --color-item: #60a5fa;
    --color-weight: #9ca3af;

    --font-main: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;
}

body {
    margin: 0;
    font-family: var(--font-main);
    background: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    font-size: 16px;
    overflow: hidden;
}

* {
    box-sizing: border-box;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-app);
}

::-webkit-scrollbar-thumb {
    background: #404040;
    border-radius: 5px;
    border: 2px solid var(--bg-app);
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* --- Sidebar --- */
.sidebar {
    width: 350px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-x: auto;
}

.sidebar-header {
    padding: 20px;
    background: var(--bg-header);
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.search-box {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-box input {
    width: 100%;
    background: #121212;
    border: 1px solid #333;
    padding: 12px 15px;
    color: white;
    border-radius: 6px;
    font-size: 15px;
    font-family: var(--font-main);
    transition: border-color 0.2s;
}

.search-box input:focus {
    border-color: var(--accent);
    outline: none;
}

.tree-root {
    overflow-y: auto;
    flex: 1;
    padding: 10px 0;
}

/* Tree Nodes */
.node-item {
    position: relative;
}

.node-label {
    display: flex;
    align-items: center;
    padding: 8px 20px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    color: #ccc;
    font-size: 14px;
    transition: background 0.1s;
}

.node-label:hover {
    background: var(--highlight);
    color: white;
}

.node-label.active {
    background: #2d3748;
    color: var(--accent);
    border-right: 3px solid var(--accent);
}

.node-icon {
    margin-right: 10px;
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.icon-folder {
    color: #dcb67a;
    opacity: 0.8;
}

.icon-file {
    color: var(--text-muted);
    opacity: 0.6;
}

.node-children {
    padding-left: 24px;
    display: none;
    border-left: 1px solid #333;
    margin-left: 20px;
}

.node-children.open {
    display: block;
}

.arrow {
    width: 16px;
    text-align: center;
    margin-right: 4px;
    font-size: 10px;
    color: #666;
    transition: transform 0.15s;
}

/* --- Main Content --- */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-app);
    overflow: hidden;
}

.top-bar {
    padding: 25px 40px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 10;
    flex-shrink: 0;
}

.prefab-title {
    font-size: 28px;
    font-weight: 700;
    color: white;
    margin: 0;
    letter-spacing: -0.5px;
}

.prefab-path {
    font-family: var(--font-mono);
    color: var(--text-muted);
    font-size: 13px;
    opacity: 0.7;
}

.stats-bar {
    margin-top: 10px;
    display: flex;
    gap: 25px;
    font-size: 14px;
    color: #aaa;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #2a2a2a;
    padding: 6px 12px;
    border-radius: 6px;
}

.stat-value {
    color: white;
    font-weight: 600;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
    gap: 25px;
    align-content: start;
}

/* --- Loot Card --- */
.loot-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: box-shadow 0.2s;
    height: fit-content;
}

.loot-card:hover {
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3);
    border-color: #444;
}

.card-header {
    background: var(--bg-header);
    padding: 15px 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    user-select: none;
}

.card-header:hover {
    background: var(--highlight);
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-bundle);
    font-family: var(--font-mono);
}

.card-meta {
    color: var(--text-muted);
    font-size: 12px;
    background: #1a1a1a;
    padding: 2px 8px;
    border-radius: 4px;
}

/* Coordinates Box */
.coords-box {
    background: #151515;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    max-height: 100px;
    overflow-y: auto;
}

.coords-label {
    font-size: 11px;
    text-transform: uppercase;
    color: #666;
    font-weight: bold;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.coords-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.coord-chip {
    background: #252525;
    border: 1px solid #333;
    color: #ccc;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    cursor: copy;
    transition: all 0.1s;
}

.coord-chip:hover {
    background: #333;
    border-color: var(--accent);
    color: white;
    transform: translateY(-1px);
}

/* --- Item Grid (Inventory Style) --- */
.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 8px;
    padding: 15px;
    background: #151515;
}

.item-slot {
    width: 72px;
    height: 72px;
    background: #222;
    border: 2px solid #333;
    border-radius: 6px;
    position: relative;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.item-slot:hover {
    border-color: var(--accent);
    background: #2a2a2a;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    z-index: 10;
}

.item-slot img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 6px;
}

.item-qty {
    position: absolute;
    bottom: 3px;
    right: 5px;
    font-size: 12px;
    font-weight: 700;
    color: white;
    text-shadow: 1px 1px 2px #000;
    font-family: var(--font-mono);
    pointer-events: none;
}

.item-chance {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #fbbf24;
    color: #000;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 5px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    font-family: var(--font-mono);
    z-index: 5;
}

/* Tooltip */
.slot-tooltip {
    position: fixed;
    background: rgba(15, 15, 15, 0.95);
    border: 1px solid #555;
    color: white;
    padding: 10px;
    border-radius: 6px;
    font-size: 13px;
    z-index: 1000;
    pointer-events: none;
    white-space: nowrap;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    font-family: var(--font-main);
}

.btn-icon {
    background: transparent;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: #333;
    color: white;
}

/* Logic Rows in Grid Mode */
.logic-row {
    grid-column: 1 / -1;
    background: #1a1a1a;
    padding: 8px 12px;
    border-radius: 4px;
    margin: 5px 0;
    font-size: 13px;
    font-weight: 600;
    color: #ddd;
    border-left: 3px solid var(--color-select);
}

.logic-row.bundle {
    border-color: var(--color-bundle);
}

.droplist-content {
    grid-column: 1 / -1;
    margin-left: 15px;
    padding-left: 10px;
    border-left: 2px solid var(--color-ref);
}

/* Upload Screen */
#upload-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
}

.upload-box {
    border: 2px dashed #555;
    padding: 80px;
    border-radius: 12px;
    text-align: center;
    background: #1a1a1a;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.upload-box h1 {
    margin-top: 0;
    color: white;
    font-size: 28px;
    margin-bottom: 10px;
}

.upload-box p {
    color: #aaa;
    margin-bottom: 20px;
}

.btn-upload {
    margin-top: 25px;
    padding: 12px 30px;
    background: var(--accent);
    border: none;
    color: white;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    transition: background 0.2s;
}

.btn-upload:hover {
    background: var(--accent-hover);
}

.hidden {
    display: none !important;
}

.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* Collapsible Selection Rows */
.logic-row {
    cursor: pointer !important;
    user-select: none;
    transition: background 0.15s;
}

.logic-row:hover {
    background: #252525 !important;
}

.logic-row.collapsed::before {
    content: '? ';
    font-size: 10px;
    margin-right: 5px;
}

.logic-row.expanded::before {
    content: '� ';
    font-size: 10px;
    margin-right: 5px;
}

.selection-content {
    grid-column: 1 / -1;
    display: contents;
}

.selection-content.hidden>* {
    display: none !important;
}

/* Item Search Box */
.item-search {
    padding: 10px 15px;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
}

.item-search input {
    width: 100%;
    background: #0f0f0f;
    border: 1px solid #333;
    padding: 8px 12px;
    color: white;
    border-radius: 4px;
    font-size: 13px;
    transition: border-color 0.2s;
}

.item-search input:focus {
    border-color: var(--accent);
    outline: none;
}

.item-search input::placeholder {
    color: #666;
}

/* Full Width Grid */
.item-grid {
    width: 100% !important;
}

/* ================================================= */
/* styles from fixes.css - merged */
/* ================================================= */

/* CSS Fixes - Load this AFTER style.css */

/* --- Layout Fixes --- */
.content-area {
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
}

.loot-card {
    width: 100% !important;
    flex-shrink: 0;
}

/* Sidebar Layout: Fixed Header, Scrolling Content */
.sidebar {
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden;
    /* Fixed per user request */
}

.sidebar-header {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: #222;
    border-bottom: 1px solid #333;
}

.sidebar-header>div {
    display: flex;
    gap: 5px;
    /* Icons next to each other */
}

.tree-root {
    flex: 1;
    overflow: auto;
    /* Enable both scrollbars */
    padding: 10px;
    padding-bottom: 20px;
    width: 100%;
    /* Fit sidebar width */
}

.tree-root>div {
    min-width: fit-content;
}

/* Fix white scrollbar corner */
::-webkit-scrollbar-corner {
    background: transparent;
}

/* --- Sidebar Nesting & Styling --- */
.node-item {
    /* Default block behavior */
}

.node-item>.node-children {
    display: none;
    padding-left: 12px !important;
    border-left: 1px solid #333;
    margin-left: 6px;
}

.node-item.expanded>.node-children {
    display: block;
}

.node-label {
    padding: 4px 6px !important;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #ccc;
    cursor: pointer;
    border-radius: 3px;
    user-select: none;
    white-space: nowrap;
    /* Prevent wrapping to trigger horizontal scroll */
}

.node-label:hover {
    background: #2a2a2a;
    color: white;
}

.node-label.active {
    background: var(--accent, #3b82f6);
    color: white;
}

/* Arrow Rotation */
.node-item .arrow svg,
.node-item .node-arrow svg {
    transition: transform 0.2s;
    transform: rotate(0deg);
}

.node-item.expanded>.node-label .arrow svg,
.node-item.expanded>.node-header .node-arrow svg {
    transform: rotate(90deg);
}

/* --- Icons --- */
.btn-icon {
    width: 28px;
    height: 28px;
    padding: 5px;
    border-radius: 4px;
    background: transparent;
    border: 1px solid transparent;
    color: #888;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: #333;
    color: white;
    border-color: #444;
}

.btn-icon svg {
    width: 100%;
    height: 100%;
}

.stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 6px;
    color: var(--accent, #3b82f6);
}

/* --- Search Box --- */
.search-box {
    flex-shrink: 0;
    position: relative;
    /* For absolute positioning of clear button */
    padding: 10px;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
}

.search-box input {
    width: 100%;
    padding: 8px 32px 8px 10px;
    background: #0f0f0f;
    border: 1px solid #333;
    border-radius: 4px;
    color: white;
    font-size: 13px;
}

.search-box input:focus {
    border-color: var(--accent, #3b82f6);
    outline: none;
}

.search-clear {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    z-index: 10;
}

.search-clear:hover {
    color: white;
    background: #333;
}

.search-clear svg {
    width: 14px;
    height: 14px;
}

.hidden {
    display: none !important;
}

/* --- Help Modal --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #1a1a1a;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    border-radius: 8px;
    border: 1px solid #333;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #222;
    border-radius: 8px 8px 0 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    color: white;
}

.modal-close {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: #333;
    color: white;
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    color: #ccc;
    font-size: 14px;
    line-height: 1.6;
}

.help-section {
    margin-bottom: 30px;
}

.help-section h3 {
    color: var(--accent, #3b82f6);
    font-size: 16px;
    margin-bottom: 15px;
    border-bottom: 1px solid #333;
    padding-bottom: 8px;
}

.help-section h4 {
    color: #eee;
    font-size: 14px;
    margin: 15px 0 8px 0;
}

.help-list {
    padding-left: 20px;
    margin: 0;
}

.help-list li {
    margin-bottom: 6px;
}

.help-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.help-table th,
.help-table td {
    padding: 10px;
    border: 1px solid #333;
    text-align: left;
}

.help-table th {
    background: #222;
    color: white;
}

.code-block {
    background: #0f0f0f;
    padding: 12px;
    border-radius: 4px;
    border: 1px solid #333;
    overflow-x: auto;
    font-family: 'Consolas', monospace;
    font-size: 12px;
    color: #a5d6ff;
    margin: 10px 0;
}

.code-toggle {
    background: #2a2a2a;
    border: 1px solid #444;
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.code-toggle:hover {
    background: #333;
    border-color: #555;
}

kbd {
    background: #222;
    border: 1px solid #444;
    border-radius: 3px;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 11px;
    color: #eee;
}

/* --- Misc Fixes --- */
.logic-row.collapsed::before,
.logic-row.expanded::before {
    content: '' !important;
}

.droplist-content .item-grid {
    border-left: none !important;
    margin-left: 0 !important;
}
