/* ==========================================================================
   CSS Variables & Theme Definitions
   ========================================================================== */
:root {
    /* Color Palette */
    --primary: #4e73df;
    --primary-light: #a6b7f1;
    --primary-dark: #2c56d1;
    --primary-alpha-10: rgba(78, 115, 223, 0.1);
    --primary-alpha-20: rgba(78, 115, 223, 0.2);
    --primary-alpha-25: rgba(78, 115, 223, 0.25);
    --primary-alpha-05: rgba(78, 115, 223, 0.05);
    
    --secondary: #1cc88a;
    --secondary-dark: #17a673;
    
    --accent: #f6c23e;
    
    /* Neutral Colors */
    --dark: #2a3f54;
    --light: #f8f9fc;
    --gray: #858796;
    --light-gray: #d1d3e2;
    
    /* Status Colors */
    --success: #1cc88a;
    --danger: #e74a3b;
    --warning: #f6c23e;
    --info: #36b9cc;
    
    /* UI Properties */
    --border: 1px solid #e3e6f0;
    --border-radius: 0.35rem;
    --border-radius-sm: 0.25rem;
    --border-radius-lg: 0.5rem;
    
    /* Shadows */
    --shadow-sm: 0 0.15rem 0.5rem rgba(0, 0, 0, 0.1);
    --shadow-md: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.2);
    --shadow-inset: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition-fast: all 0.15s ease;
    --transition-base: all 0.3s ease;
    --transition-slow: all 0.5s ease;
    
    /* Typography */
    --font-family-base: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-family-heading: 'Poppins', 'Roboto', -apple-system, sans-serif;
    --font-family-mono: 'Roboto Mono', 'Courier New', monospace;
    
    /* Layout */
    --header-height: 4rem;
    --container-max-width: 1200px;
    --sidebar-width: 250px;
    
    /* Z-index Layers */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-tooltip: 1070;
    --z-toast: 1080;
}

/* Dark Theme */
[data-theme="dark"] {
    --primary: #4e73df;
    --primary-light: #3a56a5;
    --primary-dark: #2c56d1;
    --primary-alpha-10: rgba(78, 115, 223, 0.1);
    --primary-alpha-20: rgba(78, 115, 223, 0.2);
    --primary-alpha-25: rgba(78, 115, 223, 0.25);
    
    --dark: #e4e6eb;
    --light: #242526;
    --gray: #b0b3b8;
    --light-gray: #3a3b3c;
    
    --border: 1px solid #3e4042;
    --shadow-sm: 0 0.15rem 0.5rem rgba(0, 0, 0, 0.3);
    --shadow-md: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.5);
}

/* High Contrast Theme */
[data-theme="high-contrast"] {
    --primary: #0056b3;
    --primary-light: #007bff;
    --primary-dark: #003d82;
    --dark: #ffffff;
    --light: #000000;
    --gray: #cccccc;
    --light-gray: #333333;
    --border: 2px solid #ffffff;
}

/* ==========================================================================
   Base Styles & Reset
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family-base);
    background-color: var(--light);
    color: var(--dark);
    line-height: 1.6;
    margin: 0;
    padding: 1rem;
    cursor: default;
    transition: background-color var(--transition-base), color var(--transition-base);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(78, 115, 223, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(28, 200, 138, 0.05) 0%, transparent 50%);
    z-index: -1;
    pointer-events: none;
}

/* Selection Styles */
::selection {
    background-color: var(--primary-alpha-20);
    color: var(--dark);
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--light);
    border-radius: var(--border-radius);
}

::-webkit-scrollbar-thumb {
    background: var(--light-gray);
    border-radius: var(--border-radius);
    border: 2px solid var(--light);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray);
}

/* ==========================================================================
   Typography
   ========================================================================== */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-family-heading);
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 0.5rem;
    color: var(--dark);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.75rem; }
h4 { font-size: 1.5rem; }
h5 { font-size: 1.25rem; }
h6 { font-size: 1rem; }

