/**
 * Theme CSS - Light and Dark Mode Support
 * Uses CSS Custom Properties for centralized theme management
 */

/* ========================================
   LIGHT THEME (Default)
   ======================================== */
:root {
    /* Backgrounds */
    --color-bg: #f5f5f5;
    --color-bg-secondary: #ffffff;
    --color-bg-tertiary: #fafafa;

    /* Text */
    --color-text: #333;
    --color-text-secondary: #666;
    --color-text-muted: #999;

    /* Borders */
    --color-border: #e0e0e0;
    --color-border-light: #f0f0f0;

    /* Primary (Blue) */
    --color-primary: #1976d2;
    --color-primary-hover: #1565c0;
    --color-primary-light: #e3f2fd;

    /* Canvas */
    --canvas-bg: #fafafa;
    --canvas-border: #e0e0e0;

    /* Status Colors */
    --color-success: #4caf50;
    --color-warning: #ff9800;
    --color-error: #f44336;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12);
    --shadow-md: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* ========================================
   DARK THEME
   ======================================== */
[data-theme="dark"] {
    /* Backgrounds */
    --color-bg: #121212;
    --color-bg-secondary: #1e1e1e;
    --color-bg-tertiary: #2a2a2a;

    /* Text - Improved contrast */
    --color-text: #f0f0f0;
    --color-text-secondary: #b8b8b8;
    --color-text-muted: #888888;

    /* Borders - More visible */
    --color-border: #3a3a3a;
    --color-border-light: #2a2a2a;

    /* Primary (Lighter blue for dark mode) */
    --color-primary: #42a5f5;
    --color-primary-hover: #64b5f6;
    --color-primary-light: #1e3a5f;

    /* Canvas */
    --canvas-bg: #1a1a1a;
    --canvas-border: #3a3a3a;

    /* Status Colors (brighter for better visibility) */
    --color-success: #81c784;
    --color-success-bg: rgba(129, 199, 132, 0.15);
    --color-warning: #ffb74d;
    --color-error: #e57373;
    --color-error-bg: rgba(229, 115, 115, 0.15);

    /* Shadows (more pronounced in dark mode) */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 10px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.6);
}

/* ========================================
   SMOOTH TRANSITIONS
   ======================================== */
* {
    transition: background-color 0.3s ease,
                color 0.3s ease,
                border-color 0.3s ease;
}

/* Disable transitions on page load to prevent flash */
.no-transitions,
.no-transitions * {
    transition: none !important;
}

/* ========================================
   THEME TOGGLE BUTTON STYLES
   ======================================== */
.theme-toggle-btn {
    padding: 8px 12px;
    background: var(--color-bg-tertiary);
    border: 2px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 44px;
    min-height: 44px;
}

.theme-toggle-btn:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
    transform: scale(1.05);
}

/* Theme icon span styles - ensure exact sizing */
.theme-icon-light,
.theme-icon-dark {
    font-size: 20px !important;
    line-height: 1;
    display: inline-block;
    width: 20px;
    height: 20px;
    text-align: center;
}

/* Show/hide theme icons based on current theme */
[data-theme="light"] .theme-icon-light {
    display: inline-block;
}

[data-theme="light"] .theme-icon-dark {
    display: none;
}

[data-theme="dark"] .theme-icon-light {
    display: none;
}

[data-theme="dark"] .theme-icon-dark {
    display: inline-block;
}

/* ========================================
   MODAL STYLES
   ======================================== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9998;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-width: 450px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
    position: relative;
}

.modal-header {
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Form Styles */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-error {
    margin-top: 8px;
    font-size: 13px;
    color: var(--color-error);
}

.form-help {
    margin-top: 6px;
    font-size: 12px;
    color: var(--color-text-secondary);
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.form-link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 14px;
}

.form-link:hover {
    text-decoration: underline;
}

.form-divider {
    text-align: center;
    margin: 20px 0;
    position: relative;
    color: var(--color-text-secondary);
    font-size: 14px;
}

.form-divider::before,
.form-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 45%;
    height: 1px;
    background: var(--color-border);
}

.form-divider::before {
    left: 0;
}

.form-divider::after {
    right: 0;
}

/* ========================================
   AUTO-SAVE STATUS INDICATOR
   ======================================== */
.save-status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 12px;
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    transition: all 0.3s ease;
}

.save-status-indicator svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
}

.save-status-indicator.saved {
    color: var(--color-success);
    background: var(--color-success-bg, rgba(76, 175, 80, 0.1));
    border-color: var(--color-success);
}

.save-status-indicator.saving {
    color: var(--color-primary);
    background: var(--color-primary-light);
    border-color: var(--color-primary);
}

.save-status-indicator.offline {
    color: var(--color-error);
    background: var(--color-error-bg, rgba(244, 67, 54, 0.1));
    border-color: var(--color-error);
}

/* Spinning animation for saving state */
.save-status-indicator.saving svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   CONNECTION STATUS BANNER
   ======================================== */
.connection-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--color-warning);
    color: white;
    padding: 12px 20px;
    z-index: 10000;
    box-shadow: var(--shadow-md);
    animation: slideDown 0.3s ease;
}

.connection-banner.error {
    background: var(--color-error);
}

.connection-banner.connecting {
    background: var(--color-primary);
}

