/* =============================================================================
   Field Notes — front-end styles
   Covers: two-pane archive, single note, note cards, callout block, homepage teaser
   ============================================================================= */

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.fn-page-wrap {
    --fn-desktop-gap: 20px;
    --fn-desktop-sticky-top: 110px;
    --fn-desktop-sidebar-height: calc(100vh - var(--fn-desktop-sticky-top) - var(--fn-desktop-gap));
    background: var(--color-bg-light);
    padding: var(--fn-desktop-gap) var(--fn-desktop-gap) 40px;
}

.fn-layout {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    align-items: start;
    overflow: visible;
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-std);
    max-width: 1200px;
    margin: 0 auto;
    box-shadow: 0 10px 30px rgb(0 0 0 / 0.06);
}

/* ─── Left pane — note list ──────────────────────────────────────────────── */
.fn-sidebar {
    background: linear-gradient(180deg, var(--color-white) 0%, var(--color-bg-light) 100%);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: var(--fn-desktop-sticky-top);
    align-self: start;
    max-height: var(--fn-desktop-sidebar-height);
    overflow: hidden;
}

.fn-sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 1px;
    background: var(--color-border);
    pointer-events: none;
}

.fn-sidebar__header {
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--color-border);
    background: linear-gradient(180deg, var(--color-white) 0%, var(--color-bg-light) 100%);
    position: sticky;
    top: 0;
    z-index: 10;
}

.fn-search-wrap {
    position: relative;
}

.fn-search-input {
    width: 100%;
    padding: 9px 12px 9px 36px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-std);
    background: var(--color-white);
    font-family: var(--font-main);
    font-size: 0.875rem;
    color: var(--color-text-main);
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}
.fn-search-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.15);
}
.fn-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: var(--color-text-muted);
    pointer-events: none;
}

/* Tag filter pills */
.fn-filters {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.fn-filters::-webkit-scrollbar {
    display: none;
}

.fn-filter-btn {
    white-space: nowrap;
    padding: 4px 12px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-white);
    color: var(--color-text-muted);
    font-family: var(--font-main);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.fn-filter-btn:hover {
    background: var(--color-bg-light);
    border-color: var(--color-primary);
    color: var(--color-primary);
}
.fn-filter-btn.is-active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-white);
}

/* Note list scroll container */
.fn-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Individual note item */
.fn-note-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 16px 16px;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--color-border);
    border-left: 3px solid transparent;
    background: transparent;
    cursor: pointer;
    transition: background 0.12s, border-left-color 0.12s;
    font-family: var(--font-main);
}
.fn-note-item:last-child {
    border-bottom: none;
}
.fn-note-item:hover {
    background: var(--color-white);
}
.fn-note-item.is-active {
    background: var(--color-white);
    border-left-color: var(--color-accent);
    box-shadow: inset 0 -1px 0 var(--color-border);
}
.fn-note-item.is-hidden {
    display: none;
}

.fn-note-item__meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.fn-note-item__title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-text-main);
    line-height: 1.45;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
/* Dynamic size — medium title (60–120 chars) */
.fn-note-item__title--md {
    font-size: 0.8125rem;
    -webkit-line-clamp: 4;
}
/* Dynamic size — long title (>120 chars) */
.fn-note-item__title--lg {
    font-size: 0.75rem;
    line-height: 1.5;
    -webkit-line-clamp: 5;
}
.fn-note-item__excerpt {
    display: none;
}

/* Note type badge */
.fn-type-badge {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--color-accent);
}
.fn-note-item.is-active .fn-type-badge { color: var(--color-accent); }

/* Read-time label */
.fn-read-time {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

/* Empty state */
.fn-list__empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    display: none;
}
.fn-list__empty.is-visible {
    display: block;
}

/* ─── Right pane — reading view ──────────────────────────────────────────── */
.fn-reading-pane {
    overflow: visible;
    background: var(--color-white);
    position: relative;
    border-top: 3px solid var(--color-accent);
    min-height: var(--fn-desktop-sidebar-height);
    padding-left: 12px;
}

.fn-reading-pane__inner {
    max-width: 720px;
    margin: 0 auto;
    padding: 56px 40px 80px;
}

/* Loading state */
.fn-reading-pane.is-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-accent) 0%, transparent 100%);
    animation: fn-progress 1s ease-in-out infinite;
}
@keyframes fn-progress {
    0%   { transform: scaleX(0); transform-origin: left; }
    50%  { transform: scaleX(1); transform-origin: left; }
    100% { transform: scaleX(0); transform-origin: right; }
}

/* ─── Reading content ─────────────────────────────────────────────────────── */
.fn-note-header {
    margin-bottom: 40px;
    padding-bottom: 32px;
    border-bottom: 2px solid var(--color-border);
}
.fn-note-header__top {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.fn-note-header__date {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}
.fn-note-header__read-time {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-left: auto;
}
.fn-note-title {
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--color-primary);
    margin: 0 0 24px;
}
.fn-note-divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 0;
}

