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

:root {
    /* Professional Dark Mode Colors (Default) */
    --bg-primary: #1a1d23;
    --bg-secondary: #242830;
    --bg-card: #2a2f3a;
    --bg-input: #1f2329;
    --bg-result: linear-gradient(135deg, #2ecc71, #27ae60);
    --bg-factorization: #242830;
    --bg-details: #1f2329;
    --bg-commands: #242830;
    --bg-command-item: #2a2f3a;
    --bg-abjad: linear-gradient(135deg, #5b6d8f, #6b5b8f);
    --bg-footer: #1a1d23;

    --text-primary: #e4e6eb;
    --text-secondary: #b0b3b8;
    --text-light: #ffffff;
    --text-muted: #8a8d91;

    --border-color: #3e4451;
    --border-focus: #58a6ff;

    --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.45);

    --transition: all 0.3s ease;

    --accent-primary: #58a6ff;
    --accent-secondary: #2ecc71;
}

/* Light Mode */
[data-theme="light"] {
    --bg-primary: #f5f7fa;
    --bg-secondary: #e8ecf1;
    --bg-card: #ffffff;
    --bg-input: #f0f2f5;
    --bg-result: linear-gradient(135deg, #2ecc71, #27ae60);
    --bg-factorization: #f0f2f5;
    --bg-details: #f5f7fa;
    --bg-commands: #e8ecf1;
    --bg-command-item: #ffffff;
    --bg-abjad: linear-gradient(135deg, #7b8db0, #8b7bb0);
    --bg-footer: #e8ecf1;

    --text-primary: #1a1d23;
    --text-secondary: #4a5568;
    --text-light: #ffffff;
    --text-muted: #718096;

    --border-color: #d1d5db;
    --border-focus: #3b82f6;

    --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.16);

    --accent-primary: #3b82f6;
    --accent-secondary: #10b981;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Focus Visible - Accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Remove default outline for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

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

/* Header */
.header {
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: var(--transition);
}

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

.logo {
    font-size: 1.8rem;
    color: var(--text-primary);
    font-weight: 700;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--accent-primary);
    flex-shrink: 0;
}

.logo-subtitle {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-right: 0.5rem;
}

/* Navigation */
.main-nav {
    display: flex;
    gap: 1.5rem;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.nav-link.active {
    color: var(--accent-primary);
    background: rgba(88, 166, 255, 0.1);
}

a.logo {
    text-decoration: none;
    color: inherit;
}

/* Main Content */
.main-content {
    padding: 2rem 0;
}

/* Calculator Card */
.calculator-card {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.calculator-card h2 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 1.8rem;
    transition: var(--transition);
}

.description {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 1.05rem;
    transition: var(--transition);
}

.description::before {
    content: '✨';
    display: inline-block;
    margin-left: 8px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.1); }
}

/* Input Section */
.input-section {
    margin-bottom: 2rem;
}

.arabic-input {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 1.2rem;
    font-family: 'Arial', sans-serif;
    resize: vertical;
    transition: var(--transition);
    direction: rtl;
    background: var(--bg-input);
    color: var(--text-primary);
}

.arabic-input:focus {
    outline: none;
    border-color: var(--border-focus);
}

.arabic-input::placeholder {
    color: var(--text-muted);
}

.options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

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

/* Calculate Button */
.btn-calculate {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(52, 152, 219, 0.3);
}

.btn-calculate:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(52, 152, 219, 0.4);
}

.btn-calculate:active {
    transform: translateY(0);
}

/* Results Section */
.results-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border-color);
    transition: var(--transition);
}

.result-header h3 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin-bottom: 1rem;
    transition: var(--transition);
}

.main-result {
    background: var(--bg-result);
    color: var(--text-light);
    padding: 1.25rem 1.5rem;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.result-label {
    font-size: 0.95rem;
    margin-bottom: 0.4rem;
    opacity: 0.95;
}

.result-value {
    font-size: 2.25rem;
    font-weight: 700;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    letter-spacing: 0.05em;
    font-variant-numeric: tabular-nums;
}

/* Factorization */
.factorization {
    background: var(--bg-factorization);
    color: var(--text-primary);
    padding: 1.25rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    text-align: center;
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
    transition: var(--transition);
    border: 1px solid var(--border-color);
}

/* Details Breakdown */
.details-breakdown {
    background: var(--bg-details);
    padding: 1.5rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.details-breakdown table {
    width: 100%;
    border-collapse: collapse;
}

.details-breakdown th,
.details-breakdown td {
    padding: 0.75rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: var(--transition);
}

.details-breakdown th {
    background: #3498db;
    color: #fff;
    font-weight: 600;
}

.details-breakdown tr:hover {
    background: var(--bg-secondary);
}

/* Mizan Commands - Collapsible */
.mizan-commands-wrapper {
    margin-top: 1.5rem;
}

.mizan-toggle {
    width: 100%;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.3s ease;
    text-align: right;
}

.mizan-toggle:hover {
    background: var(--bg-card);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

.toggle-icon {
    font-size: 0.85rem;
    transition: transform 0.3s ease;
    display: inline-block;
    color: var(--accent-primary);
}

.mizan-commands {
    background: var(--bg-commands);
    color: var(--text-light);
    padding: 1.5rem;
    border-radius: 0 0 6px 6px;
    margin-top: 0.5rem;
    animation: slideDown 0.3s ease-out;
    transition: var(--transition);
}

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

.mizan-commands h4 {
    margin-bottom: 1rem;
    color: var(--text-light);
}

.command-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.command-item {
    background: var(--bg-command-item);
    padding: 0.75rem;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', 'Liberation Mono', monospace;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.command-item code {
    color: var(--text-light);
}

.copy-btn {
    background: #3498db;
    color: #fff;
    border: none;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.3s;
}

.copy-btn:hover {
    background: #2980b9;
}

/* Reference Section */
.reference-section {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.reference-section h2 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 1.8rem;
    transition: var(--transition);
}

.table-description {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

/* Abjad Grid */
.abjad-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(65px, 1fr));
    gap: 0.6rem;
    margin-top: 1.5rem;
}

.abjad-item {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 0.5rem;
    border-radius: 8px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.abjad-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    opacity: 0;
    transition: opacity 0.2s ease;
}

.abjad-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-primary);
    background: var(--bg-secondary);
}

