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

:root {
    --bg:          #0d0f1a;
    --bg-card:     #141624;
    --bg-sidebar:  #111320;
    --border:      #1e2235;
    --border-hover:#2d3255;
    --accent:      #6366f1;
    --accent-hover:#5558e3;
    --accent-dim:  rgba(99,102,241,.15);
    --text:        #e2e8f0;
    --text-muted:  #64748b;
    --text-dim:    #94a3b8;
    --success:     #10b981;
    --warning:     #f59e0b;
    --error:       #ef4444;
    --radius:      10px;
    --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== KIRJAUTUMINEN ===== */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }

.login-wrap { width: 100%; max-width: 400px; }

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 40px 36px;
}

.login-logo {
    display: flex; align-items: center; gap: 10px;
    font-size: 1.1rem; font-weight: 600; color: var(--text);
    margin-bottom: 28px;
}

.login-card h1 { font-size: 1.4rem; margin-bottom: 4px; }
.login-sub    { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 24px; }

/* ===== YLÄPALKKI ===== */
.topbar {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; justify-content: space-between;
    height: 56px; padding: 0 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.topbar-left  { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-weight: 600; font-size: 0.95rem; }
.topbar-agency { color: var(--text-muted); font-size: 0.8rem; padding: 2px 8px; background: var(--bg); border-radius: 20px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user  { color: var(--text-muted); font-size: 0.85rem; }

/* ===== LAYOUT ===== */
.app-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: calc(100vh - 56px);
}

/* ===== SIVUPALKKI ===== */
.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 16px 12px;
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .06em; color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.sidebar-list { overflow-y: auto; flex: 1; padding: 8px 0; }

.sidebar-empty { padding: 20px 16px; color: var(--text-muted); font-size: 0.85rem; }

.sidebar-item {
    display: block; padding: 10px 16px; cursor: pointer;
    border-left: 2px solid transparent;
    transition: background .15s, border-color .15s;
}
.sidebar-item:hover     { background: var(--border); text-decoration: none; }
.sidebar-item.active    { background: var(--accent-dim); border-left-color: var(--accent); }

.sidebar-item-name { font-weight: 500; font-size: 0.88rem; color: var(--text); }
.sidebar-item-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-item-date { font-size: 0.72rem; color: var(--text-muted); margin-top: 3px; opacity: .7; }

/* ===== PÄÄSISÄLTÖ ===== */
.main-content { padding: 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }

/* ===== KORTIT ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.section-title { font-size: 1rem; font-weight: 600; margin-bottom: 6px; }
.section-desc  { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 16px; }

/* ===== LOMAKE ===== */
.form-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.82rem; font-weight: 500; color: var(--text-dim); }

.label-optional { font-weight: 400; color: var(--text-muted); }

input[type=text],
input[type=password] {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color .2s;
    width: 100%;
}
input[type=text]:focus,
input[type=password]:focus { border-color: var(--accent); }

.form-actions { display: flex; align-items: center; gap: 10px; }

