:root {
    --bg-color: #f8f9fa;
    --text-color: #1a1a1a;
    --card-bg: #ffffff;
    --card-border: rgba(0, 0, 0, 0.08);
    --accent: #2563eb;
    --accent-glow: rgba(37, 99, 235, 0.2);
    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 32px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.06);
    --font-main: 'Outfit', sans-serif;
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0f0f0f;
        --text-color: #ededed;
        --card-bg: #1a1a1a;
        --card-border: rgba(255, 255, 255, 0.1);
        --accent: #3b82f6;
        --accent-glow: rgba(59, 130, 246, 0.3);
        --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    transition: background-color 0.5s ease;
    overflow-x: hidden;
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

/* Custom BG Mode */
body.custom-bg::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
    backdrop-filter: blur(5px);
}

body.custom-bg {
    color: white;
    --text-color: white;
    --card-bg: rgba(255, 255, 255, 0.1);
    --card-border: rgba(255, 255, 255, 0.2);
}

.app-container {
    width: 100%;
    max-width: 900px;
    padding: 2rem 1rem;
    position: relative;
    z-index: 1;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.6s var(--transition) forwards;
}

/* COMPONENTS: BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    background: var(--text-color);
    color: var(--bg-color);
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    gap: 0.5rem;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    opacity: 0.9;
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--card-border);
}

.btn-danger {
    background: #ff4757;
    color: white;
}

/* Inverted Button (used for Primary Actions like Generate SQL) */
.btn-invert {
    /* Originally inverted relative to theme */
    background: var(--bg-color);
    color: var(--text-color);
    border: 2px solid var(--text-color);
    /* Add border to ensure visibility */
}

/* Custom BG Overrides */
body.custom-bg .btn {
    background: white;
    color: black;
}

/* In Custom BG, make invert button Distinct (Black) */
body.custom-bg .btn-invert {
    background: black;
    color: white;
    border-color: white;
}

.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-color);
    opacity: 0.8;
}

.input-field,
select.input-field {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-color);
    font-family: var(--font-main);
    font-size: 1rem;
    transition: var(--transition);
}

.input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

/* BENTO GRID */
.bento-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    grid-auto-flow: dense;
    padding-bottom: 2rem;
}

@media (min-width: 600px) {
    .bento-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.span-2 {
    grid-column: span 2;
}

.span-row-2 {
    grid-row: span 2;
}

/* Bento Card */
.bento-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 140px;
    color: var(--text-color);
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
    text-decoration: none;
}

.bento-card:hover {
    box-shadow: var(--shadow-sm);
}

.bento-card.editable {
    cursor: pointer;
}

.bento-card.editable:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

/* Spacer */
.bento-card.is-spacer {
    background: transparent;
    border: none;
    box-shadow: none !important;
    pointer-events: none;
}

.bento-card.editable.is-spacer {
    border: 2px dashed rgba(125, 125, 125, 0.2);
    pointer-events: auto;
    background: rgba(125, 125, 125, 0.05);
}

.bento-card.editable.is-spacer::after {
    content: 'Spacer';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8rem;
    opacity: 0.3;
}

/* Sortable */
.sortable-ghost {
    opacity: 0.4;
    background: var(--accent-glow);
    border: 2px dashed var(--accent);
}

.sortable-drag {
    cursor: grabbing;
}

/* Icon Size fix requested by user previously */
.bento-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: rgba(125, 125, 125, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    flex-shrink: 0;
}

.bento-card-inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.bento-content {
    flex: 1;
    min-width: 0;
}

.bento-title {
    font-weight: 600;
    margin-bottom: 0.2rem;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bento-desc {
    font-size: 0.85rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Card Backgrounds */
.bento-card.has-bg {
    border: none;
    background-size: cover;
    background-position: center;
}

.bento-card.has-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.1) 100%);
    z-index: 1;
}

.bento-card.has-bg .bento-card-inner {
    position: relative;
    z-index: 2;
    color: white;
}

.bento-card.has-bg .bento-icon {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    backdrop-filter: blur(4px);
}

.bento-card.has-bg .bento-desc {
    opacity: 0.9;
}

/* Small Card */
.bento-card.is-small {
    padding: 1rem;
    align-items: center;
    text-align: center;
}

.bento-card.is-small .bento-card-inner {
    flex-direction: column;
    justify-content: center;
    gap: 0.5rem;
}

.bento-card.is-small .bento-title {
    font-size: 0.8rem;
}

.bento-card.is-small .bento-desc {
    display: none;
}

/* Add Placeholder */
.add-card-placeholder {
    border: 2px dashed var(--card-border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 140px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-color);
    opacity: 0.6;
    grid-column: span 2;
}

.add-card-placeholder:hover {
    border-color: var(--accent);
    color: var(--accent);
    opacity: 1;
    background: var(--accent-glow);
}

.add-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: #1a1a1a;
    color: white;
    width: 90%;
    max-width: 500px;
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: white;
    opacity: 0.5;
}

.close-modal:hover {
    opacity: 1;
}

.modal .input-field {
    background: #333;
    border-color: #444;
    color: white;
}

/* Profile Header */
.profile-header {
    text-align: center;
    margin-bottom: 3rem;
    max-width: 600px;
    margin: 0 auto 3rem auto;
}

.avatar-container {
    position: relative;
    margin: 0 auto 1rem auto;
    border-radius: 50%;
    border: 4px solid var(--card-bg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    width: 120px;
    height: 120px;
    background: #e0e0e0;
}

.avatar-container.av-small {
    width: 80px;
    height: 80px;
}

.avatar-container.av-large {
    width: 180px;
    height: 180px;
}

.profile-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.avatar-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    opacity: 0;
    transition: opacity 0.2s;
    cursor: pointer;
}

.avatar-container.editable:hover .avatar-overlay {
    opacity: 1;
}

.avatar-container.editable:hover {
    border-color: var(--accent);
}

.profile-name {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
    border: 1px dashed transparent;
}

.profile-bio {
    opacity: 0.7;
    font-size: 1.1rem;
    line-height: 1.6;
    border: 1px dashed transparent;
}

.editable-text:hover {
    border-bottom-color: var(--card-border);
    cursor: text;
}

/* Utils */
.hidden {
    display: none !important;
}

.mt-4 {
    margin-top: 1rem;
}

.text-center {
    text-align: center;
}

.row-gap {
    gap: 1rem;
    display: flex;
}

.col {
    flex: 1;
}

.floating-actions {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    gap: 1rem;
    background: var(--card-bg);
    padding: 0.5rem;
    border-radius: 50px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--card-border);
}

.sql-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #1e1e1e;
    color: #00ff9d;
    padding: 2rem;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 200;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
}

.sql-drawer.active {
    transform: translateY(0);
}