/* ZeroPeak - A minimal blog theme inspired by Hey World */

:root {
    --color-bg: #ffffff;
    --color-text: #1a1a1a;
    --color-text-secondary: #6b6b6b;
    --color-link: #1a1a1a;
    --color-link-hover: #555555;
    --color-border: #e5e5e5;
    --color-accent: #f5f5f5;
    --color-code: #2d2d2d;

    --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --max-width: 680px;
    --spacing-unit: 1rem;
}

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

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

body {
    font-family: var(--font-serif);
    font-size: 1rem;
    line-height: 1.7;
    color: var(--color-text);
    background-color: var(--color-bg);
}

/* Container */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 3rem 1.5rem 5rem;
}

/* Links */
a {
    color: var(--color-link);
    text-decoration: underline;
    text-decoration-color: var(--color-border);
    text-underline-offset: 2px;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

a:hover {
    color: var(--color-link-hover);
    text-decoration-color: var(--color-link-hover);
}

/* Site Header */
.site-header {
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--color-border);
    text-align: center;
}

.author-section {
    margin-bottom: 1.25rem;
}

.author-row {
    display: inline-flex;
    align-items: center;
    gap: 1rem;
}

.author-link {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--color-text);
    text-decoration: none;
}

.author-link:hover {
    color: var(--color-text);
}

.avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-small {
    width: 36px;
    height: 36px;
}

