/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== DARK THEME (default) ===== */
:root {
    --bg: #0a0a0f;
    --bg-card: #13131a;
    --bg-card-hover: #1a1a24;
    --border: #23232f;
    --border-hover: #35354a;
    --text: #e8e8ed;
    --text-muted: #8888a0;
    --text-dim: #55556a;
    --accent: #c026d3;
    --accent-light: #d946ef;
    --accent-glow: rgba(192, 38, 211, 0.15);
    --gradient-instagram: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
    --header-bg: rgba(10, 10, 15, 0.85);
    --footer-bg: rgba(10, 10, 15, 0.9);
    --card-shadow: rgba(0, 0, 0, 0.4);
    --comment-bg: rgba(192, 38, 211, 0.03);
    --copy-bg: rgba(192, 38, 211, 0.12);
    --copy-border: rgba(192, 38, 211, 0.25);
    --toast-bg: #1e1e2a;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
    --bg: #f5f5f7;
    --bg-card: #ffffff;
    --bg-card-hover: #fafafa;
    --border: #e2e2ea;
    --border-hover: #c8c8d4;
    --text: #1a1a2e;
    --text-muted: #6b6b80;
    --text-dim: #9898ab;
    --accent: #a020b0;
    --accent-light: #c026d3;
    --accent-glow: rgba(160, 32, 176, 0.12);
    --header-bg: rgba(245, 245, 247, 0.88);
    --footer-bg: rgba(245, 245, 247, 0.92);
    --card-shadow: rgba(0, 0, 0, 0.08);
    --comment-bg: rgba(160, 32, 176, 0.04);
    --copy-bg: rgba(160, 32, 176, 0.08);
    --copy-border: rgba(160, 32, 176, 0.2);
    --toast-bg: #ffffff;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ===== HEADER ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--header-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header-content {
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    color: var(--accent-light);
    flex-shrink: 0;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: var(--gradient-instagram);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.stats {
    display: flex;
    gap: 24px;
}

/* ===== THEME TOGGLE ===== */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    transition: all var(--transition);
}

.theme-toggle:hover {
    border-color: var(--border-hover);
}

.theme-toggle svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: color var(--transition);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    display: none;
}

/* Dark mode: show sun icon (to switch to light) */
:root .theme-toggle .icon-sun {
    display: block;
}

