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

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

:root {
    /* SQLism Theme Colors - Light Mode */
    --primary: #8b5cf6;
    --primary-dark: #7c3aed;
    --secondary: #10b981;
    --accent: #8b5cf6;
    --accent2: #7c3aed;
    --accent3: #10b981;
    --warn: #f59e0b;
    --danger: #ef4444;
    
    /* Light Theme */
    --bg: #ffffff;
    --bg2: #f8fafc;
    --bg3: #f1f5f9;
    --bg4: #e2e8f0;
    --border: #cbd5e1;
    --border2: #94a3b8;
    --text: #0f172a;
    --text2: #334155;
    --text3: #64748b;
    
    /* Syntax Highlighting - Light */
    --keyword: #8b5cf6;
    --string: #10b981;
    --number: #f59e0b;
    --func: #3b82f6;
    
    --radius: 10px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
    --gradient: linear-gradient(135deg, #8b5cf6 0%, #10b981 100%);
}

[data-theme="dark"] {
    /* Dark Theme */
    --bg: #0f172a;
    --bg2: #1e293b;
    --bg3: #334155;
    --bg4: #475569;
    --border: #334155;
    --border2: #475569;
    --text: #f8fafc;
    --text2: #cbd5e1;
    --text3: #94a3b8;
    
    /* Syntax Highlighting - Dark */
    --keyword: #c084fc;
    --string: #4ade80;
    --number: #fbbf24;
    --func: #60a5fa;
}

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

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

.hero {
    background: var(--gradient);
    padding: 4rem 2rem;
    text-align: center;
    color: white;
    position: relative;
    overflow: hidden;
    border-bottom: 2px solid var(--border);
}

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

.hero-h1 {
    font-family: 'Inter', sans-serif;
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: white;
}

.hero-para {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.9;
    font-family: 'Inter', sans-serif;
    color: white;
}

.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);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    color: white;
}

[data-theme="dark"] .hero {
    background: var(--gradient);
}

[data-theme="dark"] .hero-para,
[data-theme="dark"] .hero-h1,
[data-theme="dark"] .hero-stats span {
    color: white;
}

/* ===========================
   MAIN CONTAINER
   =========================== */

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 3rem 2rem;
    position: relative;
    z-index: 1;
}

/* ===========================
   WORKSPACE LAYOUT
   =========================== */

.workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    margin-bottom: 30px;
}

@media (max-width: 968px) {
    .workspace {
        grid-template-columns: 1fr;
    }
}

/* ===========================
   PANELS
   =========================== */

.panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.panel:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
}

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

.panel-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text2);
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-body {
    padding: 20px;
}

/* ===========================
   TABS
   =========================== */

.tabs {
    display: flex;
    gap: 4px;
    background: var(--bg4);
    border-radius: 9px;
    padding: 3px;
}

.tab {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text3);
    background: transparent;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tab.active {
    background: var(--bg2);
    color: var(--primary);
}

.badge {
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 20px;
    font-family: 'Inter', sans-serif;
}

/* ===========================
   CONFIG GRID
   =========================== */

.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

@media (max-width: 500px) {
    .config-grid {
        grid-template-columns: 1fr;
    }
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-group.span2 {
    grid-column: span 2;
}

@media (max-width: 500px) {
    .field-group.span2 {
        grid-column: span 1;
    }
}

label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text2);
    letter-spacing: 0.03em;
    display: flex;
    align-items: center;
    gap: 6px;
}

input, select {
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 12px;
    width: 100%;
    transition: all 0.15s;
    outline: none;
}

input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

select {
    cursor: pointer;
}

select option {
    background: var(--bg3);
    color: var(--text);
}

/* ===========================
   TOGGLE GROUP
   =========================== */

.toggle-group {
    display: flex;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}

.toggle-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text2);
    background: transparent;
}

.toggle-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

/* ===========================
   CONDITIONS SECTION
   =========================== */

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

.conditions-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text2);
    letter-spacing: 0.03em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 20px;
}

.conditions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

/* ===========================
   CONDITION ROW
   =========================== */

.condition-row {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    animation: slideIn 0.2s ease;
    position: relative;
    transition: all 0.2s ease;
}

.condition-row:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.1);
}

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

.condition-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.condition-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 20px;
    background: var(--primary);
    color: white;
    letter-spacing: 0.03em;
}

.condition-controls {
    display: flex;
    gap: 6px;
}

.condition-fields {
    display: grid;
    grid-template-columns: 1fr auto 1fr 2fr;
    gap: 10px;
    align-items: center;
}

@media (max-width: 600px) {
    .condition-fields {
        grid-template-columns: 1fr 1fr;
    }
    .condition-fields .op-select {
        grid-column: span 2;
    }
    .condition-fields .result-input {
        grid-column: span 2;
    }
}

.op-select select {
    text-align: center;
    min-width: 100px;
}

.arrow-icon {
    color: var(--text3);
    display: flex;
    align-items: center;
}

/* ===========================
   ELSE SECTION
   =========================== */

.else-section {
    margin-top: 16px;
    padding: 14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 12px;
}

.else-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ===========================
   WRAP OPTIONS
   =========================== */

