/* main.css - AI Document Generation Styles (Complete with Fixed Template Menu) */

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Modern Header Base */
.header {
    margin-bottom: 20px;
    padding: 0;
    position: relative;
    color: white;
}

.header-content {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px); /* Safari support */
    border-radius: 16px;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

/* Header Sections */
.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Logo Section */
.logo-section {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: white;
    transition: opacity 0.3s ease;
}

.logo-section:hover {
    opacity: 0.8;
}

.logo-section img {
    height: 40px;
    width: 40px;
    object-fit: contain;
}

.brand-name {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin: 0;
    line-height: 1;
}

/* Visual Divider */
.header-divider {
    width: 1px;
    height: 32px;
    background: rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

/* App Title Section */
.app-title-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
    color: white;
}

.app-subtitle {
    font-size: 12px;
    opacity: 0.85;
    margin: 0;
    font-weight: 400;
    color: white;
}

/* Auth Section Improvements */
#authSection {
    margin: 0;
}

.auth-trigger {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    font-size: 13px;
    backdrop-filter: blur(10px);
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.auth-trigger:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.auth-trigger:active {
    transform: translateY(0);
}

/* User Info Card */
.user-info {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    padding: 6px 16px 6px 6px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    transition: all 0.3s ease;
}

.user-info:hover {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.user-avatar {
    flex-shrink: 0;
}

.user-avatar .avatar-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    text-transform: uppercase;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: white;
    line-height: 1;
}

.user-role {
    font-size: 11px;
    opacity: 0.8;
    color: white;
    line-height: 1;
    text-transform: capitalize;
}

.user-actions {
    margin-left: 4px;
}

.logout-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.logout-btn:hover {
    background: rgba(255, 100, 100, 0.3);
    border-color: rgba(255, 100, 100, 0.4);
}

/* Login Form Overlay */
#loginForm {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* Tablet (768px and below) */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 16px;
        padding: 16px;
    }
    
    .header-left {
        width: 100%;
        justify-content: center;
    }
    
    .header-divider {
        display: none;
    }
    
    .header-right {
        width: 100%;
        justify-content: center;
    }
    
    .app-title {
        font-size: 16px;
    }
    
    .app-subtitle {
        font-size: 11px;
    }
}

/* Mobile (480px and below) */
@media (max-width: 480px) {
    .header-left {
        flex-direction: column;
        gap: 12px;
    }
    
    .logo-section {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }
    
    .app-title-section {
        text-align: center;
    }
    
    .brand-name {
        font-size: 18px;
    }
    
    .app-title {
        font-size: 15px;
    }
    
    .app-subtitle {
        font-size: 10px;
    }
    
    .user-info {
        padding: 4px 12px 4px 4px;
        gap: 8px;
    }
    
    .user-name {
        font-size: 12px;
    }
    
    .user-role {
        font-size: 10px;
    }
    
    .logout-btn {
        padding: 4px 8px;
        font-size: 11px;
    }
}

/* ========================================
   OPTIONAL ENHANCEMENTS
   Comment/uncomment as needed
   ======================================== */

/* Optional: Sticky Header */
/*
.header {
    position: sticky;
    top: 0;
    z-index: 100;
}

.header.scrolled .header-content {
    backdrop-filter: blur(30px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}
*/

/* Optional: Hover Effect on Header */
/*
.header-content:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
}
*/

/* Optional: Gradient Background */
/*
.header-content {
    background: linear-gradient(
        135deg, 
        rgba(102, 126, 234, 0.2) 0%, 
        rgba(118, 75, 162, 0.2) 100%
    );
}
*/

/* Optional: Search Bar in Header */
/*
.header-search {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 8px 16px;
    color: white;
    width: 300px;
    font-size: 13px;
    transition: all 0.3s ease;
}

.header-search:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.header-search::placeholder {
    color: rgba(255, 255, 255, 0.6);
}
*/

/* ========================================
   ACCESSIBILITY IMPROVEMENTS
   ======================================== */

/* Focus visible for keyboard navigation */
.logo-section:focus-visible,
.auth-trigger:focus-visible,
.logout-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .header-content,
    .auth-trigger,
    .user-info,
    .logout-btn,
    .logo-section {
        transition: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .header-content {
        border: 2px solid rgba(255, 255, 255, 0.5);
    }
    
    .header-divider {
        background: rgba(255, 255, 255, 0.6);
    }
}

/* ========================================
   DARK MODE SUPPORT (if needed)
   ======================================== */
/*
@media (prefers-color-scheme: dark) {
    .header-content {
        background: rgba(0, 0, 0, 0.3);
        border-color: rgba(255, 255, 255, 0.1);
    }
}
*/

