/* ================================================================
   Pokopia Group Optimizer - Styles
   ================================================================ */

:root {
    --bg: #0f1923;
    --bg-card: #1a2736;
    --bg-card-hover: #1f3044;
    --bg-input: #152230;
    --border: #2a3f55;
    --border-light: #3a5570;
    --text: #e8edf2;
    --text-muted: #8899aa;
    --text-dim: #5a6b7c;
    --accent: #4fc3f7;
    --accent-hover: #29b6f6;
    --accent-dim: rgba(79, 195, 247, 0.15);
    --green: #66bb6a;
    --green-dim: rgba(102, 187, 106, 0.15);
    --red: #ef5350;
    --red-dim: rgba(239, 83, 80, 0.12);
    --orange: #ffa726;
    --orange-dim: rgba(255, 167, 38, 0.15);
    --purple: #ab47bc;
    --yellow: #ffee58;

    --habitat-bright: #ffee58;
    --habitat-warm: #ff7043;
    --habitat-humid: #26c6da;
    --habitat-dry: #d4a05a;
    --habitat-dark: #7e57c2;
    --habitat-cold: #90caf9;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
    --transition: 0.2s ease;

    --font: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px 60px;
}

/* ---- Header ---- */
.header {
    padding: 40px 0 20px;
    text-align: center;
}

.logo {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.logo-accent {
    background: linear-gradient(135deg, var(--accent), #81d4fa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    margin-top: 8px;
    font-size: 1.05rem;
}

/* ---- Search ---- */
.search-section {
    position: relative;
    z-index: 100;
    margin: 20px auto 30px;
    max-width: 600px;
}

.search-container {
    position: relative;
}

.search-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 16px;
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
}

#searchInput {
    width: 100%;
    padding: 14px 44px 14px 48px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 1.05rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

#searchInput:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

#searchInput::placeholder {
    color: var(--text-dim);
}

.clear-btn {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    display: none;
}

.clear-btn.visible {
    display: block;
}

.clear-btn:hover {
    color: var(--text);
    background: var(--bg-card-hover);
}

/* ---- Search Results Dropdown ---- */
.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 420px;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    z-index: 200;
}

.search-results.hidden {
    display: none;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid var(--border);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--bg-card-hover);
}

.search-result-item.already-selected {
    opacity: 0.4;
    pointer-events: none;
}

.search-result-sprite {
    width: 48px;
    height: 48px;
    object-fit: contain;
    image-rendering: pixelated;
    flex-shrink: 0;
}

.search-result-info {
    flex: 1;
    min-width: 0;
}

.search-result-name {
    font-weight: 700;
    font-size: 0.95rem;
}

.search-result-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: 10px;
    margin-top: 2px;
}

.search-result-add {
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.search-no-results {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
}

/* ---- Selected Section ---- */
.selected-section {
    margin-bottom: 30px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 14px;
    font-size: 0.85rem;
    font-weight: 700;
}

.section-actions {
    display: flex;
    gap: 10px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #29b6f6);
    color: #0a1929;
}

.btn-primary:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(79, 195, 247, 0.3);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:not(:disabled):hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

.btn-icon {
    font-size: 1.1rem;
}

/* ---- Selected Grid ---- */
.selected-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
}

.selected-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
    transition: all var(--transition);
    cursor: default;
}

.selected-card:hover {
    border-color: var(--border-light);
    background: var(--bg-card-hover);
}

.selected-card .remove-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: var(--red-dim);
    color: var(--red);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition);
}

.selected-card:hover .remove-btn {
    opacity: 1;
}

.selected-card .remove-btn:hover {
    background: var(--red);
    color: white;
}

.selected-sprite {
    width: 72px;
    height: 72px;
    object-fit: contain;
    image-rendering: pixelated;
    margin: 0 auto 6px;
    display: block;
}

.selected-name {
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.selected-habitat {
    font-size: 0.72rem;
    margin-top: 2px;
}

/* Habitat colors */
.habitat-bright { color: var(--habitat-bright); }
.habitat-warm { color: var(--habitat-warm); }
.habitat-humid { color: var(--habitat-humid); }
.habitat-dry { color: var(--habitat-dry); }
.habitat-dark { color: var(--habitat-dark); }
.habitat-cold { color: var(--habitat-cold); }

.habitat-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 700;
}

