:root {
    --bg-color: #0b0f19;
    --card-bg: rgba(20, 30, 46, 0.7);
    --primary: #00e5ff;
    --secondary: #ff9100;
    --text-main: #e0e6ed;
    --text-muted: #8b9bb4;
    --border: 1px solid rgba(255, 255, 255, 0.1);
    --glass: rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Rajdhani', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background-image: radial-gradient(circle at 50% 0%, #1a2639 0%, #0b0f19 70%);
}

.container {
    width: 100%;
    max-width: 1000px;
    /* Reduced to 1000px */
    padding: 1rem;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid rgba(0, 229, 255, 0.3);
    padding-bottom: 0.5rem;
    flex-shrink: 0;
}

h1 {
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--primary);
    text-shadow: 0 0 10px rgba(0, 229, 255, 0.4);
    font-size: 1.2rem;
}

.api-status-link {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 1px dashed rgba(139, 155, 180, 0.4);
    margin: 0 10px;
    transition: all 0.2s ease;
}

.api-status-link:hover {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.status-bar {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* MAIN LAYOUT */
.main-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    /* Fixed Left, Fluid Right */
    gap: 1rem;
    flex: 1;
    overflow: hidden;
}

/* LEFT PANEL */
.left-panel {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    overflow-y: auto;
    /* Re-enabled scrolling */
    padding-right: 4px;
    /* Minimal space for scrollbar */
}

/* RIGHT PANEL */
.right-panel {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border: var(--border);
    overflow-y: auto;
    padding: 1rem;
    position: relative;
}

/* Components */
.control-panel,
.avoid-panel {
    background: var(--card-bg);
    padding: 0.5rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: var(--border);
    position: relative;
    /* Removed z-index from panel itself to prevent clipping container creation */
}

.control-panel {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    /* Further reduced gap */
}

.input-group {
    display: flex;
    flex-direction: column;
    position: relative;
}

label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.1rem;
    /* Reduced from 0.3rem */
    letter-spacing: 1px;
}

input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.4rem 0.6rem;
    /* Reduced padding */
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    /* Reduced font size */
    border-radius: 4px;
    width: 100%;
    transition: all 0.3s ease;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.2);
}

.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1a2332;
    /* More opaque */
    border: 1px solid var(--primary);
    /* Stronger border */
    z-index: 9999;
    /* Ensure it's on top */
    max-height: 250px;
    overflow-y: auto;
    display: none;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    border-radius: 0 0 4px 4px;
}

.suggestions div {
    padding: 0.6rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.suggestions div:hover,
.suggestions div.autocomplete-active {
    background: rgba(0, 229, 255, 0.1);
    color: var(--primary);
}

.icon-exchange {
    align-self: center;
    color: var(--text-muted);
    font-size: 1rem;
    transform: rotate(90deg);
    /* Vertical flow in left panel */
}

button {
    background: var(--primary);
    color: #000;
    border: none;
    padding: 0.6rem;
    /* Reduced padding */
    font-family: inherit;
    font-weight: 700;
    font-size: 0.9rem;
    /* Reduced font size */
    text-transform: uppercase;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

button:hover {
    background: white;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

/* Avoid Tags */
.avoid-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.avoid-tag {
    background: rgba(255, 50, 50, 0.15);
    border: 1px solid rgba(255, 50, 50, 0.3);
    color: #ffcccc;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.avoid-tag:hover {
    background: rgba(255, 50, 50, 0.3);
    text-decoration: line-through;
}

/* Result Cards */
.results-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    /* Reduced from 1rem */
}

.result-card {
    background: var(--card-bg);
    padding: 0.5rem 0.8rem;
    /* Compact padding */
    border-radius: 8px;
    border: var(--border);
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

.result-card h2 {
    font-size: 0.9rem;
    margin: 0;
    color: var(--text-muted);
}

.result-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.3);
}

.result-card.selected {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(20, 30, 46, 0.9) 0%, rgba(0, 229, 255, 0.1) 100%);
    box-shadow: 0 0 15px rgba(0, 229, 255, 0.1);
}

.metric {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
}

.metric .value {
    font-size: 1.4rem;
    /* Reduced to fit line */
    font-weight: 700;
    color: white;
    line-height: 1;
}

.metric .label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.route-details {
    width: 100%;
    margin-top: 0.2rem;
    font-size: 0.8rem;
    color: var(--primary);
    text-align: right;
    white-space: pre-wrap;
}

/* Route List Items */
.route-list-header {
    display: grid;
    grid-template-columns: 40px 1.5fr 70px 70px 1.2fr;
    /* Matched to item grid */
    margin-bottom: 0.3rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    width: 100%;
}

.route-item {
    display: grid;
    grid-template-columns: 40px 1.5fr 70px 70px 1.2fr;
    /* Index | System | Kills | Jumps | Details */
    align-items: center;
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: background 0.1s;
    font-size: 0.85rem;
}

.route-item:hover {
    background: rgba(0, 229, 255, 0.1);
}

.route-index {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: right;
    padding-right: 10px;
}

