/* =============================================
   Ahmed Habib — Premium Theme
   ============================================= */

/* --- CSS Variables (Light Mode) --- */
:root {
    --color-bg: #ffffff;
    --color-bg-alt: #f8f9fa;
    --color-bg-card: #ffffff;
    --color-surface: #f1f3f5;
    --color-border: #e2e6ea;
    --color-text: #1a1a2e;
    --color-text-secondary: #6c757d;
    --color-text-muted: #adb5bd;
    --color-primary: #4361ee;
    --color-primary-hover: #3a56d4;
    --color-primary-light: rgba(67, 97, 238, 0.1);
    --color-accent: #f72585;
    --color-success: #06d6a0;
    --color-warning: #ffd166;
    --color-danger: #ef476f;
    --color-code-bg: #f4f5f7;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --font-display: 'Inter', var(--font-sans);
    --max-width: 1200px;
    --content-width: 780px;
    --transition: 0.2s ease;
    --header-height: 72px;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
    --color-bg: #0f0f1a;
    --color-bg-alt: #16162a;
    --color-bg-card: #1a1a2e;
    --color-surface: #222240;
    --color-border: #2d2d50;
    --color-text: #e8e8f0;
    --color-text-secondary: #a0a0b8;
    --color-text-muted: #6c6c8a;
    --color-primary: #5b7cfa;
    --color-primary-hover: #7b96ff;
    --color-primary-light: rgba(91, 124, 250, 0.15);
    --color-code-bg: #1e1e36;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.7;
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
}

a { color: var(--color-primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--color-primary-hover); }

img { max-width: 100%; height: auto; display: block; }

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-text);
}

h1 { font-size: 2.5rem; letter-spacing: -0.02em; }
h2 { font-size: 2rem; letter-spacing: -0.01em; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }

/* --- Utility Classes --- */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 1.5rem; }
.container-narrow { max-width: var(--content-width); margin: 0 auto; padding: 0 1.5rem; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.gap-4 { gap: 2rem; }
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-secondary); }
.text-small { font-size: 0.875rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--color-primary-hover);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}
.btn-secondary:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}
.btn-danger:hover { opacity: 0.9; }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.8rem 1.8rem; font-size: 1rem; }
.btn-ghost { background: transparent; color: var(--color-primary); }
.btn-ghost:hover { background: var(--color-primary-light); color: var(--color-primary); }

/* --- Cards --- */
.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-img {
    aspect-ratio: 16/9;
    object-fit: cover;
    width: 100%;
}

.card-body { padding: 1.25rem; }
.card-body h3 { font-size: 1.15rem; margin-bottom: 0.5rem; }
.card-body h3 a { color: var(--color-text); }
.card-body h3 a:hover { color: var(--color-primary); }
.card-meta { display: flex; gap: 1rem; font-size: 0.8rem; color: var(--color-text-secondary); margin-bottom: 0.5rem; }
.card-excerpt { font-size: 0.9rem; color: var(--color-text-secondary); line-height: 1.6; }

/* --- Header --- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    height: var(--header-height);
    backdrop-filter: blur(12px);
}

[data-theme="dark"] .site-header {
    background: rgba(15, 15, 26, 0.92);
}

.site-header .container { height: 100%; }

.site-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.site-logo {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--color-text);
    letter-spacing: -0.02em;
}
.site-logo span { color: var(--color-primary); }
.site-logo:hover { color: var(--color-text); }

.nav-links { display: flex; align-items: center; gap: 2rem; list-style: none; }
.nav-links a {
    color: var(--color-text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    transition: color var(--transition);
}
.nav-links a:hover, .nav-links a.active { color: var(--color-primary); }

.nav-actions { display: flex; align-items: center; gap: 0.75rem; }

/* Mobile Menu */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--color-text);
}

.mobile-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: currentColor;
    margin: 5px 0;
    transition: var(--transition);
}

/* --- Theme Toggle --- */
.theme-toggle {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    font-size: 1.1rem;
}
.theme-toggle:hover { border-color: var(--color-primary); }

/* --- Hero --- */
.hero {
    padding: 5rem 0 4rem;
    text-align: center;
    background: linear-gradient(135deg, var(--color-primary-light) 0%, transparent 50%);
}

.hero h1 {
    font-size: 3.2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--color-text) 0%, var(--color-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* --- Section --- */
.section { padding: 4rem 0; }
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}
.section-header h2 { font-size: 1.6rem; }

