:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --input-bg: #020617;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f1f5f9;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --input-bg: #f8fafc;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    /* App-like feel */
    height: 100vh;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar (Reused Styles) */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    z-index: 10;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 2rem;
    color: var(--text-main);
}

.logo-area i {
    color: var(--primary-color);
    font-size: 1.5rem;
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
    text-decoration: none;
}

.nav-item:hover {
    background-color: var(--bg-color);
    color: var(--text-main);
}

.nav-item.active {
    background-color: var(--primary-color);
    color: white;
}

.nav-separator {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 0;
}

/* Toggle Switch */
.theme-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    transition: .4s;
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 4px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-muted);
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider:before {
    transform: translateX(24px);
    background-color: var(--primary-color);
}

.sun-icon,
.moon-icon {
    font-size: 14px;
    color: var(--text-muted);
}

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.theme-toggle-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Main Content area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.top-bar {
    height: 70px;
    border-bottom: 1px solid var(--border-color);
    background: var(--sidebar-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
}

.page-title h1 {
    font-size: 1.25rem;
    margin-bottom: 0.2rem;
}

.page-title p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.actions {
    display: flex;
    gap: 1rem;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-full {
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--input-bg);
}

.btn-full {
    width: 100%;
    margin-top: 1rem;
    background: var(--primary-color);
    /* Default to primary for full btns */
    color: white;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.hidden {
    display: none !important;
}

/* Workspace Layout */
.workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Controls Panel (Left) */
.controls-panel {
    width: 340px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 1rem 0.5rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-main);
    background: var(--input-bg);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.panel-content {
    display: none;
    padding: 1.5rem;
    flex-direction: column;
    gap: 1.5rem;
}

.panel-content.active {
    display: flex;
}

.panel-content h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

/* Form Groups */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.form-group input[type="text"],
.form-group select {
    padding: 0.6rem;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.9rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.separator {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 0;
}

/* Color Picker */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    padding: 0.4rem;
    border-radius: 6px;
}

.color-picker-wrapper input[type="color"] {
    border: none;
    width: 30px;
    height: 30px;
    cursor: pointer;
    background: transparent;
    padding: 0;
}

.color-val {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-family: monospace;
}

/* Templates Grid */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    max-height: 480px;
    overflow-y: auto;
    padding-right: 5px;
    /* space for scrollbar */
}

/* Custom Scrollbar for Templates Grid */
.templates-grid::-webkit-scrollbar {
    width: 6px;
}

.templates-grid::-webkit-scrollbar-track {
    background: transparent;
}

.templates-grid::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 10px;
}

.templates-grid::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-color);
}

.template-card {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    /* Aspect ratio is handled by the image container now */
}

.template-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.template-preview {
    width: 100%;
    aspect-ratio: 1.75;
    /* 3.5 / 2 */
    background: #e2e8f0;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.template-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s;
}

.template-card:hover .template-preview img {
    transform: scale(1.05);
}

.template-info {
    padding: 0.8rem;
    border-top: 1px solid var(--border-color);
    background: var(--input-bg);
}

.template-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    background: var(--input-bg);
    transition: all 0.2s;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
}

