@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;700&family=Outfit:wght@500;700;800&display=swap');

/* =========================================
   1. RESET & GLOBAL STYLES
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; outline: none; }
html { font-size: 16px; height: 100%; -webkit-text-size-adjust: 100%; }

body { 
    display: flex; flex-direction: column; height: 100vh; overflow: hidden; 
    color: var(--text-main); font-family: var(--font-ui); 
    background-color: var(--app-bg);
    transition: background-color 0.4s cubic-bezier(0.16, 1, 0.3, 1), color 0.4s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 4px; transition: background 0.2s; }
::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }

/* Utility Classes */
.hide-mobile { display: inline-block; }
@media (max-width: 768px) { .hide-mobile { display: none !important; } }

/* =========================================
   2. HEADER & NAVIGATION
   ========================================= */
.header {
    height: var(--header-height);
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--panel-border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.5rem; z-index: 100; position: relative;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.brand {
    height: 40px; width: 40px;
    background: linear-gradient(135deg, var(--brand-color), var(--brand-active));
    color: white; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    cursor: default; user-select: none;
    transition: background 0.3s ease;
}

.controls { display: flex; gap: 0.75rem; align-items: center; }

.icon-btn {
    height: 40px; min-width: 40px; padding: 0 12px;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: var(--panel-bg); color: var(--text-body);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    font-size: 1rem; position: relative; overflow: hidden;
}
.icon-btn:hover { background: var(--slate-100); color: var(--text-main); transform: translateY(-1px); border-color: var(--slate-300); }
.icon-btn:active { transform: translateY(0); background: var(--slate-200); }

.icon-btn.primary { background: var(--brand-color); color: white; border-color: transparent; }
.icon-btn.primary:hover { background: var(--brand-hover); box-shadow: 0 4px 12px rgba(0,0,0,0.15); transform: translateY(-1px); }
.icon-btn.primary:active { transform: translateY(0); box-shadow: none; }

/* Mobile View Switcher */
.view-switch {
    display: none; background-color: var(--input-bg);
    padding: 4px; border-radius: 20px; border: 1px solid var(--panel-border);
    align-items: center; gap: 2px;
}
.v-btn {
    width: 44px; height: 32px; border-radius: 16px;
    color: var(--text-mute); display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.3s ease;
}
.v-btn.active { background-color: var(--panel-bg); color: var(--brand-color); box-shadow: var(--shadow-sm); }

/* =========================================
   3. WORKSPACE LAYOUT
   ========================================= */
.workspace { 
    display: flex; flex: 1; height: calc(100vh - var(--header-height)); 
    overflow: hidden; position: relative; 
}

/* =========================================
   4. SIDEBAR EDITOR
   ========================================= */
.editor {
    width: var(--sidebar-width); min-width: 320px;
    background-color: var(--panel-bg); border-right: 1px solid var(--panel-border);
    display: flex; flex-direction: column; overflow-y: auto;
    padding: 1.5rem; gap: 1.5rem; z-index: 50;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.3s ease;
}

/* Card Component */
.card {
    background-color: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px; padding: 1.75rem 1.25rem 1.25rem;
    position: relative; transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}
.card:hover { border-color: var(--slate-400); box-shadow: var(--shadow-md); transform: translateY(-2px); }

.card-head {
    position: absolute; top: -10px; left: 16px;
    background-color: var(--panel-bg); padding: 0 8px;
    color: var(--brand-color); font-size: 0.7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em;
    display: flex; align-items: center; gap: 6px;
    border-radius: 99px; white-space: nowrap;
    transition: color 0.3s ease;
}

/* Grid Options (Theme Grid) */
.grid-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.opt-card {
    background: var(--input-bg); border: 1px solid var(--panel-border);
    border-radius: 10px; padding: 10px; cursor: pointer; text-align: center;
    transition: all 0.2s ease; position: relative; overflow: hidden;
}
.opt-card:hover { border-color: var(--brand-color); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.opt-card.active { 
    border-color: var(--brand-color); 
    background: var(--primary-50); 
    box-shadow: 0 0 0 1px var(--brand-color); 
}
[data-mode="dark"] .opt-card.active { background: rgba(var(--brand-color), 0.1); }

.preview-box {
    height: 32px; border-radius: 6px; border: 1px solid var(--panel-border);
    background: var(--panel-bg); display: flex; align-items: center; justify-content: center;
    margin-bottom: 8px; pointer-events: none; font-size: 10px; color: var(--text-mute); font-weight: 600;
    transition: border-color 0.2s;
}
.opt-card:hover .preview-box { border-color: var(--slate-300); }
.label { font-size: 11px; font-weight: 600; color: var(--text-body); display: block; transition: color 0.2s; }
.opt-card.active .label { color: var(--brand-color); }

/* Toggle Switch */
.toggle-switch { display: flex; background: var(--input-bg); padding: 4px; border-radius: 10px; border: 1px solid var(--panel-border); }
.t-btn { 
    flex: 1; border: none; background: transparent; padding: 8px; 
    font-size: 13px; font-weight: 500; cursor: pointer; 
    color: var(--text-mute); border-radius: 7px; transition: all 0.2s ease;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.t-btn:hover { color: var(--text-body); background: rgba(0,0,0,0.03); }
.t-btn.active { background: var(--panel-bg); color: var(--brand-color); box-shadow: var(--shadow-sm); font-weight: 600; }

/* Color Swatches */
.color-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; padding: 4px 0; }
.c-swatch {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--c); border: 2px solid var(--panel-bg);
    box-shadow: 0 0 0 1px var(--panel-border);
    cursor: pointer; transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}
.c-swatch:hover { transform: scale(1.15); box-shadow: 0 0 0 1px var(--slate-400); }
.c-swatch.active { transform: scale(1.2); box-shadow: 0 0 0 2px var(--brand-color); z-index: 2; }

/* =========================================
   5. PREVIEW AREA (CANVAS)
   ========================================= */
.preview {
    flex: 1; background-color: var(--slate-100);
    display: flex; align-items: center; justify-content: center;
    position: relative; overflow: hidden;
    padding: 2rem;
    perspective: 1000px;
    /* Subtle Dot Pattern */
    background-image: radial-gradient(var(--slate-300) 1px, transparent 1px);
    background-size: 24px 24px;
    transition: background-color 0.4s ease;
}

/* Background Layer for Themes */
#app-bg {
    position: absolute; inset: 0; z-index: 0;
    pointer-events: none; transition: background 0.6s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Login Card Container */
.login-card {
    width: 100%; max-width: 420px; padding: 3rem;
    background: var(--panel-bg); border-radius: var(--radius);
    position: relative; z-index: 10;
    box-shadow: var(--shadow-xl);
    will-change: transform, opacity;
    border: 1px solid transparent; /* Prepare for theme borders */
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Base Card Styles */
.card-header { text-align: center; margin-bottom: 2rem; }
.app-logo {
    width: 56px; height: 56px;
    background: var(--brand-color); color: white;
    border-radius: 16px; margin: 0 auto 1.5rem;
    display: flex; align-items: center; justify-content: center; font-size: 1.75rem;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.15), 0 8px 10px -6px rgba(0,0,0,0.1);
    transition: background-color 0.3s ease, transform 0.3s ease;
}
.card-header h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--text-main); letter-spacing: -0.02em; }
.card-header p { color: var(--text-body); font-size: 0.95rem; line-height: 1.5; }

