/* MOBILE SPECIFIC CSS */
:root {
    --bg-dark: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #38bdf8;
    --accent-hover: #0284c7;
    --border-color: rgba(255, 255, 255, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-x: none;
}

html, body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    /* Prevent pull-to-refresh & swipe-to-navigate (exiting the app) */
    overscroll-behavior-y: none;
    overscroll-behavior-x: none;
    touch-action: pan-y pinch-zoom;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Unified Card Template ───────────────────────────────────────────────── */
.uc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 7px;
}
.uc-category {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.02em;
    line-height: 1.3;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.uc-date {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}
.uc-title {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.45;
    color: var(--text-primary);
    margin-bottom: 5px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
.uc-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 7px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.uc-snippet {
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--text-secondary);
    background-color: hsla(222, 20%, 8%, 0.4);
    padding: 7px 9px;
    border-radius: var(--radius-sm);
    border-left: 2px solid var(--border-color);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.uc-snippet mark {
    background: transparent;
    color: #fbbf24;
    border-bottom: none;
    padding: 0;
    font-weight: 600;
}

/* --- SCREEN NAVIGATION & SLIDING ANIMATIONS --- */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    
    /* Default hidden state */
    opacity: 0;
    pointer-events: none;
    transform: translateX(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 10;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
    z-index: 20;
}

/* Slide-Over specific animation for the reader */
.screen.slide-over {
    transform: translateX(100%);
    opacity: 1; /* Keep opacity 1 so it slides in solidly */
    z-index: 30;
    transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
}

.screen.slide-over.active {
    transform: translateX(0);
}

/* --- UI COMPONENTS --- */
.mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid var(--border-color);
    box-sizing: border-box;
    width: 100%;
    flex-shrink: 0;
    z-index: 100;
}

/* Results header: search box flexes in the top row */
#screen-results .mobile-header .search-box.compact {
    flex: 1;
    min-width: 0;
    order: 0;
    margin-top: 0;
}

/* Mode toggle takes full width on its own row at the bottom */
#screen-results .mobile-header .search-mode-toggle {
    width: 100%;
    order: 10;
    margin-top: 4px;
}

/* Remove sticky as we use flex layout now */
.mobile-header.sticky {
    /* No-op */
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-circle {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.logo-text {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: #fff;
    letter-spacing: -0.5px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.icon-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* --- SCREEN 1: HOME --- */
.home-main {
    padding: 24px 16px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    justify-content: flex-start;
    width: 100%;
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
}

.search-hero {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-top: 14px;
}

.search-hero h1 {
    font-family: 'Outfit', sans-serif;
    font-size: clamp(1.6rem, 7vw, 2.4rem);
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 12px;
    word-break: break-word;
}

.search-hero .highlight {
    color: var(--accent);
}

.search-hero p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 20px;
}

/* Category Bar */
.category-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    padding: 4px 0 12px 0;
    margin-bottom: 16px;
    width: 100%;
    box-sizing: border-box;
}
.category-bar::-webkit-scrollbar { display: none; }

.cat-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-muted);
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
}

.cat-btn.active {
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-color: transparent;
    color: #0f172a;
    font-weight: 700;
}

.search-box {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 4px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    color: #fff;
    padding: 12px 16px;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    outline: none;
}

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

.search-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
}

.search-btn:active {
    background: var(--accent-hover);
}

/* --- SCREEN 2: RESULTS --- */
.search-box.compact {
    border-radius: 20px;
    box-shadow: none;
    padding: 2px;
    margin: 0 4px;
    flex: 1 1 0%;
    min-width: 0;
}
.search-box.compact input {
    padding: 8px 8px;
    font-size: 0.85rem;
    flex: 1;
    min-width: 0;
}
.compact-btn {
    width: 36px;
    border-radius: 16px;
}

.results-main {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

#results-count-container {
    margin-bottom: 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Sort Bar */
.sort-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.sort-bar::-webkit-scrollbar { display: none; }

.sort-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-muted);
    padding: 6px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.sort-btn.active {
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.5);
    color: var(--accent);
}

.result-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    touch-action: manipulation; /* Ensures taps register correctly on iOS */
    -webkit-tap-highlight-color: rgba(56,189,248,0.1);
    transition: transform 0.15s, background 0.15s;
    -webkit-user-select: none;
    user-select: none;
}

.result-card:active {
    transform: scale(0.98);
    background: rgba(255, 255, 255, 0.08);
}

