/* ============================================================
   Hadith Image Maker — App CSS
   Apple-inspired design tokens, glass morphism, responsive
   ============================================================ */

/* ── CSS Custom Properties (Light Mode) ───────────────────── */
:root {
    --bg-body: #f5f5f7;
    --bg-glass: rgba(255, 255, 255, 0.72);
    --bg-glass-hover: rgba(255, 255, 255, 0.88);
    --border-glass: rgba(0, 0, 0, 0.04);
    --border-light: rgba(0, 0, 0, 0.06);
    --text-primary: #1d1d1f;
    --text-secondary: #424245;
    --text-tertiary: #6e6e73;
    --text-muted: #aeaeb2;

    /* Shadows — softer, more diffused */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.03), 0 1px 2px rgba(0, 0, 0, 0.02);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.02);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.03);
    --shadow-glow: 0 0 20px rgba(16, 185, 129, 0.12);
    --shadow-glass: 0 4px 24px rgba(0, 0, 0, 0.04);

    /* Timing */
    --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-out: cubic-bezier(0, 0, 0.2, 1);

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-2xl: 24px;
}

/* ── Dark Mode ────────────────────────────────────────────── */
.dark {
    --bg-body: #000000;
    --bg-glass: rgba(28, 28, 30, 0.72);
    --bg-glass-hover: rgba(44, 44, 46, 0.85);
    --border-glass: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.08);
    --text-primary: #f5f5f7;
    --text-secondary: #d1d1d6;
    --text-tertiary: #98989d;
    --text-muted: #636366;
}

