/* ==================================================================
   全自動 AI 新聞產製 · POC Demo portal
   中性色、排版乾淨、給決策者/媒體主管看的能力展示頁
   ================================================================== */

:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --text: #111827;
    --text-muted: #6b7280;
    --text-subtle: #9ca3af;
    --accent: #1f2937;
    --accent-soft: #f3f4f6;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --radius: 8px;
    --radius-lg: 12px;
    --max-w: 1280px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Segoe UI",
                 "Microsoft JhengHei", "Noto Sans TC", sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

a { color: inherit; }

.container {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 24px;
}

/* ---------- header ---------- */

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 28px 0 24px;
}

.brand h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.brand .sub {
    margin-top: 4px;
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

/* ---------- tab bar ---------- */

.tab-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.tab-bar .container {
    display: flex;
    gap: 4px;
    overflow-x: auto;
}

.tab-bar-row {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 16px !important;
}

.tab-group {
    display: flex;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
}

.demo-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--text);
    color: #fff;
    border: none;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, transform 0.08s;
    letter-spacing: 0.02em;
}

.demo-btn:hover:not(:disabled) {
    background: #000;
    transform: translateY(-1px);
}

.demo-btn:active:not(:disabled) {
    transform: translateY(0);
}

.demo-btn:disabled {
    background: var(--border-strong);
    cursor: not-allowed;
}

.demo-btn-icon {
    font-size: 14px;
}

/* progress banner */

.demo-banner {
    background: #fffbeb;
    border-bottom: 1px solid #fcd34d;
    padding: 12px 0;
}

.demo-banner.hidden { display: none; }

.demo-banner.success { background: #ecfdf5; border-bottom-color: #6ee7b7; }
.demo-banner.error { background: #fef2f2; border-bottom-color: #fca5a5; }

.demo-banner-row {
    display: flex !important;
    align-items: center !important;
    gap: 20px !important;
}

.demo-banner-text {
    flex-shrink: 0;
    font-size: 13px;
    color: var(--text);
    display: flex;
    gap: 10px;
    align-items: center;
}

.demo-banner-stage {
    color: var(--text-muted);
    font-size: 12px;
}

.demo-banner-progress {
    flex: 1;
    height: 4px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    overflow: hidden;
}

.demo-banner-bar {
    height: 100%;
    width: 0%;
    background: var(--text);
    border-radius: 2px;
    transition: width 0.4s ease;
}

.demo-banner.success .demo-banner-bar { background: #10b981; width: 100% !important; }
.demo-banner.error   .demo-banner-bar { background: #ef4444; width: 100% !important; }

/* new-article highlight */

.card.new-flash {
    animation: newFlash 2.4s ease;
    border-color: var(--text) !important;
}

@keyframes newFlash {
    0%   { box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.18); }
    100% { box-shadow: 0 0 0 0 rgba(17, 24, 39, 0); }
}

.tab {
    background: transparent;
    border: none;
    padding: 16px 20px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    position: relative;
    white-space: nowrap;
    font-family: inherit;
    transition: color 0.15s;
}

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

.tab.active {
    color: var(--text);
    font-weight: 600;
}

.tab.active::after {
    content: "";
    position: absolute;
    bottom: -1px;
    left: 16px;
    right: 16px;
    height: 2px;
    background: var(--text);
    border-radius: 2px 2px 0 0;
}

/* ---------- metrics band ---------- */

.metrics-band {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 20px 0;
}

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

.metric-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.metric-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    letter-spacing: 0.02em;
}

/* ---------- feed ---------- */

.feed {
    padding: 24px 0 64px;
}

.tab-metrics {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0 20px;
    font-size: 13px;
    color: var(--text-muted);
}

.date-filter-wrap {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-filter-wrap label {
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}

#date-filter {
    font-family: inherit;
    font-size: 13px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    min-width: 160px;
}

#date-filter:hover {
    border-color: var(--border-strong);
}

#date-filter:focus {
    outline: none;
    border-color: var(--text);
}

.tab-metric-label {
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
    letter-spacing: 0.02em;
}

.tab-metric-stats {
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.tab-metric-stats .dot {
    color: var(--border-strong);
    padding: 0 6px;
}

.feed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

@media (max-width: 1024px) {
    .metrics-band .container { grid-template-columns: repeat(2, 1fr); row-gap: 16px; }
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.card-topic {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.card-mode {
    color: var(--text-subtle);
    font-weight: 400;
}

.card-title {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--text);
    margin: 0 0 10px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-lead {
    font-size: 13px;
    line-height: 1.65;
    color: var(--text-muted);
    margin: 0 0 auto;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    display: flex;
    gap: 12px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-subtle);
}

.card-meta .dot { color: var(--border-strong); }

.skel {
    background: linear-gradient(90deg, #eef0f3 0%, #f6f7fa 50%, #eef0f3 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.skel-title { height: 18px; margin-bottom: 8px; width: 85%; }
.skel-title.sh { width: 65%; }
.skel-lead  { height: 12px; margin-bottom: 6px; width: 100%; }
.skel-lead.sh { width: 78%; }

/* ---------- hybrid layout (運動 tab) ---------- */

.hybrid-layout {
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.hybrid-section-head {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--text);
}

.hybrid-section-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.hybrid-section-mode {
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}

.hybrid-hot-grid {
    /* 重用 feed-grid 的基本樣式 */
}

/* ---------- subgroup layout (weather / earthquake / airquality tab) ---------- */

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

@media (max-width: 1024px) {
    .subgroup-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .subgroup-grid { grid-template-columns: 1fr; }
}

.subgroup {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.subgroup-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.subgroup-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.02em;
}

.subgroup-mode {
    font-size: 11px;
    color: var(--text-subtle);
    letter-spacing: 0.04em;
}

.subgroup-refresh-btn {
    font-size: 11px;
    padding: 3px 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-subtle);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    margin-left: auto;
}

.subgroup-refresh-btn:hover:not(:disabled) {
    border-color: #3b82f6;
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.05);
}

.subgroup-refresh-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.subgroup-hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    display: flex;
    flex-direction: column;
    min-height: 180px;
}

.subgroup-hero:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.subgroup-hero .card-title {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--text);
    margin: 0 0 10px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.subgroup-hero .card-lead {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-muted);
    margin: 0 0 auto;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.subgroup-hero .card-meta {
    display: flex;
    gap: 12px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-subtle);
}

