/* ========================================
   GLOBAL STYLES & CSS VARIABLES
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: #f6f9fc;
    color: #1a2c3e;
    transition: background 0.25s ease, color 0.2s ease;
    line-height: 1.5;
}

/* Dark mode variables - FIXED for all elements */
body.dark {
    background: #0b1120;
    color: #e2e8f0;
}

/* Dark mode card backgrounds - ensures visibility */
body.dark .search-card,
body.dark .profile-card,
body.dark .repo-card,
body.dark .lang-section,
body.dark .history-section {
    background: #111827;
    border-color: #1f2a3e;
    color: #e2e8f0;
}

/* Dark mode form elements */
body.dark input,
body.dark select,
body.dark button {
    background: #1f2a3e;
    border-color: #334155;
    color: #f1f5f9;
}

body.dark input::placeholder {
    color: #94a3b8;
}

/* Dark mode language bar background */
body.dark .language-bar-bg {
    background: #1e293b;
}

/* Dark mode stats background */
body.dark .stat {
    background: #1f2a3e;
    color: #cbd5e1;
}

/* Dark mode repo card links */
body.dark .repo-card a {
    color: #84dcc6;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
}

/* ========================================
   HEADER SECTION
   ======================================== */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

h1 {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, #0f2b3d, #1e6f5c);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

body.dark h1 {
    background: linear-gradient(135deg, #84dcc6, #a5f0e0);
    -webkit-background-clip: text;
    background-clip: text;
}

.dark-toggle {
    background: none;
    border: none;
    font-size: 1.6rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: 0.2s;
    color: #1e6f5c;
}

body.dark .dark-toggle {
    color: #facc15;
}

.dark-toggle:hover {
    transform: scale(1.1);
}

/* ========================================
   SEARCH CARD
   ======================================== */

.search-card {
    background: white;
    border-radius: 28px;
    padding: 1.5rem 2rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.03);
    transition: all 0.2s;
    border: 1px solid #e2edf2;
}

.search-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.input-wrapper {
    flex: 3;
    min-width: 200px;
}

.token-wrapper {
    flex: 2;
    min-width: 220px;
}

label {
    font-weight: 500;
    font-size: 0.8rem;
    margin-bottom: 0.3rem;
    display: block;
    color: #2c5f6e;
}

body.dark label {
    color: #94a3b8;
}

input,
select {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 60px;
    border: 1px solid #cbd5e1;
    background: white;
    font-size: 0.95rem;
    transition: 0.2s;
}

input:focus,
select:focus {
    outline: none;
    border-color: #1e6f5c;
    box-shadow: 0 0 0 3px rgba(30, 111, 92, 0.1);
}

button {
    background: #1e6f5c;
    border: none;
    padding: 0 1.6rem;
    border-radius: 60px;
    font-weight: 600;
    color: white;
    cursor: pointer;
    font-size: 1rem;
    height: 48px;
    transition: 0.2s;
}

button:hover {
    background: #0f4e41;
    transform: scale(0.98);
}

.rate-info {
    margin-top: 0.8rem;
    font-size: 0.7rem;
    color: #4b6b7a;
}

/* ========================================
   SEARCH HISTORY SECTION
   ======================================== */

.history-section {
    background: white;
    border-radius: 20px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid #e2edf2;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.clear-history-btn {
    background: #ef4444;
    padding: 0.3rem 1rem;
    height: auto;
    font-size: 0.75rem;
}

.clear-history-btn:hover {
    background: #dc2626;
}

.history-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.history-item {
    background: #eef2ff;
    padding: 0.4rem 1rem;
    border-radius: 40px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

body.dark .history-item {
    background: #1f2a3e;
    color: #e2e8f0;
}

.history-item:hover {
    background: #1e6f5c;
    color: white;
    transform: translateY(-2px);
}

.history-item i {
    font-size: 0.7rem;
}

/* ========================================
   LOADER
   ======================================== */

.loader {
    text-align: center;
    padding: 3rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid #1e6f5c;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   PROFILE CARD
   ======================================== */

.profile-card {
    background: white;
    border-radius: 32px;
    padding: 1.8rem;
    margin-bottom: 2rem;
    border: 1px solid #e2edf2;
    display: flex;
    flex-wrap: wrap;
    gap: 1.8rem;
    align-items: center;
}

.avatar img {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid #1e6f5c;
}

.profile-info {
    flex: 1;
}

.profile-info h2 {
    font-size: 1.9rem;
    margin-bottom: 0.3rem;
}

.bio {
    margin: 0.6rem 0;
    opacity: 0.85;
}

.stats-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem;
    margin-top: 1rem;
}

.stat {
    background: #f0f7fa;
    padding: 0.3rem 1rem;
    border-radius: 40px;
    font-weight: 500;
    font-size: 0.85rem;
}

.profile-link {
    margin-top: 1rem;
    display: inline-block;
}

.profile-link a {
    color: #1e6f5c;
    font-weight: 600;
    text-decoration: none;
}

.profile-link a:hover {
    text-decoration: underline;
}

/* ========================================
   REPOSITORY CONTROLS
   ======================================== */

.repo-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    align-items: center;
}

.filter-sort {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.filter-sort input,
.filter-sort select {
    width: auto;
    min-width: 180px;
}

.clear-btn {
    background: #475569;
    padding: 0 1rem;
    height: 44px;
}

/* ========================================
   REPOSITORY GRID
   ======================================== */

.repos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    margin: 1.8rem 0;
}

.repo-card {
    background: white;
    border-radius: 20px;
    padding: 1.2rem;
    transition: transform 0.15s ease, box-shadow 0.2s;
    border: 1px solid #e9edf2;
}

.repo-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
}

