/* view-dashboard.css — dashboard: today hero, memory stats, deck tiles, collection catalog, heatmap. Owner: Phase 8.
   Token-only colours (no hex/rgba) so Light and Dark both pass WCAG AA (spec §1.4). Dynamic widths arrive as --pct (css-vars.js). */

/* ---------- Today hero ---------- */
.today-hero {
    position: relative;
    margin-bottom: var(--space-6);
    padding: var(--space-6);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
    overflow: hidden;
}

.today-hero::before { /* gradient hairline on top (spec §2.3) */
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: var(--gradient-brand);
}

.today-hero-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.welcome-text h1 {
    font-family: var(--font-ui);
    font-weight: var(--fw-bold);
    font-size: var(--fs-3xl);
    line-height: var(--lh-tight);
    letter-spacing: -0.01em;
    color: var(--text-1);
    overflow-wrap: anywhere;
}

.level-line { margin-top: var(--space-2); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* Primary progress chip: what the learner owns ("Đã nhớ 128 từ"). The XP level chip below is the smaller secondary one. */
.known-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    background: var(--brand-soft);
    color: var(--text-brand);
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
}

.known-chip strong { font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }

.level-chip-sub { background: var(--surface-2); color: var(--text-2); font-size: var(--fs-xs); font-weight: var(--fw-medium); }

.level-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-3);
    border-radius: var(--radius-full);
    background: var(--brand-soft);
    color: var(--text-brand);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
}

.streak-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--state-learning-soft);
    border: 1px solid color-mix(in srgb, var(--state-learning) 30%, transparent);
    color: var(--state-learning);
    font-weight: var(--fw-bold);
    font-family: var(--font-ui);
}

.dash-icon { width: 20px; height: 20px; flex: none; }
.dash-icon-sm { width: 16px; height: 16px; flex: none; color: var(--text-brand); }

.today-headline {
    margin-top: var(--space-4);
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
    color: var(--text-1);
}

/* Hero body: headline + CTA on the left, daily-goal ring on the right (stacks on narrow screens) */
.today-hero-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-5);
}

.today-hero-main { flex: 1 1 280px; min-width: 0; }

.today-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.today-actions .btn[hidden] { display: none; }

.today-more {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-4);
}

.btn-lg { min-height: var(--control-h-lg); padding: 0 var(--space-6); font-size: var(--fs-md); font-weight: var(--fw-bold); }

/* Daily-goal ring: conic-gradient driven by --pct (set from JS with setProperty). The % text and the "12/20 thẻ hôm nay"
   caption carry the information, so the colour is never the only signal. */
.today-goal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    flex: 0 0 auto;
    text-align: center;
}

.goal-ring {
    --ring: 96px;
    position: relative;
    display: grid;
    place-items: center;
    width: var(--ring);
    height: var(--ring);
    border-radius: 50%;
    background: conic-gradient(from 0deg, var(--brand-1), var(--brand-2) calc(var(--pct, 0) * 1%), var(--surface-3) calc(var(--pct, 0) * 1%));
}

.goal-ring::before { /* hole */
    content: '';
    position: absolute;
    inset: 10px;
    border-radius: 50%;
    background: var(--surface-1);
}

.goal-ring-pct {
    position: relative;
    font-family: var(--font-display);
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
    color: var(--text-1);
    font-variant-numeric: tabular-nums;
}

.goal-text { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-1); }

/* ---------- Progress meter (CSS-only; width from --pct) ---------- */
.meter {
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--surface-3);
    overflow: hidden;
}

.meter-fill {
    width: calc(var(--pct, 0) * 1%);
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--gradient-brand);
    transition: width var(--dur-slow) var(--ease-out);
}

/* ---------- Shared small bits ---------- */
.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.section-head .section-title { margin-bottom: 0; }

.clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ---------- Memory progress ---------- */
.progress-overview-card {
    margin-bottom: var(--space-6);
    padding: var(--space-6);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
}

.stats-overview-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

.stat-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-4);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    text-align: center;
}

.stat-value {
    font-family: var(--font-display);
    font-size: var(--fs-3xl);
    font-weight: var(--fw-bold);
    line-height: var(--lh-tight);
    color: var(--text-1);
    font-variant-numeric: tabular-nums;
}

.stat-label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-1); }
.stat-help { font-size: var(--fs-xs); color: var(--text-3); min-height: 1em; }
.stats-link-row { margin-top: var(--space-4); text-align: right; }
.stats-link { color: var(--text-brand); font-weight: var(--fw-semibold); text-decoration: underline; text-underline-offset: 3px; }
.stats-link:hover { text-decoration-thickness: 2px; }

.stat-progress-bar {
    width: 100%;
    height: 6px;
    margin-top: var(--space-2);
    border-radius: var(--radius-full);
    background: var(--surface-3);
    overflow: hidden;
}

.stat-progress-fill {
    width: calc(var(--pct, 0) * 1%);
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--gradient-brand);
    transition: width var(--dur-slow) var(--ease-out);
}

@media (max-width: 480px) {
    .stats-overview-grid { grid-template-columns: 1fr; }
    .today-goal { flex-direction: row; gap: var(--space-3); text-align: left; }
    .goal-ring { --ring: 72px; }
    .goal-ring::before { inset: 8px; }
    .goal-ring-pct { font-size: var(--fs-md); }
    .today-hero, .progress-overview-card { padding: var(--space-4); }
    .welcome-text h1 { font-size: var(--fs-2xl); }
}

/* ---------- Decks ---------- */
.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-8);
}

.deck-list { display: grid; gap: var(--space-4); }

.collection-accordion {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-1);
    overflow: hidden;
}