.subgroup-hero .card-meta .dot { color: var(--border-strong); }

.subgroup-empty {
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 24px;
    color: var(--text-subtle);
    font-size: 13px;
    text-align: center;
}

/* LIVE 監聽空狀態 */
.subgroup-empty.live-monitor {
    border: 1px solid var(--border);
    background: linear-gradient(180deg, #f9fafb 0%, #ffffff 100%);
    text-align: left;
    padding: 20px;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
    70%  { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.live-text {
    font-size: 12px;
    font-weight: 600;
    color: #059669;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.monitor-source {
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
}

.monitor-schedule {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}

.monitor-last {
    font-size: 12px;
    color: var(--text-subtle);
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* NEW badge for recently-generated articles */
.new-badge {
    position: absolute;
    top: -6px;
    left: 12px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 3px 8px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.4);
    z-index: 1;
}

.card, .subgroup-hero {
    position: relative;
}

.subgroup-history {
    border-top: 1px solid var(--border);
    padding-top: 14px;
}

.subgroup-history h4 {
    margin: 0 0 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.subgroup-history ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    transition: color 0.15s;
}

.history-item:last-child { border-bottom: none; }

.history-item:hover { color: var(--accent); }

.hist-date {
    flex-shrink: 0;
    color: var(--text-subtle);
    font-size: 12px;
    min-width: 80px;
}

.hist-label {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 64px 24px;
    color: var(--text-muted);
}

.empty-state .em-icon {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ---------- modal ---------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 48px 24px;
    overflow-y: auto;
}

.modal.hidden { display: none; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.55);
    backdrop-filter: blur(2px);
}

.modal-card {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-lg);
    max-width: 720px;
    width: 100%;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
    animation: modalIn 0.2s ease;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-category {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

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

.modal-close:hover {
    background: var(--accent-soft);
    color: var(--text);
}

.modal-body {
    padding: 28px 36px 36px;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
}

.article-title {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
    margin: 0 0 8px;
    letter-spacing: -0.01em;
}

.article-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 24px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.article-meta .dot { color: var(--border-strong); }

.article-lead {
    font-size: 15px;
    line-height: 1.95;
    color: var(--text);
    margin: 0 0 16px;
}

.article-body {
    font-size: 15px;
    line-height: 1.95;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

.article-body p {
    margin: 0 0 16px;
}

.article-body strong {
    font-weight: 700;
    color: var(--text);
}

.article-body .md-inline-head {
    /* 段落獨佔一行的 **小標**,由 portal.js 的 renderArticleBody 判定輸出為 h4 */
    display: block;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin: 20px 0 8px;
    padding-top: 8px;
}

/* ---- Markdown 元素(for 條列式文章,如超商優惠)---- */

.article-body .md-h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin: 24px 0 10px;
    padding: 6px 0 4px;
    border-bottom: 1px solid var(--border);
}

.article-body .md-bullets {
    list-style: disc outside;
    padding-left: 22px;
    margin: 0 0 18px;
}

.article-body .md-bullets li {
    margin-bottom: 6px;
    line-height: 1.85;
    font-size: 14.5px;
}

/* Override:bullet 裡的粗體不做 block display(保持 inline) */
.article-body .md-bullets li strong {
    display: inline;
    font-size: inherit;
    margin: 0;
    padding: 0;
    color: #c33;  /* 價格/折扣用紅強調 */
}

/* 三層優惠稿 level 1 通路 header(🟡 全家便利商店) */
.article-body .md-promo-l1 {
    font-size: 17px;
    margin-top: 28px;
    border-bottom: 2px solid #fbbf24;  /* 🟡 底線 */
    padding-bottom: 6px;
}

/* level 2 下單管道 + 日期(📍 APP | 4/22 10:00) */
.article-body .md-subhead {
    font-size: 14px;
    color: #374151;
    font-weight: 600;
    margin: 14px 0 6px;
    padding: 4px 10px;
    background: #f3f4f6;
    border-radius: 4px;
    display: inline-block;
}

.article-sources {
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.article-sources h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0 0 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.article-sources ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.article-sources li {
    font-size: 13px;
    color: var(--text-muted);
}

.article-sources a {
    color: var(--text);
    text-decoration: none;
}

.article-sources a:hover { text-decoration: underline; }

/* ---------- footer ---------- */

.site-footer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 18px 0;
    font-size: 12px;
    color: var(--text-subtle);
    margin-top: 32px;
}

.site-footer .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.site-footer a {
    color: var(--text-muted);
    text-decoration: none;
}

.site-footer a:hover {
    color: var(--text);
    text-decoration: underline;
}