p {
    margin-bottom: 1rem;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.text-muted {
    color: var(--gray) !important;
}

.text-small {
    font-size: 0.875rem;
}

.text-xsmall {
    font-size: 0.75rem;
}

/* ==========================================================================
   Layout Components
   ========================================================================== */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--info) 100%);
    color: white;
    padding: 1.5rem;
    text-align: center;
    position: relative;
    overflow: hidden;
    margin: -1rem -1rem 2rem -1rem;
    box-shadow: var(--shadow-md);
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.logo {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 0.5rem;
    position: relative;
    z-index: 1;
}

.logo i {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    color: white;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.logo h1 {
    font-family: var(--font-family-heading);
    font-size: 2rem;
    color: white;
    margin: 0;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.logo span {
    font-weight: 300;
    opacity: 0.9;
}

.tagline {
    font-size: 1rem;
    opacity: 0.9;
    font-weight: 300;
    margin-top: 0.25rem;
}

/* Header Controls */
.header-controls {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 2;
}

/* Theme Switch */
.theme-switch-wrapper {
    display: flex;
    align-items: center;
}

.theme-switch {
    display: inline-block;
    height: 24px;
    position: relative;
    width: 46px;
}

.theme-switch input {
    display: none;
}

.slider {
    background-color: #ccc;
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
    box-shadow: var(--shadow-inset);
}

.slider:before {
    background-color: white;
    bottom: 3px;
    content: "";
    height: 18px;
    left: 4px;
    position: absolute;
    transition: .4s;
    width: 18px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(19px);
}

.slider.round {
    border-radius: 28px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Credit Button */
.credit-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all var(--transition-base);
}

.credit-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ==========================================================================
   Setup Panel & Steps
   ========================================================================== */
.setup-panel {
    padding: 2rem;
    background: var(--light);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    border: var(--border);
    position: relative;
    overflow: hidden;
}

.setup-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(to bottom, var(--primary), var(--info));
}

.setup-step {
    display: none;
    animation: fadeInSlide 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.setup-step.active {
    display: block;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--info));
    color: white;
    border-radius: 50%;
    font-weight: 700;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
    font-family: var(--font-family-heading);
    position: relative;
    overflow: hidden;
}

.step-number::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
    animation: shimmer 2s infinite;
}

.setup-step h3 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    position: relative;
    padding-bottom: 0.75rem;
    font-family: var(--font-family-heading);
    color: var(--dark);
}

.setup-step h3::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 60px;
    height: 4px;
    background: linear-gradient(to right, var(--primary), var(--info));
    border-radius: 2px;
}

/* ==========================================================================
   Form Elements
   ========================================================================== */
.form-group {
    margin-bottom: 1.5rem;
    position: relative;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--dark);
    font-family: var(--font-family-heading);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    border: var(--border);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: all var(--transition-base);
    background-color: var(--light);
    color: var(--dark);
    font-family: var(--font-family-base);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 0.25rem var(--primary-alpha-25);
    transform: translateY(-1px);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--gray);
    opacity: 0.7;
}

/* Password Input */
.password-input {
    position: relative;
}

.toggle-password {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray);
    cursor: pointer;
    background: none;
    border: none;
    padding: 0.25rem;
    font-size: 1.1rem;
    transition: color var(--transition-fast);
}

.toggle-password:hover {
    color: var(--primary);
}