.result-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 6px;
    line-height: 1.3;
    color: #fff;
    word-break: break-word;
    overflow-wrap: break-word;
}

.result-meta {
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 8px;
    font-weight: 500;
}

.result-snippet {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    word-break: break-word;
    overflow-wrap: break-word;
    overflow: hidden;
}

/* --- SCREEN 3: READER --- */
.reader-header {
    padding-left: 8px;
}

#close-reader-btn {
    width: auto;
    padding: 0 12px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    border-radius: 20px;
}

.reader-actions {
    display: flex;
    gap: 4px;
}

.reader-main {
    padding: 20px 16px 60px 16px; /* extra bottom padding for scrolling */
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

#reader-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 8px;
}

.reader-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.document-text {
    font-size: 1rem;
    line-height: 1.6;
    color: #e2e8f0;
}

.document-text p {
    margin-bottom: 1em;
}

/* Highlighted search terms */
.result-snippet mark,
#reader-body mark {
    background: rgba(56, 189, 248, 0.25);
    color: #7dd3fc;
    border-radius: 3px;
    padding: 0 2px;
}

/* Reader Links & Citations */
#reader-body a,
.case-text a,
.case-crosslink,
.legal-link {
    color: #38bdf8 !important;
    text-decoration: underline;
    text-decoration-color: rgba(56, 189, 248, 0.4);
    transition: color 0.2s, text-decoration-color 0.2s;
}
#reader-body a:hover,
#reader-body a:active,
.case-text a:hover,
.case-crosslink:hover,
.legal-link:hover {
    color: #7dd3fc !important;
    text-decoration-color: #7dd3fc;
}

/* Load More Button */
#load-more-btn {
    display: none;
    width: 100%;
    margin: 20px 0;
    padding: 14px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#load-more-btn:active {
    background: rgba(255,255,255,0.1);
}

/* Empty / loading state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
}

/* --- Active / Focused input borders --- */
.search-box input:focus {
    outline: none;
    border: none;
}

.search-box:focus-within {
    border-color: rgba(56, 189, 248, 0.5);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

/* Scrollbar styling for reader */
#screen-reader::-webkit-scrollbar {
    width: 4px;
}
#screen-reader::-webkit-scrollbar-track {
    background: transparent;
}
#screen-reader::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

/* General button base */
.btn {
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 12px;
    color: var(--accent);
    padding: 12px 20px;
    font-size: 0.95rem;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.2s;
}

.btn:active {
    background: rgba(56, 189, 248, 0.25);
}

/* --- TOAST (SweetAlert2) override --- */
.swal-mobile-toast {
    background: #1e293b !important;
    color: #f1f5f9 !important;
    border: 1px solid rgba(255,255,255,0.12) !important;
    font-size: 14px !important;
    font-family: 'Inter', sans-serif !important;
}
.swal-mobile-toast .swal2-title {
    color: #f1f5f9 !important;
    font-size: 14px !important;
    font-weight: 500 !important;
}

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

/* --- TERMS AND DISCLAIMER MODAL (Mobile) --- */

@keyframes termsHeartbeat {
    0%   { transform: scale(1); box-shadow: none; }
    14%  { transform: scale(1.04); box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.35); }
    28%  { transform: scale(1); box-shadow: none; }
    42%  { transform: scale(1.04); box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.35); }
    70%  { transform: scale(1); box-shadow: none; }
    100% { transform: scale(1); box-shadow: none; }
}
.terms-reading-box-header.heartbeat {
    animation: termsHeartbeat 1.4s ease forwards;
}

.terms-modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    z-index: 999999; display: flex; align-items: flex-end; justify-content: center;
    opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 0;
}
.terms-modal-overlay.active { opacity: 1; visibility: visible; }

.terms-small-modal {
    background: #1a1f2e;
    border: 1.5px solid rgba(255, 255, 255, 0.14);
    border-radius: 20px 20px 0 0;
    width: 100%; max-width: 100%;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.6);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: hidden;
    display: flex; flex-direction: column;
    max-height: 92vh;
}
.terms-modal-overlay.active .terms-small-modal { transform: translateY(0); }

/* Drag handle bar */
.terms-small-modal::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    margin: 10px auto 0;
    flex-shrink: 0;
}

