/* Global Reset & Basic Typography */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif; /* Modern, clean font */
    margin: 0;
    padding: 0;
    background-color: #eef2f6; /* Gray-ish white body background */
    height: 100vh;
    display: flex;
    flex-direction: column;
    color: #333;
}

/* Header */
.header {
    padding: 15px 20px;
    background-color: #fcfcfc; /* Very light, almost white background */
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between; /* Space out left and right groups */
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
    position: relative; /* For absolute positioning of burger/mobile menu */
}

.header h1 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 600;
    color: #4a4a4a;
}

.header-left-group {
    display: flex;
    align-items: center;
    gap: 20px; /* Space between title and desktop nav button */
}

.header-right-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.nav-button {
    background-color: #6a8cff; /* Primary accent color */
    color: white;
    border: none;
    padding: 8px 15px;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 2px 8px rgba(106, 140, 255, 0.2);
    white-space: nowrap;
    display: inline-block;
}

.nav-button:hover {
    background-color: #5377eb;
    box-shadow: 0 4px 12px rgba(106, 140, 255, 0.3);
}

/* Hide mobile-only nav button by default */
.nav-button.mobile-only {
    display: none;
}

/* Main Layout Container */
.main-container {
    display: flex;
    flex-grow: 1;
    padding: 20px;
    gap: 20px;
}

/* Chart Section (Left/Main Area) */
.chart-section {
    flex: 3;
    min-width: 60%;
    background-color: #fcfcfc;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-container-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    padding: 20px;
}

.chart-container {
    position: absolute;
    width: calc(100% - 40px);
    height: calc(100% - 40px);
    left: 20px;
    bottom: 20px;
    border-left: 2px solid #ced4da;
    border-bottom: 2px solid #ced4da;
    background-color: #fdfdfd;
}

.zoom-controls {
  display: flex;
  gap: 8px;
  background: rgba(255,255,255,0.9);
  border-radius: 4px;
  padding: 4px;
  z-index: 10;
}

.zoom-controls button {
  border: none;
  background: none;
  padding: 9px 9px 6px 10px;;
  cursor: pointer;
}

.zoom-controls button:hover {
    background-color: rgba(0, 0, 0, 0.04);
    box-shadow: none;
}

.zoom-controls img {
  width: 24px;
  height: 24px;
}

.custom-entity-form {
    margin-top: 20px;
    border-top: 1px solid #ddd;
    padding-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.custom-entity-form h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #4a4a4a;
}

.custom-entity-form input,
.custom-entity-form button {
    padding: 8px 10px;
    font-size: 0.9rem;
}

/* Controls Section (Right Sidebar - Entity Picker) */
.controls-section {
    flex: 1;
    min-width: 300px;
    max-width: 400px;
    background-color: #fcfcfc;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.controls-row {
    margin-bottom: 15px;
}

/* Form Elements: Select, Button, Input */
select, button, input[type="text"], input[type="number"], input[type="file"] {
    padding: 10px 15px;
    font-size: 0.95rem;
    border-radius: 8px;
    border: 1px solid #dcdfe4;
    background-color: #fcfcfc;
    color: #4a4a4a;
    transition: all 0.2s ease-in-out;
    outline: none;
}

select:focus, input[type="text"]:focus {
    border-color: #6a8cff;
    box-shadow: 0 0 0 2px rgba(106, 140, 255, 0.2);
}

button {
    background-color: #6a8cff;
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 500;
}

button:hover {
    background-color: #5377eb;
    box-shadow: 0 2px 8px rgba(106, 140, 255, 0.3);
}

.clear-btn {
    background-color: #dc3545;
}

.clear-btn:hover {
    background-color: #c82333;
}

.unit-selector {
    width: auto;
    min-width: 120px;
}

.search-bar {
    width: 100%;
}

/* Height Marks & Lines on Chart */
.height-marks {
    position: absolute;
    left: -60px;
    width: 50px;
    text-align: right;
}

.height-mark {
    position: absolute;
    width: 100%;
    text-align: right;
}

.height-mark > div:last-child {
    position: relative;
    top: -0.6em;
    color: #6c757d;
    font-size: 0.8rem;
    font-weight: 300;
}