.fn-note-body {
    color: var(--color-text-main);
    font-size: 1.0625rem;
    line-height: 1.75;
}
.fn-note-body h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    margin: 2.5rem 0 1rem;
    line-height: 1.3;
}
.fn-note-body h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-primary);
    margin: 2rem 0 0.75rem;
    line-height: 1.3;
}
.fn-note-body p {
    margin: 0 0 1.25rem;
}
.fn-note-body ul,
.fn-note-body ol {
    padding-left: 1.5rem;
    margin: 0 0 1.25rem;
}
.fn-note-body li {
    margin-bottom: 0.5rem;
}
.fn-note-body strong {
    font-weight: 600;
    color: var(--color-primary);
}
.fn-note-body a {
    color: var(--color-accent);
    text-decoration: underline;
}
.fn-note-body a:hover {
    color: #2563EB;
}

/* ─── Key Insight callout block ──────────────────────────────────────────── */
.fn-callout {
    background: #eff6ff;
    border-left: 4px solid var(--color-accent);
    border-radius: 0 var(--radius-std) var(--radius-std) 0;
    padding: 20px 24px;
    margin: 2rem 0;
}
.fn-callout__heading {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-accent);
    margin: 0 0 10px;
}
.fn-callout__body {
    font-size: 1rem;
    line-height: 1.65;
    color: var(--color-text-main);
    margin: 0;
}

/* ─── Note footer / actions ──────────────────────────────────────────────── */
.fn-note-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 32px;
    margin-top: 48px;
    border-top: 1px solid var(--color-border);
}

/* ─── Empty / placeholder reading pane ──────────────────────────────────── */
.fn-reading-pane__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: var(--fn-desktop-sidebar-height);
    color: var(--color-text-muted);
    text-align: center;
    padding: 40px;
}
.fn-reading-pane__placeholder p {
    margin: 8px 0 0;
    font-size: 0.875rem;
}

/* ─── Single note page (no two-pane) ────────────────────────────────────── */
.fn-single {
    max-width: 720px;
    margin: 0 auto;
    padding: 56px 24px 80px;
}

/* ─── Homepage teaser section ────────────────────────────────────────────── */
.home-fn-teaser {
    padding: var(--spacing-section) 0;
    background: var(--color-bg-light);
}
.home-fn-teaser__header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 40px;
    flex-wrap: wrap;
    gap: 12px;
}
.home-fn-teaser__title {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--color-primary);
    margin: 0;
}
.home-fn-teaser__sub {
    color: var(--color-text-muted);
    font-size: 1rem;
    margin: 8px 0 0;
}
.home-fn-teaser__link {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-accent);
    text-decoration: none;
    white-space: nowrap;
}
.home-fn-teaser__link:hover { text-decoration: underline; }

.home-fn-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
}

.home-fn-card {
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-std);
    padding: 24px;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: box-shadow 0.15s, transform 0.15s;
}
.home-fn-card:hover {
    box-shadow: 0 8px 20px rgb(0 0 0 / 0.08);
    transform: translateY(-2px);
}
.home-fn-card__type {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-accent);
}
.home-fn-card__title {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--color-primary);
    line-height: 1.35;
    margin: 0;
}
.home-fn-card__excerpt {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    line-height: 1.55;
    margin: 0;
    flex: 1;
}
.home-fn-card__meta {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: auto;
}

/* ─── Mobile back bar (hidden on desktop) ─────────────────────────────── */
.fn-mobile-back-bar {
    display: none;
}
.fn-mobile-back {
    background: none;
    border: none;
    color: var(--color-accent);
    font-family: var(--font-main);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.fn-mobile-back:hover {
    text-decoration: underline;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .fn-page-wrap {
        padding: 0;
        min-height: 0;
    }
    .fn-layout {
        display: block;
        height: auto;
        overflow: visible;
        margin: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        box-shadow: none;
    }

    /* Default mobile: show sidebar, hide reading pane */
    .fn-reading-pane {
        display: none;
        padding-left: 0;
    }

    /* When a note is open on mobile: hide sidebar, show reading pane */
    .fn-layout.note-open .fn-sidebar {
        display: none;
    }
    .fn-layout.note-open .fn-reading-pane {
        display: block;
        border-top: none; /* remove accent top bar on mobile — back bar replaces it */
    }

    /* Show back bar only on mobile */
    .fn-mobile-back-bar {
        display: flex;
        align-items: center;
        padding: 12px 16px;
        border-bottom: 1px solid var(--color-border);
        background: var(--color-bg-light);
        position: sticky;
        top: 0;
        z-index: 5;
    }

    .fn-sidebar {
        position: static;
        top: auto;
        align-self: stretch;
        max-height: none;
        overflow: visible;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }
    .fn-list {
        overflow: visible;
        flex: none;
    }
    .fn-note-title {
        font-size: 1.5rem;
    }
    .fn-reading-pane__inner {
        padding: 24px 20px 56px;
    }
    .fn-reading-pane__placeholder {
        min-height: calc(100vh - 140px);
    }
    .home-fn-grid {
        grid-template-columns: 1fr;
    }
    .home-fn-teaser__title {
        font-size: 1.75rem;
    }
}

@media (max-width: 768px) {
    .home-fn-grid {
        grid-template-columns: 1fr;
    }
}