.wrap-options {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-wrapper input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

.checkbox-wrapper label {
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
}

/* ===========================
   OUTPUT AREA
   =========================== */

.output-area {
    position: relative;
}

.sql-output {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    min-height: 250px;
    white-space: pre;
    overflow-x: auto;
    tab-size: 4;
    color: var(--text);
}

.copy-float {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text2);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    opacity: 0.7;
}

.copy-float:hover {
    opacity: 1;
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
}

/* ===========================
   STATS BAR
   =========================== */

.stats-bar {
    display: flex;
    gap: 16px;
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--bg3);
    border-radius: 10px;
    flex-wrap: wrap;
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text2);
}

.stat-chip span {
    color: var(--primary);
    font-weight: 600;
}

/* ===========================
   BUTTONS
   =========================== */

.btn {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-primary {
    background: var(--gradient);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-ghost {
    background: var(--bg3);
    color: var(--text2);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.15);
}

.btn-success {
    background: var(--primary);
    color: white;
}

.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
    border-radius: 6px;
}

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

/* ===========================
   ACTION BUTTONS
   =========================== */

.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 30px;
}

.action-buttons button {
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-format {
    background: var(--gradient);
    color: white;
}

.btn-format:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.btn-copy {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-copy:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
}

.btn-download {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-download:hover {
    border-color: var(--secondary);
    color: var(--secondary);
    transform: translateY(-2px);
}

.btn-clear {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-clear:hover {
    border-color: var(--danger);
    color: var(--danger);
    transform: translateY(-2px);
}

.btn-share {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-share:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-2px);
}

/* ===========================
   HISTORY SECTION
   =========================== */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.history-item:hover {
    border-color: var(--primary);
    transform: translateX(4px);
}

.history-snippet {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.history-time {
    font-size: 0.75rem;
    color: var(--text3);
    white-space: nowrap;
}

/* ===========================
   EMPTY STATE
   =========================== */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text3);
}

.empty-state .icon {
    font-size: 2.5rem;
    margin-bottom: 15px;
    color: var(--border2);
}

.empty-state p {
    font-size: 0.9rem;
    line-height: 1.6;
}

/* ===========================
   DRAG AND DROP
   =========================== */

.drag-handle {
    cursor: grab;
    color: var(--text3);
    font-size: 1rem;
    padding: 0 4px;
}

.drag-handle:active {
    cursor: grabbing;
}

.condition-row.dragging {
    opacity: 0.4;
}

.condition-row.drag-over {
    border-color: var(--primary);
    background: rgba(139, 92, 246, 0.05);
}

/* ===========================
   MODAL
   =========================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: transform 0.2s;
}

.modal-overlay.open .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg3);
    position: sticky;
    top: 0;
    z-index: 1;
}

.modal-title {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text2);
    transition: all 0.15s;
}

.modal-close:hover {
    border-color: var(--danger);
    color: var(--danger);
    transform: rotate(90deg);
}

.modal-body {
    padding: 20px;
}

/* ===========================
   TEMPLATE GRID
   =========================== */

.template-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 500px) {
    .template-grid {
        grid-template-columns: 1fr;
    }
}

.template-card {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.15s;
}

.template-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.1);
}

.template-card h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 10px 0 4px;
    color: var(--text);
}

.template-card p {
    font-size: 0.8rem;
    color: var(--text2);
    line-height: 1.5;
}

.template-icon {
    font-size: 2rem;
}

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

.notification {
    position: fixed;
    top: 80px;
    right: 20px;
    padding: 12px 20px;
    background: var(--bg2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 2000;
    transform: translateX(400px);
    opacity: 0;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-lg);
}

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

.notification.success {
    border-color: var(--secondary);
    color: var(--secondary);
}

.notification.error {
    border-color: var(--danger);
    color: var(--danger);
}

.notification.warning {
    border-color: var(--warn);
    color: var(--warn);
}

/* ===========================
   SYNTAX HIGHLIGHTING
   =========================== */

.kw {
    color: var(--keyword);
    font-weight: 600;
}

.str {
    color: var(--string);
}

.num {
    color: var(--number);
}

.fn {
    color: var(--func);
}

.cm {
    color: var(--text3);
    font-style: italic;
}

.op {
    color: var(--warn);
}

.id {
    color: var(--primary);
}

/* ===========================
   SCROLLBAR
   =========================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* ===========================
   PANEL ACTIONS
   =========================== */

.panel-actions {
    display: flex;
    gap: 6px;
}

.panel-btn {
    padding: 6px 10px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text2);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.85rem;
}

.panel-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.panel-btn.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
}

.panel-btn.btn-primary:hover {
    background: var(--primary-dark);
}

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

@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;
    }

    .container {
        padding: 2rem 1rem;
    }

    .panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .tabs {
        width: 100%;
    }

    .tab {
        flex: 1;
        text-align: center;
    }

    .action-buttons {
        flex-direction: column;
        align-items: center;
    }

    .action-buttons button {
        width: 100%;
        max-width: 300px;
        justify-content: center;
    }
}

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

    .panel-body {
        padding: 16px;
    }

    .sql-output {
        min-height: 200px;
        padding: 12px;
        font-size: 0.8rem;
    }

    .condition-controls .btn-icon {
        width: 28px;
        height: 28px;
    }

    .stats-bar {
        flex-direction: column;
        gap: 8px;
    }

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

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