.upload-area i {
    font-size: 2rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.box-check {
    flex-direction: row;
    align-items: center;
}

/* Canvas Area (Right) */
.canvas-area {
    flex: 1;
    background: #e2e8f0;
    /* Neutral grey for contrast */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 2rem;
    overflow: hidden;
    /* Prevent scrollbars here, we scale to fit */
    height: 100vh;
    /* Full height of view */
    max-height: 100vh;
}

[data-theme="dark"] .canvas-area {
    background: #0f172a;
    /* Keep dark in dark mode, but maybe lighter than panel */
    background-image: radial-gradient(#1e293b 1px, transparent 1px);
    background-size: 20px 20px;
}

.side-toggles {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    z-index: 20;
    /* Ensure above canvas */
}

.side-btn {
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}

.side-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.canvas-wrapper-outer {
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    border-radius: 0;
    /* Business cards are sharp. */
    overflow: visible;
    background: white;
    /* Fallback */
    transition: transform 0.1s ease-out;
    /* Smooth scale updates */
}

.canvas-container-wrapper {
    /* Fabric JS container needs to be wrapped for centering if needed */
    position: relative;
}

.zoom-controls {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-family: monospace;
    background: var(--sidebar-bg);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--sidebar-bg);
    width: 400px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 0;
    overflow: hidden;
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.1rem;
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.modal-body {
    padding: 1.5rem;
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    margin-bottom: 1.5rem;
}

.option-group label {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.nav-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    background: var(--input-bg);
    padding: 0.5rem;
    border-radius: 4px;
}

/* Responsive adjustments */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .sidebar {
        display: none;
        /* Hide sidebar on mobile for now or use toggle */
    }

    .workspace {
        flex-direction: column;
        overflow-y: visible;
        height: auto;
    }

    .controls-panel {
        width: 100%;
        height: auto;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .canvas-area {
        height: 50vh;
        min-height: 300px;
        padding: 1rem;
    }
}

/* --- Global Styles (continuation) --- */

.upload-area {
    cursor: pointer;
    background: var(--input-bg);
    transition: all 0.2s;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
}

.upload-area i {
    font-size: 2rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.box-check {
    flex-direction: row;
    align-items: center;
}

/* Canvas Area (Right) */
.canvas-area {
    flex: 1;
    background: #e2e8f0;
    /* Neutral grey for contrast */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 2rem;
    overflow: hidden;
    /* Prevent scrollbars here, we scale to fit */
    height: 100vh;
    /* Full height of view */
    max-height: 100vh;
}

[data-theme="dark"] .canvas-area {
    background: #0f172a;
    /* Keep dark in dark mode */
    background-image: radial-gradient(#1e293b 1px, transparent 1px);
    background-size: 20px 20px;
}

.side-toggles {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    z-index: 20;
    /* Ensure above canvas */
}

.side-btn {
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}

.side-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.canvas-wrapper-outer {
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    border-radius: 0;
    /* Business cards are sharp. */
    overflow: visible;
    background: white;
    /* Fallback */
    transition: transform 0.1s ease-out;
    /* Smooth scale updates */
}

.canvas-container-wrapper {
    /* Fabric JS container needs to be wrapped for centering if needed */
    position: relative;
}

.zoom-controls {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-family: monospace;
    background: var(--sidebar-bg);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--sidebar-bg);
    width: 400px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 0;
    overflow: hidden;
}

/* Interactive Toolbar */
.canvas-toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    justify-content: center;
    background: var(--bg-color);
    padding: 0.75rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    z-index: 50;
    /* Ensure on top */
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: var(--border-color);
    transform: translateY(-1px);
}

.tool-btn:active {
    transform: translateY(0);
}

.tool-btn.danger {
    color: #ef4444;
    border-color: #fca5a5;
    background: #fef2f2;
}

.tool-btn.danger:hover {
    background: #fee2e2;
    border-color: #f87171;
}

.tool-btn i {
    font-size: 1.2rem;
}

[data-theme="dark"] .canvas-area {
    background: #0f172a;
    /* Keep dark in dark mode, but maybe lighter than panel */
    background-image: radial-gradient(#1e293b 1px, transparent 1px);
    background-size: 20px 20px;
}

.side-toggles {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    z-index: 20;
    /* Ensure above canvas */
}

.side-btn {
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}

.side-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.canvas-wrapper-outer {
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    border-radius: 0;
    /* Business cards are sharp. */
    overflow: visible;
    background: white;
    /* Fallback */
    transition: transform 0.1s ease-out;
    /* Smooth scale updates */
}

.canvas-container-wrapper {
    /* Fabric JS container needs to be wrapped for centering if needed */
    position: relative;
}

.zoom-controls {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-family: monospace;
    background: var(--sidebar-bg);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--sidebar-bg);
    width: 400px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 0;
    overflow: hidden;
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.1rem;
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.modal-body {
    padding: 1.5rem;
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    margin-bottom: 1.5rem;
}

.option-group label {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.nav-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    background: var(--input-bg);
    padding: 0.5rem;
    border-radius: 4px;
}

/* Responsive adjustments */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .sidebar {
        display: none;
        /* Hide sidebar on mobile for now or use toggle */
    }

    .workspace {
        flex-direction: column;
        overflow-y: visible;
        height: auto;
    }

    .controls-panel {
        width: 100%;
        height: auto;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .canvas-area {
        height: 50vh;
        /* Split screen on mobile */
        min-height: 300px;
        padding: 1rem;
    }
}

/* Canvas Toolbar */
.canvas-toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    justify-content: center;
    background: var(--bg-color);
    padding: 0.75rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: var(--border-color);
    transform: translateY(-1px);
}

.tool-btn:active {
    transform: translateY(0);
}

.tool-btn.danger {
    color: #ef4444;
    border-color: #fca5a5;
    background: #fef2f2;
}

.tool-btn.danger:hover {
    background: #fee2e2;
    border-color: #f87171;
}

.tool-btn i {
    font-size: 1.2rem;
}/ *   T e x t   T a b   S t y l e s   ( C a n v a - l i k e )   * /  
 . t e x t - p r e s e t s   {  
         d i s p l a y :   f l e x ;  
         f l e x - d i r e c t i o n :   c o l u m n ;  
         g a p :   1 r e m ;  
         m a r g i n - t o p :   1 r e m ;  
 }  
  
 . t e x t - p r e s e t - b t n   {  
         w i d t h :   1 0 0 % ;  
         b a c k g r o u n d :   v a r ( - - i n p u t - b g ) ;  
         b o r d e r :   1 p x   s o l i d   v a r ( - - b o r d e r - c o l o r ) ;  
         b o r d e r - r a d i u s :   8 p x ;  
         p a d d i n g :   1 r e m ;  
         c u r s o r :   p o i n t e r ;  
         t e x t - a l i g n :   l e f t ;  
         t r a n s i t i o n :   a l l   0 . 2 s ;  
         c o l o r :   v a r ( - - t e x t - c o l o r ) ;  
 }  
  
 . t e x t - p r e s e t - b t n : h o v e r   {  
         b a c k g r o u n d :   v a r ( - - b o r d e r - c o l o r ) ;  
         b o r d e r - c o l o r :   v a r ( - - p r i m a r y - c o l o r ) ;  
         t r a n s f o r m :   t r a n s l a t e X ( 2 p x ) ;  
 }  
  
 . t e x t - p r e s e t - b t n . h e a d i n g   {  
         f o n t - s i z e :   1 . 5 r e m ;  
         f o n t - w e i g h t :   8 0 0 ;  
 }  
  
 . t e x t - p r e s e t - b t n . s u b h e a d i n g   {  
         f o n t - s i z e :   1 . 1 r e m ;  
         f o n t - w e i g h t :   6 0 0 ;  
 }  
  
 . t e x t - p r e s e t - b t n . b o d y   {  
         f o n t - s i z e :   0 . 9 r e m ;  
         f o n t - w e i g h t :   4 0 0 ;  
 }  
 