/* ========================================
   END OF HEADER IMPROVEMENTS
   ======================================== */

/* Navigation Styles */
.nav-tabs {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 4px;
    backdrop-filter: blur(10px);
}

.nav-item {
    padding: 12px 24px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.nav-item:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-1px);
}

.nav-item.active {
    background: rgba(255,255,255,0.25);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Section Styles */
.section {
    display: none;
    background: white;
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    backdrop-filter: blur(10px);
}

.section.active {
    display: block;
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Dashboard Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.stat-card h3 {
    font-size: 2rem;
    margin-bottom: 8px;
}

.stat-card p {
    opacity: 0.9;
    font-size: 14px;
}

/* Form Styles */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
    background: #f8f9fa;
}

.form-control:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 120px;
    font-family: 'Consolas', 'Monaco', monospace;
}

/* Button Styles */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
    opacity: 0.6;
    transform: none;
    box-shadow: none;
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    border: 2px solid #667eea;
    color: #667eea;
}

.btn-outline:hover {
    background: #667eea;
    color: white;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
    transform: translateY(-1px);
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
}

.btn-icon {
    padding: 8px;
    min-width: auto;
    flex: none;
}

/* Enhanced Template Grid (Complete with Fixed Menu) */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    padding: 20px 0;
    position: relative;
    z-index: 1;
}

.template-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    border: 1px solid #e1e5e9;
    position: relative;
    overflow: visible; /* FIXED: Allow dropdown to overflow */
}

.template-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

/* Template Header */
.template-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.template-title {
    font-weight: 600;
    font-size: 16px;
    color: #333;
    flex: 1;
    margin-right: 12px;
    line-height: 1.3;
}

.template-badges {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-end;
}

.template-category {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-transform: capitalize;
}

.complexity-badge {
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
}

.complexity-basic {
    background: #d4edda;
    color: #155724;
}

.complexity-medium {
    background: #fff3cd;
    color: #856404;
}

.complexity-advanced {
    background: #f8d7da;
    color: #721c24;
}

/* Template Description */
.template-description {
    color: #666;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 16px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Template Meta-badges */
.template-meta-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    margin-right: 6px;
    margin-bottom: 4px;
}