.repo-name {
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.repo-name a {
    text-decoration: none;
    color: inherit;
}

.repo-name a:hover {
    color: #1e6f5c;
}

.repo-desc {
    font-size: 0.85rem;
    margin: 0.6rem 0;
    opacity: 0.8;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.repo-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.75rem;
    margin-top: 0.7rem;
}

.lang-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
}

/* ========================================
   LANGUAGE SECTION
   ======================================== */

.lang-section {
    background: white;
    border-radius: 28px;
    padding: 1.5rem;
    margin-top: 1rem;
    border: 1px solid #e2edf2;
}

.lang-section h3 {
    margin-bottom: 1rem;
}

.lang-bars {
    margin-top: 1rem;
}

.lang-item {
    margin-bottom: 1rem;
}

.lang-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
}

.language-bar-bg {
    height: 8px;
    background: #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
}

.language-fill {
    height: 100%;
    width: 0%;
    border-radius: 10px;
    transition: width 0.5s ease;
}

/* ========================================
   ERROR MESSAGE
   ======================================== */

.error-message {
    background: #fee2e2;
    color: #b91c1c;
    padding: 1rem;
    border-radius: 24px;
    text-align: center;
}

body.dark .error-message {
    background: #7f1d1d;
    color: #fecaca;
}

/* ========================================
   FOOTER
   ======================================== */

.footer {
    text-align: center;
    margin-top: 2.5rem;
    font-size: 0.75rem;
    opacity: 0.7;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .profile-card {
        flex-direction: column;
        text-align: center;
    }

    .stats-grid {
        justify-content: center;
    }

    .repo-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-sort {
        flex-direction: column;
    }

    .filter-sort input,
    .filter-sort select {
        width: 100%;
    }

    h1 {
        font-size: 1.4rem;
    }
}

@media (max-width: 480px) {
    .avatar img {
        width: 90px;
        height: 90px;
    }

    .profile-info h2 {
        font-size: 1.4rem;
    }

    .repos-grid {
        grid-template-columns: 1fr;
    }
}