/* ----- base ----- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 Helvetica, Arial, sans-serif;
    background: #f4f6fa;
    color: #1f2937;
    font-size: 14px;
    line-height: 1.5;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 16px 0 8px; }
h2 { font-size: 16px; margin: 24px 0 8px; color: #374151; }
.muted { color: #6b7280; font-size: 13px; }
.err   { color: #b91c1c; font-weight: 600; }

/* ----- header ----- */
.top {
    background: #111827;
    color: #f9fafb;
    padding: 10px 22px;
    display: flex;
    align-items: center;
    gap: 24px;
}
.top .brand { font-weight: 700; font-size: 16px; }
.top nav { display: flex; align-items: center; gap: 18px; margin-left: auto; }
.top nav a { color: #d1d5db; }
.top nav a:hover { color: #fff; text-decoration: none; }
.top .user { color: #9ca3af; font-size: 13px; }

/* ----- layout ----- */
main { max-width: 1200px; margin: 0 auto; padding: 22px; }

/* ----- flash ----- */
.flash {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.flash-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-info  { background: #eff6ff; color: #1e3a8a; border-color: #bfdbfe; }

/* ----- login ----- */
.login-card {
    max-width: 380px;
    margin: 80px auto;
    background: #fff;
    padding: 28px 32px;
    border-radius: 10px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
}
.login-card h1 { margin-top: 0; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.login-card label { display: flex; flex-direction: column; font-weight: 600; gap: 4px; }
.login-card input {
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 400;
}
.login-card button {
    margin-top: 8px;
    padding: 10px;
    background: #2563eb;
    color: white;
    border: 0;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
}
.login-card button:hover { background: #1d4ed8; }

/* ----- stats ----- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat {
    background: #fff;
    padding: 16px 18px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}
.stat-value { font-size: 24px; font-weight: 700; color: #111827; }
.stat-label { color: #6b7280; font-size: 12px; margin-top: 2px; }

/* ----- actions row ----- */
.actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.actions button {
    padding: 8px 16px;
    border-radius: 6px;
    border: 0;
    background: #2563eb;
    color: white;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}
.actions button:hover { background: #1d4ed8; }
.actions button.secondary { background: #6b7280; }
.actions button.secondary:hover { background: #4b5563; }

/* ----- tables ----- */
table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
}
th, td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: top;
}
th {
    background: #f9fafb;
    color: #374151;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
tr:last-child td { border-bottom: 0; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.ts  { color: #4b5563; white-space: nowrap; font-size: 12px; }
.headline { max-width: 440px; }
.headline .source { font-size: 11px; margin-top: 2px; }
.headline .rationale {
    font-size: 12px;
    color: #4b5563;
    margin-top: 4px;
    font-style: italic;
}
.ticker .source { font-size: 10px; margin-top: 2px; color: #9ca3af; }

.row-long  td.ticker  strong { color: #047857; }
.row-short td.ticker  strong { color: #b91c1c; }

/* status badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.badge.open    { background: #e0f2fe; color: #0369a1; }
.badge.correct { background: #dcfce7; color: #166534; }
.badge.wrong   { background: #fee2e2; color: #991b1b; }
.badge.on      { background: #dcfce7; color: #166534; }
.badge.off     { background: #fee2e2; color: #991b1b; }

/* ----- settings form ----- */
.settings-form {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 18px 22px;
    max-width: 720px;
}
.setting { margin-bottom: 18px; }
.setting label { display: block; margin-bottom: 6px; }
.setting input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}
.setting .help { font-size: 12px; margin-top: 4px; }
.setting button {
    padding: 10px 22px;
    background: #2563eb;
    color: #fff;
    border: 0;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}
.setting button:hover { background: #1d4ed8; }

/* ----- scanner cards ----- */
.scanner-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
    margin-top: 12px;
}
.scanner-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px 16px;
}
.scanner-head { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.scanner-price { margin-bottom: 8px; }
.scanner-indicators {
    margin: 0;
    padding-left: 18px;
    color: #374151;
}
.scanner-indicators li { margin: 2px 0; }
.scanner-summary {
    margin-top: 10px;
    color: #047857;
    font-style: italic;
}
.scanner-earnings {
    margin-top: 8px;
    padding: 6px 10px;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

/* ----- macro card ----- */
.macro-card {
    border-radius: 10px;
    padding: 16px 20px;
    margin: 14px 0 22px;
    border: 1px solid #e5e7eb;
    background: #fff;
}
.macro-card.macro-risk-on  { border-color: #86efac; background: #f0fdf4; }
.macro-card.macro-neutral  { border-color: #fde68a; background: #fffbeb; }
.macro-card.macro-risk-off { border-color: #fca5a5; background: #fef2f2; }

.macro-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.macro-label { font-size: 18px; font-weight: 700; }
.macro-score { font-weight: 600; color: #374151; }
.macro-when  { margin-left: auto; font-size: 12px; }

.macro-summary { margin-top: 6px; font-style: italic; color: #374151; }

.macro-indicators {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 4px 18px;
}
.macro-indicators li { padding: 2px 0; font-size: 13px; }
.macro-ind-label { color: #4b5563; }
.macro-ind-status { margin: 0 4px; }

/* ----- world news list ----- */
.news-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.news-list li {
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    margin-bottom: 6px;
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
}
.news-score {
    display: inline-block;
    min-width: 56px;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: center;
    font-size: 12px;
}
.news-score.pos { background: #dcfce7; color: #166534; }
.news-score.neg { background: #fee2e2; color: #991b1b; }

/* ----- API status box ----- */
.api-status {
    border-radius: 8px;
    padding: 14px 18px;
    margin: 14px 0 22px;
    border: 1px solid #e5e7eb;
    background: #fff;
}
.api-status.ok   { border-color: #86efac; background: #f0fdf4; }
.api-status.warn { border-color: #fca5a5; background: #fef2f2; }
.api-status.off  { border-color: #d1d5db; background: #f9fafb; }
.api-status .secondary { background: #6b7280; color: #fff; padding: 6px 12px;
    border: 0; border-radius: 6px; cursor: pointer; }
.api-status .secondary:hover { background: #4b5563; }
table.api-stats {
    width: auto;
    margin: 8px 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    font-size: 13px;
}
table.api-stats th, table.api-stats td {
    border: 0;
    padding: 4px 14px 4px 0;
    background: transparent;
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
}
table.api-stats th { color: #6b7280; }