/* Inputs */
.field { margin-bottom: 1.5rem; position: relative; }
.field label { 
    display: block; font-size: 0.85rem; margin-bottom: 0.5rem; 
    font-weight: 600; color: var(--text-main); letter-spacing: 0.01em;
}
.input-wrap { position: relative; }
input {
    width: 100%; padding: 0.875rem 1rem;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    color: var(--text-main); font-family: var(--font-ui);
    font-size: 1rem; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
input:hover { border-color: var(--slate-400); }
input:focus {
    outline: none; background-color: var(--panel-bg);
    border-color: var(--brand-color);
    box-shadow: 0 0 0 4px var(--input-focus-ring);
}
input::placeholder { color: var(--text-mute); }

.toggle-pass {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    background: none; border: none; font-size: 0.75rem; font-weight: 600;
    color: var(--text-mute); cursor: pointer; padding: 4px 8px; border-radius: 4px;
    transition: color 0.2s, background-color 0.2s;
}
.toggle-pass:hover { color: var(--brand-color); background-color: var(--slate-100); }

/* Validation States */
.field.error input { border-color: var(--c-error); background-color: rgba(239, 68, 68, 0.05); }
.field.error input:focus { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15); }
.error-msg { 
    font-size: 0.75rem; color: var(--c-error); margin-top: 0.5rem; 
    display: none; font-weight: 500; animation: slideDown 0.2s ease-out;
}
.field.error .error-msg { display: block; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* Actions */
.actions { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; margin-bottom: 2rem; }
.check-wrap { display: flex; align-items: center; gap: 8px; color: var(--text-body); cursor: pointer; user-select: none; }
.check-wrap input[type="checkbox"] { width: 1rem; height: 1rem; border-radius: 4px; border: 1px solid var(--input-border); accent-color: var(--brand-color); cursor: pointer; }
.actions a { color: var(--brand-color); text-decoration: none; font-weight: 600; transition: color 0.2s; }
.actions a:hover { color: var(--brand-hover); text-decoration: underline; }

/* Button */
.btn-main {
    width: 100%; padding: 1rem;
    background: var(--brand-color); color: white;
    border: none; border-radius: 8px;
    font-weight: 600; font-size: 1rem; cursor: pointer;
    position: relative; overflow: hidden;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}
.btn-main:hover { background: var(--brand-hover); transform: translateY(-1px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05); }
.btn-main:active { transform: translateY(0); box-shadow: none; }
.btn-main:disabled { opacity: 0.7; cursor: not-allowed; transform: none; }

/* Loader */
.loader {
    width: 20px; height: 20px; margin: 0 auto;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff; border-radius: 50%;
    animation: spin 0.8s linear infinite; display: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Ripple Effect */
.ripple {
    position: absolute; border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    transform: scale(0); animation: ripple 0.6s linear;
    pointer-events: none;
}
@keyframes ripple { to { transform: scale(4); opacity: 0; } }

/* =========================================
   6. TOAST NOTIFICATIONS
   ========================================= */
#toast-container { 
    position: fixed; bottom: 30px; right: 30px; z-index: 9999; 
    display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
    background: var(--panel-bg); color: var(--text-main);
    padding: 12px 20px; border-radius: 10px;
    font-size: 0.9rem; font-weight: 500;
    border: 1px solid var(--panel-border);
    box-shadow: 0 10px 30px -5px rgba(0,0,0,0.15), 0 4px 6px -2px rgba(0,0,0,0.05);
    display: flex; align-items: center; gap: 10px; pointer-events: auto;
    animation: slideInToast 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.toast::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-color); flex-shrink: 0; }
