/* ============================================
   CSS Variables for Theming
   ============================================ */
:root {
    /* Light Theme Colors (SEU Inspired) */
    --primary-color: #1e3a8a;
    --primary-dark: #1e40af;
    --secondary-color: #0ea5e9;
    --accent-color: #f59e0b;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);
}

.dark-theme {
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --secondary-color: #60a5fa;
    --accent-color: #fbbf24;
    --bg-primary: #1e293b;
    --bg-secondary: #334155;
    --bg-tertiary: #475569;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #475569;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-lg: rgba(0, 0, 0, 0.5);
}

/* ============================================
   Font Face Declarations
   ============================================ */
@font-face {
    font-family: 'FrutigerLTArabic';
    src: url('../fonts/FrutigerLTArabic45Light.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
}

@font-face {
    font-family: 'FrutigerLTArabic';
    src: url('../fonts/FrutigerLTArabic55Roman.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

@font-face {
    font-family: 'FrutigerLTArabic';
    src: url('../fonts/FrutigerLTArabic65Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

/* ============================================
   Base Styles
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'FrutigerLTArabic', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ============================================
   Header Styles
   ============================================ */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1.5rem 0;
    box-shadow: 0 2px 10px var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-section {
    display: flex;
    flex-direction: column;
}

[dir="rtl"] .logo-section {
    text-align: right;
    align-items: flex-end;
}

.logo {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.logo-subtitle {
    font-size: 0.85rem;
    font-weight: 400;
    margin: 0.25rem 0 0 0;
    opacity: 0.9;
    letter-spacing: 0.5px;
}

[dir="rtl"] .logo-subtitle {
    text-align: right;
}

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

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: background-color 0.3s ease;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
}

.language-switcher {
    display: flex;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.25rem;
    border-radius: 8px;
}

.lang-btn {
    background: transparent;
    border: none;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    font-weight: 500;
}

.lang-btn.active {
    background: white;
    color: var(--primary-color);
}

.lang-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    padding: 2rem 0;
    min-height: calc(100vh - 200px);
}

.banner-maker {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
    grid-template-areas:
        "preview preview"
        "controls gallery";
    gap: 2rem;
    margin-top: 2rem;
}

[dir="rtl"] .banner-maker {
    grid-template-columns: 1.3fr 1fr;
    grid-template-areas:
        "preview preview"
        "gallery controls";
}

/* ============================================
   Controls Panel
   ============================================ */
.controls-panel {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 4px 6px var(--shadow);
    height: fit-content;
    max-height: calc(100vh - 250px);
    overflow-y: auto;
    grid-area: controls;
}

.controls-panel::-webkit-scrollbar {
    width: 8px;
}

.controls-panel::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.controls-panel::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.section h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--primary-color);
    font-weight: 600;
}

[dir="rtl"] .section h2 {
    text-align: right;
}

/* ============================================
   Form Controls
   ============================================ */
.form-group {
    margin-bottom: 1rem;
}

/* Inline row for size slider and alignment buttons */
.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.form-row .flex-1 { flex: 1; }
.form-row .align-col { flex: 0 0 auto; }

/* Course code/title sizing */
.form-row .code-col {
    flex: 0 0 220px;
    max-width: 260px;
}
.form-row .title-col {
    flex: 1 1 300px;
}

[dir="rtl"] .form-row {
    flex-direction: row-reverse;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

[dir="rtl"] .form-group label {
    text-align: right;
}

.form-control {
    width: 100%;
    padding: 0.6rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

[dir="rtl"] .form-control {
    text-align: right;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

.color-input {
    height: 50px;
    cursor: pointer;
}

.range-input {
    width: calc(100% - 60px);
    display: inline-block;
    vertical-align: middle;
}

[dir="rtl"] .range-input { direction: rtl; }

.range-value {
    display: inline-block;
    width: 50px;
    text-align: center;
    font-weight: 600;
    color: var(--primary-color);
}

.form-group input[type="checkbox"] {
    margin-right: 0.5rem;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* ============================================
   Image Gallery
   ============================================ */
.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

[dir="rtl"] .image-gallery {
    direction: rtl;
}

.gallery-item {
    position: relative;
    aspect-ratio: 5 / 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-lg);
}

.gallery-item.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.2);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.no-images {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
    font-style: italic;
}

[dir="rtl"] .no-images {
    text-align: right;
    direction: rtl;
}

/* ============================================
   Buttons
   ============================================ */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-lg);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* Actions row: place download/reset side-by-side */
.actions-row {
    display: flex;
    gap: 0.75rem;
}
.actions-row .btn-primary,
.actions-row .btn-secondary {
    width: auto;
    flex: 1;
}
[dir="rtl"] .actions-row { flex-direction: row-reverse; }

/* Alignment button group */
.align-group {
    display: inline-flex;
    gap: 0.5rem;
}

[dir="rtl"] .align-group {
    flex-direction: row-reverse;
    justify-content: flex-end;
}

[dir="rtl"] .form-group {
    text-align: right;
}

.align-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.align-btn:hover {
    border-color: var(--primary-color);
}

.align-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #ffffff;
}

.align-btn svg {
    fill: currentColor;
}

/* ============================================
   Preview Panel
   ============================================ */
.preview-panel {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 6px var(--shadow);
    height: fit-content;
    align-items: center;
    justify-content: center;
    position: relative;
    top: 0;
    grid-area: preview;
}

.preview-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.preview-container h2 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
    font-weight: 600;
}

.canvas-wrapper {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: fit-content;
    margin: 0 auto 0.5rem auto; /* center within container */
    overflow: auto;
}

#bannerCanvas {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 2px 8px var(--shadow);
    background: white;
    width: fit-content;
}

