/*
 * Tikkeri - Päätyylitiedosto (Versio 5.0)
 * * Versio 5.0: Lisätty tuki fallback-kuvalaatikoille (flex-keskitys).
 * * Description: Tyylit. Tehty <3 Kalajoella.
 * Author: Markus Haapasaari / Kaupunkilehti Kalajokinen
 */

:root {
    --brand-orange: #FF7D40;
    --brand-charcoal: #2E2E2E;

    --header-height: 60px;
    --cat-nav-height: 50px;
    --container-width: 800px;
    --spacing-md: 16px;
    --border-radius: 8px;

    --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.theme-light {
    --bg-body: #F4F4F4;
    --bg-card: #FFFFFF;
    --bg-modal: #FFFFFF;
    --text-main: #2E2E2E;
    --text-muted: #666666;
    --border-color: #E0E0E0;
    --shadow: 0 2px 5px rgba(0,0,0,0.05);
    --btn-secondary-bg: #E0E0E0;
    --btn-secondary-text: #2E2E2E;
    --ghost-opacity: 0.6;
}

body.theme-dark {
    --bg-body: #121212;
    --bg-card: #1E1E1E;
    --bg-modal: #1E1E1E;
    --text-main: #E0E0E0;
    --text-muted: #AAAAAA;
    --border-color: #333333;
    --shadow: 0 2px 5px rgba(0,0,0,0.3);
    --btn-secondary-bg: #333333;
    --btn-secondary-text: #E0E0E0;
    --ghost-opacity: 0.5;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { margin: 0; padding: 0; font-family: var(--font-main); background: var(--bg-body); color: var(--text-main); }

/* Header */
#app-header {
    position: fixed; top: 0; left: 0; width: 100%; height: var(--header-height);
    background: var(--brand-orange); color: #FFF; box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1000; display: flex; justify-content: center; align-items: center;
}
.header-content { width: 100%; max-width: var(--container-width); padding: 0 var(--spacing-md); display: flex; justify-content: space-between; align-items: center; }
.logo-area { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.logo-icon { width: 32px; height: 32px; background: var(--brand-charcoal); color: var(--brand-orange); display: flex; justify-content: center; align-items: center; font-weight: 900; border-radius: 4px; }
#app-header h1 { margin: 0; font-size: 1.25rem; font-weight: 700; }
button { background: none; border: none; color: inherit; cursor: pointer; }
.rotating { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Kategoriavalikko */
#category-nav {
    position: fixed; top: var(--header-height); left: 0; width: 100%; height: var(--cat-nav-height);
    background: var(--bg-body); border-bottom: 1px solid var(--border-color); z-index: 900;
    display: flex; align-items: center; overflow-x: auto; padding: 0 var(--spacing-md); gap: 10px;
    scrollbar-width: none;
}
#category-nav::-webkit-scrollbar { display: none; }
.cat-btn { color: var(--text-muted); font-weight: 600; padding: 6px 12px; border-radius: 20px; white-space: nowrap; }
.cat-btn.active { background: var(--brand-orange); color: #FFF; }

/* Main */
#main-content {
    padding-top: calc(var(--header-height) + var(--cat-nav-height) + var(--spacing-md));
    padding-bottom: 60px; padding-left: var(--spacing-md); padding-right: var(--spacing-md);
    max-width: 1120px; margin: 0 auto; min-height: 100vh;
}
.content-layout { display: flex; gap: 24px; align-items: flex-start; flex-wrap: nowrap; }
.feed-column { flex: 1 1 0; min-width: 0; }
.feed-container { display: flex; flex-direction: column; gap: var(--spacing-md); }

.sidebar {
    width: 280px;
    flex: 0 0 280px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: calc(var(--header-height) + var(--cat-nav-height) + 16px);
}

.sidebar-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.sidebar-card h3 { margin: 0 0 12px 0; font-size: 1rem; }
.sidebar-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.sidebar-list li { font-size: 0.9rem; color: var(--text-muted); line-height: 1.4; }
.sidebar-list a { color: inherit; text-decoration: none; }
.sidebar-list a:hover { color: var(--text-main); }
.sidebar-empty { color: var(--text-muted); font-style: italic; }

/* News Card */
.news-card {
    background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--border-radius);
    padding: var(--spacing-md); box-shadow: var(--shadow); text-decoration: none; color: inherit;
    display: flex; justify-content: space-between; gap: var(--spacing-md);
    transition: all 0.2s ease;
}
.news-card:active { transform: scale(0.98); }
.news-card.read-story { opacity: var(--ghost-opacity); filter: grayscale(100%); }
.news-card.paid-content { border-left: 4px solid #fdb913; background: rgba(255,200,0,0.05); }

.news-text-content { flex: 1; min-width: 0; }
.news-meta { font-size: 0.8rem; font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; flex-wrap: wrap; }
.news-source { font-weight: 700; text-transform: uppercase; }
.paywall-badge { background: #d32f2f; color: #fff; font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; margin-right: 6px; }
.news-time { color: var(--text-muted); font-weight: 400; margin-left: 6px; }
.news-title { margin: 0 0 8px 0; font-size: 1.1rem; font-weight: 700; line-height: 1.3; }
.news-excerpt { font-size: 0.95rem; color: var(--text-muted); margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Thumbnail & Placeholder */
.news-thumb {
    width: 90px; height: 90px;
    background-color: #eee;
    background-size: cover;
    background-position: center;
    border-radius: 4px;
    flex-shrink: 0;
    overflow: hidden;

    /* Placeholder teksti-asetukset */
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 900;
    font-size: 2rem;
    color: #FFFFFF;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.news-thumb-placeholder {
    opacity: 0.9;
}

.news-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.news-thumb-logo {
    object-fit: contain;
    padding: 10px;
    background-color: #fff;
}

@media (max-width: 400px) {
    .news-thumb { width: 70px; height: 70px; font-size: 1.5rem; }
}

@media (max-width: 760px) {
    .content-layout { flex-direction: column; }
    .sidebar { width: 100%; position: static; }
}

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 2000; display: flex; justify-content: center; align-items: center; padding: 16px; }
.modal-content { background: var(--bg-modal); width: 100%; max-width: 500px; border-radius: var(--border-radius); display: flex; flex-direction: column; max-height: 85vh; }
.modal-header { padding: 16px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px; overflow-y: auto; }
.settings-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.source-item { display: flex; align-items: center; padding: 10px; background: var(--bg-body); border-radius: 4px; }
.source-item input { margin-right: 12px; width: 20px; height: 20px; accent-color: var(--brand-orange); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn-primary { background: var(--brand-orange); color: #FFF; padding: 10px 20px; border-radius: 4px; font-weight: 600; }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--btn-secondary-text); padding: 10px 20px; border-radius: 4px; font-weight: 600; }

.loader-container { padding: 40px; text-align: center; color: var(--text-muted); }
.spinner { width: 40px; height: 40px; border: 4px solid var(--border-color); border-top: 4px solid var(--brand-orange); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 10px auto; }
.error-msg { background: #ffebee; color: #c62828; padding: 16px; border-radius: 8px; text-align: center; border: 1px solid #ef9a9a; }
#app-footer { text-align: center; padding: 24px 0; color: var(--text-muted); font-size: 0.85rem; }
.heart-text { color: var(--brand-orange); font-weight: 600; }