@keyframes slideInToast { 
    from { transform: translateY(20px) scale(0.9); opacity: 0; } 
    to { transform: translateY(0) scale(1); opacity: 1; } 
}

/* =========================================
   7. RESPONSIVE DESIGN (MOBILE)
   ========================================= */
@media (max-width: 1024px) {
    .view-switch { display: flex; }
    
    .workspace { flex-direction: column; height: auto; overflow: visible; }
    
    .editor { 
        width: 100%; height: auto; min-width: 0;
        border-right: none; border-bottom: 1px solid var(--panel-border); 
        padding: 1rem;
    }
    
    .preview { 
        min-height: 80vh; padding: 1.5rem; 
        background-size: 20px 20px;
    }
    
    /* View State Classes (Managed by JS) */
    body.mode-edit .preview { display: none; }
    body.mode-preview .editor { display: none; }
    
    .card { padding: 1.25rem 1rem 1rem; }
    .login-card { padding: 2rem; max-width: 100%; }
    .app-logo { width: 48px; height: 48px; font-size: 1.5rem; margin-bottom: 1rem; }
    .card-header h1 { font-size: 1.5rem; }
    
    #toast-container { bottom: 20px; right: 20px; left: 20px; align-items: center; }
    .toast { width: 100%; justify-content: center; }
}


