/* ======================================
   Kalam Academy — Custom CSS
   Mobile-First App-Like Design System
   ====================================== */

/* --- Google Fonts Import --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Noto+Nastaliq+Urdu:wght@400;700&display=swap');

/* --- CSS Custom Properties --- */
:root {
    --primary: #059669;
    --primary-hover: #047857;
    --primary-light: #ecfdf5;
    --primary-border: #a7f3d0;
    --primary-glow: rgba(5, 150, 105, 0.15);

    --amber: #d97706;
    --amber-light: #fffbeb;
    --amber-border: #fde68a;

    --purple: #7c3aed;
    --purple-light: #f5f3ff;
    --purple-border: #ddd6fe;

    --bg-body: #f1f5f9;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    --text-primary: #0f172a;
    --text-body: #334155;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --font-urdu: 'Noto Nastaliq Urdu', 'Jameel Noori Nastaleeq', 'Urdu Typesetting', serif;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);

    --transition: 0.2s ease;

    /* Safe area padding for mobile notches */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-body);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    padding-bottom: calc(70px + var(--safe-bottom)); /* space for bottom nav on mobile */
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* --- Urdu / Nastaliq Font --- */
.urdu-font,
[dir="rtl"] .urdu-content {
    font-family: var(--font-urdu);
    line-height: 2.4;
    direction: rtl;
    text-align: right;
}

/* --- Links --- */
a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover { color: var(--primary-hover); }
a:active { opacity: 0.8; }

/* === HEADER — App-style sticky glass header === */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background var(--transition);
}
@media (min-width: 768px) {
    .app-header { height: 64px; padding: 0 1.5rem; }
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}
.app-header__logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #059669, #10b981);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1rem;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
    flex-shrink: 0;
}
.app-header__title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}
.app-header__subtitle {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.app-header__nav {
    display: none;
}
@media (min-width: 768px) {
    .app-header__nav {
        display: flex;
        align-items: center;
        gap: 1.5rem;
    }
    .app-header__nav a {
        font-size: 0.8125rem;
        font-weight: 600;
        color: var(--text-muted);
        transition: color var(--transition);
    }
    .app-header__nav a:hover,
    .app-header__nav a.active {
        color: var(--primary);
    }
}

.app-header__actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* === MOBILE BOTTOM NAVIGATION BAR === */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: calc(60px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
}
@media (min-width: 768px) {
    .mobile-bottom-nav { display: none; }
    body { padding-bottom: 0; }
}

.mobile-bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 12px;
    color: var(--text-light);
    font-size: 0.625rem;
    font-weight: 600;
    text-decoration: none;
    transition: color var(--transition);
    position: relative;
}
.mobile-bottom-nav__item i {
    font-size: 1.125rem;
    transition: transform var(--transition);
}
.mobile-bottom-nav__item.active {
    color: var(--primary);
}
.mobile-bottom-nav__item.active i {
    transform: scale(1.1);
}
.mobile-bottom-nav__item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 4px 4px;
}

/* === CARDS === */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}
.card:hover {
    box-shadow: var(--shadow-md);
}
.card:active {
    transform: scale(0.985);
}

/* === BADGES === */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge--emerald { background: var(--primary-light); color: var(--primary); border: 1px solid var(--primary-border); }
.badge--amber   { background: var(--amber-light);   color: var(--amber);   border: 1px solid var(--amber-border); }
.badge--purple  { background: var(--purple-light);   color: var(--purple);  border: 1px solid var(--purple-border); }
.badge--slate   { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: none;
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 600;
    border-radius: var(--radius-full);
    transition: all var(--transition);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.btn:active {
    transform: scale(0.96);
}

.btn--primary {
    background: linear-gradient(135deg, #059669, #10b981);
    color: white;
    font-size: 0.75rem;
    padding: 0.5rem 1.125rem;
    box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
}
.btn--primary:hover {
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.35);
}

.btn--outline {
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 0.45rem 1rem;
    border: 1px solid var(--border);
}
.btn--outline:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn--ghost {
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
}
.btn--ghost:hover {
    background: #f1f5f9;
    color: var(--text-body);
}

.btn--icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.875rem;
}
.btn--icon:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-border);
}

/* === SHER / VERSE CARDS === */
.sher-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1rem 1rem 2.75rem;
    position: relative;
    transition: all var(--transition);
}
.sher-card:hover {
    border-color: var(--primary-border);
    box-shadow: var(--shadow-sm);
}

.sher-card__number {
    position: absolute;
    top: 0.875rem;
    left: 0.75rem;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.6875rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sher-card__urdu {
    font-family: var(--font-urdu);
    font-size: 1.25rem;
    line-height: 2.3;
    color: var(--text-primary);
    text-align: center;
    direction: rtl;
}
@media (min-width: 640px) {
    .sher-card__urdu { font-size: 1.4rem; }
}

.sher-card__roman {
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
    line-height: 1.55;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border-light);
}

.sher-card__actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.375rem;
    margin-top: 0.625rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border-light);
}

/* === FORM FIELDS (Submit Editor) === */
.form-section {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1rem;
    margin-bottom: 0.875rem;
    border: 1px solid var(--border);
}

.form-section__title {
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    margin-bottom: 0.75rem;
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--border);
}
.form-section__title--emerald { color: var(--primary); }
.form-section__title--amber   { color: var(--amber);   }
.form-section__title--purple  { color: var(--purple);  }

