/* styles/widgets/metrics.css
 *
 * Extracted from styles/main.css during T4#20 (the May-2026
 * CSS-split refactor). Originally lived at lines 2086-2524
 * of main.css. Cascade order is preserved: main.css loads first
 * (themes + base + modal/tab/layout infra), then per-widget
 * files in alphabetical order via <link> tags in index.html.
 */

/* ── CUSTOM METRICS WIDGET (Phase 2.11.5 Slice 1) ─
   List view of user-defined metrics. Slice 1 ships the bones:
   empty state, list of metrics with name + unit + type icon, a
   delete button per row, and a "+ New metric" CTA at the bottom.
   Slice 2 adds quick-log inputs inline; Slice 3 adds sparklines;
   Slice 4 adds archive + reorder. */
.cm-panel { gap: 0; }
.cm-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}
.cm-empty {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.55;
    text-align: center;
    padding: 14px 12px;
}
.cm-empty b { color: var(--text); }
.cm-row {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color 120ms ease;
    overflow: hidden;
}
.cm-row:hover                   { border-color: var(--accent); }
.cm-row.expanded                { border-color: var(--accent); }
.cm-row-head {
    appearance: none;
    background: transparent;
    border: none;
    width: 100%;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    text-align: left;
    color: var(--text);
}
.cm-row-icon {
    font-size: 18px;
    line-height: 1;
    flex: 0 0 auto;
}
.cm-row-body {
    flex: 1 1 auto;
    min-width: 0;
}
.cm-row-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}
.cm-row-unit {
    font-weight: 400;
    color: var(--muted);
    font-size: 11px;
    margin-left: 4px;
}
.cm-row-meta {
    font-size: 10px;
    color: var(--muted);
    margin-top: 2px;
}
.cm-row-latest {
    flex: 0 0 auto;
    text-align: right;
    font-size: 11px;
    color: var(--text);
    line-height: 1.25;
    white-space: nowrap;
}
.cm-row-latest b {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.cm-row-latest-when {
    color: var(--muted);
    font-size: 10px;
    margin-left: 4px;
}
.cm-row-latest-empty {
    color: var(--muted);
    font-style: italic;
    font-size: 10px;
}
.cm-row-caret {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
    margin-left: 6px;
    transition: color 120ms ease;
}
.cm-row.expanded .cm-row-caret { color: var(--accent); }
.cm-row-expanded {
    border-top: 1px solid var(--border);
    padding: 10px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.cm-row-del-link {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    align-self: flex-end;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 120ms ease, background 120ms ease;
}
.cm-row-del-link:hover {
    color: var(--red);
    background: color-mix(in srgb, var(--red) 10%, transparent);
}

/* Quick-add row inside an expanded card. Wraps onto multiple
   lines on narrow viewports so each input keeps a usable width. */
.cm-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px;
}
.cm-quick-date  { flex: 0 0 130px; }
.cm-quick-value { flex: 0 0 110px; }
.cm-quick-note  { flex: 1 1 160px; }
.cm-quick-save  { flex: 0 0 auto; }

/* Past-entry list inside the expanded card. */
.cm-log-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 280px;
    overflow-y: auto;
}
.cm-log-empty {
    font-size: 11px;
    color: var(--muted);
    text-align: center;
    padding: 8px;
    font-style: italic;
}
.cm-log-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 11px;
}
.cm-log-row:hover { border-color: var(--accent); }
.cm-log-date {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    flex: 0 0 90px;
}
.cm-log-value {
    font-weight: 600;
    color: var(--text);
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
}
.cm-log-note {
    flex: 1 1 auto;
    color: var(--muted);
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cm-log-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 4px;
    margin-left: auto;
}
.cm-log-btn {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: color 120ms ease, background 120ms ease;
}
.cm-log-btn:hover         { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.cm-log-btn-del:hover     { color: var(--red);    background: color-mix(in srgb, var(--red) 10%, transparent); }
.cm-log-btn-save          { padding: 4px 10px !important; font-size: 11px !important; }

/* Inline-edit version of a log row. Same gap so things line up. */
.cm-log-row-edit { padding: 4px 6px; }
.cm-log-row-edit .cm-quick-date  { flex: 0 0 130px; }
.cm-log-row-edit .cm-quick-value { flex: 0 0 110px; }
.cm-log-row-edit .cm-quick-note  { flex: 1 1 140px; }

/* Slice 3: Chart container inside an expanded card. Fixed height
   so the canvas has something to size against (Chart.js needs a
   non-zero parent height when maintainAspectRatio is false). */
.cm-chart {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    height: 180px;
    position: relative;
}
.cm-chart canvas { width: 100% !important; height: 100% !important; }

/* Slice 4: Reorder buttons live on the row head. Stop click
   propagation so pressing one doesn't also expand/collapse the row. */
.cm-row-reorder {
    flex: 0 0 auto;
    display: inline-flex;
    flex-direction: column;
    gap: 1px;
    margin-left: 4px;
}
.cm-row-reorder-btn {
    appearance: none;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    cursor: pointer;
    font-size: 8px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    transition: color 120ms ease, border-color 120ms ease;
}
.cm-row-reorder-btn:hover:not(:disabled) {
    color: var(--accent);
    border-color: var(--accent);
}
.cm-row-reorder-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Slice 4: Two-button row at the bottom of an expanded card. */
.cm-row-actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.cm-row-edit-link,
.cm-row-del-link {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 120ms ease, background 120ms ease;
}
.cm-row-edit-link:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.cm-row-del-link:hover  { color: var(--red);    background: color-mix(in srgb, var(--red) 10%, transparent); }

/* Slice 3: Preset cards in the new-metric modal. */
.cm-presets {
    margin-bottom: 14px;
}
.cm-presets-label { margin-bottom: 4px; }
.cm-presets-help {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 8px;
}
.cm-presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 6px;
}
.cm-preset-card {
    appearance: none;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: border-color 120ms ease, background 120ms ease;
}
.cm-preset-card:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--surface2));
}
.cm-preset-icon { font-size: 16px; line-height: 1; }
.cm-preset-label { font-size: 12px; font-weight: 600; }
.cm-preset-blurb { font-size: 10px; color: var(--muted); }
.cm-presets-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 14px 0 4px 0;
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
}
.cm-presets-divider::before,
.cm-presets-divider::after {
    content: '';
    flex: 1 1 auto;
    height: 1px;
    background: var(--border);
}
.cm-presets-divider span { flex: 0 0 auto; }