.canvas-info {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Gallery Panel */
.gallery-panel {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 4px 6px var(--shadow);
    grid-area: gallery;
    height: fit-content;
}

.design-credit {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.5;
    font-weight: 400;
}

.design-credit a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

.design-credit a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

[dir="rtl"] .design-credit {
    text-align: right;
    direction: rtl;
}

/* ============================================
   Footer
   ============================================ */
.footer {
    background: var(--bg-primary);
    padding: 1.5rem 0;
    text-align: center;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    margin-top: 3rem;
}

[dir="rtl"] .footer {
    direction: rtl;
}

.footer-credit {
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.footer-credit a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

.footer-credit a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

[dir="rtl"] .footer-credit {
    direction: rtl;
}

.footer-developer {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.footer-developer p {
    margin: 0;
    font-size: 0.9rem;
}

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

.social-link {
    color: var(--text-secondary);
    transition: color 0.3s ease, transform 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.social-link:hover {
    color: var(--primary-color);
    transform: translateY(-2px);
}

.social-link svg {
    width: 20px;
    height: 20px;
}

/* Tooltip for social links */
.social-link[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background-color: var(--text-primary);
    color: var(--bg-primary);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 1000;
    font-weight: 500;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.social-link[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-2px);
    border: 5px solid transparent;
    border-top-color: var(--text-primary);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 1001;
}

.social-link[data-tooltip]:hover::after,
.social-link[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

[dir="rtl"] .social-link[data-tooltip]::after {
    left: auto;
    right: 50%;
    transform: translateX(50%) translateY(-8px);
}

[dir="rtl"] .social-link[data-tooltip]::before {
    left: auto;
    right: 50%;
    transform: translateX(50%) translateY(-2px);
}

[dir="rtl"] .social-link[data-tooltip]:hover::after,
[dir="rtl"] .social-link[data-tooltip]:hover::before {
    transform: translateX(50%) translateY(0);
}

/* ============================================
   RTL Support
   ============================================ */
[dir="rtl"] .header-content {
    flex-direction: row-reverse;
}

[dir="rtl"] .language-switcher {
    flex-direction: row-reverse;
}

[dir="rtl"] .form-group input[type="checkbox"] {
    margin-right: 0;
    margin-left: 0.5rem;
}

[dir="rtl"] .range-input {
    margin-left: 0;
    margin-right: 10px;
}

[dir="rtl"] .range-value {
    margin-right: 0;
    margin-left: 10px;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1024px) {
    .banner-maker {
        grid-template-columns: 1fr;
        grid-template-areas:
            "preview"
            "gallery"
            "controls";
    }

    .preview-panel {
        position: relative;
        top: 0;
    }

    .controls-panel,
    .gallery-panel,
    .preview-panel {
        max-height: none;
    }

    [dir="rtl"] .banner-maker {
        grid-template-columns: 1fr;
        grid-template-areas:
            "preview"
            "gallery"
            "controls";
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }

    .logo {
        font-size: 1.4rem;
    }

    .controls-panel,
    .preview-panel {
        padding: 1.5rem;
    }

    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    #bannerCanvas {
        width: 100%;
    }
}

/* ============================================
   Loading States
   ============================================ */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.gallery-item {
    animation: fadeIn 0.3s ease;
}

/* Utility: temporarily hide future features */
.hidden-feature { display: none !important; }
