/**
 * Khatmah - CMU-Q MSA
 * Custom overrides, glassmorphism, scrollbar hiding
 */

:root {
    --cmu-red: #C41230;
    --cmu-gold: #F2A900;
    --slate-900: #0f172a;
    --slate-800: #1e293b;
    --slate-700: #334155;
    --slate-600: #475569;
    --slate-500: #64748b;
    --slate-400: #94a3b8;
    --slate-300: #cbd5e1;
    --slate-100: #f1f5f9;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
}

.app-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--slate-900);
    color: var(--slate-100);
    font-family: Inter, system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.app-header {
    text-align: center;
    padding: 1.25rem 0;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}

.app-logo {
    width: 5rem;
    height: 5rem;
    display: block;
    margin: 0 auto 0.5rem;
    border-radius: 1rem;
    object-fit: contain;
}

.app-title {
    margin: 0;
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-weight: 700;
    color: var(--slate-100);
}

.app-subtitle {
    margin: 0.25rem 0 0;
    font-size: 0.875rem;
    color: var(--slate-500);
}

.mode-toggle-row {
    display: flex;
    justify-content: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}

.progress-shell {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}

.progress-content {
    max-width: 42rem;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.progress-labels {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.progress-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--slate-300);
}

.progress-completed {
    font-size: 0.75rem;
    color: var(--slate-500);
}

.progress-track {
    flex: 1;
    height: 0.5rem;
    background: var(--slate-800);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--cmu-red), var(--cmu-gold));
    border-radius: 999px;
    transition: width 0.3s ease-out;
}

.controls-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}

@media (min-width: 640px) {
    .controls-bar {
        flex-direction: row;
    }
}

.control-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-label {
    font-size: 0.75rem;
    color: var(--slate-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.khatmah-input-group {
    display: flex;
    align-items: center;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid var(--slate-600);
}

.stepper-btn {
    width: 2.25rem;
    height: 2.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    font-weight: 700;
}

.touch-stepper {
    min-width: 44px;
    min-height: 44px;
}

@media (min-width: 640px) {
    .touch-stepper {
        min-width: 2.25rem;
        min-height: 2.25rem;
    }
}

.duration-value {
    width: 3.5rem;
    padding: 0.5rem 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--cmu-gold);
    background: rgba(30, 41, 59, 0.5);
}

.khatmah-count-value {
    width: 3rem;
    padding: 0.5rem 0;
    font-size: 1.125rem;
    font-weight: 600;
    background: rgba(30, 41, 59, 0.5);
}

.day-display {
    width: 2rem;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--cmu-gold);
}

.ramadan-banner {
    margin: 0.75rem 1rem 0;
    padding: 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(217, 119, 6, 0.3);
    color: #fde68a;
    font-size: 0.875rem;
    text-align: center;
}

.hidden {
    display: none !important;
}

/* --- Day-card content (semantic) --- */
.day-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.day-card-day-num {
    font-size: 1.125rem;
    line-height: 1.75rem;
    font-weight: 700;
    color: var(--slate-300);
}

.day-card.current-day .day-card-day-num {
    color: var(--cmu-red);
}

.day-card-check {
    display: none;
    font-size: 1.25rem;
    line-height: 1.75rem;
    color: #4ade80;
}

.day-card.completed .day-card-check {
    display: inline;
}

.day-card-juz {
    color: var(--cmu-red);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.day-card-pages {
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--slate-500);
}

.day-card-khatmah {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--slate-500);
}