/* --- Post Grid --- */
.post-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

/* --- Featured Post Card --- */
.featured-card {
    grid-column: span 3;
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition);
}
.featured-card:hover { box-shadow: var(--shadow-lg); }
.featured-card .card-body { padding: 2rem; display: flex; flex-direction: column; justify-content: center; }
.featured-card h3 { font-size: 1.5rem; margin-bottom: 0.75rem; }

/* --- Tags/Badges --- */
.tag {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 50px;
    background: var(--color-primary-light);
    color: var(--color-primary);
}
.tag:hover { background: var(--color-primary); color: #fff; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-success { background: rgba(6,214,160,0.1); color: var(--color-success); }
.badge-warning { background: rgba(255,209,102,0.15); color: #c29000; }
.badge-danger { background: rgba(239,71,111,0.1); color: var(--color-danger); }
.badge-info { background: var(--color-primary-light); color: var(--color-primary); }

/* --- Forms --- */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.4rem;
    color: var(--color-text);
}
.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

textarea.form-control { resize: vertical; min-height: 120px; }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%236c757d'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

/* --- Alerts --- */
.alert {
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    border: 1px solid transparent;
}
.alert-success { background: rgba(6,214,160,0.1); border-color: rgba(6,214,160,0.2); color: #05a77d; }
.alert-error { background: rgba(239,71,111,0.1); border-color: rgba(239,71,111,0.2); color: #d94060; }
.alert-warning { background: rgba(255,209,102,0.1); border-color: rgba(255,209,102,0.2); color: #b08600; }
.alert-info { background: var(--color-primary-light); border-color: rgba(67,97,238,0.2); color: var(--color-primary); }

[data-theme="dark"] .alert-success { color: var(--color-success); }
[data-theme="dark"] .alert-error { color: #ff6b8a; }

/* --- Search --- */
.search-box {
    position: relative;
    max-width: 320px;
}
.search-box input {
    padding-left: 2.5rem;
    width: 100%;
}
.search-box svg {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
}

/* Search toggle button in header */
.search-toggle {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--color-text-secondary);
}
.search-toggle:hover { border-color: var(--color-primary); color: var(--color-primary); }

/* Search overlay */
.search-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 15vh 1.5rem 2rem;
}
.search-overlay-content {
    width: 100%;
    max-width: 560px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.search-overlay-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}
.search-overlay-form svg {
    flex-shrink: 0;
    color: var(--color-text-muted);
}
.search-overlay-form input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1rem;
    font-family: var(--font-sans);
    color: var(--color-text);
}
.search-overlay-form input::placeholder { color: var(--color-text-muted); }
.search-overlay-form kbd {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.4rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
    background: var(--color-surface);
    flex-shrink: 0;
}

.search-overlay-results {
    max-height: 50vh;
    overflow-y: auto;
}
.search-overlay-results:empty { display: none; }

.search-result-item {
    display: block;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
    text-decoration: none;
    transition: background var(--transition);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--color-bg-alt); color: var(--color-text); }
.search-result-item h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.15rem; }
.search-result-item p { font-size: 0.8rem; color: var(--color-text-secondary); line-height: 1.5; }

.search-no-results {
    padding: 2rem 1.25rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem 0;
}
.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
}
.pagination a {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}
.pagination a:hover { border-color: var(--color-primary); color: var(--color-primary); }
.pagination .active {
    background: var(--color-primary);
    color: #fff;
    border: 1px solid var(--color-primary);
}

/* --- Footer --- */
.site-footer {
    border-top: 1px solid var(--color-border);
    padding: 3rem 0;
    margin-top: 4rem;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}
.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 2rem;
}
.footer-col h4 { color: var(--color-text); margin-bottom: 1rem; font-size: 0.95rem; }
.footer-col ul { list-style: none; }
.footer-col li { margin-bottom: 0.5rem; }
.footer-col a { color: var(--color-text-secondary); }
.footer-col a:hover { color: var(--color-primary); }
.footer-bottom {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
    text-align: center;
    color: var(--color-text-muted);
}

/* --- Newsletter --- */
.newsletter-form {
    display: flex;
    gap: 0.5rem;
    max-width: 420px;
}
.newsletter-form input { flex: 1; }