/* Validation */
.validation-message {
    font-size: 0.85rem;
    margin-top: 0.5rem;
    min-height: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.validation-message.valid {
    color: var(--success);
}

.validation-message.invalid {
    color: var(--danger);
}

.hint {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.875rem;
    color: var(--gray);
    line-height: 1.4;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 1.5rem;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    font-family: var(--font-family-heading);
    border: none;
    gap: 0.75rem;
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn i {
    font-size: 1.1em;
    transition: transform var(--transition-fast);
}

.btn:hover i {
    transform: translateX(3px);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn:disabled::before {
    display: none;
}

/* Button Variants */
.professional-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: var(--shadow-sm);
}

.professional-btn:hover {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    box-shadow: var(--shadow-md);
    transform: translateY(-3px);
}

.professional-btn-secondary {
    background-color: var(--light);
    color: var(--dark);
    border: 2px solid var(--light-gray);
}

.professional-btn-secondary:hover {
    background-color: var(--light-gray);
    color: var(--dark);
    border-color: var(--primary);
}

.professional-btn-success {
    background: linear-gradient(135deg, var(--success), var(--secondary-dark));
    color: white;
}

.professional-btn-success:hover {
    background: linear-gradient(135deg, var(--secondary-dark), var(--success));
    transform: translateY(-3px);
}

.professional-btn-danger {
    background: linear-gradient(135deg, var(--danger), #c82333);
    color: white;
}

.professional-btn-danger:hover {
    background: linear-gradient(135deg, #c82333, var(--danger));
    transform: translateY(-3px);
}

/* Button Sizes */
.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.125rem;
}

/* ==========================================================================
   Upload Components
   ========================================================================== */
.upload-area {
    border: 2px dashed var(--light-gray);
    border-radius: var(--border-radius-lg);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-base);
    margin-bottom: 1.5rem;
    background-color: var(--light);
    position: relative;
    overflow: hidden;
}

.upload-area.drag-over {
    border-color: var(--primary);
    background-color: var(--primary-alpha-05);
    transform: scale(1.02);
    box-shadow: var(--shadow-md);
}

.upload-area i {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1rem;
    transition: transform var(--transition-base);
}

.upload-area:hover i {
    transform: scale(1.1) rotate(5deg);
}

.upload-area p {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--dark);
    font-weight: 500;
}

/* File Info */
.file-info {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    display: none;
}

.file-info.show {
    display: flex;
    animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.file-info-icon {
    margin-bottom: 0.75rem;
    font-size: 1.75rem;
    color: var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.file-info-text {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.file-info-text p {
    margin: 0;
    font-size: 0.95rem;
}

/* ==========================================================================
   Variables & Attachments
   ========================================================================== */
.variables-container,
.attachments-container {
    background-color: var(--light);
    border: var(--border);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.variables-header h4,
.attachments-header h4 {
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    color: var(--dark);
}

.variables-instructions,
.attachments-instructions {
    font-size: 0.9rem;
    color: var(--gray);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.variables-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.variable-item {
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, var(--primary-alpha-10), transparent);
    color: var(--primary);
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: 2px solid var(--primary-alpha-20);
    cursor: pointer;
    user-select: none;
}

.variable-item:hover {
    background: linear-gradient(135deg, var(--primary-alpha-20), transparent);
    transform: translateY(-3px) scale(1.05);
    box-shadow: var(--shadow-sm);
    border-color: var(--primary);
}

.variable-item:active {
    transform: translateY(-1px) scale(1.02);
}

.attachments-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.attachment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem;
    background-color: var(--light);
    border: var(--border);
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.attachment-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(to bottom, var(--primary), var(--info));
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.attachment-item:hover::before {
    opacity: 1;
}

.attachment-item:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

.attachment-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-grow: 1;
    min-width: 0;
}

.attachment-icon {
    color: var(--primary);
    font-size: 1.25rem;
    flex-shrink: 0;
}

.attachment-name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.attachment-size {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.attachment-size-warning {
    color: var(--warning);
}

.attachment-size-error {
    color: var(--danger);
}

.remove-attachment {
    color: var(--danger);
    cursor: pointer;
    background: none;
    border: none;
    padding: 0.25rem;
    font-size: 1.1rem;
    transition: all var(--transition-fast);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-attachment:hover {
    background-color: rgba(231, 74, 59, 0.1);
    transform: rotate(90deg);
}

/* ==========================================================================
   Editor Components
   ========================================================================== */
.editor-tabs {
    margin-top: 2rem;
}

.nav-tabs {
    border-bottom: var(--border);
    display: flex;
    gap: 0.25rem;
    padding-bottom: 0;
}

.nav-link {
    color: var(--gray);
    border: none;
    padding: 1rem 1.5rem;
    font-weight: 500;
    background: none;
    position: relative;
    transition: all var(--transition-fast);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.nav-link:hover {
    color: var(--primary);
    background-color: var(--primary-alpha-05);
}

.nav-link.active {
    color: var(--primary);
    background-color: var(--light);
    border-bottom: 3px solid var(--primary);
    font-weight: 600;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(to right, var(--primary), var(--info));
    border-radius: 3px 3px 0 0;
}

.editor-toolbar {
    padding: 0.75rem;
    background-color: var(--light);
    border-bottom: var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.editor-toolbar .btn-group {
    display: flex;
    gap: 0.125rem;
    border-radius: var(--border-radius);
    overflow: hidden;
    border: var(--border);
}

.format-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--light);
    border: none;
    color: var(--dark);
    transition: all var(--transition-fast);
    cursor: pointer;
}

.format-btn:hover {
    background-color: var(--primary-alpha-10);
    color: var(--primary);
}

.format-btn.active {
    background-color: var(--primary);
    color: white;
}

.format-btn:not(:last-child) {
    border-right: var(--border);
}

.email-editor {
    min-height: 400px;
    padding: 1.5rem;
    outline: none;
    background-color: var(--light);
    color: var(--dark);
    border: var(--border);
    border-top: none;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    caret-color: var(--primary);
    line-height: 1.8;
    overflow-y: auto;
}

.email-editor:focus {
    box-shadow: inset 0 0 0 1px var(--primary), 0 0 0 0.25rem var(--primary-alpha-25);
}

.email-editor img {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
}

.html-editor {
    width: 100%;
    min-height: 400px;
    padding: 1.5rem;
    border: var(--border);
    border-top: none;
    font-family: var(--font-family-mono);
    background-color: var(--light);
    color: var(--dark);
    resize: vertical;
    font-size: 0.95rem;
    line-height: 1.6;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    tab-size: 2;
}

.html-editor:focus {
    outline: none;
    box-shadow: inset 0 0 0 1px var(--primary), 0 0 0 0.25rem var(--primary-alpha-25);
}

.editor-footer {
    padding: 1rem;
    background-color: var(--light);
    border-top: var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

/* ==========================================================================
   Table Components
   ========================================================================== */
.excel-preview-container {
    margin-top: 1.5rem;
    border: var(--border);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    background-color: var(--light);
    box-shadow: var(--shadow-sm);
}

.preview-summary {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: var(--border);
}

.preview-summary .file-info-icon {
    margin-right: 1rem;
    color: var(--success);
}

.preview-summary .file-info-text {
    flex: 1;
}

.table-controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.table-controls .btn-group {
    display: flex;
    gap: 0;
    border-radius: var(--border-radius);
    overflow: hidden;
    border: var(--border);
}

.table-controls .btn {
    border-radius: 0;
    padding: 0.5rem 1rem;
}

.table-controls .btn:first-child {
    border-top-left-radius: var(--border-radius);
    border-bottom-left-radius: var(--border-radius);
}

.table-controls .btn:last-child {
    border-top-right-radius: var(--border-radius);
    border-bottom-right-radius: var(--border-radius);
}

#excelDataTable,
.preview-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

#excelDataTable th,
#excelDataTable td,
.preview-table th,
.preview-table td {
    border: 1px solid var(--light-gray);
    padding: 0.875rem 1rem;
    text-align: left;
    transition: background-color var(--transition-fast);
}

#excelDataTable th,
.preview-table th {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    position: sticky;
    top: 0;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.875rem;
    letter-spacing: 0.5px;
}

#excelDataTable tr:nth-child(even),
.preview-table tr:nth-child(even) {
    background-color: var(--primary-alpha-05);
}

#excelDataTable tr:hover,
.preview-table tr:hover {
    background-color: var(--primary-alpha-10);
}

#excelDataTable td[contenteditable="true"],
.preview-table td[contenteditable="true"] {
    min-width: 120px;
    padding: 0.75rem;
    outline: none;
    cursor: text;
}

#excelDataTable td[contenteditable="true"]:focus,
.preview-table td[contenteditable="true"]:focus {
    background-color: var(--primary-alpha-10);
    box-shadow: inset 0 0 0 2px var(--primary);
    position: relative;
    z-index: 1;
}

/* File Type Tabs */
.file-type-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--light-gray);
    gap: 0.25rem;
}

.file-type-tab {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--gray);
    transition: all var(--transition-base);
    position: relative;
    font-family: var(--font-family-heading);
}

.file-type-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.file-type-tab:hover:not(.active) {
    color: var(--dark);
    background-color: var(--primary-alpha-05);
}

.file-type-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(to right, var(--primary), var(--info));
}

/* History Stack */
.history-stack {
    position: absolute;
    top: -24px;
    right: 10px;
    font-size: 0.8rem;
    color: var(--gray);
    background: var(--light);
    padding: 0.25rem 0.5rem;
    border-radius: var(--border-radius-sm);
    border: var(--border);
    opacity: 0.8;
}

/* ==========================================================================
   Progress & Result Panels
   ========================================================================== */
.progress-panel {
    display: none;
    padding: 2rem;
    text-align: center;
    background-color: var(--light);
    border-radius: var(--border-radius-lg);
    margin: 1.5rem 0;
    border: var(--border);
    box-shadow: var(--shadow-md);
}

.progress-panel h3 {
    margin-bottom: 1.5rem;
    color: var(--dark);
}

.progress {
    height: 12px;
    background-color: var(--light-gray);
    border-radius: 6px;
    margin-bottom: 1.5rem;
    overflow: hidden;
    border: var(--border);
    position: relative;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--info), var(--success));
    width: 0%;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
    animation: shimmer 2s infinite;
}

.progress-stats {
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
    color: var(--dark);
    font-weight: 500;
}

.progress-log {
    max-height: 250px;
    overflow-y: auto;
    text-align: left;
    padding: 1rem;
    background-color: var(--light);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    border: var(--border);
    font-family: var(--font-family-mono);
}

.progress-log p {
    padding: 0.5rem;
    border-bottom: 1px solid var(--light-gray);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.progress-log p:last-child {
    border-bottom: none;
}

.progress-log .error {
    color: var(--danger);
    background-color: rgba(231, 74, 59, 0.05);
    border-left: 3px solid var(--danger);
}

.progress-log .success {
    color: var(--success);
    background-color: rgba(28, 200, 138, 0.05);
    border-left: 3px solid var(--success);
}

.progress-log .info {
    color: var(--info);
    background-color: rgba(54, 185, 204, 0.05);
    border-left: 3px solid var(--info);
}

.result-panel {
    display: none;
    padding: 3rem 2rem;
    text-align: center;
    background: var(--light);
    border-radius: var(--border-radius-lg);
    margin: 1.5rem 0;
    border: var(--border);
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.result-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(to right, var(--primary), var(--info), var(--success));
}

.result-icon {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-icon .fa-check-circle {
    position: relative;
    z-index: 3;
    font-size: 3rem;
    color: var(--success);
    animation: scaleIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes scaleIn {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.success-animation {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background-color: rgba(28, 200, 138, 0.2);
    z-index: 1;
}

.success-animation.pulse {
    animation: pulseCircle 2s infinite;
}

.result-panel h3 {
    margin-bottom: 2rem;
    font-size: 1.75rem;
    color: var(--dark);
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
    padding: 1rem;
    background: var(--light);
    border-radius: var(--border-radius);
    border: var(--border);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-base);
}

.stat-item:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
}

.stat-item i {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.stat-item.success i {
    color: var(--success);
}

.stat-item.danger i {
    color: var(--danger);
}

.stat-item.info i {
    color: var(--info);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0.25rem 0;
    color: var(--dark);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    justify-content: center;
    flex-wrap: wrap;
}

#downloadReportBtn {
    margin-top: 0;
    position: relative;
    overflow: hidden;
}

#downloadReportBtn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255, 255, 255, 0.5);
    opacity: 0;
    border-radius: 100%;
    transform: scale(1, 1) translate(-50%);
    transform-origin: 50% 50%;
}

#downloadReportBtn:focus:not(:active)::after {
    animation: ripple 1s ease-out;
}

@keyframes ripple {
    0% {
        transform: scale(0, 0);
        opacity: 0.5;
    }
    100% {
        transform: scale(40, 40);
        opacity: 0;
    }
}

/* ==========================================================================
   Modal & Toast Notifications
   ========================================================================== */
.modal-content {
    background-color: var(--light);
    color: var(--dark);
    border-radius: var(--border-radius-lg);
    border: var(--border);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    border-bottom: var(--border);
    background: linear-gradient(135deg, var(--primary-alpha-05), transparent);
    padding: 1.5rem;
}

.modal-footer {
    border-top: var(--border);
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, transparent, var(--primary-alpha-05));
}