.collection-accordion-header {
    all: unset;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-4) var(--space-5);
    cursor: pointer;
    user-select: none;
}

.collection-accordion-header:hover { background: var(--surface-2); }
.collection-accordion-header:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }

.accordion-arrow {
    display: inline-block;
    color: var(--text-brand);
    transition: transform var(--dur-fast) var(--ease-out);
}

/* Long (user-authored) names must wrap inside the header instead of widening it. */
.collection-title-text { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--text-1); min-width: 0; overflow-wrap: anywhere; }
.collection-deck-count { font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; }

.collection-accordion-content { display: none; padding: 0 var(--space-5) var(--space-5); }
.collection-accordion.expanded .accordion-arrow { transform: rotate(90deg); }
.collection-accordion.expanded .collection-accordion-content { display: block; }

.decks-vertical-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
    gap: var(--space-4);
}

.deck-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-5);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-1);
    min-width: 0;
}

.deck-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2); }

.deck-header { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-2); }
.deck-info { min-width: 0; }

.deck-info h3 {
    font-family: var(--font-ui);
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
    color: var(--text-1);
    line-height: var(--lh-heading);
    overflow-wrap: anywhere;
}

.deck-desc, .deck-mode { font-size: var(--fs-sm); color: var(--text-2); }
.deck-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.deck-mode { font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--space-1); }

.deck-menu-btn {
    all: unset;
    box-sizing: border-box;
    flex: none;
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: var(--fs-lg);
    cursor: pointer;
}

.deck-menu-btn:hover { background: var(--surface-2); color: var(--text-1); }
.deck-menu-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.deck-options {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
}

.deck-option { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); font-size: var(--fs-sm); color: var(--text-1); }

.deck-stats { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.stat-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    font-variant-numeric: tabular-nums;
}

.deck-mastery { display: flex; align-items: center; gap: var(--space-3); font-size: var(--fs-xs); color: var(--text-2); }
.deck-mastery .meter { flex: 1; height: 6px; }
.deck-mastery-pct { min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }

.deck-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: auto; }
.deck-card .is-done { color: var(--success); }

/* Native controls inside tiles: same look as the shared select-sm */
.deck-option select, .select-sm {
    min-height: var(--control-h-sm);
    padding: 0 var(--space-3);
    background: var(--surface-1);
    color: var(--text-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: var(--fs-sm);
    max-width: 100%;
}

/* ---------- Empty states ---------- */
.empty-state-boxed {
    max-width: none;
    margin: 0;
    padding: var(--space-8) var(--space-4);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface-1);
}

/* ---------- Catalog ---------- */
.collections-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
    gap: var(--space-4);
}

.collection-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-5);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
    min-width: 0;
}

.collection-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2); }
.collection-badges { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-bottom: var(--space-2); }

.collection-info h3, .collection-info .manage-card-title {
    font-family: var(--font-ui);
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
    color: var(--text-1);
    margin-bottom: var(--space-2);
    overflow-wrap: anywhere;
}

.collection-info p { color: var(--text-2); font-size: var(--fs-sm); line-height: var(--lh-body); }
.collection-meta { margin-top: var(--space-3); font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-brand); }
.collection-action .btn { width: 100%; }

/* "Đã đăng ký ✓" -> reveals "Hủy đăng ký" on hover / keyboard focus (spec §3.5) */
.btn-subscribed .label-off { display: none; }
.btn-subscribed:hover .label-on, .btn-subscribed:focus-visible .label-on { display: none; }
.btn-subscribed:hover .label-off, .btn-subscribed:focus-visible .label-off { display: inline; }
.btn-subscribed:hover, .btn-subscribed:focus-visible { color: var(--danger); }

/* ---------- Heatmap (spec §3.12) ---------- */
.heatmap-wrapper {
    margin-top: var(--space-8);
    padding: var(--space-5);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.heatmap-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--space-3); }
.heatmap-head .section-title { margin-bottom: 0; }
.heatmap-summary { margin: var(--space-1) 0 var(--space-3); }
.heatmap-legend { display: flex; align-items: center; gap: var(--space-1); font-size: var(--fs-xs); color: var(--text-2); }
.heatmap-scroll { overflow-x: auto; padding-bottom: var(--space-2); }

.heatmap-grid {
    display: grid;
    grid-template-rows: repeat(7, 12px);
    grid-auto-flow: column;
    grid-auto-columns: 12px;
    gap: 3px;
    width: max-content;
}

.heat-tile {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background: var(--heat-0);
    box-shadow: inset 0 0 0 1px var(--heat-edge);
}

.heat-tile[data-level="1"] { background: var(--heat-1); }
.heat-tile[data-level="2"] { background: var(--heat-2); }
.heat-tile[data-level="3"] { background: var(--heat-3); }
.heat-tile[data-level="4"] { background: var(--heat-4); }
.heat-tile.is-today { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

/* ---------- Tip ---------- */
.tip-card {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-8);
    padding: var(--space-3) var(--space-4);
    background: var(--brand-soft);
    border-radius: var(--radius-md);
    color: var(--text-1);
    font-size: var(--fs-sm);
}

.tip-card strong { color: var(--text-brand); }

/* ---------- Settings: "Mục tiêu hằng ngày" group (lives with the goal feature; classes are unique to it) ---------- */
.goal-options { display: flex; flex-direction: column; gap: var(--space-3); }
.goal-option-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); }
.goal-option-row .goal-count-input { width: 6.5rem; flex: 0 0 auto; } /* beats the generic .input width:100% so "thẻ" sits beside the field */
.goal-count-input:disabled { opacity: 0.6; cursor: not-allowed; }
