/* ===========================
   CSS VARIABLES & RESET
   =========================== */

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

:root {
    --primary: #8b5cf6;
    --primary-dark: #7c3aed;
    --secondary: #10b981;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);
    --accent: #8b5cf6;
    --navbar-bg: #ffffff;
    --gradient: linear-gradient(135deg, #8b5cf6 0%, #10b981 100%);
    --code-bg: #1e1e1e;
    --code-text: #d4d4d4;
    --a: #ff6b6b;
    --b: #4ecdc4;
    --overlap: #f7dc6f;
    --surface: #12121a;
    /*--navbar-height: 68px;*/
}

[data-theme="dark"] {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-card: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --border: #374151;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-lg: rgba(0, 0, 0, 0.5);
    --navbar-bg: #111827;
    --code-bg: #0f172a;
    --code-text: #cbd5e1;
    --surface: #1f2937;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    padding-top: var(--navbar-height);
}

/* ===========================
   HERO SECTION
   =========================== */

.hero {
    background: var(--gradient);
    padding: 4rem 2rem;
    text-align: center;
    color: white;
    position: relative;
    overflow: hidden;
    border-bottom: 2px solid var(--border);
    /*margin-top: calc(-1 * var(--navbar-height));*/
}

.hero-content {
    position: relative;
    z-index: 1;
    max-width: 800px;
    margin: 0 auto;
}

.hero-h1 {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.hero-para {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

.hero-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.hero-stats span {
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 20px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(10px);
}

[data-theme="dark"] .hero {
    background: linear-gradient(to right, #111827, #1f2937);
}

[data-theme="dark"] .hero-para {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

[data-theme="dark"] .hero-h1 {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

[data-theme="dark"] .hero-stats span {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    border: 1px solid #7c3aed;
}

/* ===========================
   LAYOUT WRAPPER
   =========================== */

.layout-wrapper {
    display: flex;
    min-height: calc(100vh - var(--navbar-height));
    position: relative;
}

/* ===========================
   SIDEBAR
   =========================== */

.sidebar {
    width: 260px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    overflow-y: auto;
    position: sticky;
    top: var(--navbar-height);
    height: calc(100vh - var(--navbar-height));
    flex-shrink: 0;
    box-shadow: 2px 0 10px var(--shadow);
    z-index: 5;
}

.sidebar-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 0 1.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#join-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.join-btn {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.85rem 1.5rem;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    color: var(--text-primary);
}

.join-btn:hover { 
    background: rgba(139, 92, 246, 0.05); 
    border-left-color: var(--primary);
}

.join-btn.active {
    background: rgba(139, 92, 246, 0.1);
    border-left-color: var(--primary);
}

.join-btn .mini-venn { 
    width: 36px; 
    height: 24px; 
    flex-shrink: 0; 
}

.join-btn .btn-text { 
    display: flex; 
    flex-direction: column; 
    gap: 0.15rem; 
}

.join-btn .btn-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.join-btn.active .btn-name { 
    color: var(--primary); 
}

.join-btn .btn-sub {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ===========================
   MAIN CONTENT
   =========================== */

.main-content {
    flex: 1;
    padding: 2rem;
    background: var(--bg-primary);
    min-width: 0; /* Prevent flex item from overflowing */
}

/* ===========================
   JOIN HEADER
   =========================== */

.join-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.join-title {
    font-size: clamp(1.5rem, 3vw, 2.2rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

.join-desc {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    max-width: 600px;
    margin-top: 0.5rem;
}

.sql-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    white-space: pre;
    line-height: 1.75;
    overflow-x: auto;
    max-width: 100%;
    box-shadow: 0 2px 8px var(--shadow);
}

.sql-badge .kw  { color: var(--primary); }
.sql-badge .tbl { color: var(--secondary); }
.sql-badge .jt  { color: var(--overlap); }

/* ===========================
   NOTES STRIP
   =========================== */

.notes-strip {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.note-chip {
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.note-chip i {
    color: var(--primary);
    font-size: 0.7rem;
}

/* ===========================
   VISUAL AREA
   =========================== */

.visual-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
    margin-bottom: 2rem;
}

.venn-card,
.tables-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: 0 4px 15px var(--shadow);
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.venn-card:hover,
.tables-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.venn-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

.venn-card h3,
.tables-card h3 {
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-secondary);
    align-self: flex-start;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.venn-card h3 i,
.tables-card h3 i {
    color: var(--primary);
}

svg.venn {
    width: 100%;
    max-width: 280px;
    height: auto;
    overflow: visible;
}

.venn-legend {
    display: flex;
    gap: 1.5rem;
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    flex-wrap: wrap;
    justify-content: center;
}

.legend-dot {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.legend-dot .dot {
    width: 10px; 
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* ===========================
   SAMPLE TABLES
   =========================== */

.input-tables {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    overflow-x: auto;
}

.tbl-label {
    font-size: 0.7rem;
    margin-bottom: 0.5rem;
    letter-spacing: 0.08em;
    font-family: 'JetBrains Mono', monospace;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tbl-a .tbl-label { color: var(--a); }
.tbl-b .tbl-label { color: var(--b); }

.tbl-a .tbl-label i,
.tbl-b .tbl-label i {
    font-size: 0.65rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
}

th {
    padding: 0.4rem 0.6rem;
    text-align: left;
    font-weight: 700;
    font-size: 0.65rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    white-space: nowrap;
}

.tbl-a th { color: var(--a); background: rgba(255,107,107,0.08); }
.tbl-b th { color: var(--b); background: rgba(78,205,196,0.08); }

td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid rgba(139, 92, 246, 0.1);
    color: var(--text-primary);
    white-space: nowrap;
}

/* ===========================
   RESULT AREA
   =========================== */

.result-area {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: 0 4px 15px var(--shadow);
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.result-area:hover {
    border-color: var(--primary);
}

.result-area h3 {
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.result-area h3 i {
    color: var(--primary);
}

.result-table-wrap { 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
}

#result-table {
    width: 100%;
    border-collapse: collapse;
}

#result-table th {
    color: var(--primary);
    background: rgba(139, 92, 246, 0.08);
    padding: 0.6rem 0.8rem;
    font-size: 0.7rem;
}

#result-table td {
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid var(--border);
}

.row-highlight {
    animation: rowIn 0.3s ease forwards;
    opacity: 0;
}

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

.null-cell { 
    color: var(--text-secondary); 
    font-style: italic; 
    opacity: 0.7;
}
.row-a     { background: rgba(255,107,107,0.04); }
.row-b     { background: rgba(78,205,196,0.04); }
.row-match { background: rgba(247,220,111,0.06); }

.count-badge {
    display: inline-block;
    background: rgba(139, 92, 246, 0.15);
    color: var(--primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin-left: 0.6rem;
    font-weight: normal;
}

/* ===========================
   NOTIFICATION
   =========================== */

.notification {
    position: fixed;
    top: calc(var(--navbar-height) + 20px);
    right: 20px;
    padding: 16px 24px;
    background: var(--gradient);
    color: white;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
    transform: translateX(400px);
    transition: transform 0.4s ease;
    z-index: 9999;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.notification.show {
    transform: translateX(0);
}

.notification.error {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.notification.success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.notification.warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

/* ===========================
   ANIMATIONS
   =========================== */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* ===========================
   RESPONSIVE DESIGN
   =========================== */

@media (max-width: 1024px) {
    .hero-h1 {
        font-size: 2.8rem;
    }

    .sidebar {
        width: 220px;
    }

    .join-btn {
        padding: 0.75rem 1.25rem;
    }

    .join-btn .btn-name {
        font-size: 0.85rem;
    }
}

@media (max-width: 820px) {
    .hero-h1 {
        font-size: 2.5rem;
    }

    .hero-para {
        font-size: 1.1rem;
    }

    .hero-stats {
        gap: 1.5rem;
    }

    .hero-stats span {
        padding: 6px 18px;
        font-size: 0.9rem;
    }

    .layout-wrapper {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        top: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 0.75rem 0.5rem;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        box-shadow: 0 2px 10px var(--shadow);
    }

    .sidebar-label { 
        display: none; 
    }

    #join-nav {
        display: flex;
        flex-direction: row;
        gap: 0.25rem;
        width: max-content;
        padding: 0 0.5rem;
    }

    .join-btn {
        flex-direction: column;
        align-items: center;
        text-align: center;
        width: auto;
        min-width: 100px;
        padding: 0.5rem 0.75rem;
        border-left: none;
        border-bottom: 2px solid transparent;
        border-radius: 8px;
        gap: 0.35rem;
    }

    .join-btn.active {
        border-left-color: transparent;
        border-bottom-color: var(--primary);
        background: rgba(139, 92, 246, 0.1);
    }

    .join-btn .btn-sub { 
        display: none; 
    }

    .join-btn .btn-name { 
        font-size: 0.75rem; 
    }

    .join-btn .mini-venn { 
        width: 30px; 
        height: 22px; 
    }

    .visual-area {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    svg.venn { 
        max-width: 240px; 
    }

    .main-content {
        padding: 1.5rem;
    }
}

@media (max-width: 768px) {
    .hero-h1 {
        font-size: 2rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .hero-para {
        font-size: 1rem;
    }

    .hero-stats {
        gap: 1rem;
    }

    .hero-stats span {
        padding: 6px 15px;
        font-size: 0.9rem;
    }

    .join-header {
        flex-direction: column;
        gap: 0.75rem;
    }

    .join-title {
        font-size: 1.5rem;
    }

    .join-desc {
        font-size: 0.9rem;
    }

    .sql-badge {
        font-size: 0.7rem;
        padding: 0.6rem 0.75rem;
        width: 100%;
    }

    .venn-card { 
        padding: 1rem; 
    }

    .tables-card { 
        padding: 1rem; 
    }

    .input-tables { 
        grid-template-columns: 1fr; 
        gap: 1rem; 
    }

    .result-area { 
        padding: 1rem; 
    }

    table { 
        font-size: 0.65rem; 
    }

    td, th { 
        padding: 0.35rem 0.45rem; 
    }

    .venn-legend { 
        gap: 0.75rem; 
        font-size: 0.65rem; 
        flex-direction: column;
        align-items: flex-start;
    }

    .note-chip { 
        font-size: 0.65rem; 
    }

    .cookie-buttons {
        flex-direction: column;
    }

    .cookie-btn {
        width: 100%;
        justify-content: center;
    }

    .cookie-settings-buttons {
        flex-direction: column;
    }

    .cookie-settings-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .hero {
        padding: 3rem 1rem;
    }

    .hero-h1 {
        font-size: 1.8rem;
    }

    .hero-stats span {
        font-size: 0.8rem;
        padding: 5px 12px;
    }

    .main-content {
        padding: 1rem;
    }

    .join-btn {
        min-width: 85px;
        padding: 0.4rem 0.5rem;
    }
    
    .join-btn .btn-name { 
        font-size: 0.65rem; 
    }

    .join-btn .mini-venn { 
        width: 26px; 
        height: 20px; 
    }

    .notification {
        left: 10px;
        right: 10px;
        width: calc(100% - 20px);
        transform: translateY(-100px);
        top: calc(var(--navbar-height) + 10px);
    }

    .notification.show {
        transform: translateY(0);
    }
}

@media (max-width: 380px) {
    .join-btn { 
        min-width: 75px; 
        padding: 0.35rem 0.4rem; 
    }
    .join-btn .btn-name { 
        font-size: 0.6rem; 
    }
    .join-btn .mini-venn { 
        width: 24px; 
        height: 18px; 
    }
}