/* ── Base Reset ───────────────────────────────────────────── */
*, *::before, *::after {
    -webkit-tap-highlight-color: transparent;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

/* ── Glass Morphism ───────────────────────────────────────── */
.glass {
    background: var(--bg-glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border-glass);
    box-shadow: var(--shadow-glass);
}

/* ── Background Patterns (subtler) ────────────────────────── */
.pattern-islamic {
    background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 0L20 40M0 20L40 20' stroke='%2310b981' stroke-width='0.3' opacity='0.04'/%3E%3C/svg%3E");
}

.pattern-geometric {
    background-image: url("data:image/svg+xml,%3Csvg width='48' height='48' viewBox='0 0 48 48' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M24 4L44 24L24 44L4 24Z' fill='none' stroke='%2310b981' stroke-width='0.4' opacity='0.03'/%3E%3C/svg%3E");
}

/* ── Theme Toggle Icon Visibility ─────────────────────────── */
.icon-sun { display: none; }
.icon-moon { display: inline; }
.dark .icon-sun { display: inline; }
.dark .icon-moon { display: none; }

/* ── Animations ───────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.animate-fadeIn { animation: fadeIn 0.25s var(--ease-out); }
.animate-slideUp { animation: slideUp 0.4s var(--ease-spring); }
.animate-spin { animation: spin 1s linear infinite; }

/* ── Toast Notification ───────────────────────────────────── */
.toast {
    position: fixed;
    bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    background: var(--text-primary);
    color: var(--bg-body);
    padding: 0.75rem 1.25rem;
    border-radius: 100px;
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    opacity: 0;
    transition: transform 0.4s var(--ease-spring), opacity 0.3s var(--ease-out);
    pointer-events: none;
    max-width: 90vw;
    text-align: center;
}

.toast.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* ── Template Cards ───────────────────────────────────────── */
.template-card {
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 2px solid var(--border-light);
    background: var(--bg-body);
    cursor: pointer;
    transition: border-color 0.2s var(--ease-out), transform 0.2s var(--ease-spring), box-shadow 0.2s var(--ease-out);
    outline: none;
    text-align: left;
}

.template-card:hover {
    border-color: #10b981;
    transform: scale(1.02);
    box-shadow: var(--shadow-md);
}

.template-card:focus-visible {
    box-shadow: 0 0 0 2px var(--bg-body), 0 0 0 4px #10b981;
}

.template-card:active {
    transform: scale(0.98);
}

.template-preview {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.template-preview-lines {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    width: 65%;
    opacity: 0.7;
}

.template-line-long { width: 100%; height: 3px; border-radius: 2px; }
.template-line-medium { width: 75%; height: 3px; border-radius: 2px; }
.template-line-short { width: 50%; height: 3px; border-radius: 2px; }
.template-divider { width: 30%; height: 1px; margin: 3px 0; opacity: 0.6; }
.template-line-ref { width: 40%; height: 2px; border-radius: 2px; opacity: 0.5; }

.template-info {
    padding: 0.625rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.template-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.template-desc {
    font-size: 0.6875rem;
    color: var(--text-muted);
    line-height: 1.3;
}

/* ── Share Buttons (brand colors) ─────────────────────────── */
.btn-share {
    border-radius: var(--radius-sm);
    transition: opacity 0.15s ease, transform 0.15s var(--ease-spring);
}

.btn-share:active {
    transform: scale(0.96);
}

.btn-share.whatsapp { background-color: #25d366; }
.btn-share.facebook { background-color: #1877f2; }
.btn-share.twitter { background-color: #1d1d1f; }
.dark .btn-share.twitter { background-color: #3a3a3c; }
.btn-share.telegram { background-color: #0088cc; }

/* ── Palette Swatches ─────────────────────────────────────── */
.palette-btn {
    position: relative;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s var(--ease-out), transform 0.15s var(--ease-spring), box-shadow 0.2s var(--ease-out);
    flex-shrink: 0;
    outline: none;
}

.palette-btn:hover { transform: scale(1.12); }
.palette-btn:active { transform: scale(0.95); }
.palette-btn:focus-visible { box-shadow: 0 0 0 2px var(--bg-body), 0 0 0 4px #10b981; }

.palette-btn.active {
    border-color: #10b981;
    box-shadow: var(--shadow-glow);
    transform: scale(1.05);
}

.palette-btn .sw-t, .palette-btn .sw-b {
    position: absolute;
    left: 0;
    right: 0;
    height: 50%;
}
.palette-btn .sw-t { top: 0; }
.palette-btn .sw-b { bottom: 0; }

/* ── Pill Buttons ─────────────────────────────────────────── */
.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4375rem 0.875rem;
    border-radius: 100px;
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    cursor: pointer;
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-secondary);
    transition: all 0.2s var(--ease-spring);
    outline: none;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
}

.pill:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
}

.pill:active {
    transform: scale(0.95);
}

.pill:focus-visible {
    box-shadow: 0 0 0 2px var(--bg-body), 0 0 0 4px #10b981;
}

.pill.active {
    background: #10b981;
    color: #ffffff;
    border-color: #10b981;
    box-shadow: 0 1px 4px rgba(16, 185, 129, 0.3);
}

/* ── FAQ Accordion ────────────────────────────────────────── */
.faq-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s var(--ease-spring);
}

.faq-body-inner {
    padding: 0 1.25rem 1.25rem;
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.7;
}

.faq-item.open .faq-body { max-height: 600px; }
.faq-item.open .faq-toggle i.fa-chevron-down { transform: rotate(180deg); }
.faq-toggle { transition: background 0.15s ease; }
.faq-toggle:hover { background: var(--bg-glass-hover); }

/* ── Form Controls ────────────────────────────────────────── */
.form-input,
.form-select,
.form-textarea {
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-md);
    background: var(--bg-body);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.5;
    transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
    outline: none;
    width: 100%;
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

.form-textarea {
    resize: vertical;
    min-height: 5rem;
}

/* ── Palette Group Labels ─────────────────────────────────── */
.palette-group-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
}

/* ── No-underline Links ───────────────────────────────────── */
a.no-underline { text-decoration: none; }

/* ── Selection Color ──────────────────────────────────────── */
::selection {
    background: rgba(16, 185, 129, 0.2);
    color: var(--text-primary);
}

/* ── Scrollbar (Apple-style subtle) ───────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Firefox */
* { scrollbar-width: thin; scrollbar-color: var(--border-light) transparent; }

/* ── Skip to Content (a11y) ───────────────────────────────── */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 999;
    padding: 0.5rem 1rem;
    background: #10b981;
    color: #ffffff;
    font-weight: 600;
    border-radius: 0 0 0.5rem 0;
}
.skip-link:focus { left: 0; }

/* ── Mobile-first responsive helpers ──────────────────────── */

/* Touch-friendly minimum tap targets */
@media (pointer: coarse) {
    .pill {
        min-height: 44px;
        padding: 0.5rem 1rem;
    }

    .palette-btn {
        width: 2.75rem;
        height: 2.75rem;
    }

    .faq-toggle {
        min-height: 52px;
    }

    .btn-share {
        min-height: 44px;
        padding: 0.5rem 1rem;
    }
}

/* Smooth iOS momentum scrolling */
.overflow-y-auto,
#editorModalBody {
    -webkit-overflow-scrolling: touch;
}

/* Safe area insets for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ── Tab Navigation ───────────────────────────────────────── */
.tab-nav-wrapper {
    position: relative;
}

.tab-nav {
    display: flex;
    gap: 4px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border-glass);
    border-radius: 100px;
    padding: 4px;
    overflow-x: auto;
    scrollbar-width: none;
}

.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0.5rem 1rem;
    border-radius: 100px;
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.25s var(--ease-spring);
    white-space: nowrap;
    outline: none;
    -webkit-user-select: none;
    user-select: none;
    min-height: 40px;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn:active {
    transform: scale(0.97);
}

.tab-btn.active {
    background: var(--text-primary);
    color: var(--bg-body);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.tab-btn:focus-visible {
    box-shadow: 0 0 0 2px var(--bg-body), 0 0 0 4px #10b981;
}

@media (pointer: coarse) {
    .tab-btn {
        min-height: 44px;
        padding: 0.5rem 1.25rem;
    }
}

/* ── Tab Panels ───────────────────────────────────────────── */
.tab-panel {
    display: none;
    animation: fadeIn 0.2s var(--ease-out);
}

.tab-panel.active {
    display: block;
}

/* ── Control Labels ───────────────────────────────────────── */
.control-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

/* ── Action Buttons ───────────────────────────────────────── */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    border-radius: 100px;
    border: none;
    cursor: pointer;
    transition: all 0.2s var(--ease-spring);
    outline: none;
    white-space: nowrap;
    min-height: 40px;
}

.action-btn:active {
    transform: scale(0.95);
}

.action-btn:focus-visible {
    box-shadow: 0 0 0 2px var(--bg-body), 0 0 0 4px #10b981;
}

.action-btn-primary {
    background: #10b981;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

.action-btn-primary:hover {
    background: #059669;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.action-btn-accent {
    background: #f59e0b;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
}

.action-btn-accent:hover {
    background: #d97706;
}

.action-btn-glass {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
}

.action-btn-glass:hover {
    background: var(--bg-glass-hover);
}

.action-btn-ghost {
    background: transparent;
    color: var(--text-tertiary);
    padding: 0.5rem 0.75rem;
}

.action-btn-ghost:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
}

@media (pointer: coarse) {
    .action-btn {
        min-height: 44px;
        padding: 0.5rem 1.25rem;
    }
}

/* ── Scrollbar Hide Utility ───────────────────────────────── */
.scrollbar-hide {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* ── Skeleton Loading States ──────────────────────────────── */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(90deg,
        var(--border-light) 25%,
        var(--bg-glass-hover) 50%,
        var(--border-light) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

/* Palette container skeleton — show placeholder until JS renders */
#paletteContainer:empty {
    min-height: 200px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#paletteContainer:empty::before,
#paletteContainer:empty::after {
    content: '';
    height: 16px;
    width: 120px;
    border-radius: 4px;
    background: linear-gradient(90deg,
        var(--border-light) 25%,
        var(--bg-glass-hover) 50%,
        var(--border-light) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

/* Pill containers skeleton */
#fontPills:empty,
#ratioPills:empty,
#sizePills:empty,
#alignPills:empty,
#borderPills:empty,
#layoutPills:empty {
    min-height: 40px;
    border-radius: 100px;
    background: linear-gradient(90deg,
        var(--border-light) 25%,
        var(--bg-glass-hover) 50%,
        var(--border-light) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

/* ── Mobile Bottom Toolbar ────────────────────────────────── */
.mobile-tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 4px 10px;
    font-size: 0.625rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: color 0.15s ease;
    outline: none;
    -webkit-user-select: none;
    user-select: none;
}

.mobile-tab-btn i {
    font-size: 1.125rem;
    transition: transform 0.2s var(--ease-spring);
}

.mobile-tab-btn.active {
    color: #10b981;
}

.mobile-tab-btn:active i {
    transform: scale(0.9);
}

/* Safe area bottom for notched devices */
.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Mobile Bottom Sheet ──────────────────────────────────── */
#mobileSheet .glass {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