.route-system {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.route-sec {
    font-size: 0.8em;
    color: #666;
    margin-left: 5px;
}

.route-stat {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.route-stat.high {
    color: #ff4444;
    font-weight: bold;
}

.route-stat.medium {
    color: #ffbb33;
}

.zkill-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: opacity 0.2s;
}

.zkill-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.route-info {
    font-size: 0.8rem;
    color: var(--secondary);
    text-align: right;
    padding-right: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.placeholder-msg {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* Footer */
footer {
    margin-top: 0.6rem;
    padding-top: 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: none;
}

footer a {
    color: inherit;
    text-decoration: underline;
    opacity: 0.8;
}

footer a:hover {
    color: var(--primary);
    opacity: 1;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr;
        overflow-y: auto;
    }

    .container {
        height: auto;
        display: block;
    }

    .right-panel {
        min-height: 400px;
    }

    .route-item {
        font-size: 0.8rem;
    }
}

/* Avoid Panel */
.avoid-panel {
    background: var(--card-bg);
    padding: 0.6rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: var(--border);
    position: relative;
    /* Create stacking context for autocomplete */
}

/* Favorites Panel */
.favorites-panel {
    background: var(--card-bg);
    padding: 0.6rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: var(--border);
    margin-top: 0.6rem;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    /* Don't shrink below a reasonable size */
    min-height: 200px;
    /* Ensure visible even with many waypoints */
}

.favorites-panel h3 {
    font-size: 0.8rem;
    color: var(--primary);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.2rem;
}

.favorites-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    flex: 1;
    /* Fill the panel */
}

.fav-item {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.1rem 0.4rem;
    /* Further reduced from 0.2/0.5 */
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.75rem;
    /* Reduced from 0.8rem */
    height: 22px;
    /* Fixed height for uniformity */
}

.fav-item:hover {
    background: rgba(0, 229, 255, 0.1);
    border-color: var(--primary);
}

.fav-route-text {
    flex: 1;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
    /* Slightly more space before badge/x */
    font-size: 0.68rem;
    /* Smaller font for long names */
}

.fav-jump-badge {
    background: rgba(0, 229, 255, 0.2);
    color: var(--primary);
    font-size: 0.6rem;
    /* Smaller badge font */
    padding: 0px 3px;
    border-radius: 3px;
    margin-right: 6px;
    /* Space between badge and x */
    font-weight: bold;
    flex-shrink: 0;
    /* Don't shrink the badge */
}

.fav-jump-badge.low-jumps {
    color: #ffcc00;
    /* Yellow */
    background: rgba(255, 204, 0, 0.2);
    border: 1px solid rgba(255, 204, 0, 0.3);
}

.fav-delete-btn {
    color: #ff4444;
    background: none !important;
    /* Force no background */
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    /* Slightly smaller x */
    display: flex;
    align-items: center;
    padding: 2px;
    border-radius: 2px;
}

.fav-delete-btn:hover {
    color: #ff0000;
}

/* Button Row */
.btn-row {
    display: flex;
    gap: 0.5rem;
}

#calculate-btn {
    flex: 1;
}

#save-fav-btn {
    width: 50px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--secondary);
    font-size: 1.2rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 145, 0, 0.3);
    cursor: pointer;
}

#save-fav-btn:hover {
    background: var(--secondary);
    color: black;
    box-shadow: 0 0 10px rgba(255, 145, 0, 0.4);
}

/* Waypoints */
.waypoint-item {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    margin-bottom: 0.4rem;
    /* Reduced from 0.8rem */
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.waypoint-item .input-group {
    flex: 1;
    margin-bottom: 0;
}

.remove-waypoint-btn {
    background: rgba(255, 68, 68, 0.1);
    color: #ff4444;
    border: 1px solid rgba(255, 68, 68, 0.3);
    border-radius: 4px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    margin-bottom: 0px;
}

.remove-waypoint-btn:hover {
    background: #ff4444;
    color: white;
}

.input-group,
.input-wrapper {
    margin-bottom: 0.4rem;
    /* Reduced from 0.8rem */
    position: relative;
    /* For autocomplete suggestions */
}

/* Preference Toggle */
.preference-row {
    margin-bottom: 0.4rem;
    /* Reduced from 0.6rem */
    display: flex;
    justify-content: center;
    /* Center buttons */
    align-items: center;
    gap: 0.8rem;
}

.preference-row label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0;
}

.toggle-group {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.toggle-btn {
    cursor: pointer;
    position: relative;
}

.toggle-btn input {
    display: none;
}

.toggle-btn span {
    display: block;
    padding: 4px 12px;
    font-size: 0.75rem;
    border-radius: 4px;
    transition: all 0.2s;
    color: var(--text-muted);
}

.toggle-btn input:checked+span {
    background: var(--primary);
    color: black;
    font-weight: 600;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 0.2rem;
    /* Reduced from 0.4rem */
}

/* Row Highlighting */
.route-item.highlight {
    background: rgba(0, 229, 255, 0.15) !important;
    border-left: 3px solid var(--primary);
}

.route-item.highlight .route-index {
    color: var(--primary);
    font-weight: bold;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}