.height-line {
    position: absolute;
    width: 100%;
    height: 1px;
    background-color: rgba(206, 212, 218, 0.5);
    z-index: 1;
}

/* Item on Chart (Image, Labels) */
.item-image {
    position: absolute;
    cursor: grab;
    user-select: none;
    bottom: 0;
    transition: transform 0.15s ease-out;
    z-index: 2;
    touch-action: none;
    transform-origin: bottom center;
}

.item-image.dragging {
    opacity: 0.6;
    pointer-events: none;
}

.item-image:hover {
    transform: scale(1.02);
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
}

.item-label, .item-stats {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    background-color: rgba(252, 252, 252, 0.9);
    padding: 4px 8px;
    border-radius: 5px;
    white-space: nowrap;
    cursor: grab;
    user-select: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    color: #4a4a4a;
}

.item-label {
    top: -30px;
    font-weight: 500;
}

.item-stats {
    top: -55px;
    font-weight: 400;
    color: #6c757d;
}

/* Library Container (Scrollable Area for Items) */
.library-container {
    max-height: 77vh;
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 5px;
    margin-top: 10px;
}

/* Custom Scrollbar for Webkit Browsers */
.library-container::-webkit-scrollbar {
    width: 8px;
}

.library-container::-webkit-scrollbar-track {
    background: #f8f8f8;
    border-radius: 10px;
}

.library-container::-webkit-scrollbar-thumb {
    background: #e0e0e0;
    border-radius: 10px;
}

.library-container::-webkit-scrollbar-thumb:hover {
    background: #c0c0c0;
}

.animal-library, .building-library {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-start;
}

.import-library {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-start;
  margin-bottom: 20px;
}

/* Individual Library Item */
.library-item {
    width: calc(33.33% - 8px);
    min-width: 90px;
    text-align: center;
    cursor: grab;
    padding: 10px;
    border-radius: 8px;
    background-color: #fefefe;
    border: 1px solid #e9ecef;
    transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.library-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.library-item img {
    width: 60px;
    height: auto;
    margin-bottom: 5px;
    pointer-events: none;
}

.library-item p {
    margin: 0;
    font-size: 0.85rem;
    color: #4a4a4a;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.library-item {
    position: relative; 
}

.no-results {
    text-align: center;
    font-size: 0.95rem;
    color: #999;
    margin: 15px 0;
    padding: 10px;
    font-style: italic;
    display: none;
}

.add-to-chart-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 8px 12px;
    font-size: 0.9rem;
    font-weight: 600;
    background-color: hsla(227, 100%, 71%, 0.9);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    z-index: 5;
    
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
}

.library-item:hover .add-to-chart-btn {
    opacity: 1;
    visibility: visible;
}

.library-item:hover img, .library-item:hover p {
    opacity: 0.6;
    transition: opacity 0.2s ease-in-out;
}

.remove-from-chart-btn {
    position: absolute;
    top: -95px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 30px;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);

    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.item-image:hover .remove-from-chart-btn {
    opacity: 1;
    visibility: visible;
}

.item-stats {
    top: -55px;
}

.item-label {
    top: -30px;
}

/* Remove Indicator */
.remove-indicator {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #dc3545;
    color: white;
    padding: 12px 25px;
    border-radius: 8px;
    display: none;
    z-index: 100;
    font-size: 1rem;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Ghost Image (when dragging from chart) */
.item-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.7;
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.2));
    transform-origin: top left;
}

/* Category Tabs */
.category-tabs {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 5px;
}

.category-tab {
    flex-grow: 1;
    text-align: center;
    padding: 10px 0;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    color: #6c757d;
    transition: color 0.2s, border-bottom-color 0.2s;
    border-bottom: 2px solid transparent;
}

.category-tab:hover {
    color: #4a4a4a;
}

.category-tab.active {
    color: #6a8cff;
    border-bottom-color: #6a8cff;
    font-weight: 600;
}

/* Category Panels (Content areas for each tab) */
.category-panel {
    display: none;
}

.category-panel.active {
    display: block;
}

