/* ══════════════════════════════════════════════════════════════
   Components — reusable UI elements
   ══════════════════════════════════════════════════════════════ */

/* ── Grid Layouts ── */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3); }
.grid-auto { display: grid; gap: var(--space-3); }

/* ── Metrics ── */
.metric { text-align: center; padding: var(--space-2); }
.metric .value { font-size: var(--font-size-3xl); font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.metric .label { font-size: var(--font-size-sm); color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }

/* ── KPI Row ── */
.kpi-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--space-3); margin-bottom: var(--space-4); }
.kpi { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-2xl); padding: var(--space-4); text-align: center; }
.kpi .val { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .lbl { font-size: var(--font-size-sm); color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-top: var(--space-1); }

/* ── Mini KPI ── */
.mini-kpi { text-align: center; padding: var(--space-3); background: var(--bg); border-radius: var(--radius-lg); border: 1px solid var(--border); }
.mini-kpi .val { font-size: var(--font-size-xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-kpi .lbl { font-size: var(--font-size-xs); color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }

/* ── Status Indicators ── */
.status-dot { width: 8px; height: 8px; border-radius: var(--radius-full); display: inline-block; }
.status-ok { background: var(--green); box-shadow: 0 0 4px var(--green); }
.status-warn { background: var(--orange); box-shadow: 0 0 4px var(--orange); }
.status-err { background: var(--red); box-shadow: 0 0 4px var(--red); }

/* ── Phase Colors ── */
.phase-bull { color: var(--green); }
.phase-accumulation { color: var(--blue); }
.phase-recovery { color: var(--orange); }
.phase-caution { color: var(--orange); }
.phase-bear { color: var(--red); }

/* ── Regime Badges ── */
.regime { display: inline-block; padding: 3px 12px; border-radius: 12px; font-size: var(--font-size-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.regime-aggressive { background: rgba(63,185,80,.15); color: var(--green); }
.regime-neutral { background: rgba(210,153,34,.15); color: var(--orange); }
.regime-defensive { background: rgba(248,81,73,.15); color: var(--red); }

/* ── Badge (pill) ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: var(--font-size-xs); font-weight: 700; color: #fff; }
.badge-green { background: var(--green); }
.badge-red { background: var(--red); }
.badge-orange { background: var(--orange); }
.badge-blue { background: var(--blue); }
.badge-purple { background: var(--purple); }
.badge-buy { background: rgba(63,185,80,.15); color: var(--green); padding: 2px 10px; border-radius: var(--radius-sm); font-size: var(--font-size-sm); }
.badge-sell { background: rgba(248,81,73,.15); color: var(--red); padding: 2px 10px; border-radius: var(--radius-sm); font-size: var(--font-size-sm); }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; font-size: var(--font-size-base); }
th { text-align: left; color: var(--text2); font-weight: 600; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: var(--font-size-sm); text-transform: uppercase; letter-spacing: 0.5px; }
th.right { text-align: right; }
th.center { text-align: center; }
td { padding: 10px 8px; border-bottom: 1px solid var(--gray-800); }
td.right { text-align: right; }
td.center { text-align: center; }
td.mono { font-variant-numeric: tabular-nums; }
td.right.mono { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover { background: var(--bg-hover); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 580px; }

/* ── Forms ── */
.form-group { margin-bottom: var(--space-3); }
.form-group label { display: block; font-size: var(--font-size-base); color: var(--text2); margin-bottom: var(--space-1); }
.form-group input, .form-group select { width: 100%; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text); font-size: var(--font-size-md); }
.form-group input:focus { border-color: var(--blue); outline: none; }
.param-help { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: var(--radius-full); background: var(--border); color: var(--text3); font-size: var(--font-size-xs); font-weight: 700; cursor: help; flex-shrink: 0; }
.param-help:hover { background: var(--blue); color: #fff; }

/* ── Buttons ──
   `display: inline-flex` is required for <a class="btn"> on iOS Safari:
   inline <a> with padding sometimes has a broken tap hitbox, especially
   when the link contains child elements (e.g., the strategy tabs embed a
   <span> with the equity value). */
.btn { display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px; border-radius: var(--radius-md); border: none;
    cursor: pointer; font-size: var(--font-size-base); font-weight: 600;
    text-decoration: none;
    transition: background var(--transition-base), color var(--transition-base); }
.btn-primary { background: var(--green-600); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-sm { padding: 4px 12px; font-size: var(--font-size-sm); }
/* Make children non-interactive so taps always register on the <a>/<button>
   itself. Without this, iOS Safari lands the tap on the inner <span> (the
   equity badge in strategy tabs) and the enclosing link never fires. */
.btn > * { pointer-events: none; }
/* Hover styles only on devices that actually hover — otherwise iOS requires
   a first tap just to reveal the hover state, then a second tap to click. */
@media (hover: hover) and (pointer: fine) {
    .btn-primary:hover { background: var(--green-700); }
    .btn-secondary:hover { background: var(--gray-600); }
}

/* ── Toggle ── */
.toggle { display: flex; align-items: center; gap: var(--space-2); }
.toggle input[type=checkbox] { width: 36px; height: 20px; appearance: none; background: var(--border); border-radius: 10px; position: relative; cursor: pointer; }
.toggle input[type=checkbox]::after { content: ''; width: 16px; height: 16px; background: var(--text2); border-radius: var(--radius-full); position: absolute; top: 2px; left: 2px; transition: .2s; }
.toggle input[type=checkbox]:checked { background: var(--green-600); }
.toggle input[type=checkbox]:checked::after { left: 18px; background: #fff; }

/* ── Flash Messages ── */
.flash { padding: 10px 16px; border-radius: var(--radius-lg); margin-bottom: var(--space-3); font-size: var(--font-size-md); }
.flash-ok { background: rgba(63,185,80,.1); color: var(--green); border: 1px solid var(--green-600); }
.flash-err { background: rgba(248,81,73,.1); color: var(--red); border: 1px solid var(--red-600); }

/* ── Settings Tabs ── */
.settings-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: var(--space-5); overflow-x: auto; }
.settings-tabs a { padding: 10px 20px; font-size: var(--font-size-base); font-weight: 600; color: var(--text3); border-bottom: 2px solid transparent; white-space: nowrap; transition: all var(--transition-base); cursor: pointer; text-decoration: none; }
.settings-tabs a:hover { color: var(--text); }
.settings-tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Page Header ── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin: var(--space-4) 0; flex-wrap: wrap; gap: var(--space-2); }
.page-header h1 { font-size: var(--font-size-2xl); font-weight: 700; letter-spacing: -0.5px; }
.header-row { display: flex; align-items: center; justify-content: space-between; margin: var(--space-4) 0; flex-wrap: wrap; gap: var(--space-2); }
.header-row h1 { font-size: var(--font-size-2xl); font-weight: 700; letter-spacing: -0.5px; }
.header-actions { display: flex; gap: var(--space-2); align-items: center; }

/* ── Strategy Tabs ── */
.strategy-tabs { display: flex; gap: 6px; margin-bottom: var(--space-4); flex-wrap: wrap; }
.strategy-tabs .btn { font-size: var(--font-size-sm); padding: 6px 16px; }

/* ── Progress Bar ── */
.progress { height: 8px; background: var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--radius-sm); transition: width .3s; }
.progress-sm { height: 4px; }
.progress-lg { height: 16px; }

/* ── Info Box ── */
.info-box { padding: var(--space-3); background: var(--bg); border-radius: var(--radius-lg); border: 1px solid var(--border); font-size: var(--font-size-base); }

/* ── Trial Wizard ── */
.trial-sleeve-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: var(--space-3); margin-bottom: var(--space-3); }
.trial-sleeve-header { display: flex; justify-content: space-between; align-items: center;
    margin-bottom: var(--space-2); padding-bottom: var(--space-2); border-bottom: 1px solid var(--border); }
.trial-param-row { display: flex; align-items: center; gap: var(--space-3); padding: 6px 0;
    border-bottom: 1px solid rgba(48,54,61,.2); }
.trial-param-row:last-child { border-bottom: none; }
.trial-param-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-1); }
.trial-param-value { width: 70px; text-align: right; font-size: var(--font-size-sm); }
.trial-param-action { width: 160px; display: flex; justify-content: flex-end; }

@media (max-width: 480px) {
    .trial-param-row { flex-wrap: wrap; gap: var(--space-1); }
    .trial-param-action { width: 100%; justify-content: flex-start; margin-top: var(--space-1); }
}

/* ── Empty State ── */
.empty-state { text-align: center; padding: 60px var(--space-5); }
.empty-state-icon { font-size: 48px; margin-bottom: var(--space-4); }
.empty-state-title { font-size: var(--font-size-lg); font-weight: 600; margin-bottom: var(--space-2); }
.empty-state-desc { color: var(--text3); max-width: 400px; margin: 0 auto; line-height: 1.6; }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6);
    z-index: 1000; backdrop-filter: blur(4px); justify-content: center; align-items: center; }