.habitat-tag-bright { background: rgba(255,238,88,0.15); color: var(--habitat-bright); }
.habitat-tag-warm { background: rgba(255,112,67,0.15); color: var(--habitat-warm); }
.habitat-tag-humid { background: rgba(38,198,218,0.15); color: var(--habitat-humid); }
.habitat-tag-dry { background: rgba(212,160,90,0.15); color: var(--habitat-dry); }
.habitat-tag-dark { background: rgba(126,87,194,0.15); color: var(--habitat-dark); }
.habitat-tag-cold { background: rgba(144,202,249,0.15); color: var(--habitat-cold); }

/* ---- Results ---- */
.results-section {
    margin-top: 20px;
}

.results-section.hidden {
    display: none;
}

.results-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.group-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
}

.group-rank {
    font-size: 1.2rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
}

.group-rank .rank-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), #81d4fa);
    color: #0a1929;
    border-radius: 50%;
    font-size: 0.95rem;
}

.group-meta {
    display: flex;
    gap: 16px;
    align-items: center;
}

.group-meta-item {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.group-body {
    padding: 20px 24px;
}

.group-pokemon-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.group-poke-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 12px;
    text-align: center;
}

.group-poke-sprite {
    width: 80px;
    height: 80px;
    object-fit: contain;
    image-rendering: pixelated;
    margin: 0 auto 8px;
    display: block;
}

.group-poke-name {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.group-poke-match {
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.match-good { color: var(--green); }
.match-great { color: var(--accent); }
.match-bad { color: var(--red); }

.fav-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
}

.fav-tag {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.fav-matched {
    background: var(--green-dim);
    color: var(--green);
}

.fav-unmatched {
    background: rgba(255,255,255,0.05);
    color: var(--text-dim);
}

.fav-food {
    background: var(--orange-dim);
    color: var(--orange);
}

/* ---- Items Section ---- */
.items-section {
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.items-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.item-cat-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
}

.item-cat-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--accent);
    margin-bottom: 6px;
}

.item-list {
    list-style: none;
}

.item-list li {
    padding: 3px 0;
    font-size: 0.82rem;
    color: var(--text-muted);
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.item-list li::before {
    content: "•";
    color: var(--text-dim);
    flex-shrink: 0;
}

.food-section {
    margin-top: 16px;
}

.food-cat-card {
    border-left: 3px solid var(--orange) !important;
}

.food-cat-card .item-cat-name {
    color: var(--orange) !important;
}

/* ---- Loading ---- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 25, 35, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .logo { font-size: 1.6rem; }
    .subtitle { font-size: 0.9rem; }
    .group-pokemon-row { grid-template-columns: repeat(2, 1fr); }
    .section-header { flex-direction: column; align-items: flex-start; }
    .selected-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
    .items-grid { grid-template-columns: 1fr; }
    .comfort-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .app { padding: 0 12px 40px; }
    .group-body { padding: 16px; }
    .group-header { padding: 12px 16px; }
}

/* ---- Item sprites ---- */
.item-sprite {
    width: 28px;
    height: 28px;
    object-fit: contain;
    vertical-align: middle;
    margin-right: 6px;
    border-radius: 4px;
    background: var(--bg-input);
    flex-shrink: 0;
}

.item-list li {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.item-name {
    flex: 1 1 auto;
    min-width: 0;
}

/* ---- Effect badges ---- */
.effect-badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
    font-weight: 600;
    vertical-align: middle;
    white-space: nowrap;
}

.effect-toy        { background: rgba(171, 71, 188, 0.2); color: #ce93d8; }
.effect-decoration { background: rgba(255, 167, 38, 0.2); color: #ffb74d; }
.effect-relaxation { background: rgba(79, 195, 247, 0.2); color: #4fc3f7; }
.effect-food       { background: rgba(102, 187, 106, 0.2); color: #81c784; }
.effect-road       { background: rgba(158, 158, 158, 0.2); color: #bdbdbd; }

/* ---- Multi-need tag ---- */
.multi-need-tag {
    display: inline-block;
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 8px;
    background: rgba(255, 238, 88, 0.2);
    color: #ffee58;
    margin-left: 4px;
    font-weight: 700;
    white-space: nowrap;
}

/* ---- Comfort section ---- */
.comfort-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.comfort-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    margin-top: 8px;
}

.comfort-card {
    background: var(--bg-input);
    border-radius: 10px;
    padding: 12px 14px;
    border-left: 3px solid transparent;
}

.comfort-toy        { border-left-color: #ce93d8; }
.comfort-decoration { border-left-color: #ffb74d; }
.comfort-relaxation { border-left-color: #4fc3f7; }

.comfort-title {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 6px;
}

.served-cats {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 4px;
}