/* Burger Menu Button */
.burger-menu-btn {
    display: none; /* Hidden by default on desktop */
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    z-index: 20;
    position: absolute; /* Position relative to header */
    right: 15px; /* Adjust as needed */
    top: 50%;
    transform: translateY(-50%);
}

.burger-icon {
    display: block;
    width: 25px;
    height: 3px;
    background-color: #4a4a4a;
    margin: 5px 0;
    transition: all 0.3s ease-in-out;
}

/* Animation for burger to 'X' */
.burger-menu-btn.open .burger-icon:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.burger-menu-btn.open .burger-icon:nth-child(2) {
    opacity: 0;
}

.burger-menu-btn.open .burger-icon:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* Mobile Menu Container (for Pet VS button) */
.header-mobile-menu {
    display: none; /* Hidden by default */
    position: absolute;
    top: 100%; /* Position below the header */
    right: 0; /* Align to the right */
    background-color: #fcfcfc;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
    flex-direction: column;
    padding: 10px 20px;
    gap: 8px;
    z-index: 15;
    border-top: 1px solid #e0e0e0;
    min-width: 150px; /* Ensure it's wide enough for the button */
    align-items: flex-end; /* Align button to the right within the menu */
}

.header-mobile-menu.active {
    display: flex;
    top: 70px;
    width: 100%;
    height: 110px;
    justify-content: center;
}

/* Ensure mobile-only nav button is displayed when menu is active */
.header-mobile-menu.active .nav-button.mobile-only {
    display: block; /* Change from none to block */
    width: 100%; /* Make it full width in the menu */
    text-align: center; /* Center text */
}


/* Responsive Adjustments */
@media (max-width: 992px) {
    .main-container {
        flex-direction: column;
        padding: 15px;
    }

    .chart-section {
        min-width: auto;
        height: 60vh;
        flex: none;
    }

    .controls-section {
        min-width: auto;
        max-width: none;
        height: 65vh;
        flex: none;
    }

    .library-container {
        height: calc(100% - 100px);
    }

    .library-item {
        width: calc(25% - 9px);
    }
}

@media (max-width: 768px) {
    .header {
        flex-direction: column; /* Stack header items vertically */
        align-items: flex-start; /* Align title to the left */
        padding: 10px 15px;
        position: relative; /* Ensure absolute positioning works */
    }

    .header-left-group {
        width: 100%;
        align-items: center;
        margin-bottom: 25px;
        padding-top: 15px;
        padding-left: 15px;
    }

    .header h1 {
        font-size: 1.4rem;
        margin-bottom: 0;
    }

    .nav-button.desktop-only {
        display: none; /* Hide desktop nav button on mobile */
    }

    .header-right-group {
        flex-direction: column;
        width: 100%;
        gap: 8px;
        align-items: center;
    }

    .zoom-controls {
        order: 2; /* Middle position */
        width: 100%;
        justify-content: center; /* Center zoom buttons */
    }

    .unit-selector {
        order: 3; /* Bottom position */
        width: auto;
    }

    .clear-btn {
        order: 4; /* Bottom position */
        width: auto;
    }

    .burger-menu-btn {
        display: block; /* Show burger button */
        position: absolute; /* Position it in the top-right */
        right: 15px;
        top: 15px;
        transform: translateY(0); /* Reset transform */
    }

    /* Adjust main content sections for mobile */
    .chart-section {
        height: 55vh;
    }
    .controls-section {
        height: 65vh;
    }
    .library-item {
        width: calc(33.33% - 8px);
    }

    .height-mark > div:last-child {
        font-size: 0.7rem;
        top: -0.4em;
    }
    .height-line {
        height: 1px;
        background-color: rgba(206, 212, 218, 0.4);
    }
}

@media (max-width: 480px) {
    .main-container {
        padding: 10px;
        gap: 10px;
    }
    .library-item {
        width: calc(50% - 6px);
    }
    .header h1 {
        font-size: 1.4rem;
    }
    select, button, input[type="text"] {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .height-mark > div:last-child {
        font-size: 0.6rem;
        top: -0.3em;
    }
    .height-line {
        background-color: rgba(206, 212, 218, 0.3);
    }
}
