/* ============================================================
   Warm Editorial Search — Google-inspired, magazine-refined
   ============================================================ */

/* ---- CSS Variables ---- */
:root {
    --white: #fafaf8;
    --cream: #f5f3ef;
    --gray-50: #f0eee9;
    --gray-100: #e6e3dd;
    --gray-200: #d4d1ca;
    --gray-300: #b8b4ab;
    --gray-400: #9a958a;
    --gray-500: #7a756a;
    --gray-600: #5c574e;
    --gray-700: #403c34;
    --gray-800: #2a2620;
    --gray-900: #1a1712;
    --accent: #c44536;
    --accent-hover: #a3382b;
    --accent-soft: rgba(196, 69, 54, 0.08);
    --link: #1a56db;
    --link-hover: #1344b3;
    --link-visited: #681da8;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.04);
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
    background: var(--white);
    color: var(--gray-800);
    min-height: 100dvh;
    line-height: 1.5;
}

/* ---- Typography ---- */
h1, h2, h3, h4, h5, h6 {
    font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 600;
    line-height: 1.2;
}

/* ---- Layout States ---- */
.app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Homepage: centered */
.app.home {
    justify-content: center;
    align-items: center;
}

/* Results: top-aligned */
.app.results {
    justify-content: flex-start;
}

/* ============================================================
   Homepage
   ============================================================ */
.home-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    width: 100%;
    max-width: 640px;
    animation: fadeInUp 0.5s ease both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.brand {
    margin-bottom: 40px;
    text-align: center;
}

.brand h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.02em;
}

.brand .dot {
    color: var(--accent);
}

.brand .subtitle {
    font-family: "DM Sans", sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--gray-400);
    margin-top: 4px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* ---- Homepage Search Box ---- */
.search-box-home {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--white);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 4px;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.search-box-home:focus-within {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-md);
}

.search-box-home .search-icon {
    padding: 0 4px 0 16px;
    color: var(--gray-400);
    font-size: 1.1rem;
    flex-shrink: 0;
    line-height: 1;
}

.search-box-home input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: "DM Sans", sans-serif;
    font-size: 1rem;
    color: var(--gray-800);
    padding: 12px 8px;
    min-width: 0;
}

.search-box-home input::placeholder {
    color: var(--gray-300);
}

.search-box-home .clear-btn {
    border: none;
    background: none;
    color: var(--gray-400);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 50%;
    transition: all var(--transition);
    display: none;
    line-height: 1;
}

.search-box-home .clear-btn.visible {
    display: block;
}

.search-box-home .clear-btn:hover {
    color: var(--gray-600);
    background: var(--gray-50);
}

.search-box-home .search-submit {
    border: none;
    background: var(--gray-800);
    color: var(--white);
    border-radius: var(--radius-full);
    padding: 10px 24px;
    font-family: "DM Sans", sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.search-box-home .search-submit:hover {
    background: var(--gray-900);
    transform: translateY(-1px);
}

.search-box-home .search-submit:active {
    transform: translateY(0);
}

/* ---- Homepage Options ---- */
.home-options {
    display: flex;
    gap: 20px;
    margin-top: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.home-options label {
    font-family: "DM Sans", sans-serif;
    font-size: 0.8rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.home-options select {
    background: var(--cream);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-family: "DM Sans", sans-serif;
    font-size: 0.8rem;
    color: var(--gray-700);
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition);
}

.home-options select:focus {
    border-color: var(--gray-300);
}

.home-options input[type="checkbox"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
}

/* ---- Depth Toggle Buttons ---- */
.depth-toggle {
    display: flex;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.depth-btn {
    border: none;
    background: transparent;
    font-family: "DM Sans", sans-serif;
    font-size: 0.78rem;
    color: var(--gray-500);
    padding: 5px 14px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    border-right: 1px solid var(--gray-200);
}

.depth-btn:last-child {
    border-right: none;
}

.depth-btn:hover {
    background: var(--gray-50);
    color: var(--gray-700);
}

.depth-btn.active {
    background: var(--gray-800);
    color: var(--white);
}

/* ============================================================
   Results Page
   ============================================================ */

/* ---- Search Header (sticky, like Google) ---- */
.search-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--white);
    border-bottom: 1px solid var(--gray-100);
    padding: 16px 24px 10px;
    animation: slideDown 0.25s ease both;
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.search-header-top {
    display: flex;
    align-items: center;
    gap: 20px;
    max-width: 640px;
    margin: 0 auto;
}

.search-header-top .logo-sm {
    font-family: "DM Sans", sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--gray-900);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
    letter-spacing: -0.02em;
    flex-shrink: 0;
}

.search-header-top .logo-sm .dot {
    color: var(--accent);
}

.search-header .search-box {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--white);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 4px;
    transition: all var(--transition);
    min-width: 0;
}

.search-header .search-box:focus-within {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-sm);
}

.search-header .search-box input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: "DM Sans", sans-serif;
    font-size: 0.95rem;
    color: var(--gray-800);
    padding: 10px 14px;
    min-width: 0;
}

.search-header .search-box input::placeholder {
    color: var(--gray-300);
}