/* --- Table --- */
.table-wrapper { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.table th {
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
    padding: 0.75rem 1rem;
    border-bottom: 2px solid var(--color-border);
}
.table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.table tr:hover td { background: var(--color-bg-alt); }

/* --- FAQ Accordion --- */
.faq-section { margin-top: 3rem; padding-top: 2.5rem; border-top: 1px solid var(--color-border); }
.faq-section h2 { font-size: 1.5rem; margin-bottom: 1.25rem; }

.faq-list { display: flex; flex-direction: column; gap: 0.5rem; }

.faq-item {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-card);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.faq-item[open] {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 1px var(--color-primary-light);
}

.faq-item summary {
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    user-select: none;
    transition: color var(--transition);
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::marker { display: none; content: ""; }

.faq-item summary::after {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--color-text-secondary);
    border-bottom: 2px solid var(--color-text-secondary);
    transform: rotate(-45deg);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}
.faq-item[open] summary::after {
    transform: rotate(45deg);
}
.faq-item summary:hover { color: var(--color-primary); }

.faq-item .faq-answer {
    padding: 0 1.25rem 1.125rem;
    font-size: 0.925rem;
    line-height: 1.75;
    color: var(--color-text-secondary);
}

/* --- Tools Grid --- */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* --- Search Form --- */
.search-form { max-width: 500px; }

/* --- Error Page --- */
.error-code { font-size: 6rem; font-weight: 800; color: var(--color-primary); margin-bottom: 0.5rem; }
.error-message { font-size: 1.3rem; color: var(--color-text-secondary); margin-bottom: 2rem; }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .post-grid { grid-template-columns: repeat(2, 1fr); }
    .featured-card { grid-column: span 2; }
    .footer-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    /* Header */
    :root { --header-height: 56px; }
    .site-logo { font-size: 1.1rem; }
    .nav-links { display: none; }
    .mobile-toggle { display: block; }
    .nav-links.open {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: var(--header-height);
        left: 0;
        right: 0;
        background: var(--color-bg);
        border-bottom: 1px solid var(--color-border);
        padding: 1rem 1.5rem;
        box-shadow: var(--shadow-md);
        z-index: 99;
    }
    .nav-actions .btn { display: none; }
    .search-toggle { width: 34px; height: 34px; }
    .search-toggle svg { width: 16px; height: 16px; }
    .theme-toggle { width: 34px; height: 34px; font-size: 1rem; }
    .search-overlay { padding: 10vh 1rem 2rem; }

    /* Hero */
    .hero { padding: 3rem 0 2.5rem; }
    .hero h1 { font-size: 2rem; }
    .hero p { font-size: 0.95rem; }
    .hero .btn-lg { padding: 0.6rem 1.2rem; font-size: 0.85rem; }

    /* Layout */
    .section { padding: 2rem 0; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
    .section-header h2 { font-size: 1.3rem; }
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.5rem; }

    /* Grids */
    .post-grid { grid-template-columns: 1fr; }
    .featured-card { grid-column: span 1; grid-template-columns: 1fr; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .footer-grid { grid-template-columns: 1fr; }
    .tools-grid { grid-template-columns: 1fr; }

    /* Cards */
    .card-body { padding: 1rem; }
    .card-body h3 { font-size: 1.05rem; }
    .featured-card .card-body { padding: 1.25rem; }
    .featured-card h3 { font-size: 1.25rem; }

    /* Search */
    .search-box { max-width: 100%; }
    .search-form { max-width: 100%; }

    /* Forms */
    .newsletter-form { flex-direction: column; }

    /* Error page */
    .error-code { font-size: 4rem; }
    .error-message { font-size: 1.05rem; margin-bottom: 1.5rem; }

    /* FAQ */
    .faq-section { margin-top: 2rem; padding-top: 1.5rem; }
    .faq-section h2 { font-size: 1.25rem; }
    .faq-item summary { padding: 0.85rem 1rem; font-size: 0.9rem; }
    .faq-item .faq-answer { padding: 0 1rem 1rem; font-size: 0.875rem; }

    /* Footer */
    .site-footer { padding: 2rem 0; margin-top: 2rem; }
    .footer-col h4 { margin-bottom: 0.75rem; }
}

@media (max-width: 480px) {
    html { font-size: 15px; }
    .container, .container-narrow { padding: 0 1rem; }
    .hero h1 { font-size: 1.6rem; }
    .hero p { font-size: 0.875rem; margin-bottom: 1.5rem; }
    .hero .flex-center { flex-direction: column; }
    .hero .btn-lg { width: 100%; justify-content: center; }
    .error-code { font-size: 3rem; }
    .section-header h1 { font-size: 1.5rem; }
}
