* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
}

h1 {
    text-align: center;
    margin-bottom: 10px;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    font-size: 36px;
}

.subtitle {
    text-align: center;
    color: #aaa;
    margin-bottom: 40px;
    font-size: 14px;
}

/* ===== SEARCH CONTAINER ===== */
.search-container {
    background: #0f3460;
    border: 2px solid #ffd700;
    border-radius: 10px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

.form-group {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 15px;
    align-items: flex-start;
}

.input-wrapper {
    display: flex;
    flex-direction: column;
}

label {
    font-size: 13px;
    color: #ffd700;
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

input,
select {
    padding: 12px 15px;
    border: 2px solid #ffd700;
    border-radius: 5px;
    background: #1a1a2e;
    color: #fff;
    font-size: 14px;
    transition: all 0.3s;
    font-family: inherit;
}

input::placeholder {
    color: #666;
}

input:focus,
select:focus {
    outline: none;
    background: #16213e;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.6);
    border-color: #ffed4e;
}

select {
    cursor: pointer;
    padding-right: 30px;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffd700' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px;
}

select:disabled {
    background-color: #0a1a2e;
    color: #666;
    cursor: not-allowed;
    opacity: 0.6;
}

button {
    padding: 12px 35px;
    background: #ffd700;
    color: #000;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
    align-self: flex-end;
}

button:hover:not(:disabled) {
    background: #ffed4e;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 215, 0, 0.4);
}

button:disabled {
    background: #999;
    cursor: not-allowed;
    opacity: 0.7;
}

/* ===== REALM INPUT WRAPPER ===== */
.realm-input-wrapper {
    position: relative;
}

.realm-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #0f3460;
    border: 2px solid #ffd700;
    border-top: none;
    border-radius: 0 0 5px 5px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

.realm-dropdown.show {
    display: block;
}

.realm-option {
    padding: 12px 15px;
    border-bottom: 1px solid #ffd70022;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
}

.realm-option:hover,
.realm-option.selected {
    background: #ffd700;
    color: #000;
    font-weight: bold;
}

.realm-option.region-header {
    background: #1a1a2e;
    color: #ffd700;
    font-weight: bold;
    font-size: 12px;
    text-transform: uppercase;
    padding: 8px 15px;
    cursor: default;
}

.realm-option.region-header:hover {
    background: #1a1a2e;
    color: #ffd700;
}

.realm-option.region-item {
    padding-left: 30px;
}

/* ===== CHARACTER DISPLAY ===== */
.character-display {
    background: #0f3460;
    border: 2px solid #ffd700;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.character-info {
    flex: 1;
}

.character-name {
    font-size: 28px;
    color: #ffd700;
    margin: 0 0 10px 0;
    font-weight: bold;
}

.character-details p {
    color: #aaa;
    font-size: 13px;
    margin: 3px 0;
}

.gear-button {
    padding: 12px 30px;
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    color: #000;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ===== GEAR SECTION ===== */
.gear-section {
    display: none;
}

.gear-section.active {
    display: block;
}

.filters-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.filters-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.filters-col .mplus-key-selector {
    background: #0f3460;
    border: 2px solid #ffd700;
    border-radius: 8px;
    padding: 12px 16px;
}

#instancePriorityPanel {
    min-height: 140px;
}

#instancePriorityPanel .instance-priority-card {
    margin-bottom: 0;
}

/* ===== SOURCE FILTER CONTAINER ===== */
.filter-container {
    background: #0f3460;
    border: 2px solid #ffd700;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

.filter-title {
    font-size: 16px;
    color: #ffd700;
    font-weight: bold;
    margin-bottom: 20px;
    text-transform: uppercase;
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

.filter-section {
    background: #1a1a2e;
    border: 1px solid #ffd70044;
    border-radius: 8px;
    padding: 15px;
}

.filter-section-title {
    font-size: 14px;
    color: #ffd700;
    font-weight: bold;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #ffd700;
}

.checkbox-item label {
    margin: 0;
    color: #bbb;
    cursor: pointer;
    font-size: 13px;
    user-select: none;
    flex: 1;
    font-weight: normal;
}

.checkbox-item input[type="checkbox"]:checked + label {
    color: #ffd700;
    font-weight: 500;
}

/* ===== STATS PRIORITY FILTER ===== */
.stats-filter-container {
    background: #0f3460;
    border: 2px solid #ffd700;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

.stats-section {
    background: #1a1a2e;
    border: 1px solid #ffd70044;
    border-radius: 8px;
    padding: 15px;
}

.stats-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 500px;
    overflow-y: auto;
}

.stats-actions {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

.mplus-key-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #ccc;
    width: 100%;
}

.mplus-key-selector label {
    white-space: nowrap;
    color: #aaa;
}

.mplus-key-selector select {
    background: #1a1a2e;
    color: #ffd700;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    flex: 1;
}

.search-stuff-btn {
    padding: 10px 14px;
    font-size: 12px;
    letter-spacing: 0.5px;
}

.stat-group-title {
    font-size: 12px;
    color: #ffed4e;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 6px;
    margin-bottom: 2px;
}

.stat-item {
    background: #0f3460;
    padding: 12px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid #ffd70044;
    user-select: none;
    transition: all 0.3s;
}

.stat-item:hover {
    background: #16213e;
    border-color: #ffd700;
}

.stat-priority {
    background: #ffd700;
    color: #000;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 12px;
    flex-shrink: 0;
}

.stat-name {
    flex: 1;
    font-weight: 500;
    color: #ffd700;
}

.stat-level-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.level-btn {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 1px solid #ffd70066;
    background: #1a1a2e;
    color: #ffd700;
    font-size: 12px;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

.level-btn:hover {
    background: #ffd70022;
    border-color: #ffd700;
    transform: none;
    box-shadow: none;
}

.stat-level-badge {
    min-width: 52px;
    text-align: center;
    font-size: 11px;
    color: #cfd8e3;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    padding: 3px 5px;
}

.stat-toggle {
    display: flex;
    gap: 8px;
    align-items: center;
}

.toggle-btn {
    padding: 4px 12px;
    background: #1a1a2e;
    color: #888;
    border: 1px solid #ffd70044;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s;
}

.toggle-btn.active {
    background: #ffd700;
    color: #000;
    border-color: #ffd700;
    font-weight: bold;
}

.toggle-btn:hover {
    border-color: #ffd700;
    color: #ffd700;
}

/* ===== GEAR DISPLAY ===== */
.gear-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 25px;
    margin-top: 30px;
}

.slot-card {
    background: #0f3460;
    border: 2px solid #ffd700;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    animation: slideIn 0.3s ease;
}

.slot-header {
    background: linear-gradient(135deg, #1a3a52 0%, #0f3460 100%);
    padding: 15px 20px;
    border-bottom: 2px solid #ffd700;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.min-key-badge {
    font-size: 11px;
    color: #fff;
    background: #1e5a8a;
    border: 1px solid #4a9fd4;
    border-radius: 4px;
    padding: 2px 8px;
    white-space: nowrap;
}

.min-key-badge.maxed {
    background: #1a4a2e;
    border-color: #4caf50;
}

/* ===== KEY RECOMMENDATION PANEL ===== */
.key-recommendation-panel {
    background: #0f2a40;
    border: 2px solid #4a9fd4;
    border-radius: 10px;
    padding: 16px 20px;
}

.rec-title {
    font-size: 15px;
    font-weight: bold;
    color: #4a9fd4;
    margin-bottom: 10px;
}

.rec-summary {
    font-size: 13px;
    color: #cde;
    margin-bottom: 12px;
}

.rec-maxed {
    font-size: 12px;
    color: #4caf50;
    margin-top: 8px;
}

.rec-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.rec-table th {
    background: #0d2035;
    color: #aac;
    padding: 5px 10px;
    text-align: left;
    border-bottom: 1px solid #1e4060;
}

.rec-table td {
    padding: 5px 10px;
    border-bottom: 1px solid #162a3a;
    color: #dde;
}

.rec-table tr:last-child td { border-bottom: none; }

.track-label {
    font-size: 10px;
    background: #1a4060;
    color: #8bc8f0;
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 4px;
}


.slot-name {
    font-size: 18px;
    color: #ffd700;
    font-weight: bold;
}

.results-table-wrapper {
    max-height: 460px;
    overflow: auto;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.results-table thead th {
    position: sticky;
    top: 0;
    background: #16213e;
    color: #ffd700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 11px;
    z-index: 1;
}

.results-table th,
.results-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #ffd70022;
    text-align: left;
    white-space: nowrap;
}

.results-table tbody tr:hover {
    background: #1a1a2e;
}

.results-table tbody td:nth-child(2) {
    white-space: normal;
    min-width: 180px;
    color: #fff;
    font-weight: 600;
}

.current-item-row {
    background: #0f2d50;
}

.current-item-row td {
    color: #9fc8ff;
    font-weight: 600;
}

.table-empty {
    text-align: center;
    color: #888;
    padding: 18px 10px;
}

.current-item {
    background: #1a1a2e;
    padding: 15px;
    border-bottom: 1px solid #ffd70044;
}

.current-item-title {
    font-size: 11px;
    color: #aaa;
    text-transform: uppercase;
    margin-bottom: 8px;
    font-weight: bold;
}

.current-item-name {
    font-size: 14px;
    color: #ffd700;
    font-weight: bold;
    margin-bottom: 4px;
}

.current-item-level {
    font-size: 12px;
    color: #888;
}

.upgrades-list {
    max-height: 600px;
    overflow-y: auto;
    padding: 0;
}

.upgrade-item {
    padding: 15px 20px;
    border-bottom: 1px solid #ffd70022;
    transition: all 0.3s;
    cursor: pointer;
    position: relative;
}

.upgrade-item:hover {
    background: #1a1a2e;
}

.upgrade-item:last-child {
    border-bottom: none;
}

.upgrade-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.upgrade-item-name {
    font-size: 13px;
    color: #fff;
    font-weight: bold;
}

.ilvl-badge {
    background: #ffd700;
    color: #000;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
}

.item-stats {
    background: #0f346044;
    padding: 8px;
    border-radius: 4px;
    font-size: 11px;
    color: #aaa;
    margin-bottom: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.stat-badge {
    background: #1a1a2e;
    padding: 2px 6px;
    border-radius: 2px;
    border-left: 2px solid #ffd700;
}

.upgrade-sources {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.source-item {
    background: #1a1a2e;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 11px;
    color: #bbb;
    border-left: 3px solid #ffd700;
}

.source-icon {
    display: inline-block;
    margin-right: 5px;
    font-size: 12px;
}

.source-type {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 2px;
    font-size: 10px;
    font-weight: bold;
    margin-left: 4px;
    text-transform: uppercase;
}

.type-raid { background: #a335ee; color: #fff; }
.type-dungeon { background: #0070dd; color: #fff; }

.diff-lfr { background: #1eff00; color: #000; }
.diff-nm { background: #0070dd; color: #fff; }
.diff-hm { background: #a335ee; color: #fff; }
.diff-mm { background: #ff8000; color: #000; }
.diff-heroic { background: #a335ee; color: #fff; }
.diff-m0 { background: #0070dd; color: #fff; }

.difficulty-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 2px;
    font-size: 10px;
    font-weight: bold;
    margin-left: 4px;
    text-transform: uppercase;
}

.no-upgrades {
    padding: 20px;
    text-align: center;
    color: #888;
    font-size: 12px;
}

.scrollbar-custom::-webkit-scrollbar {
    width: 8px;
}

.scrollbar-custom::-webkit-scrollbar-track {
    background: #1a1a2e;
}

.scrollbar-custom::-webkit-scrollbar-thumb {
    background: #ffd700;
    border-radius: 4px;
}

.scrollbar-custom::-webkit-scrollbar-thumb:hover {
    background: #ffed4e;
}

.error {
    background: linear-gradient(135deg, #8b0000 0%, #600000 100%);
    color: #fff;
    padding: 15px 20px;
    border-radius: 5px;
    margin-bottom: 20px;
    border-left: 4px solid #ff6b6b;
}

.score-badge {
    background: #ffd700;
    color: #000;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    margin-right: 8px;
}

.quality-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: bold;
    padding: 1px 5px;
    border-radius: 3px;
    border: 1px solid;
    vertical-align: middle;
    margin-right: 4px;
    opacity: 0.9;
}

.stats-cell {
    white-space: nowrap;
}

.source-cell {
    min-width: 180px;
    color: #9fc8ff;
    font-size: 12px;
    line-height: 1.3;
}

.instance-priority-card {
    margin-bottom: 20px;
    border: 1px solid #ffd70033;
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(22, 28, 45, 0.95) 0%, rgba(17, 22, 35, 0.95) 100%);
    overflow: hidden;
}

.instance-priority-header {
    padding: 12px 14px 4px;
    color: #ffd700;
    font-weight: 700;
}

.instance-priority-subtitle {
    padding: 0 14px 10px;
    color: #9aa3b2;
    font-size: 12px;
}

.instance-priority-table tbody td:nth-child(2) {
    color: #c8dcff;
}

.equipped-overview-card {
    grid-column: 1 / -1;
    margin-bottom: 4px;
    border: 1px solid #ffd70055;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(20, 36, 62, 0.96) 0%, rgba(12, 23, 40, 0.96) 100%);
    overflow: hidden;
}

.equipped-overview-header {
    padding: 12px 14px 4px;
    color: #ffd700;
    font-weight: 700;
    font-size: 15px;
}

.equipped-overview-subtitle {
    padding: 0 14px 10px;
    color: #9aa3b2;
    font-size: 12px;
}

.equipped-overview-table tbody td:nth-child(2) {
    color: #fff;
    font-weight: 600;
}

.stat-chip {
    display: inline-block;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 11px;
    margin-right: 4px;
    color: #bbb;
    letter-spacing: 0.02em;
}

.stat-chip strong {
    color: #ffd700;
    font-weight: 600;
}

.no-stats {
    color: #444;
}

.rank-cell {
    color: #888;
    font-size: 12px;
    text-align: center;
    width: 30px;
}

.ilvl-cell {
    color: #ffd700;
    font-weight: bold;
    text-align: center;
    white-space: nowrap;
}

.ilvl-max {
    color: #88cc88;
    font-size: 0.85em;
    font-weight: normal;
}

.max-ilvl {
    color: #4caf50;
    font-weight: bold;
}

.max-ilvl-unknown {
    color: #666;
    font-weight: normal;
    font-size: 0.85em;
}

.score-cell {
    text-align: center;
    white-space: nowrap;
}

.upgrade-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid transparent;
}

.upgrade-positive {
    color: #9dffb5;
    background: rgba(20, 90, 42, 0.35);
    border-color: rgba(60, 195, 102, 0.7);
}

.upgrade-negative {
    color: #ffb0b0;
    background: rgba(99, 30, 30, 0.35);
    border-color: rgba(210, 80, 80, 0.7);
}

.upgrade-neutral {
    color: #d6d6d6;
    background: rgba(74, 74, 74, 0.35);
    border-color: rgba(130, 130, 130, 0.7);
}

.item-name-cell {
    min-width: 160px;
}

.loading-spinner {
    text-align: center;
    padding: 40px 20px;
}

.spinner {
    border: 4px solid #333;
    border-top: 4px solid #ffd700;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
    .filters-wrapper {
        grid-template-columns: 1fr;
    }
    
    .form-group {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    .form-group {
        grid-template-columns: 1fr;
    }
    
    button {
        width: 100%;
    }
    
    .gear-container {
        grid-template-columns: 1fr;
    }
    
    .character-display {
        flex-direction: column;
        gap: 20px;
    }
    
    .filters-wrapper {
        grid-template-columns: 1fr;
    }
}