/* Slice 3: Chart-kind picker. Three small horizontal cards. */
.cm-chart-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 4px;
}
.cm-chart-card {
    flex: 1 1 90px;
    cursor: pointer;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text);
    transition: border-color 120ms ease, background 120ms ease;
}
.cm-chart-card:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 6%, var(--surface2));
}
.cm-chart-card input[type="radio"] {
    accent-color: var(--accent);
    flex: 0 0 auto;
}
.cm-chart-card:has(input[type="radio"]:checked) {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface2));
}

.cm-archive-field { padding-top: 8px; border-top: 1px solid var(--border); margin-top: 12px; }
.cm-add-btn {
    appearance: none;
    width: 100%;
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--muted);
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}
.cm-add-btn:hover {
    border-color: var(--accent);
    border-style: solid;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* ── New Metric modal ─────────────────────────────
   Reuses .modal-overlay / .modal scaffolding. .cm-modal narrows
   the standard modal slightly. The two type cards stack on
   narrow viewports via flex-wrap so the modal stays readable. */
.cm-modal { width: 480px; }
.cm-type-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}
.cm-type-card {
    flex: 1 1 200px;
    cursor: pointer;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    transition: border-color 120ms ease, background 120ms ease;
}
.cm-type-card:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 6%, var(--surface2));
}
.cm-type-card input[type="radio"] {
    margin-top: 2px;
    accent-color: var(--accent);
    flex: 0 0 auto;
}
.cm-type-card:has(input[type="radio"]:checked) {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface2));
}
.cm-type-card-body { flex: 1 1 auto; }
.cm-type-card-icon { font-size: 18px; line-height: 1; margin-bottom: 4px; }
.cm-type-card-label { font-size: 13px; font-weight: 600; color: var(--text); }
.cm-type-card-note { font-size: 10px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.cm-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