/* ===== NAPIT ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px; border-radius: 8px;
    font-size: 0.88rem; font-weight: 500;
    border: none; cursor: pointer; transition: background .15s, opacity .15s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
    background: transparent; color: var(--text-dim);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--border); color: var(--text); }

.btn-full  { width: 100%; justify-content: center; }
.btn-sm    { padding: 6px 12px; font-size: 0.82rem; }

/* ===== ILMOITUKSET ===== */
.alert {
    border-radius: 8px; padding: 12px 16px;
    font-size: 0.88rem; margin-bottom: 12px;
}
.alert-error   { background: rgba(239,68,68,.1);  border: 1px solid rgba(239,68,68,.3);  color: #fca5a5; }
.alert-success { background: rgba(16,185,129,.1); border: 1px solid rgba(16,185,129,.3); color: #6ee7b7; }

/* ===== STATS ===== */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--accent); line-height: 1.1; }
.stat-label { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* ===== SUBREDDIT-TAGIT ===== */
.subreddit-tags { display: flex; flex-wrap: wrap; gap: 8px; }

.subreddit-tag {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 20px; padding: 5px 12px;
    font-size: 0.82rem; color: var(--text-dim);
    transition: border-color .15s, color .15s;
}
.subreddit-tag:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.subreddit-count {
    background: var(--accent-dim); color: var(--accent);
    border-radius: 10px; padding: 1px 6px; font-size: 0.75rem;
}

/* ===== TAULUKOT ===== */
.table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th {
    text-align: left; padding: 10px 12px;
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .05em; color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }

.rank          { color: var(--text-muted); width: 36px; }
.keyword-cell  { font-size: 0.9rem; }
.score         { color: var(--warning); white-space: nowrap; }
.comments      { color: var(--text-muted); white-space: nowrap; }

.freq-bar-wrap { display: flex; align-items: center; gap: 8px; }
.freq-bar { height: 4px; background: var(--accent); border-radius: 2px; min-width: 4px; }
.freq-bar-wrap span { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }

.post-link { color: var(--text); font-size: 0.88rem; }
.post-link:hover { color: var(--accent); }

.post-flair {
    display: inline-block; margin-left: 6px;
    background: var(--accent-dim); color: var(--accent);
    border-radius: 4px; padding: 1px 6px; font-size: 0.72rem;
}

.sub-tag {
    display: inline-block;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 4px; padding: 2px 6px;
    font-size: 0.78rem; color: var(--text-muted);
}

/* ===== BADGET ===== */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 500;
    background: var(--accent-dim); color: var(--accent);
}
.badge-info { background: rgba(99,102,241,.15); color: #a5b4fc; }
.badge-kaup { background: rgba(245,158,11,.15); color: #fcd34d; }
.badge-tran { background: rgba(16,185,129,.15);  color: #6ee7b7; }
.badge-navi { background: rgba(100,116,139,.15); color: #94a3b8; }

/* ===== KYSYMYSLISTA ===== */
.question-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.question-item {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.4;
}
.question-item svg { flex-shrink: 0; margin-top: 2px; }

/* ===== SISÄLTÖIDEAT ===== */
.ideas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }

.idea-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    transition: border-color .15s;
}
.idea-card:hover { border-color: var(--border-hover); }

.idea-format { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin-bottom: 6px; }
.idea-title  { font-size: 0.9rem; font-weight: 500; color: var(--text); line-height: 1.4; }
.idea-source { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; font-style: italic; }

/* ===== TYHJÄTILA ===== */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 16px; padding: 80px 40px; text-align: center;
}
.empty-state h3 { font-size: 1.1rem; color: var(--text-dim); }
.empty-state p  { color: var(--text-muted); max-width: 400px; font-size: 0.9rem; line-height: 1.6; }

/* ===== LATAUSANIMAATIO ===== */
.loading-wrap {
    display: flex; flex-direction: column; align-items: center; gap: 16px;
    padding: 60px 40px; color: var(--text-muted); font-size: 0.9rem;
}

.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

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

/* ===== KILPAILIJA-ANALYYSI ===== */
.competitor-grid { display: flex; flex-direction: column; gap: 20px; }

.competitor-summary {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
    padding: 16px; background: var(--bg); border-radius: 8px;
    border: 1px solid var(--border);
}
.competitor-stat { text-align: center; }
.stat-value-sm { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.competitor-positive, .competitor-positive-title { color: #10b981 !important; }
.competitor-negative, .competitor-negative-title { color: #ef4444 !important; }
.competitor-neutral { color: #64748b; }
.competitor-opportunity-title { color: #f59e0b !important; }

.competitor-section { }
.competitor-section-title {
    font-size: 0.88rem; font-weight: 600; margin-bottom: 10px;
    padding-bottom: 6px; border-bottom: 1px solid var(--border);
}

.competitor-list {
    list-style: none; padding: 0;
    display: flex; flex-direction: column; gap: 6px;
}
.competitor-list li {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 8px 12px; background: var(--bg);
    border-radius: 6px; border: 1px solid var(--border);
    font-size: 0.88rem;
}
.competitor-list a { color: var(--text); flex: 1; }
.competitor-list a:hover { color: var(--accent); }
.competitor-sub { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; }

.competitor-opportunities {
    list-style: none; padding: 0;
    display: flex; flex-direction: column; gap: 8px;
}
.competitor-opportunities li {
    padding: 12px 16px; background: var(--bg);
    border-radius: 8px; border: 1px solid var(--border);
    border-left: 3px solid var(--warning);
}
.opp-title { display: block; font-size: 0.9rem; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.opp-reason { display: block; font-size: 0.82rem; color: var(--text-muted); font-style: italic; }

.form-row-2col { grid-template-columns: 1fr 1fr; }

/* ===== MODAALI (BRIEF) ===== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 100%; max-width: 800px;
    max-height: 90vh;
    display: flex; flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 600; padding-right: 20px; }

.modal-close {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.5rem; cursor: pointer; padding: 4px 8px;
    border-radius: 6px; transition: background .15s, color .15s;
    line-height: 1;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body {
    padding: 24px;
    overflow-y: auto; flex: 1;
}

.modal-footer {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.copy-feedback { color: var(--success); font-size: 0.85rem; font-weight: 500; }

/* Brief sisältö */
.brief-meta {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 12px; margin-bottom: 24px;
    padding: 16px;
    background: var(--bg); border-radius: 8px;
    border: 1px solid var(--border);
}
.brief-meta-item { display: flex; flex-direction: column; gap: 2px; }
.brief-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.brief-meta-item > span:last-child { font-size: 0.9rem; color: var(--text); }

.brief-format-badge {
    display: inline-block;
    background: var(--accent-dim); color: var(--accent);
    padding: 2px 8px; border-radius: 4px; font-size: 0.82rem; font-weight: 500;
}

.brief-intent-badge {
    display: inline-block;
    padding: 2px 8px; border-radius: 4px; font-size: 0.82rem; font-weight: 500;
}
.brief-intent-informational { background: rgba(99,102,241,.15); color: #a5b4fc; }
.brief-intent-commercial { background: rgba(245,158,11,.15); color: #fcd34d; }
.brief-intent-transactional { background: rgba(16,185,129,.15); color: #6ee7b7; }
.brief-intent-navigational { background: rgba(100,116,139,.15); color: #94a3b8; }

.brief-section { margin-bottom: 20px; }
.brief-section h3 {
    font-size: 0.85rem; font-weight: 600; color: var(--accent);
    text-transform: uppercase; letter-spacing: .04em;
    margin-bottom: 8px; padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.brief-hint { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 10px; }

.brief-h1 {
    font-size: 1.2rem; font-weight: 700; color: var(--text);
    padding: 12px 16px;
    background: var(--bg); border-radius: 8px;
    border-left: 3px solid var(--accent);
}

.brief-outline {
    list-style: decimal; padding-left: 20px;
    display: flex; flex-direction: column; gap: 6px;
}
.brief-outline li {
    font-size: 0.9rem; color: var(--text);
    padding: 6px 10px;
    background: var(--bg); border-radius: 6px;
}

.brief-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.brief-kw-tag {
    display: inline-block;
    background: var(--accent-dim); color: var(--accent);
    padding: 4px 10px; border-radius: 20px;
    font-size: 0.82rem; font-weight: 500;
}

.brief-questions {
    list-style: none; padding: 0;
    display: flex; flex-direction: column; gap: 6px;
}
.brief-questions li {
    padding: 8px 12px;
    background: var(--bg); border-radius: 6px;
    border-left: 3px solid var(--warning);
    font-size: 0.88rem;
}

.brief-sources {
    list-style: none; padding: 0;
    display: flex; flex-direction: column; gap: 6px;
}
.brief-sources li {
    padding: 8px 12px;
    background: var(--bg); border-radius: 6px;
    font-size: 0.88rem;
}
.brief-sources a { color: var(--accent); }
.brief-sub { color: var(--text-muted); font-size: 0.78rem; margin-left: 6px; }

.brief-guidelines {
    list-style: disc; padding-left: 20px;
    display: flex; flex-direction: column; gap: 4px;
}
.brief-guidelines li { font-size: 0.88rem; color: var(--text-dim); }

/* Klikkaus-vihje idea-korteissa */
.idea-card-clickable { cursor: pointer; }
.idea-card-clickable:hover { border-color: var(--accent); }

.idea-click-hint {
    font-size: 0.72rem; color: var(--text-muted);
    margin-top: 8px; opacity: 0;
    transition: opacity .15s;
}
.idea-card-clickable:hover .idea-click-hint { opacity: 1; }

/* ===== RESPONSIIVISUUS ===== */
@media (max-width: 900px) {
    .app-layout { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 500px) {
    .stats-row { grid-template-columns: 1fr 1fr; }
    .main-content { padding: 16px; }
}