/* Light mode: show moon icon (to switch to dark) */
[data-theme="light"] .theme-toggle .icon-moon {
    display: block;
}
[data-theme="light"] .theme-toggle .icon-sun {
    display: none;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-number {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== MAIN ===== */
.main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px 24px 120px;
}

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.search-box {
    flex: 1;
    position: relative;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-dim);
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

.search-box input::placeholder {
    color: var(--text-dim);
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ===== TIME FILTER ===== */
.filter-group {
    display: flex;
    gap: 0;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.btn-filter {
    padding: 10px 14px;
    background: var(--bg-card);
    border: none;
    border-right: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-filter:last-child {
    border-right: none;
}

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

.btn-filter.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.btn-sort {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-sort svg {
    width: 16px;
    height: 16px;
    transition: transform var(--transition);
}

.btn-sort:hover {
    border-color: var(--border-hover);
    color: var(--text);
}

.btn-sort.asc svg {
    transform: rotate(180deg);
}

/* ===== GRID ===== */
.grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    align-items: stretch;
}

/* ===== CARD ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.card:hover {
    border-color: var(--border-hover);
    transform: translateY(-3px);
    box-shadow: 0 8px 30px var(--card-shadow);
}

.card-link {
    cursor: pointer;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-thumb {
    aspect-ratio: 1;
    width: 100%;
    background: var(--border);
    position: relative;
    overflow: hidden;
}

.card-thumb img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}

.card-type-right {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 7px;
    border-radius: 5px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.card-type-right.reel {
    background: rgba(239, 68, 68, 0.7);
    color: #fff;
}

.card-type-right.post {
    background: rgba(59, 130, 246, 0.7);
    color: #fff;
}

.card-type-right.story {
    background: rgba(234, 179, 8, 0.7);
    color: #fff;
}

.card-type-right.default {
    background: rgba(192, 38, 211, 0.7);
    color: #fff;
}

.card-avatar {
    position: absolute;
    bottom: 8px;
    left: 8px;
    z-index: 1;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
    overflow: hidden;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.card-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-avatar-initial {
    font-size: 0.6rem;
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
    line-height: 1;
}

.card-likes-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    z-index: 1;
}

.card-likes {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 3px 8px;
    border-radius: 5px;
}

.card-likes svg {
    color: #ef4444;
}

.card-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
}

.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-owner {
    font-size: 0.68rem;
    color: var(--text-dim);
}

.card-date {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ===== CARD COMMENT SECTION ===== */
.card-comment {
    padding: 8px 10px 10px;
    border-top: 1px solid var(--border);
    background: var(--comment-bg);
}

.card-comment-header {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.58rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 5px;
}

.card-comment-header svg {
    color: var(--accent-light);
    flex-shrink: 0;
}

.card-comment-text {
    font-size: 0.65rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin-bottom: 6px;
    word-break: break-word;
}

.btn-copy {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--copy-bg);
    border: 1px solid var(--copy-border);
    border-radius: 6px;
    color: var(--accent-light);
    font-size: 0.6rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    width: 100%;
    justify-content: center;
}

.btn-copy:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.btn-copy.copied {
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.4);
    color: #22c55e;
}

/* ===== LOADING ===== */
.loading {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 60px 0;
    color: var(--text-muted);
}

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

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

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 60px 0;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* ===== FOOTER / OPEN ALL ===== */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 24px;
    background: var(--footer-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    z-index: 100;
}

.btn-open-all {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 32px;
    background: var(--gradient-instagram);
    border: none;
    border-radius: var(--radius);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 4px 20px rgba(192, 38, 211, 0.3);
}

.btn-open-all:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(192, 38, 211, 0.4);
}

.btn-open-all:active {
    transform: translateY(0);
}

.btn-open-all svg {
    width: 20px;
    height: 20px;
}

.btn-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* ===== POPUP TOAST ===== */
.popup-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--toast-bg);
    border: 1px solid #f59e0b;
    color: #d97706;
    padding: 12px 20px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    z-index: 200;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    transition: transform 0.3s ease;
    max-width: 90vw;
}

.popup-toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ===== ANIMATIONS ===== */
.card {
    animation: fadeInUp 0.3s ease both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* stagger cards */
.card:nth-child(1) { animation-delay: 0.02s; }
.card:nth-child(2) { animation-delay: 0.04s; }
.card:nth-child(3) { animation-delay: 0.06s; }
.card:nth-child(4) { animation-delay: 0.08s; }
.card:nth-child(5) { animation-delay: 0.10s; }
.card:nth-child(6) { animation-delay: 0.12s; }
.card:nth-child(7) { animation-delay: 0.14s; }
.card:nth-child(8) { animation-delay: 0.16s; }
.card:nth-child(9) { animation-delay: 0.18s; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1400px) {
    .grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1000px) {
    .grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    .logo {
        justify-content: center;
    }

    .header-right {
        justify-content: center;
        flex-wrap: wrap;
    }

    .stats {
        justify-content: center;
    }

    .toolbar {
        flex-direction: column;
    }

    .toolbar > * {
        width: 100%;
    }

    .filter-group {
        order: -1;
    }

    .btn-filter {
        flex: 1;
        text-align: center;
        padding: 10px 8px;
    }

    .btn-sort {
        align-self: flex-end;
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

@media (max-width: 480px) {
    .main {
        padding: 16px 16px 120px;
    }

    .header-content {
        padding: 12px 16px;
    }

    .btn-open-all {
        padding: 12px 24px;
        font-size: 0.9rem;
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .card-title {
        font-size: 0.72rem;
    }

    .card-body {
        padding: 8px;
    }

    .card-comment {
        padding: 6px 8px 8px;
    }

    .card-comment-text {
        font-size: 0.6rem;
    }
}