.search-header .search-box .results-clear {
    border: none;
    background: none;
    color: var(--gray-400);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 50%;
    transition: all var(--transition);
    display: none;
    line-height: 1;
}

.search-header .search-box .results-clear.visible {
    display: block;
}

.search-header .search-box .results-clear:hover {
    color: var(--gray-600);
    background: var(--gray-50);
}

.search-header .search-box .search-submit {
    border: none;
    background: var(--gray-800);
    color: var(--white);
    border-radius: var(--radius-full);
    padding: 8px 20px;
    font-family: "DM Sans", sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.search-header .search-box .search-submit:hover {
    background: var(--gray-900);
}

/* ---- Search Options Row ---- */
.search-options {
    display: flex;
    align-items: center;
    gap: 18px;
    max-width: 640px;
    margin: 10px auto 0;
    padding-left: 0;
    flex-wrap: wrap;
}

.search-options .opt-group {
    font-family: "DM Sans", sans-serif;
    font-size: 0.78rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.search-options select {
    background: var(--cream);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 3px 6px;
    font-family: "DM Sans", sans-serif;
    font-size: 0.78rem;
    color: var(--gray-700);
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition);
}

.search-options select:focus {
    border-color: var(--gray-300);
}

.search-options input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
}

/* Depth toggle in search options (reuse global .depth-toggle styles) */


/* ---- Results Body ---- */
.results-main {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
}

.results-main::-webkit-scrollbar {
    width: 6px;
}
.results-main::-webkit-scrollbar-track {
    background: transparent;
}
.results-main::-webkit-scrollbar-thumb {
    background: var(--gray-200);
    border-radius: 3px;
}

/* ---- Results Stats ---- */
.results-stats {
    font-family: "DM Sans", sans-serif;
    font-size: 0.78rem;
    color: var(--gray-400);
    padding: 12px 24px 4px;
    max-width: 664px;
    margin: 0 auto;
    width: 100%;
}

/* ---- Results List ---- */
.results-container {
    max-width: 664px;
    margin: 0 auto 80px;
    width: 100%;
    padding: 0 24px;
}

/* AI Answer Card */
.ai-answer {
    background: var(--cream);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    margin-bottom: 24px;
    animation: resultFadeIn 0.35s ease both;
}

.ai-answer .ai-label {
    font-family: "DM Sans", sans-serif;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.ai-answer .ai-text {
    font-size: 0.92rem;
    color: var(--gray-700);
    line-height: 1.6;
}

/* Result Item */
.result-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--gray-50);
    cursor: pointer;
    transition: all var(--transition);
    animation: resultFadeIn 0.35s ease both;
    border-radius: var(--radius-sm);
    padding-left: 12px;
    padding-right: 12px;
    margin: 0 -12px;
}

.result-item:hover {
    background: var(--cream);
}

.result-item.active {
    background: var(--accent-soft);
    border-bottom-color: transparent;
    border-radius: var(--radius-md);
}

@keyframes resultFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-item .r-url {
    font-family: "DM Sans", sans-serif;
    font-size: 0.72rem;
    color: var(--gray-400);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

.result-item .r-url .favicon {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    flex-shrink: 0;
}

.result-item .r-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--link);
    margin-bottom: 4px;
    line-height: 1.3;
    transition: color var(--transition);
}

.result-item:hover .r-title {
    color: var(--link-hover);
    text-decoration: underline;
}

.result-item.active .r-title {
    color: var(--link-hover);
}

.result-item .r-snippet {
    font-size: 0.85rem;
    color: var(--gray-600);
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.result-item .r-meta {
    font-family: "DM Sans", sans-serif;
    font-size: 0.72rem;
    color: var(--gray-400);
    margin-top: 4px;
    display: flex;
    gap: 12px;
}

/* ---- States ---- */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--gray-400);
    gap: 12px;
    font-family: "DM Sans", sans-serif;
    font-size: 0.85rem;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--gray-400);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--gray-400);
    text-align: center;
    gap: 8px;
}

.empty-state .icon {
    font-size: 2.5rem;
    opacity: 0.4;
    margin-bottom: 4px;
}

.empty-state .msg {
    font-family: "DM Sans", sans-serif;
    font-size: 0.9rem;
    color: var(--gray-500);
}

.empty-state .hint {
    font-family: "DM Sans", sans-serif;
    font-size: 0.78rem;
    color: var(--gray-300);
}

.error-state {
    font-family: "DM Sans", sans-serif;
    color: var(--accent);
    text-align: center;
    padding: 40px 20px;
    font-size: 0.85rem;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .brand h1 {
        font-size: 1.8rem;
    }

    .home-options {
        gap: 12px;
    }

    .home-options label {
        font-size: 0.75rem;
    }

    .search-header {
        padding: 12px 16px 8px;
    }

    .search-header-top {
        gap: 12px;
    }

    .search-header-top .logo-sm {
        font-size: 1.1rem;
    }

    .search-options {
        gap: 12px;
    }

    .results-stats {
        padding: 10px 16px;
    }

    .results-container {
        padding: 0 16px;
    }

    .result-item {
        padding-left: 8px;
        padding-right: 8px;
        margin: 0 -8px;
    }

    .result-item .r-title {
        font-size: 1.05rem;
    }
}