.badge.category {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.badge.type {
    background: #e9ecef;
    color: #495057;
}

.badge.complexity {
    text-transform: capitalize;
}

.badge.quality {
    background: #28a745;
    color: white;
}

/* Template Stats */
.template-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.stat-label {
    color: #666;
    font-weight: 500;
}

.stat-value {
    color: #333;
    font-weight: 600;
}

/* Template Metrics */
.template-meta {
    margin-bottom: 12px;
}

.template-metrics {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

.metric {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #666;
}

.metric i {
    width: 12px;
    height: 12px;
    opacity: 0.7;
}

/* Quality Score */
.template-quality {
    display: flex;
    justify-content: flex-end;
}

.quality-score {
    display: flex;
    align-items: center;
    gap: 6px;
}

.score-value {
    font-size: 12px;
    font-weight: 600;
    color: #333;
    min-width: 20px;
}

.score-bar {
    width: 40px;
    height: 4px;
    background: #e1e5e9;
    border-radius: 2px;
    overflow: hidden;
}

.score-fill {
    height: 100%;
    background: linear-gradient(90deg, #dc3545 0%, #ffc107 50%, #28a745 100%);
    transition: width 0.3s ease;
}

/* Template Tags */
.template-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.tag {
    background: #f8f9fa;
    color: #495057;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 500;
    border: 1px solid #e9ecef;
}

.tag.more {
    background: #e9ecef;
    color: #6c757d;
}

/* Template Footer */
.template-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-size: 11px;
    color: #999;
}

.template-author {
    font-weight: 500;
}

.template-date {
    color: #aaa;
}

/* FIXED: Template Actions with Proper Menu Positioning */
.template-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative; /* FIXED: Required for menu positioning context */
}

.template-actions .btn {
    flex: 1;
    justify-content: center;
    padding: 8px 12px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* FIXED: Template Menu Container */
.template-menu {
    position: relative;
    display: inline-block;
}

/* FIXED: Menu Toggle Button */
.template-menu-toggle {
    padding: 8px !important;
    min-width: auto !important;
    flex: none !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: bold !important;
    font-size: 16px !important;
    line-height: 1 !important;
}

/* FIXED: Dropdown Menu Content */
.template-menu-content {
    /* Initial hidden state */
    display: none;
    
    /* Base positioning - will be overridden by JavaScript */
    position: absolute;
    right: 0;
    top: 100%;
    
    /* Styling */
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    border: 1px solid #e1e5e9;
    min-width: 140px;
    max-width: 200px;
    z-index: 1001; /* FIXED: Ensure menu appears above everything */
    padding: 8px 0;
    
    /* Prevent text selection and improve appearance */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.template-menu-content.open {
    display: block !important;
}

/* FIXED: Menu Items */
.template-menu-content .menu-item {
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background-color 0.2s ease;
    color: #333;
    white-space: nowrap;
    outline: none;
}

.template-menu-content .menu-item:hover {
    background: #f8f9fa;
}

.template-menu-content .menu-item:focus {
    background: #f8f9fa;
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

.template-menu-content .menu-item.danger {
    color: #dc3545;
}

.template-menu-content .menu-item.danger:hover {
    background: #f8d7da;
    color: #721c24;
}

/* FIXED: Menu Separator */
.template-menu-content hr {
    margin: 4px 0;
    border: none;
    border-top: 1px solid #e9ecef;
    height: 0;
}

/* FIXED: Alternative styling for buttons inside menu */
.template-menu-content button {
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background-color 0.2s;
    color: #333;
}

.template-menu-content button:hover {
    background: #f8f9fa;
}

.template-menu-content button.danger {
    color: #dc3545;
}

.template-menu-content button.danger:hover {
    background: #f8d7da;
}

/* FIXED: Animation for menu appearance */
.template-menu-content.show {
    display: block;
    animation: menuFadeIn 0.15s ease-out;
}

@keyframes menuFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Template Management Header */
.template-header-section {
    margin-bottom: 24px;
}

.template-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.template-header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Template Statistics Summary */
.template-stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-summary-card {
    background: white;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #e1e5e9;
    text-align: center;
}

.stat-summary-value {
    font-size: 24px;
    font-weight: 700;
    color: #333;
    margin-bottom: 4px;
}

.stat-summary-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
}

/* Template Filters */
.template-filters {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 24px;
    border: 1px solid #e1e5e9;
}

.filters-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    margin-bottom: 4px;
}

.filter-group input,
.filter-group select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: #667eea;
}

.clear-filters {
    padding: 8px 16px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    color: #666;
}

.clear-filters:hover {
    background: #e9ecef;
}

.sort-controls {
    margin-top: 12px;
}

/* No Templates State */
.no-templates {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

.no-templates-content h3 {
    margin: 0 0 8px 0;
    color: #333;
}

.no-templates-content p {
    margin: 0 0 20px 0;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 32px;
}

.pagination-btn {
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(.disabled) {
    background: #f8f9fa;
    border-color: #667eea;
}

.pagination-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.pagination-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-ellipsis {
    padding: 8px 4px;
    color: #999;
    font-size: 13px;
}

/* Alert Styles */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid transparent;
}

.alert-success {
    background: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.alert-error {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.alert-warning {
    background: #fff3cd;
    border-color: #ffeaa7;
    color: #856404;
}

.alert-info {
    background: #cce7ff;
    border-color: #b8daff;
    color: #004085;
}

/* Result Area */
.result-area {
    margin-top: 20px;
    padding: 20px;
    border-radius: 8px;
    background: #f8f9fa;
}

.result-success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.result-error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Upload Styles */
.upload-area {
    border: 2px dashed #667eea;
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    background: #f8f9fa;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.upload-area:hover {
    background: #e9ecef;
    border-color: #5a67d8;
}

.upload-area.dragover {
    background: #e3f2fd;
    border-color: #2196f3;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e1e5e9;
    border-radius: 4px;
    overflow: hidden;
    margin: 15px 0;
    display: none;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    transition: width 0.3s ease;
}

.file-item {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 8px 12px;
    margin: 5px 0;
    font-size: 13px;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #dee2e6;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #333;
}

/* Status Badges */
.status-completed {
    background: #28a745;
    color: white;
}

.status-failed {
    background: #dc3545;
    color: white;
}

.status-pending {
    background: #ffc107;
    color: #212529;
}

/* Template Details Modal */
.template-details-modal {
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
}

.template-details-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e1e5e9;
}

.template-title-section h2 {
    margin: 0 0 8px 0;
    color: #333;
}

/* Edit Template Modal */
.edit-template-modal {
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

.edit-template-modal h3 {
    margin: 0 0 20px 0;
    color: #333;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e1e5e9;
}

/* Authentication Styles */
.auth-form {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

.auth-card {
    background: white;
    border-radius: 16px;
    padding: 32px;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-header h3 {
    margin: 0 0 8px 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: #333;
}

.auth-header p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

.auth-inputs {
    margin-bottom: 24px;
}

.input-group {
    position: relative;
    margin-bottom: 16px;
}

.auth-input {
    width: 100%;
    padding: 12px 16px 12px 48px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
    background: #f8f9fa;
    box-sizing: border-box;
}

.auth-input:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: #666;
}

.auth-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.auth-btn-primary {
    flex: 2;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.auth-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.auth-btn-primary:disabled {
    opacity: 0.7;
    transform: none;
    cursor: not-allowed;
}

.auth-btn-secondary {
    flex: 1;
    background: transparent;
    color: #666;
    border: 2px solid #e1e5e9;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.auth-btn-secondary:hover {
    background: #f8f9fa;
    border-color: #667eea;
    color: #667eea;
}

.btn-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.auth-demo {
    text-align: center;
    padding-top: 16px;
    border-top: 1px solid #e1e5e9;
}

.auth-demo p {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: #555;
}

.demo-users {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.demo-user {
    background: #667eea;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.demo-user:hover {
    background: #5a67d8;
    transform: translateY(-1px);
}

.auth-demo small {
    color: #999;
    font-size: 12px;
}

/* User Info Styles */
.user-info {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.15);
    padding: 12px 16px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 300px;
    margin: 0 auto;
}

.user-avatar {
    margin-right: 12px;
}

.avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    font-size: 14px;
}

.user-details {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.user-name {
    color: white;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.user-role {
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    text-transform: capitalize;
}

.user-actions {
    margin-left: 12px;
}

.logout-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

/* Auth Trigger Button */
.auth-trigger {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 8px;
}

.auth-trigger:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.auth-trigger span {
    font-size: 16px;
}

/* Icons (using CSS symbols as fallback) */
.icon-generate::before { content: "⚡"; }
.icon-view::before { content: "👁"; }
.icon-more::before { content: "⋮"; }
.icon-edit::before { content: "✏"; }
.icon-clone::before { content: "📋"; }
.icon-export::before { content: "📤"; }
.icon-share::before { content: "🔗"; }
.icon-delete::before { content: "🗑"; }
.icon-variables::before { content: "{}"; }
.icon-words::before { content: "📝"; }
.icon-usage::before { content: "📊"; }

/* Enhanced Upload Section Styles */
.upload-header {
    text-align: center;
    margin-bottom: 32px;
}

.upload-header h2 {
    margin-bottom: 8px;
}

.upload-methods {
    display: flex;
    gap: 16px;
    margin-bottom: 32px;
    justify-content: center;
}

.upload-method {
    padding: 20px;
    border: 2px solid #e1e5e9;
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 200px;
}

.upload-method:hover {
    border-color: #667eea;
}

.upload-method.active {
    border-color: #667eea;
    background: #f8f9ff;
}

.upload-method h3 {
    margin: 0 0 8px 0;
    color: #333;
}

.upload-method p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

.upload-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.upload-formats {
    color: #666;
    font-size: 13px;
    margin-top: 8px;
}

.upload-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

.content-editor {
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
}

.editor-toolbar {
    background: #f8f9fa;
    padding: 8px 12px;
    border-bottom: 1px solid #ddd;
    display: flex;
    gap: 8px;
}

.content-textarea {
    border: none;
    border-radius: 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
}

.content-help {
    margin-top: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

.content-help h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    color: #333;
}

.content-help ul {
    margin: 0;
    padding-left: 16px;
    font-size: 12px;
    color: #666;
}

.content-help code {
    background: #e9ecef;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
}

.upload-tips {
    margin-top: 40px;
}

.tips-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.tip-card {
    background: white;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #e1e5e9;
}

.tip-card h4 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 14px;
}

.tip-card p {
    margin: 0;
    font-size: 13px;
    color: #666;
    line-height: 1.4;
}

.selected-files-grid {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
}

.upload-submit {
    width: 100%;
    margin-top: 16px;
}

.upload-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* File Item Styles */
.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: #f8f9fa;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    margin-bottom: 8px;
}

.file-item.unsupported {
    background: #fff3cd;
    border-color: #ffeaa7;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.file-icon {
    font-size: 24px;
    width: 32px;
    text-align: center;
}

.file-details {
    flex: 1;
}

.file-name {
    font-weight: 500;
    font-size: 14px;
    color: #333;
    margin-bottom: 2px;
}

.file-size {
    font-size: 12px;
    color: #666;
}

.file-warning {
    font-size: 11px;
    color: #856404;
    font-weight: 500;
}

.file-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-status {
    font-size: 12px;
    font-weight: 500;
}

.file-status.error {
    color: #dc3545;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    .header h1 {
        font-size: 2rem;
    }

    .header-content {
        flex-direction: column;
        align-items: center;
    }
    
    .auth-section-top-right {
        position: static;
        margin-top: 20px;
    }

    .nav-tabs {
        flex-wrap: wrap;
        gap: 5px;
    }

    .nav-item {
        padding: 8px 16px;
        font-size: 13px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 15px;
    }

    .templates-grid {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 16px 0;
    }

    .template-card {
        padding: 16px;
    }

    .template-actions {
        flex-direction: column;
        gap: 6px;
    }

    .template-actions .btn {
        flex: none;
        width: 100%;
    }

    .template-menu {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .template-menu-content {
        /* On mobile, center the menu */
        right: auto;
        left: 50%;
        transform: translateX(-50%);
        min-width: 160px;
    }

    .template-details-header {
        flex-direction: column;
        align-items: stretch;
    }

    .template-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .filters-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .template-actions-section {
        flex-direction: column;
    }

    .form-actions {
        flex-direction: column;
    }

    .pagination {
        flex-wrap: wrap;
        gap: 4px;
    }

    .modal-content {
        padding: 20px;
        width: 95%;
    }

    .auth-card {
        padding: 24px;
        margin: 20px;
    }
    
    .user-info {
        max-width: none;
        margin: 0;
    }
    
    .auth-actions {
        flex-direction: column;
    }
    
    .auth-btn-primary,
    .auth-btn-secondary {
        flex: none;
    }

    .upload-methods {
        flex-direction: column;
        align-items: center;
    }

    .upload-method {
        width: 100%;
        max-width: 300px;
    }

    .tips-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .template-card {
        padding: 12px;
    }
    
    .template-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .template-badges {
        flex-direction: row;
        justify-content: flex-start;
        margin-top: 8px;
    }
    
    .template-metrics {
        flex-wrap: wrap;
    }
    
    .template-menu-content {
        /* On very small screens, position menu more carefully */
        right: 0;
        left: auto;
        transform: none;
        min-width: 140px;
    }
    
    /* Ensure menu doesn't overflow on small screens */
    .template-menu-content.right-overflow {
        right: auto;
        left: 0;
    }

    .file-item {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .file-actions {
        justify-content: space-between;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .template-menu-content {
        border: 2px solid #000;
        box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    }
    
    .template-menu-content .menu-item:hover {
        background: #000;
        color: #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .template-menu-content {
        animation: none;
    }
    
    .template-menu-content .menu-item {
        transition: none;
    }
    
    .btn {
        transition: none;
    }
    
    .template-card {
        transition: none;
    }
}

/* Focus management for accessibility */
.template-menu-content:focus-within {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .template-menu-content,
    .modal,
    .auth-form {
        display: none !important;
    }
    
    .template-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

.generation-metadata {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
    margin: 15px 0;
}

.metadata-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.metadata-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.metadata-item strong {
    color: #495057;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metadata-item span {
    color: #212529;
    font-weight: 500;
}

.status-completed {
    color: #28a745;
    font-weight: 600;
}

.document-preview {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    margin: 15px 0;
    overflow: hidden;
}

.preview-header {
    background: #f8f9fa;
    padding: 15px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-actions {
    display: flex;
    gap: 10px;
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .metadata-grid {
        grid-template-columns: 1fr;
    }
    
    .preview-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .action-buttons {
        flex-direction: column;
    }
}

/* Enhanced template selection styling */
.usage-high_usage {
  border-left: 4px solid #28a745 !important;
}

.usage-moderate_usage {
  border-left: 4px solid #ffc107 !important;
}

.usage-low_usage {
  border-left: 4px solid #17a2b8 !important;
}

.usage-unused {
  border-left: 4px solid #6c757d !important;
}

.usage-inactive {
  border-left: 4px solid #dc3545 !important;
}

/* Template stats display */
.template-stats {
  background: #f8f9fa;
  border-radius: 6px;
  padding: 12px;
  margin: 10px 0;
  font-size: 12px;
}

.template-stats .stat-item {
  display: inline-block;
  margin-right: 15px;
}

.template-stats .stat-value {
  font-weight: 600;
  color: #495057;
}

.usage-pattern-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.usage-pattern-high_usage { background: #d4edda; color: #155724; }
.usage-pattern-moderate_usage { background: #fff3cd; color: #856404; }
.usage-pattern-low_usage { background: #d1ecf1; color: #0c5460; }
.usage-pattern-unused { background: #e2e3e4; color: #383d41; }
.usage-pattern-inactive { background: #f8d7da; color: #721c24; }