.author-name {
    font-family: var(--font-sans);
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.author-bio {
    font-size: 0.95rem;
    line-height: 1.65;
    color: var(--color-text);
    margin-bottom: 1.5rem;
}

.author-bio a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Subscribe Section */
.subscribe-section {
    margin-top: 1.5rem;
}

.subscribe-text {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    margin-bottom: 0.75rem;
}

.feed-link {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.subscribe-form {
    display: flex;
    gap: 0.5rem;
    max-width: 400px;
    margin: 0 auto;
}

.email-input {
    flex: 1;
    padding: 0.6rem 0.85rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color 0.15s ease;
}

.email-input:focus {
    outline: none;
    border-color: var(--color-text);
}

.email-input::placeholder {
    color: var(--color-text-secondary);
}

.subscribe-btn {
    padding: 0.6rem 1.25rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-bg);
    background: var(--color-text-secondary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.subscribe-btn:hover {
    opacity: 0.8;
}

.subscribe-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

.subscribe-btn:disabled::after {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 6px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}

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

.subscribe-message {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.subscribe-message.success {
    color: var(--color-success, #22863a);
}

.subscribe-message.error {
    color: var(--color-error, #cb2431);
}

/* Posts Section */
.posts-section {
    margin-top: 2rem;
}

/* Post Preview (Index page) */
.post-preview {
    margin-bottom: 2.5rem;
    padding-bottom: 2.5rem;
    border-bottom: 1px solid var(--color-border);
}

.post-preview:last-of-type {
    border-bottom: none;
}

.post-date {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
}

.post-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.35;
    margin-bottom: 0.65rem;
}

.post-title a {
    color: var(--color-text);
    text-decoration: none;
}

.post-title a:hover {
    color: var(--color-link);
}

.post-excerpt {
    font-size: 1rem;
    line-height: 1.65;
    color: var(--color-text);
    margin-bottom: 0.75rem;
}

.read-more-container {
    text-align: center;
}

.read-more {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    opacity: 0.8;
}

.read-more:hover {
    opacity: 1;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Pagination */
.pagination-container {
    margin-top: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.pagination-link {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--color-link);
    text-decoration: none;
}

.pagination-link:hover {
    text-decoration: underline;
}

.pagination-prev {
    margin-right: auto;
}

.pagination-next {
    margin-left: auto;
}

/* Legacy - can be removed if not used elsewhere */
.load-more-container {
    margin-top: 2rem;
    text-align: center;
}

.load-more-link {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--color-link);
    text-decoration: none;
}

.load-more-link:hover {
    text-decoration: underline;
}

/* Post Header (Single post page) */
.post-header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.post-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.author-link-small {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--color-text);
    text-decoration: none;
}

.author-link-small:hover {
    color: var(--color-text);
}

.author-name-small {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
}

/* Full Post */
.post-full {
    margin-bottom: 3rem;
}

.post-meta {
    margin-bottom: 0.75rem;
}

.post-title-full {
    font-family: var(--font-serif);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.02em;
    margin-bottom: 2rem;
}

/* Prose Content */
.prose,
.post-content {
    font-size: 1.05rem;
    line-height: 1.75;
}

.prose p {
    margin-bottom: 1.5rem;
}

.prose h2 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 600;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    line-height: 1.35;
}

.prose h3 {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.prose ul,
.prose ol {
    margin-bottom: 1.5rem;
    padding-left: 1.5rem;
}

.prose li {
    margin-bottom: 0.5rem;
}

.prose blockquote {
    margin: 1.5rem 0;
    padding-left: 1.25rem;
    border-left: 3px solid var(--color-border);
    font-style: italic;
    color: var(--color-text-secondary);
}

.prose pre,
.post-content pre {
    margin: 1.5rem 0 !important;
    padding: 1.25rem !important;
    background: var(--color-accent) !important;
    border: 1px solid var(--color-border) !important;
    border-radius: 8px !important;
    overflow-x: auto !important;
    font-size: 0.88rem !important;
    line-height: 1.6 !important;
}

.prose code,
.post-content code {
    font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace !important;
    font-size: 0.9em !important;
    color: var(--color-code) !important;
}

.prose p code,
.post-content p code {
    padding: 0.15rem 0.4rem !important;
    background: var(--color-accent) !important;
    border-radius: 4px !important;
    font-weight: 500 !important;
}

/* Enhanced code block styling */
.prose pre code,
.post-content pre code {
    display: block !important;
    color: var(--color-text) !important;
    font-weight: normal !important;
}

.prose img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.5rem 0;
}

.prose a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.prose hr {
    margin: 2.5rem 0;
    border: none;
    border-top: 1px solid var(--color-border);
}

/* Tags */
.post-tags-row {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.post-tags-row .back-home {
    margin-left: auto;
}

.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    text-decoration: none;
}

/* Post Footer */
.post-footer {
    padding-top: 2rem;
    border-top: 1px solid var(--color-border);
}

.footer-subscribe {
    text-align: center;
}

.back-home {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    opacity: 0.8;
}

.back-home:hover {
    opacity: 1;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* HTMX Loading States */
.htmx-request {
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.htmx-request .load-more-link::after {
    content: '...';
}

/* Responsive */
@media (max-width: 640px) {
    html {
        font-size: 16px;
    }

    .container {
        padding: 2rem 1.25rem 3rem;
    }

    .avatar {
        width: 48px;
        height: 48px;
    }

    .author-name {
        font-size: 1.1rem;
    }

    .post-title {
        font-size: 1.35rem;
    }

    .post-title-full {
        font-size: 1.65rem;
    }

    .subscribe-form {
        flex-direction: column;
    }

    .subscribe-btn {
        width: 100%;
    }
}

/* Theme Toggle Slider */
.theme-toggle-slider {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
}

.toggle-track {
    width: 36px;
    height: 20px;
    background: var(--color-border);
    border-radius: 10px;
    position: relative;
    transition: background 0.2s ease;
}

.toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--color-text);
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.dark-mode .toggle-thumb,
html.dark-mode .toggle-thumb {
    transform: translateX(16px);
}

@media (prefers-color-scheme: dark) {
    .toggle-thumb {
        transform: translateX(16px);
    }

    html.light-mode .toggle-thumb {
        transform: translateX(0);
    }
}

/* Dark mode colors - system preference */
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #141414;
        --color-text: #e8e8e8;
        --color-text-secondary: #999999;
        --color-link: #e8e8e8;
        --color-link-hover: #aaaaaa;
        --color-border: #2a2a2a;
        --color-accent: #1f1f1f;
        --color-code: #d4d4d4;
    }
}

/* Manual dark mode - overrides system preference */
html.dark-mode {
    --color-bg: #141414;
    --color-text: #e8e8e8;
    --color-text-secondary: #999999;
    --color-link: #e8e8e8;
    --color-link-hover: #aaaaaa;
    --color-border: #2a2a2a;
    --color-accent: #1f1f1f;
    --color-code: #d4d4d4;
}

/* Manual light mode - overrides system dark preference */
html.light-mode {
    --color-bg: #ffffff;
    --color-text: #1a1a1a;
    --color-text-secondary: #6b6b6b;
    --color-link: #1a1a1a;
    --color-link-hover: #555555;
    --color-border: #e5e5e5;
    --color-accent: #f5f5f5;
    --color-code: #2d2d2d;
}

/* Analytics Dashboard */
.analytics-page {
    max-width: 900px;
}

.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.analytics-header h1 {
    font-family: var(--font-serif);
    font-size: 1.75rem;
    font-weight: 600;
}

.date-filter {
    display: flex;
    gap: 0.5rem;
}

.date-filter a {
    padding: 0.4rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    text-decoration: none;
}

.date-filter a:hover,
.date-filter a.active {
    color: var(--color-text);
    border-color: var(--color-text);
}

.analytics-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    padding: 1.25rem;
    background: var(--color-accent);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    text-align: center;
}

.stat-value {
    display: block;
    font-family: var(--font-sans);
    font-size: 2rem;
    font-weight: 600;
    color: var(--color-text);
}

.stat-label {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.analytics-section {
    margin-bottom: 1.5rem;
}

.analytics-section h2 {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.analytics-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-sans);
    font-size: 0.9rem;
}

.analytics-table th,
.analytics-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.analytics-table th {
    font-weight: 500;
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.analytics-table td:nth-child(2),
.analytics-table td:nth-child(3),
.analytics-table th:nth-child(2),
.analytics-table th:nth-child(3) {
    text-align: right;
    width: 80px;
}

.analytics-table a {
    color: var(--color-text);
}

.analytics-table a:hover {
    color: var(--color-link);
}

.referrer-url {
    font-size: 0.85rem;
    word-break: break-all;
}

.no-data {
    color: var(--color-text-secondary);
    font-style: italic;
    padding: 1rem 0;
}

.analytics-chart-section {
    margin-top: 1rem;
}

.chart-container {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 150px;
    padding: 1rem 0;
    border-bottom: 1px solid var(--color-border);
    overflow-x: auto;
}

.chart-bar {
    flex: 1;
    min-width: 20px;
    max-width: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.chart-bar .bar {
    width: 100%;
    background: var(--color-link);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    margin-top: auto;
}

.chart-bar .bar-label {
    font-family: var(--font-sans);
    font-size: 0.65rem;
    color: var(--color-text-secondary);
    margin-top: 0.5rem;
    white-space: nowrap;
}

.analytics-footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

@media (max-width: 640px) {
    .analytics-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .analytics-grid {
        grid-template-columns: 1fr;
    }
}

/* Newsletter Admin */
.newsletter-page {
    max-width: 900px;
}

.newsletter-header {
    margin-bottom: 2rem;
}

.newsletter-header h1 {
    font-family: var(--font-serif);
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.newsletter-description {
    color: var(--color-text-secondary);
    font-size: 0.95rem;
}

.notification {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
}

.notification.hidden {
    display: none;
}

.notification.success {
    background: rgba(34, 134, 58, 0.1);
    border: 1px solid rgba(34, 134, 58, 0.3);
    color: #22863a;
}

.notification.error {
    background: rgba(203, 36, 49, 0.1);
    border: 1px solid rgba(203, 36, 49, 0.3);
    color: #cb2431;
}

.posts-list h2 {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.newsletter-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-sans);
    font-size: 0.9rem;
}

.newsletter-table th,
.newsletter-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.newsletter-table th {
    font-weight: 500;
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.newsletter-table .post-link {
    color: var(--color-text);
    text-decoration: none;
    font-weight: 500;
}

.newsletter-table .post-link:hover {
    color: var(--color-link);
}

.newsletter-table .post-excerpt {
    display: block;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    margin-top: 0.25rem;
}

.newsletter-table .post-date {
    white-space: nowrap;
    color: var(--color-text-secondary);
}

.newsletter-table .post-actions {
    text-align: right;
    white-space: nowrap;
}

.btn-draft {
    padding: 0.5rem 1rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-bg);
    background: var(--color-text-secondary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.btn-draft:hover:not(:disabled) {
    opacity: 0.8;
}

.btn-draft:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-draft.success {
    background: #22863a;
    color: white;
}

.newsletter-footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 1.5rem;
}

.newsletter-footer .nav-link {
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
}

.newsletter-footer .nav-link:hover {
    color: var(--color-text);
}

@media (max-width: 640px) {
    .newsletter-table th:nth-child(2),
    .newsletter-table td:nth-child(2) {
        display: none;
    }

    .newsletter-table .post-excerpt {
        display: none;
    }
}