.field-group {
    position: relative;
    margin-bottom: 0.625rem;
}

.field-group__label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 2px;
    display: block;
}

.field-group__input {
    width: 100%;
    font-size: 0.8125rem;
    font-family: var(--font-sans);
    padding: 0.5rem 2.25rem 0.5rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text-primary);
    transition: all var(--transition);
}
.field-group__input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    outline: none;
}

.field-group--rtl .field-group__input {
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    text-align: right;
    direction: rtl;
    font-family: var(--font-urdu);
    line-height: 2;
}
.field-group--rtl .field-group__label {
    text-align: right;
}

.field-group__paste-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: #f8fafc;
    border: 1px solid var(--border);
    color: var(--text-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.625rem;
    cursor: pointer;
    z-index: 5;
    transition: all var(--transition);
}
.field-group--rtl .field-group__paste-btn {
    left: 6px;
    right: auto;
}
.field-group__paste-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-border);
}

.auto-filled {
    background-color: #f0fdf4 !important;
    border-color: #86efac !important;
}

textarea.field-group__input {
    resize: vertical;
    min-height: 140px;
    line-height: 1.7;
}
textarea.field-group__input.urdu-font {
    line-height: 2.2;
}

/* === POETICS METRICS CARD === */
.poetics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
}
@media (max-width: 480px) {
    .poetics-grid { grid-template-columns: 1fr; }
}

.poetics-item {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.625rem;
}
.poetics-item__label {
    font-size: 0.5625rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--text-light);
    margin-bottom: 2px;
}
.poetics-item__value {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}
.poetics-item__value.urdu-font {
    font-size: 0.875rem;
}

/* === VIEW MODE TOGGLE === */
.view-toggle {
    display: inline-flex;
    background: #f1f5f9;
    padding: 3px;
    border-radius: var(--radius-md);
    gap: 2px;
}
.view-toggle__btn {
    padding: 0.35rem 0.75rem;
    border-radius: 9px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-sans);
}
.view-toggle__btn.active {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow-xs);
}

/* === MODAL === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
@media (min-width: 640px) {
    .modal-overlay {
        align-items: center;
        padding: 1.5rem;
    }
}

.modal-content {
    background: white;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.25rem;
    box-shadow: var(--shadow-lg);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.modal-overlay.open .modal-content {
    transform: translateY(0);
}
@media (min-width: 640px) {
    .modal-content {
        border-radius: var(--radius-xl);
        max-width: 560px;
        transform: translateY(20px) scale(0.98);
    }
    .modal-overlay.open .modal-content {
        transform: translateY(0) scale(1);
    }
}

.modal-handle {
    width: 36px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 4px;
    margin: 0 auto 0.875rem;
}
@media (min-width: 640px) {
    .modal-handle { display: none; }
}

/* === ARCHIVE GRID === */
.archive-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}
@media (min-width: 640px) {
    .archive-grid { grid-template-columns: 1fr 1fr; gap: 1rem; }
}
@media (min-width: 1024px) {
    .archive-grid { grid-template-columns: 1fr 1fr 1fr; }
}

.archive-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all var(--transition);
}
.archive-card:hover {
    border-color: var(--primary-border);
    box-shadow: var(--shadow-md);
}
.archive-card:active {
    transform: scale(0.985);
}

/* === SEARCH BAR === */
.search-bar {
    display: flex;
    gap: 0.5rem;
}
.search-bar__input {
    flex: 1;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.15);
    color: white;
    font-size: 0.8125rem;
    font-family: var(--font-sans);
    backdrop-filter: blur(4px);
}
.search-bar__input::placeholder { color: rgba(255,255,255,0.6); }
.search-bar__input:focus {
    outline: none;
    border-color: rgba(255,255,255,0.5);
    background: rgba(255,255,255,0.2);
}
.search-bar__btn {
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-md);
    background: #f59e0b;
    color: #0f172a;
    font-weight: 700;
    font-size: 0.8125rem;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all var(--transition);
    font-family: var(--font-sans);
}
.search-bar__btn:hover { background: #eab308; }

/* === UTILITIES === */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding-left: 1rem;
    padding-right: 1rem;
}
.container--narrow {
    max-width: 680px;
}
.container--submit {
    max-width: 540px;
}

.text-gradient {
    background: linear-gradient(135deg, #059669, #10b981);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* === SKELETON LOADING (placeholder animations) === */
@keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}
.skeleton {
    background: linear-gradient(90deg, #f1f5f9 0px, #e8edf2 50px, #f1f5f9 100px);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

/* === PWA / App Feel Touches === */
@supports (padding: env(safe-area-inset-top)) {
    .app-header {
        padding-top: var(--safe-top);
        height: calc(56px + var(--safe-top));
    }
    @media (min-width: 768px) {
        .app-header { height: calc(64px + var(--safe-top)); }
    }
}

/* Prevent overscroll bounce on iOS */
body {
    overscroll-behavior-y: none;
}

/* Selection color */
::selection {
    background: rgba(5, 150, 105, 0.15);
    color: inherit;
}

/* Print: hide nav */
@media print {
    .app-header,
    .mobile-bottom-nav { display: none !important; }
    body { padding-bottom: 0 !important; }
}