.modal-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
    padding: 28px 32px; max-width: 420px; width: 90%; box-shadow: 0 16px 48px rgba(0,0,0,.4); }
.modal-title { font-size: var(--font-size-lg); font-weight: 700; margin-bottom: var(--space-3); }
.modal-body { font-size: var(--font-size-md); color: var(--text2); margin-bottom: var(--space-5); line-height: 1.6; }
.modal-actions { display: flex; gap: var(--space-3); justify-content: flex-end; }

/* ── Spinner ── */
.spinner-wrap { text-align: center; padding: var(--space-6); }
.spinner-ring { display: inline-block; width: 24px; height: 24px;
    border: 3px solid var(--border); border-top-color: var(--blue);
    border-radius: var(--radius-full); animation: spin 1s linear infinite; }

/* ── Rolling Returns ── */
.rolling-returns-card { margin-bottom: var(--space-4); }
.rolling-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--space-3);
}
.rolling-item {
    text-align: center;
    padding: var(--space-3) var(--space-2);
    background: var(--bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    transition: border-color var(--transition-base), background var(--transition-base);
}
.rolling-item.rolling-pos {
    border-color: rgba(63,185,80,0.25);
    background: rgba(63,185,80,0.04);
}
.rolling-item.rolling-neg {
    border-color: rgba(248,81,73,0.25);
    background: rgba(248,81,73,0.04);
}
.rolling-value {
    font-size: var(--font-size-xl);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}
.rolling-pos .rolling-value { color: var(--green); }
.rolling-neg .rolling-value { color: var(--red); }
.rolling-item:not(.rolling-pos):not(.rolling-neg) .rolling-value { color: var(--text3); }
.rolling-label {
    font-size: var(--font-size-xs);
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
    font-weight: 600;
}
.rolling-bar {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}
.rolling-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width .4s ease;
    min-width: 2px;
}
.rolling-bar-fill.bar-green { background: var(--green); }
.rolling-bar-fill.bar-red { background: var(--red); }

/* ── Charts ── */
.chart-md { height: 340px; }
.chart-sm { height: 200px; }
.chart-spark { height: 80px; }

/* ── HTMX partials / shared card internals ── */
.health-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 12px;
}
.status-dot-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
/* Sleeve row atoms used by components/cards.html sleeve_row macro */
.sleeve-name {
    width: 60px;
    font-weight: 600;
}
.sleeve-spacer {
    flex: 1;
}
.sleeve-bar {
    width: 60px;
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    overflow: hidden;
}
.sleeve-bar-fill {
    height: 100%;
    border-radius: 2px;
}

/* ── Animations ── */
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