.connection-banner-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.connection-banner-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.connection-banner-icon svg {
    width: 20px;
    height: 20px;
    stroke: white;
}

.connection-banner-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 14px;
    font-weight: 500;
}

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

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

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

/* Notification Container */
.notification-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column-reverse;
    gap: 12px;
    max-width: 420px;
    pointer-events: none;
}

/* Individual Notification */
.notification {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 320px;
    max-width: 420px;
    pointer-events: all;
    transform: translateX(450px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

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

.notification.hiding {
    transform: translateX(450px);
    opacity: 0;
}

/* Notification Icon */
.notification-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notification-icon svg {
    width: 20px;
    height: 20px;
}

/* Success */
.notification-success {
    border-left: 4px solid #10b981;
}

.notification-success .notification-icon {
    color: #10b981;
}

.notification-success .notification-progress {
    background: #10b981;
}

/* Error */
.notification-error {
    border-left: 4px solid #ef4444;
}

.notification-error .notification-icon {
    color: #ef4444;
}

.notification-error .notification-progress {
    background: #ef4444;
}

/* Warning */
.notification-warning {
    border-left: 4px solid #f59e0b;
}

.notification-warning .notification-icon {
    color: #f59e0b;
}

.notification-warning .notification-progress {
    background: #f59e0b;
}

/* Info */
.notification-info {
    border-left: 4px solid #3b82f6;
}

.notification-info .notification-icon {
    color: #3b82f6;
}

.notification-info .notification-progress {
    background: #3b82f6;
}

/* Notification Body */
.notification-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.notification-message {
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Notification Actions */
.notification-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.notification-action {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    padding: 4px 12px;
    transition: all 0.2s;
}

.notification-action:hover {
    background: var(--color-bg-tertiary);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.notification-action:active {
    transform: scale(0.96);
}

/* Close Button */
.notification-close {
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 2px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.notification-close:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
}

.notification-close svg {
    width: 16px;
    height: 16px;
}

/* Progress Bar */
.notification-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: var(--color-primary);
    transition: width 0.1s linear;
}

/* Responsive */
@media (max-width: 640px) {
    .notification-container {
        right: 10px;
        left: 10px;
        bottom: 10px;
        max-width: none;
    }

    .notification {
        min-width: auto;
        max-width: none;
    }
}

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

/* Empty State Overlay */
.empty-state-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-bg-primary);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
}

.empty-state-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.empty-state-container {
    max-width: 800px;
    width: 90%;
    text-align: center;
    padding: 40px 20px;
}

/* Welcome Message */
.empty-state-header {
    margin-bottom: 40px;
}

.empty-state-title {
    font-size: 32px;
    font-weight: 700;
    color: var(--color-text);
    margin: 0 0 12px 0;
}

.empty-state-subtitle {
    font-size: 16px;
    color: var(--color-text-muted);
    margin: 0;
}

/* Quick Action Buttons */
.empty-state-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 50px;
    flex-wrap: wrap;
}

.empty-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 16px 24px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
}

.empty-action-primary {
    background: var(--color-primary);
    color: white;
}

.empty-action-primary:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}

.empty-action-secondary {
    background: var(--color-bg-secondary);
    color: var(--color-text);
    border: 2px solid var(--color-border);
}

.empty-action-secondary:hover {
    background: var(--color-bg-tertiary);
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.empty-action-btn svg {
    width: 24px;
    height: 24px;
}

/* Template Suggestions */
.empty-state-templates {
    margin-bottom: 40px;
}

.templates-heading {
    font-size: 20px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 24px 0;
}

.template-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    max-width: 660px;
    margin: 0 auto;
}

.template-card {
    background: var(--color-bg-secondary);
    border: 2px solid var(--color-border);
    border-radius: 12px;
    padding: 16px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.template-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
    border-color: var(--color-primary);
}

.template-preview {
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--color-bg-tertiary);
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
}

.template-preview-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.template-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 12px 0;
}

.template-use-btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.template-use-btn:hover {
    background: var(--color-primary-hover);
}

/* Keyboard Shortcut Hint */
.empty-state-hint {
    font-size: 14px;
    color: var(--color-text-muted);
    margin: 0;
}

.empty-state-hint kbd {
    display: inline-block;
    padding: 2px 6px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* First-Time Tooltip */
.first-time-tooltip {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 350px;
    background: var(--color-bg-secondary);
    border: 2px solid var(--color-primary);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: all;
}

.first-time-tooltip.visible {
    opacity: 1;
}

.tooltip-content {
    position: relative;
}

.tooltip-content p {
    margin: 0;
    font-size: 14px;
    color: var(--color-text);
    line-height: 1.5;
}

.tooltip-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: all 0.2s ease;
}

.tooltip-close:hover {
    background: var(--color-danger);
    border-color: var(--color-danger);
}

.tooltip-close:hover svg {
    stroke: white;
}

.tooltip-arrow {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid var(--color-primary);
}

/* Responsive */
@media (max-width: 768px) {
    .empty-state-title {
        font-size: 24px;
    }

    .empty-state-subtitle {
        font-size: 14px;
    }

    .empty-state-actions {
        flex-direction: column;
        gap: 12px;
    }

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

    .template-cards {
        grid-template-columns: 1fr;
    }

    .first-time-tooltip {
        max-width: 280px;
        bottom: 80px;
    }
}