.terms-modal-header {
    padding: 16px 20px 16px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
    background: #1e2435;
}
.terms-modal-logo {
    height: 64px; width: auto;
    margin-bottom: 10px;
    display: block; margin-left: auto; margin-right: auto;
}
.terms-modal-header h2 {
    margin: 0 0 4px 0; font-size: 1.1rem; color: #f1f5f9; font-weight: 700;
}
.terms-modal-header p {
    margin: 0; font-size: 0.82rem; color: #94a3b8; line-height: 1.4;
}

.terms-modal-body {
    padding: 16px 16px 0;
    overflow-y: auto; flex-shrink: 1;
}

.terms-content-box {
    border: 1.5px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    overflow: hidden;
    background: #141824;
}

.terms-reading-box-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 13px 14px; cursor: pointer; user-select: none;
    background: #1c2133;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    transition: background 0.2s;
}
.terms-reading-box-header:active { background: #202639; }
.terms-reading-box-title {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.88rem; font-weight: 600; color: #e2e8f0;
}
.terms-reading-box-title i { color: #60a5fa; font-size: 0.85rem; }
.terms-reading-box-arrow {
    font-size: 0.75rem; color: #94a3b8;
    transition: transform 0.3s ease;
}
.terms-content-box.open .terms-reading-box-arrow { transform: rotate(180deg); }

.terms-reading-box-content {
    max-height: 0; overflow: hidden;
    transition: max-height 0.4s ease;
    background: #141824;
}
.terms-content-box.open .terms-reading-box-content {
    max-height: 200px;
    overflow-y: auto;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.terms-reading-box-content-inner {
    padding: 14px; font-size: 0.8rem; color: #94a3b8; line-height: 1.55;
}
.terms-reading-box-content-inner h4 {
    color: #e2e8f0; margin: 14px 0 6px; font-size: 0.85rem;
}
.terms-reading-box-content-inner h4:first-child { margin-top: 0; }
.terms-reading-box-content-inner ol { padding-left: 16px; margin: 0; }
.terms-reading-box-content-inner li { margin-bottom: 6px; }

.terms-disclaimer-inner {
    background: rgba(220, 38, 38, 0.08);
    border-left: 3px solid #ef4444;
    padding: 10px 12px; border-radius: 0 6px 6px 0; margin-bottom: 12px;
}
.terms-disclaimer-inner strong { color: #ef4444; display: block; margin-bottom: 4px; font-size: 0.8rem; }

.terms-read-badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 0.72rem; color: #10b981; font-weight: 600;
    opacity: 0; transition: opacity 0.3s; white-space: nowrap;
}
.terms-read-badge.visible { opacity: 1; }

.terms-checkbox-row {
    padding: 14px; background: #1a1f2e;
}
.terms-checkbox-container {
    display: flex; align-items: flex-start; gap: 10px;
    cursor: pointer; transition: opacity 0.2s;
}
.terms-checkbox-container.disabled { opacity: 0.4; cursor: not-allowed; }
.terms-checkbox-container input {
    width: 20px; height: 20px; cursor: pointer;
    accent-color: #3b82f6; flex-shrink: 0; margin-top: 1px;
}
.terms-checkbox-container input:disabled { cursor: not-allowed; }
.terms-checkbox-text { font-size: 0.82rem; color: #e2e8f0; user-select: none; line-height: 1.4; }

.terms-modal-footer {
    padding: 14px 16px 24px; flex-shrink: 0; background: #1a1f2e;
}
.terms-accept-btn {
    background: #3b82f6; color: white; border: none; width: 100%;
    padding: 14px; border-radius: 10px; font-size: 1rem;
    font-weight: 700; cursor: pointer; transition: all 0.2s ease;
}
.terms-accept-btn:disabled {
    background: #2a3148; color: #64748b; cursor: not-allowed; opacity: 0.8;
}
.terms-accept-btn:not(:disabled):active {
    background: #2563eb; transform: scale(0.98);
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* =============================================
   PULL-TO-REFRESH INDICATOR
   ============================================= */
#pull-refresh-indicator {
    position: fixed;
    top: -60px;
    left: 0;
    right: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    background: hsl(222, 20%, 15%);
    border-bottom: 1px solid rgba(56,189,248,0.2);
    color: rgba(255,255,255,0.7);
    font-size: 13px;
    font-family: inherit;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}
#pull-refresh-indicator.active {
    pointer-events: none;
}
.ptr-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(56,189,248,0.3);
    border-top-color: hsl(190,95%,55%);
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
@keyframes ptr-spin {
    to { transform: rotate(360deg); }
}