/* --- Safe area (notched phones, home indicator) --- */
.safe-area-padding {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.safe-area-top {
    padding-top: max(0.75rem, env(safe-area-inset-top));
}

/* --- Khatmahs display (span, no native spinners) --- */
.khatmah-value {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Custom +/- Buttons --- */
.khatmah-btn {
    background: rgba(30, 41, 59, 0.6);
    color: #94a3b8;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.khatmah-btn:hover {
    background: rgba(196, 18, 48, 0.2);
    color: #C41230;
}

.khatmah-btn:active {
    background: rgba(196, 18, 48, 0.3);
}

/* Larger touch targets on mobile (44px min) */
.khatmah-btn-touch {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* --- Glassmorphism --- */
.glass-bar {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.glass-card {
    background: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* --- Carousel: Scroll Snap + Drag --- */
.carousel-container {
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    cursor: grab;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.carousel-container:active {
    cursor: grabbing;
}

.carousel-inner {
    display: flex;
    gap: 1rem;
    padding: 1.5rem 7.5vw;
    min-height: min-content;
    width: max-content;
}

@media (min-width: 768px) {
    .carousel-inner {
        padding-left: calc(50% - 10rem);
        padding-right: calc(50% - 10rem);
    }
}

.carousel-card {
    flex-shrink: 0;
    width: 85vw;
    max-width: 85vw;
    scroll-snap-align: center;
}

@media (min-width: 768px) {
    .carousel-card {
        width: 20rem;
        max-width: 20rem;
    }
}

/* --- Day Card: Glassmorphism --- */
.day-card {
    background: rgba(30, 41, 59, 0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 1rem;
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.3s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
    min-height: 7rem;
}

@media (max-width: 767px) {
    .day-card {
        padding: 1.5rem;
        min-height: 8rem;
    }
}

.day-card:hover {
    border-color: rgba(148, 163, 184, 0.3);
}

.day-card.current-day {
    border-color: #C41230;
    box-shadow: 0 0 24px rgba(196, 18, 48, 0.25);
    transform: scale(1.02);
}

.day-card.completed {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.4);
}

.day-card.completed.current-day {
    border-color: #C41230;
}

/* --- Hide Scrollbar (keep functionality) --- */
.carousel-container {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.carousel-container::-webkit-scrollbar {
    display: none;
}

/* --- Mode toggle --- */
.mode-toggle {
    display: inline-flex;
    border-radius: 0.75rem;
    border: 1px solid rgba(100, 116, 139, 0.4);
    overflow: hidden;
    background: rgba(30, 41, 59, 0.5);
}

.mode-toggle-btn {
    padding: 0.5rem 1.125rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #94a3b8;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mode-toggle-btn:hover {
    color: #e2e8f0;
}

.mode-toggle-btn.mode-toggle-active {
    background: rgba(196, 18, 48, 0.3);
    color: #f8fafc;
}

/* --- My schedule: plan settings --- */
.plan-settings {
    margin: 0.75rem 1rem 0;
    padding: 1rem 1.125rem 1.125rem;
    max-width: 28rem;
    margin-left: auto;
    margin-right: auto;
    border-radius: 1rem;
    background: rgba(30, 41, 59, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(148, 163, 184, 0.12);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.plan-settings-title {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #94a3b8;
    margin: 0 0 0.875rem;
    text-align: center;
}

.plan-settings-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (min-width: 480px) {
    .plan-settings-grid {
        flex-direction: row;
        align-items: flex-end;
        gap: 1.25rem;
    }

    .plan-field-date {
        flex: 1;
        min-width: 0;
    }

    .plan-field-duration {
        flex: 1.2;
    }
}

.plan-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.plan-field-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #64748b;
}

.plan-date-input {
    width: 100%;
    color-scheme: dark;
    font-size: 0.9375rem;
    font-weight: 500;
    color: #f1f5f9;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(100, 116, 139, 0.45);
    border-radius: 0.625rem;
    padding: 0.625rem 0.75rem;
    min-height: 2.75rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.plan-date-input:hover {
    border-color: rgba(148, 163, 184, 0.5);
}

.plan-date-input:focus {
    outline: none;
    border-color: rgba(196, 18, 48, 0.6);
    box-shadow: 0 0 0 3px rgba(196, 18, 48, 0.15);
}

.plan-duration-control {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.plan-duration-unit {
    font-size: 0.8125rem;
    color: #64748b;
}

.plan-status {
    margin: 0.75rem 0 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    text-align: center;
    color: #fcd34d;
    background: rgba(245, 158, 11, 0.08);
    border-radius: 0.5rem;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.plan-status.hidden {
    display: none;
}

.plan-finish-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.875rem;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.plan-finish-label {
    font-size: 0.75rem;
    color: #64748b;
}

.plan-finish-date {
    font-size: 0.875rem;
    font-weight: 600;
    color: #F2A900;
}

.controls-bar.controls-bar--custom-only {
    justify-content: center;
}

#day-stepper-row.is-hidden {
    display: none;
}

.khatmah-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

.app-footer {
    padding: 1rem 0 max(1rem, env(safe-area-inset-bottom));
    text-align: center;
    color: var(--slate-500);
    font-size: 0.875rem;
    border-top: 1px solid rgba(51, 65, 85, 0.3);
}

.app-footer p {
    margin: 0;
}

/* --- Focus-visible rings (keyboard navigation) --- */
.carousel-container:focus-visible {
    outline: 2px solid var(--cmu-gold);
    outline-offset: -2px;
}

.day-card:focus-visible {
    outline: 2px solid var(--cmu-gold);
    outline-offset: 2px;
}

.mode-toggle-btn:focus-visible,
.khatmah-btn:focus-visible {
    outline: 2px solid var(--cmu-gold);
    outline-offset: 2px;
}

/* --- Screen-reader-only --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