.toast-notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 400px;
    z-index: var(--z-toast);
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.toast-notification.fade-out {
    animation: slideOutRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

.toast-info {
    background: linear-gradient(135deg, var(--info), #2a96a5);
    color: white;
}

.toast-success {
    background: linear-gradient(135deg, var(--success), var(--secondary-dark));
    color: white;
}

.toast-error {
    background: linear-gradient(135deg, var(--danger), #c82333);
    color: white;
}

.toast-warning {
    background: linear-gradient(135deg, var(--warning), #e0a800);
    color: black;
}

.toast-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.toast-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    margin-left: 1rem;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
    padding: 0.25rem;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.toast-help-link {
    display: inline-block;
    margin-top: 0.5rem;
    color: inherit;
    text-decoration: underline;
    font-size: 0.875rem;
    opacity: 0.9;
    transition: opacity var(--transition-fast);
}

.toast-help-link:hover {
    opacity: 1;
}

.help-link {
    color: var(--danger);
    text-decoration: underline;
    margin-left: 0.5rem;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.help-link:hover {
    color: #c82333;
}

/* ==========================================================================
   Navigation & Interactive Elements
   ========================================================================== */
.step-nav {
    display: flex;
    margin-top: 2rem;
    gap: 1rem;
    justify-content: space-between;
    padding-top: 1.5rem;
    border-top: var(--border);
}

.step-nav .btn {
    min-width: 120px;
}

#undoBtn, #redoBtn {
    position: relative;
    padding-left: 2.5rem;
    padding-right: 2.5rem;
}

#undoBtn:disabled, #redoBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--light-gray);
}

#undoBtn:disabled::before, #redoBtn:disabled::before {
    display: none;
}

/* ==========================================================================
   Animations & Transitions
   ========================================================================== */
@keyframes fadeInSlide {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulseCircle {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0.7;
    }
    70% {
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
}

@keyframes fadeInScale {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */
@media (max-width: 1200px) {
    .setup-panel {
        padding: 1.75rem;
    }
    
    .result-stats {
        gap: 1.5rem;
    }
}

@media (max-width: 992px) {
    .header {
        padding: 1.25rem;
    }
    
    .logo h1 {
        font-size: 1.75rem;
    }
    
    .logo i {
        font-size: 2.25rem;
    }
    
    .setup-panel {
        padding: 1.5rem;
    }
    
    .editor-toolbar {
        justify-content: center;
    }
    
    .step-nav {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .step-nav .btn {
        width: 100%;
    }
}

@media (max-width: 768px) {
    body {
        padding: 0.75rem;
    }
    
    .header {
        padding: 1rem;
        margin: -0.75rem -0.75rem 1.5rem -0.75rem;
        border-radius: 0;
    }
    
    .header-controls {
        top: 1rem;
        right: 1rem;
        gap: 0.75rem;
    }
    
    .credit-text {
        display: none;
    }
    
    .credit-btn {
        width: 40px;
        height: 40px;
        padding: 0;
        justify-content: center;
        border-radius: 50%;
    }
    
    .setup-panel {
        padding: 1.25rem;
        margin-bottom: 1.5rem;
    }
    
    .setup-step h3 {
        font-size: 1.35rem;
    }
    
    .variables-list {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 0.5rem;
        margin-right: -0.5rem;
        margin-left: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    .variable-item {
        flex-shrink: 0;
    }
    
    .editor-toolbar {
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 0.375rem;
    }
    
    .editor-toolbar .btn-group {
        margin-bottom: 0.375rem;
    }
    
    .email-editor,
    .html-editor {
        min-height: 300px;
    }
    
    .result-panel {
        padding: 2rem 1rem;
    }
    
    .result-stats {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .stat-item {
        min-width: auto;
    }
    
    .toast-notification {
        max-width: calc(100% - 48px);
        left: 24px;
        right: 24px;
    }
    
    .file-type-tabs {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .file-type-tab {
        flex: 1;
        min-width: 120px;
        text-align: center;
        padding: 0.75rem;
    }
    
    .table-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .table-controls .btn-group {
        width: 100%;
    }
    
    .table-controls .btn {
        flex: 1;
        justify-content: center;
    }
}

@media (max-width: 576px) {
    body {
        padding: 0.5rem;
    }
    
    .header {
        padding: 0.75rem;
        margin: -0.5rem -0.5rem 1rem -0.5rem;
    }
    
    .logo h1 {
        font-size: 1.5rem;
    }
    
    .logo i {
        font-size: 2rem;
    }
    
    .tagline {
        font-size: 0.875rem;
    }
    
    .setup-panel {
        padding: 1rem;
        border-radius: var(--border-radius);
    }
    
    .btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.9375rem;
    }
    
    .upload-area {
        padding: 2rem 1rem;
    }
    
    .result-actions {
        flex-direction: column;
        align-items: stretch;
    }
    
    .result-actions .btn {
        width: 100%;
    }
    
    .nav-link {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
    
    .editor-footer {
        flex-direction: column;
        gap: 1rem;
    }
    
    .editor-footer .btn {
        width: 100%;
    }
    
    .progress-log {
        font-size: 0.85rem;
        max-height: 200px;
    }
    
    #excelDataTable th,
    #excelDataTable td,
    .preview-table th,
    .preview-table td {
        padding: 0.5rem;
        font-size: 0.875rem;
    }
    
    .attachment-item {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .attachment-size {
        order: 3;
        margin-left: auto;
    }
    
    .remove-attachment {
        order: 4;
    }
}

@media (max-width: 375px) {
    .header-controls {
        position: static;
        justify-content: center;
        margin-top: 1rem;
    }
    
    .logo {
        margin-bottom: 0;
    }
    
    .header {
        text-align: center;
        padding-bottom: 1.5rem;
    }
    
    .setup-step h3 {
        font-size: 1.25rem;
    }
    
    .stat-item {
        padding: 0.75rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    .stat-item i {
        font-size: 1.75rem;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */
@media print {
    body {
        background: white !important;
        color: black !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .header,
    .header-controls,
    .step-nav,
    .editor-toolbar,
    .btn,
    .toast-notification,
    .progress-panel,
    .result-panel .result-actions {
        display: none !important;
    }
    
    .setup-panel,
    .email-editor,
    .html-editor,
    .variables-container,
    .attachments-container,
    .excel-preview-container {
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        background: white !important;
        color: black !important;
        page-break-inside: avoid;
    }
    
    .setup-step {
        display: block !important;
    }
    
    a {
        color: black !important;
        text-decoration: underline !important;
    }
    
    .variable-item {
        border: 1px solid #ccc !important;
        background: white !important;
        color: black !important;
    }
    
    #excelDataTable,
    .preview-table {
        border: 1px solid #ccc !important;
    }
    
    #excelDataTable th,
    #excelDataTable td,
    .preview-table th,
    .preview-table td {
        border: 1px solid #ccc !important;
        background: white !important;
        color: black !important;
    }
}

/* ==========================================================================
   Accessibility Improvements
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Focus Styles for Keyboard Navigation */
:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--border-radius-sm);
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --primary: #0056b3;
        --primary-dark: #003d82;
        --border: 2px solid currentColor;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}

/* Dark Mode Preference */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --primary: #4e73df;
        --primary-light: #3a56a5;
        --primary-dark: #2c56d1;
        --dark: #e4e6eb;
        --light: #242526;
        --gray: #b0b3b8;
        --light-gray: #3a3b3c;
        --border: 1px solid #3e4042;
    }
}