.abjad-item:hover::before {
    opacity: 1;
}

.abjad-item .char {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
    color: var(--text-primary);
}

.abjad-item .value {
    display: block;
    font-size: 0.85rem;
    color: var(--accent-primary);
    font-weight: 600;
}

/* Info Section */
.info-section {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.info-section h2 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.8rem;
    transition: var(--transition);
}

.info-content {
    color: var(--text-secondary);
    line-height: 1.8;
    transition: var(--transition);
}

.info-content p {
    margin-bottom: 1rem;
}

.info-content ul {
    margin-right: 2rem;
    margin-bottom: 1rem;
}

.info-content li {
    margin-bottom: 0.5rem;
}

/* Footer */
.footer {
    background: var(--bg-footer);
    color: var(--text-light);
    padding: 2rem 0;
    text-align: center;
    margin-top: 3rem;
    transition: var(--transition);
}

.footer p {
    margin-bottom: 0.5rem;
    opacity: 0.9;
}

.footer-links a {
    color: #3498db;
    text-decoration: none;
    transition: color 0.3s;
}

.footer-links a:hover {
    color: #5dade2;
}

/* Responsive Design */
@media (max-width: 768px) {
    .logo {
        font-size: 1.4rem;
    }

    .logo-subtitle {
        display: none;
    }

    .main-nav {
        gap: 0.5rem;
    }

    .nav-link {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }

    .calculator-card h2,
    .reference-section h2,
    .info-section h2 {
        font-size: 1.4rem;
    }

    .result-value {
        font-size: 1.75rem;
    }

    .main-result {
        padding: 1rem;
    }

    .factorization {
        font-size: 1rem;
        padding: 1rem;
    }

    .abjad-grid {
        grid-template-columns: repeat(auto-fill, minmax(55px, 1fr));
        gap: 0.4rem;
    }

    .abjad-item {
        padding: 0.6rem 0.4rem;
    }

    .abjad-item .char {
        font-size: 1.3rem;
    }

    .abjad-item .value {
        font-size: 0.75rem;
    }

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

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

.results-section {
    animation: fadeIn 0.5s ease-out;
}

/* Loading State */
.btn-calculate.loading {
    background: #95a5a6;
    cursor: not-allowed;
}

.btn-calculate.loading::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Theme Toggle Button - Seamless */
.theme-toggle {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.3rem;
    opacity: 0.75;
}

.theme-toggle:hover {
    opacity: 1;
    transform: scale(1.15);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Dark mode: show sun icon (blue to match theme) */
.theme-toggle .icon-sun {
    display: block;
    color: var(--accent-primary);
}
.theme-toggle .icon-moon {
    display: none;
    color: var(--accent-primary);
}

/* Light mode: show moon icon */
[data-theme="light"] .theme-toggle .icon-sun {
    display: none;
}
[data-theme="light"] .theme-toggle .icon-moon {
    display: block;
}

/* Header Actions Container */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Language Switcher */
.lang-switcher {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 1rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lang-switcher:hover {
    background: var(--bg-input);
    border-color: var(--accent-primary);
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
    padding: 3rem 0;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.hero-content h1 {
    font-size: 2.2rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-weight: 700;
}

.hero-subtitle {
    font-size: 1.15rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 2rem;
    line-height: 1.7;
}

.hero-features {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
    background: var(--bg-primary);
    padding: 0.75rem 1.25rem;
    border-radius: 25px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.feature-item:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.feature-icon {
    font-size: 1.2rem;
}

@media (max-width: 768px) {
    .hero {
        padding: 2rem 0;
    }

    .hero-content h1 {
        font-size: 1.6rem;
    }

    .hero-subtitle {
        font-size: 1rem;
    }

    .hero-features {
        gap: 1rem;
    }

    .feature-item {
        font-size: 0.85rem;
        padding: 0.5rem 1rem;
    }
}
