/* ============================================
   GTNH Production Line Visualizer
   Cleaned & Organized Version
   ============================================ */

/* ============================================
   RESET & BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    background: #0a0f1e;
    color: #eef4ff;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ============================================
   HEADER & NAVIGATION
   ============================================ */
.app-header {
    background: #0f172ad9;
    backdrop-filter: blur(12px);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #2d3a5e;
    z-index: 20;
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    flex-wrap: wrap;
    gap: 12px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
    background: linear-gradient(135deg, #b9f3ff, #6ea8fe);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.logo p {
    font-size: 0.75rem;
    color: #8ba0c0;
}

.stats {
    background: #1e293bb3;
    padding: 6px 14px;
    border-radius: 40px;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    gap: 20px;
}

.stats i {
    margin-right: 6px;
    color: #5bc0ff;
}

.controls {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.ctrl-btn {
    background: #1e2a3e;
    border: none;
    color: white;
    padding: 6px 14px;
    border-radius: 28px;
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ctrl-btn:hover {
    background: #2d3e5c;
    transform: scale(1.02);
}

.ctrl-btn.active {
    background: #3b82f6;
    box-shadow: 0 0 10px rgba(59,130,246,0.3);
}

.search-container {
    position: relative;
}

.search-stats {
    margin-top: 5px;
    font-size: 0.75rem;
    text-align: center;
}

#searchModeToggle.active {
    background: #3b82f6;
    box-shadow: 0 0 8px rgba(59,130,246,0.5);
}

#searchModeToggle i {
    margin-right: 4px;
}

/* ============================================
   TABLE CONTAINER & SCROLLING
   ============================================ */
.table-container {
    width: 100%;
    height: calc(100vh - 140px);
    overflow: auto;
    position: relative;
    background: #0b1018;
}

/* Scrollbar */
.table-container::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.table-container::-webkit-scrollbar-track {
    background: #0f172a;
}

.table-container::-webkit-scrollbar-thumb {
    background: #2d3a5e;
    border-radius: 5px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #3b4a6e;
}

/* ============================================
   GRID LAYOUTS BY MODE
   ============================================ */
.prod-grid {
    display: flex;
    flex-direction: column;
}

.grid-header {
    display: grid;
    background: #1a2332;
    padding: 15px;
    font-weight: 600;
    border-bottom: 2px solid #2d3a5e;
    color: #cbd5e6;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Mode 1: 5 columns */
.prod-grid:not(.mode-bees):not(.mode2) .grid-header,
.prod-grid:not(.mode-bees):not(.mode2) .bee-main-row,
.prod-grid:not(.mode-bees):not(.mode2) .comb-entry {
    grid-template-columns: 15% 17% 20% 15% 33%;
}

/* Mode 2: 2 columns */
.prod-grid.mode2 .grid-header,
.prod-grid.mode2 .bee-main-row {
    grid-template-columns: 280px 1fr;
}

/* Mode 3: 2 columns */
.prod-grid.mode-bees .grid-header,
.prod-grid.mode-bees .bee-main-row,
.prod-grid.mode-bees .comb-entry {
    grid-template-columns: 20% 80%;
}

/* ============================================
   ROW STYLES
   ============================================ */
.bee-row {
    border-bottom: 1px solid #1a2332;
    background: #0f172a;
}

.bee-row:last-child {
    border-bottom: none;
}

.bee-main-row {
    display: grid;
    background: #0f172a;
}

.comb-entry {
    display: grid;
    background: #0d1422;
    border-top: 1px solid #1a2332;
}

/* Cell styling */
.cell {
    padding: 12px;
    vertical-align: top;
    background: #0f172a;
    word-break: break-word;
    border-right: 1px solid #1a2332;
}

.cell:last-child {
    border-right: none;
}

.bee-cell {
    background: #1a1f2e;
    font-weight: bold;
}

.cell-bee-placeholder {
    padding: 12px;
    background: #0d1422;
    border-right: 1px solid #1a2332;
    position: relative;
    overflow: visible;
}

/* Arrow indicator for additional comb rows */
.comb-entry .cell-bee-placeholder::before {
    content: "↳";
    color: #6ea8fe;
    margin-right: 8px;
    font-size: 0.9rem;
    display: inline-block;
}

.prod-grid.mode-bees .comb-entry .cell-bee-placeholder::before {
    content: "";
    display: none;
}

/* Hover effects */
.bee-main-row:hover .cell {
    background: #1a2332;
}

.comb-entry:hover .cell {
    background: #1a1f2e;
}

.bee-main-row:hover .bee-cell {
    background: #1e2a3e;
}

/* Alternating row colors */
.bee-main-row:nth-child(even) .cell {
    background: #0d1422;
}

.bee-main-row:nth-child(even) .bee-cell {
    background: #1a1f2e;
}

.comb-entry:nth-child(even) .cell {
    background: #0a0f1a;
}

/* Consistent spacing */
.bee-main-row .cell,
.comb-entry .cell,
.cell-bee-placeholder {
    min-height: 60px;
}

/* ============================================
   BEE NAME STYLES
   ============================================ */
.bee-name {
    font-size: 1.1rem;
    color: #d8b4fe;
    display: flex;
    align-items: center;
    gap: 10px;
}

.bee-name i {
    font-size: 1.3rem;
}

/* ============================================
   COMB STYLES
   ============================================ */
.comb-details {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.comb-name-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.comb-name {
    font-weight: bold;
    color: #facc15;
    font-size: 1rem;
}

.comb-stats {
    display: flex;
    gap: 8px;
    font-size: 0.75em;
}

.chance-badge {
    background: #1e3a5f;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    color: #90cdf4;
}

.special-badge,
.special-badge-small {
    background: #a855f7;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    color: white;
}

.recipe-count-badge {
    background: #2d3a5e;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    color: #cbd5e6;
}

.empty-comb-cell {
    color: #6ea8fe;
    font-style: italic;
    font-size: 0.8rem;
    padding: 8px 0;
}

.process-indicator {
    font-size: 0.7rem;
    color: #6ea8fe;
    margin-left: 8px;
}

/* ============================================
   INPUT & OUTPUT STYLES
   ============================================ */
.input-list,
.output-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.input-chip,
.output-chip {
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.input-chip {
    background: #3b82f622;
    border-left: 3px solid #3b82f6;
    color: #90cdf4;
}

.fluid-chip {
    background: #06b6d422;
    border-left-color: #06b6d4;
}

.output-chip {
    background: #22c55e22;
    border-left: 3px solid #22c55e;
    color: #86efac;
}

.machine-name {
    background: #47556933;
    padding: 6px 12px;
    border-radius: 6px;
    display: inline-block;
    font-size: 0.85rem;
    border-left: 3px solid #94a3b8;
    color: #cbd5e6;
}

.chance {
    font-size: 0.7rem;
    color: #22c55e;
    margin-left: 5px;
}

.empty-hint {
    color: #4a5568;
    font-style: italic;
    font-size: 0.8rem;
}

/* ============================================
   ID BADGE STYLES - CLICKABLE & LARGER
   ============================================ */

/* ID Badge - Larger, clickable, same size as chance badge */
.id-badge {
    background: #0f172a;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-family: 'Courier New', monospace;
    color: #6ea8fe;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid #2d3a5e;
    letter-spacing: 0.3px;
}

.id-badge i {
    font-size: 0.65rem;
    color: #3b82f6;
}

.id-badge:hover {
    background: #1e293b;
    border-color: #3b82f6;
    transform: scale(1.02);
    color: #b9f3ff;
}

.id-badge:active {
    transform: scale(0.98);
    background: #3b82f6;
    color: white;
}

.id-badge:active i {
    color: white;
}

/* Copied feedback animation */
.id-badge.copied {
    background: #22c55e;
    border-color: #22c55e;
    color: white;
}

.id-badge.copied i {
    color: white;
}

/* For compact views where space is limited */
.id-badge-compact {
    background: #0f172a;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.65rem;
    font-family: monospace;
    color: #6ea8fe;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.id-badge-compact:hover {
    background: #1e293b;
    color: #b9f3ff;
}

/* For Mode 2 and Mode 3 */
.comb-name .id-badge,
.recipe-item .id-badge {
    margin-left: 8px;
    vertical-align: middle;
}

/* Input/Output chips with ID badges */
.input-chip .id-badge,
.output-chip .id-badge {
    margin-left: 6px;
    font-size: 0.65rem;
    padding: 2px 8px;
}

/* Recipe item ID badge */
.recipe-item .id-badge {
    background: #1e293b;
    padding: 2px 6px;
    font-size: 0.6rem;
}

.recipe-item .id-badge:hover {
    background: #3b82f6;
    color: white;
}

/* Mode 2 comb card ID badge */
.comb-card .id-badge {
    background: #0f172a;
    padding: 3px 10px;
    font-size: 0.7rem;
    border: 1px solid #2d3a5e;
}

.comb-card .id-badge:hover {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

/* Mode 3 comb ID badge */
.prod-grid.mode-bees .id-badge {
    background: #0f172a;
    padding: 2px 8px;
    font-size: 0.65rem;
}

/* ============================================
   ID BADGE TOGGLE STYLES
   ============================================ */

/* Hide IDs by default */
.id-badge,
.id-badge-compact,
.item-id,
.item-id-compact {
    display: none;
}

/* Show IDs when toggle is active */
body.show-ids .id-badge,
body.show-ids .id-badge-compact,
body.show-ids .item-id,
body.show-ids .item-id-compact {
    display: inline-flex;
}

/* Update toggle button active state */
#toggleIdsBtn.active {
    background: #3b82f6;
    box-shadow: 0 0 10px rgba(59,130,246,0.3);
}

#toggleIdsBtn.active i {
    color: white;
}

/* Ensure ID badges still have proper styling when visible */
body.show-ids .id-badge {
    display: inline-flex;
}

body.show-ids .id-badge-compact {
    display: inline-flex;
}

body.show-ids .item-id {
    display: inline-block;
}

body.show-ids .item-id-compact {
    display: inline-block;
}

/* ============================================
   MODE 2 - COMBS ONLY (IMPROVED LAYOUT)
   ============================================ */
.prod-grid.mode2 .bee-main-row:hover {
    background: #1a2332;
}

/* Comb Card */
.comb-card {
    background: linear-gradient(135deg, #1a1f2e, #1e2a3e);
    border-radius: 12px;
    padding: 15px;
    margin: 5px;
    border-left: 4px solid #facc15;
    height: 100%;
}

.comb-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.comb-name-large {
    font-size: 1.2rem;
    font-weight: bold;
    color: #facc15;
    display: flex;
    align-items: center;
    gap: 8px;
}

.comb-badge {
    background: #facc1522;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    color: #facc15;
}

.producers-pill {
    background: #a855f722;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}

.producers-pill i {
    color: #a855f7;
}

/* Recipe Cards */
.recipes-horizontal {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.recipe-card {
    background: #0f172a;
    border-radius: 10px;
    padding: 12px 15px;
    border: 1px solid #2d3a5e;
    transition: all 0.2s;
}

.recipe-card:hover {
    border-color: #3b82f6;
    background: #131c2e;
}

.recipe-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #2d3a5e;
    flex-wrap: wrap;
}

.recipe-number {
    background: #3b82f6;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: bold;
}

.recipe-machine {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ff980022;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: #ff9800;
}

.recipe-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.recipe-section {
    background: #0d1422;
    border-radius: 8px;
    padding: 10px;
}

.recipe-section-title {
    font-size: 0.75rem;
    font-weight: bold;
    margin-bottom: 8px;
    color: #8ba0c0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.recipe-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.recipe-item {
    background: #1e293b;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.recipe-item.fluid {
    background: #06b6d422;
    border-left: 2px solid #06b6d4;
}

.recipe-item-output {
    background: #22c55e22;
    border-left: 2px solid #22c55e;
}

.item-quantity {
    color: #90cdf4;
    font-size: 0.7rem;
}

.item-chance {
    color: #22c55e;
    font-size: 0.65rem;
}

/* ============================================
   MODE 3 - BEES ONLY (COLLAPSIBLE)
   ============================================ */
.bee-header {
    cursor: pointer;
    transition: background 0.2s;
}

.bee-header:hover {
    background: #1a2332 !important;
}

.collapse-icon {
    display: inline-block;
    width: 20px;
    font-size: 0.9rem;
    transition: transform 0.2s ease;
    margin-right: 8px;
    color: #6ea8fe;
}

.collapse-icon.collapsed {
    transform: rotate(-90deg);
}

.bee-combs-container {
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: #0d1422;
}

.bee-combs-container.collapsed {
    max-height: 0 !important;
}

.prod-grid.mode-bees .comb-entry {
    background: #0d1422;
    border-left: 3px solid #a855f7;
}

.prod-grid.mode-bees .comb-entry .cell:first-child {
    background: #0d1422;
    padding-left: 30px;
}

/* ============================================
   SEARCH HIGHLIGHT
   ============================================ */
.highlight {
    background-color: #facc15;
    color: #0a0f1e;
    font-weight: bold;
    padding: 0 2px;
    border-radius: 3px;
}

@keyframes highlightPulse {
    0%, 100% { background-color: #1a1f2e; }
    50% { background-color: #facc1522; }
}

.bee-row.highlight-row {
    animation: highlightPulse 1s ease-in-out 2;
}

/* ============================================
   MACHINE FILTER DROPDOWN
   ============================================ */
.machine-filter-container {
    position: relative;
}

.filter-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: #1e293b;
    border: 1px solid #2d3a5e;
    border-radius: 12px;
    min-width: 280px;
    max-width: 350px;
    z-index: 1000;
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    backdrop-filter: blur(10px);
}

.filter-header {
    padding: 12px 15px;
    border-bottom: 1px solid #2d3a5e;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #cbd5e6;
}

.filter-actions {
    display: flex;
    gap: 8px;
}

.filter-action-btn {
    background: #0f172a;
    border: 1px solid #2d3a5e;
    color: #8ba0c0;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.7rem;
    transition: all 0.2s;
}

.filter-action-btn:hover {
    background: #2d3a5e;
    color: white;
}

.filter-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 10px;
}

.filter-list::-webkit-scrollbar {
    width: 6px;
}

.filter-list::-webkit-scrollbar-track {
    background: #0f172a;
    border-radius: 3px;
}

.filter-list::-webkit-scrollbar-thumb {
    background: #2d3a5e;
    border-radius: 3px;
}

.filter-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    margin: 2px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.filter-item:hover {
    background: #0f172a;
}

.filter-item input {
    margin-right: 10px;
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.filter-item label {
    cursor: pointer;
    flex: 1;
    color: #cbd5e6;
    font-size: 0.85rem;
}

.filter-footer {
    padding: 12px 15px;
    border-top: 1px solid #2d3a5e;
    display: flex;
    justify-content: flex-end;
}

.filter-apply-btn {
    background: #3b82f6;
    border: none;
    color: white;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.filter-apply-btn:hover {
    background: #2563eb;
}

.filter-active {
    background: #3b82f6;
    color: white;
}

/* ============================================
   BACK TO TOP BUTTON
   ============================================ */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1000;
}

.back-to-top:hover {
    background: #2563eb;
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

/* ============================================
   LOADING & ERROR STATES
   ============================================ */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 15, 30, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #1e293b;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-cell {
    text-align: center;
    padding: 50px;
    color: #8ba0c0;
}

.no-results {
    text-align: center;
    padding: 60px;
    color: #8ba0c0;
}

.no-results .emoji {
    font-size: 3em;
    margin-bottom: 20px;
}

.error {
    background: #450a0a;
    border-left: 4px solid #ef4444;
    padding: 20px;
    margin: 20px;
    border-radius: 8px;
    color: #fca5a5;
}

/* ============================================
   FOOTER STYLES
   ============================================ */
.app-footer {
    background: #0f172ad9;
    backdrop-filter: blur(12px);
    padding: 12px 24px;
    text-align: center;
    border-top: 1px solid #2d3a5e;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 15;
    font-size: 0.8rem;
    color: #8ba0c0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.app-footer img {
    height: 35px;
    width: auto;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.app-footer img:hover {
    opacity: 1;
}

.app-footer a {
    color: #6ea8fe;
    text-decoration: none;
    transition: color 0.2s;
}

.app-footer a:hover {
    color: #b9f3ff;
    text-decoration: underline;
}

.app-footer p {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Adjust table container height to account for footer */
.table-container {
    height: calc(100vh - 140px); /* Subtract header and footer height */
}

/* Responsive adjustments */
@media (max-width: 992px) {
    .table-container {
        height: calc(100vh - 200px - 60px);
    }
}

@media (max-width: 768px) {
    .app-footer {
        padding: 8px 16px;
        font-size: 0.7rem;
    }
    
    .app-footer img {
        height: 18px;
    }
    
    .table-container {
        height: calc(100vh - 160px - 50px);
    }
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 1200px) {
    .prod-grid:not(.mode-bees):not(.mode2) .bee-main-row,
    .prod-grid:not(.mode-bees):not(.mode2) .comb-entry {
        grid-template-columns: 20% 18% 22% 20% 20%;
    }
}

@media (max-width: 992px) {
    .app-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .controls {
        justify-content: space-between;
    }
    
    .stats {
        justify-content: center;
    }
    
    .table-container {
        height: calc(100vh - 200px);
    }
    
    .prod-grid.mode2 .grid-header,
    .prod-grid.mode2 .bee-main-row {
        grid-template-columns: 1fr;
    }
    
    .recipe-content {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .cell,
    .cell-bee-placeholder {
        padding: 8px;
        font-size: 0.75rem;
    }
    
    .bee-name {
        font-size: 0.9rem;
    }
}

@media (max-width: 768px) {
    .prod-grid.mode2 .grid-header,
    .prod-grid.mode2 .bee-main-row,
    .prod-grid.mode-bees .grid-header,
    .prod-grid.mode-bees .bee-main-row,
    .prod-grid.mode-bees .comb-entry,
    .prod-grid:not(.mode-bees):not(.mode2) .grid-header,
    .prod-grid:not(.mode-bees):not(.mode2) .bee-main-row,
    .prod-grid:not(.mode-bees):not(.mode2) .comb-entry {
        grid-template-columns: 1fr;
    }
    
    .cell {
        border-right: none;
        border-bottom: 1px solid #1a2332;
    }
    
    .bee-cell {
        position: static;
    }
    
    .comb-header {
        flex-direction: column;
        align-items: flex-start;
    }
}