/* ============================================================
   Hearth — Design tokens, theming, motion.
   Source of truth: design_handoff_hearth_hoa/README.md
   ============================================================ */

/* ---------- Accent presets: apply to :root via data-accent ---------- */
:root,
:root[data-accent="teal"] {
    --primary: #0e6b73;
    --primary-soft: rgba(14, 107, 115, 0.10);
}
:root[data-accent="navy"] {
    --primary: #1f4e8f;
    --primary-soft: rgba(31, 78, 143, 0.10);
}
:root[data-accent="forest"] {
    --primary: #29714d;
    --primary-soft: rgba(41, 113, 77, 0.11);
}

/* ---------- LIGHT theme (default) ---------- */
:root {
    --bg: #eef2f3;
    --bg-2: #e5ebed;
    --surface: #ffffff;
    --surface-2: #f5f8f8;
    --border: rgba(16, 44, 54, 0.11);
    --border-strong: #7d8e96;
    --ink: #17262d;
    --ink-2: #4f5f68;
    --ink-3: #57666d;
    --green: #267249;
    --green-soft: rgba(47, 143, 91, 0.12);
    --gold: #7f5f28;
    --gold-soft: rgba(166, 124, 52, 0.14);
    --danger: #aa412a;
    --danger-soft: rgba(192, 73, 47, 0.12);
    --chip-muted: rgba(16, 44, 54, 0.06);
    --shadow: 0 2px 6px rgba(16, 40, 50, .06), 0 18px 40px -22px rgba(16, 40, 50, .42);
    --shadow-sm: 0 1px 2px rgba(16, 40, 50, .06);
    --primary-ink: #ffffff;
}

/* Dark theme via data-theme="dark" on <html> */
:root[data-theme="dark"] {
    --bg: #0b1316;
    --bg-2: #0e181c;
    --surface: #13232a;
    --surface-2: #182a31;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: #5c747d;
    --ink: #e9f1f2;
    --ink-2: #9fb2b8;
    --ink-3: #91a2a7;
    --green: #4fb87e;
    --green-soft: rgba(79, 184, 126, 0.15);
    --gold: #cda861;
    --gold-soft: rgba(205, 168, 97, 0.15);
    --danger: #e48471;
    --danger-soft: rgba(224, 113, 91, 0.16);
    --chip-muted: rgba(255, 255, 255, 0.07);
    --shadow: 0 2px 6px rgba(0, 0, 0, .4), 0 22px 48px -24px rgba(0, 0, 0, .8);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .32);
    --primary-ink: #0b1316;
}

/* Dark + accent overrides */
:root[data-theme="dark"],
:root[data-theme="dark"][data-accent="teal"] {
    --primary: #3ab5ae;
    --primary-soft: rgba(58, 181, 174, 0.16);
}
:root[data-theme="dark"][data-accent="navy"] {
    --primary: #71a9e9;
    --primary-soft: rgba(113, 169, 233, 0.16);
}
:root[data-theme="dark"][data-accent="forest"] {
    --primary: #4fb87e;
    --primary-soft: rgba(79, 184, 126, 0.16);
}

/* ---------- Base ---------- */
html, body {
    background: var(--bg);
    color: var(--ink);
    font-family: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 0;
}

.hearth-mono { font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }
.hearth-editorial { font-family: 'Newsreader', Georgia, serif; }

.hearth-tabular { font-variant-numeric: tabular-nums; }

/* ---------- Focus ---------- */
/* Keyboard focus: a surface-coloured gap, then a 2px primary ring. Text inside MudBlazor
   fields and the search box is skipped: their own outline marks focus. */
:focus-visible:not(.mud-input-slot):not(.hearth-search-input) {
    outline: none;
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
}

/* Resting outline of MudBlazor text fields and selects. */
.mud-input.mud-input-outlined .mud-input-outlined-border {
    border-color: var(--border-strong);
}

/* Dark theme: a lighter shade for gradients drawn from the primary, so the dark end stays
   readable against the dark ground. */
:root[data-theme="dark"] .hearth-brand-tile,
:root[data-theme="dark"] .hearth-user-avatar {
    background: linear-gradient(150deg, var(--primary), color-mix(in oklab, var(--primary), #000 12%));
}

/* ---------- Shell layout ---------- */
.hearth-shell {
    display: grid;
    grid-template-columns: 244px minmax(0, 1fr);
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
}

.hearth-sidebar {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 20px 15px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 4;
}

.hearth-right {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    min-width: 0;
}

.hearth-topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 30px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in oklab, var(--bg), transparent 15%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 5;
    position: sticky;
    top: 0;
}

.hearth-main {
    flex: 1;
    overflow-y: auto;
    padding: 26px 30px 46px;
    position: relative;
}

/* Ambient glow behind top of main */
.hearth-main::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 340px;
    background: radial-gradient(
        ellipse at 15% 0%,
        var(--primary-soft),
        transparent 60%
    );
    pointer-events: none;
    transform-origin: 15% 0%;
    animation: hearth-breathe 8s ease-in-out infinite;
    z-index: 0;
}

.hearth-content {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
    animation: hearth-view-settle 0.55s cubic-bezier(.2, .7, .2, 1);
}

/* ---------- Sidebar brand ---------- */
.hearth-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 6px 8px 20px;
}

.hearth-brand-tile {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(150deg, var(--primary), color-mix(in oklab, var(--primary), #000 30%));
    color: var(--primary-ink);
    font-family: 'Newsreader', serif;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px -4px var(--primary-soft);
}

.hearth-brand-title {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.02em;
    color: var(--ink);
}

.hearth-brand-sub {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 10.5px;
    color: var(--ink-3);
    margin-top: 1px;
}

/* ---------- Sidebar sections ---------- */
.hearth-nav-label {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 10.5px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--ink-3);
    padding: 6px 11px 9px;
}

.hearth-nav-label--indent {
    padding-top: 18px;
}

/* ---------- Sidebar nav items ---------- */
.hearth-nav-item {
    position: relative;
    display: block;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--ink-2);
    text-decoration: none;
    font-family: inherit;
    width: 100%;
}

.hearth-nav-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1;
}

.hearth-nav-item svg {
    width: 19px;
    height: 19px;
    stroke: currentColor;
    stroke-width: 1.6;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.hearth-nav-item.active {
    color: var(--primary);
}

.hearth-nav-item.active .hearth-nav-row {
    font-weight: 600;
}

.hearth-nav-item.active svg {
    stroke-width: 1.7;
}

.hearth-nav-item.active::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 12px;
    background: var(--primary-soft);
    z-index: 0;
}

.hearth-nav-item.active::before {
    content: '';
    position: absolute;
    left: -15px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    border-radius: 0 3px 3px 0;
    background: var(--primary);
    z-index: 2;
}

.hearth-nav-badge {
    margin-left: auto;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 9.5px;
    letter-spacing: .06em;
    padding: 3px 6px;
    border-radius: 6px;
    background: var(--primary-soft);
    color: var(--primary);
    z-index: 1;
    position: relative;
}

.hearth-nav-item.active .hearth-nav-badge {
    background: var(--primary);
    color: var(--primary-ink);
}

/* ---------- Sidebar user card ---------- */
.hearth-user-card {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--ink);
    text-decoration: none;
    transition: border-color .18s ease;
}

.hearth-user-card:hover {
    border-color: color-mix(in oklab, var(--primary), transparent 55%);
}

.hearth-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(150deg, var(--primary), color-mix(in oklab, var(--primary), #000 30%));
    color: var(--primary-ink);
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.hearth-user-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--ink);
}

.hearth-user-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 10.5px;
    color: var(--ink-3);
}

.hearth-user-chev {
    margin-left: auto;
    color: var(--ink-3);
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---------- Top bar bits ---------- */
.hearth-topbar-title {
    font-weight: 700;
    font-size: 20px;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin: 0;
    line-height: 1.15;
}

.hearth-topbar-sub {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 11.5px;
    color: var(--ink-3);
    margin-top: 2px;
}

.hearth-topbar-spacer { flex: 1; }

.hearth-search {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    min-width: 250px;
    padding: 0 12px;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-3);
    font-size: 13px;
    transition: border-color .18s ease;
    cursor: pointer;
}

.hearth-search:hover { border-color: color-mix(in oklab, var(--primary), transparent 55%); }

.hearth-search-input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: 13px;
    flex: 1;
    min-width: 0;
}

.hearth-search-input::placeholder { color: var(--ink-3); }

.hearth-search svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hearth-kbd {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 10.5px;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--ink-3);
}

.hearth-icon-btn {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    transition: border-color .18s ease, transform .18s ease, color .18s ease;
    position: relative;
    padding: 0;
}

.hearth-icon-btn:hover {
    border-color: color-mix(in oklab, var(--primary), transparent 55%);
    color: var(--ink);
    transform: translateY(-2px);
}

.hearth-icon-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hearth-notif-dot {
    position: absolute;
    top: 9px;
    right: 10px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 0 2px var(--surface);
    animation: hearth-dot-pulse 2.4s ease-in-out infinite;
}

/* ---------- Chips ---------- */
.hearth-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 11.5px;
    line-height: 1;
    white-space: nowrap;
}

.hearth-chip--primary { background: var(--primary-soft); color: var(--primary); }
.hearth-chip--green   { background: var(--green-soft);   color: var(--green); }
.hearth-chip--gold    { background: var(--gold-soft);    color: var(--gold); }
.hearth-chip--danger  { background: var(--danger-soft);  color: var(--danger); }
.hearth-chip--muted   { background: var(--chip-muted);   color: var(--ink-2); }

/* ---------- Cards ---------- */
.hearth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.hearth-card--feature { border-radius: 20px; padding: 24px; }
.hearth-card--tight { padding: 16px; }

.hearth-lift {
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.hearth-lift:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: color-mix(in oklab, var(--primary), transparent 55%);
}

.hearth-eyebrow {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 10.5px;
    letter-spacing: .10em;
    text-transform: uppercase;
    color: var(--ink-3);
}

/* ---------- Buttons ---------- */
.hearth-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 13px;
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    transition: transform .15s ease, border-color .18s ease, box-shadow .18s ease;
    text-decoration: none;
    line-height: 1;
}

.hearth-btn:hover {
    transform: translateY(-2px);
    border-color: color-mix(in oklab, var(--primary), transparent 55%);
}

.hearth-btn svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hearth-btn--primary {
    background: var(--primary);
    color: var(--primary-ink);
    border-color: transparent;
    box-shadow: 0 6px 18px -8px var(--primary);
}
.hearth-btn--primary:hover {
    border-color: transparent;
    box-shadow: 0 10px 22px -8px var(--primary);
}

.hearth-btn--ghost { background: transparent; border-color: transparent; color: var(--primary); }
.hearth-btn--full { width: 100%; }

/* ---------- Live status dots ---------- */
.hearth-livedot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    color: var(--green);
    box-shadow: 0 0 0 0 currentColor;
    animation: hearth-livedot 2.5s ease-out infinite;
}
.hearth-livedot--white { background: #8fe6b0; color: #8fe6b0; }

/* ---------- Segmented control ---------- */
.hearth-seg {
    display: inline-flex;
    padding: 3px;
    border-radius: 10px;
    background: var(--surface-2);
    gap: 2px;
}

.hearth-seg-btn {
    padding: 6px 12px;
    border-radius: 8px;
    background: transparent;
    color: var(--ink-3);
    font-family: inherit;
    font-weight: 600;
    font-size: 12px;
    border: none;
    cursor: pointer;
    transition: background .18s ease, color .18s ease;
}

.hearth-seg-btn.active {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

/* ---------- Progress bar ---------- */
.hearth-bar-track {
    height: 8px;
    border-radius: 999px;
    background: var(--chip-muted);
    overflow: hidden;
}

.hearth-bar-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--primary);
    transition: width .4s ease;
}

.hearth-bar-fill--green  { background: var(--green); }
.hearth-bar-fill--gold   { background: var(--gold); }
.hearth-bar-fill--danger { background: var(--danger); }

/* ---------- Balance hero sheen ---------- */
.hearth-hero-sheen {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: inherit;
    pointer-events: none;
}

.hearth-hero-sheen::after {
    content: '';
    position: absolute;
    top: -30%;
    bottom: -30%;
    width: 38%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.22), transparent);
    transform: skewX(-18deg) translateX(-200%);
    animation: hearth-sheen 7s ease-in-out 1.5s infinite;
}

/* ---------- Chat bubbles ---------- */
.hearth-bubble {
    padding: 10px 14px;
    border-radius: 15px;
    font-size: 14px;
    line-height: 1.5;
    max-width: 88%;
    text-wrap: pretty;
}

.hearth-bubble--in  { background: var(--surface-2); color: var(--ink); border-bottom-left-radius: 5px; }
.hearth-bubble--out { background: var(--primary);   color: var(--primary-ink); border-bottom-right-radius: 5px; }

/* ---------- Assistant typing dots ---------- */
.hearth-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 12px 14px;
}
.hearth-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink-3);
    animation: hearth-typing 1.2s ease-in-out infinite;
}
.hearth-typing span:nth-child(2) { animation-delay: .18s; }
.hearth-typing span:nth-child(3) { animation-delay: .36s; }

/* ---------- Sparkline pulse dot ---------- */
.hearth-spark-dot {
    animation: hearth-spark-pulse 2s ease-in-out infinite;
}

/* ---------- Keyframes ---------- */
@keyframes hearth-breathe {
    0%, 100% { transform: scale(1); opacity: .5; }
    50%      { transform: scale(1.05); opacity: 1; }
}

@keyframes hearth-view-settle {
    from { transform: translateY(12px); }
    to   { transform: translateY(0); }
}

@keyframes hearth-sheen {
    0%   { transform: skewX(-18deg) translateX(-200%); }
    60%  { transform: skewX(-18deg) translateX(350%); }
    100% { transform: skewX(-18deg) translateX(350%); }
}

@keyframes hearth-livedot {
    0%   { box-shadow: 0 0 0 0 currentColor; }
    70%  { box-shadow: 0 0 0 7px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

@keyframes hearth-dot-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .35; }
}

@keyframes hearth-typing {
    0%, 100% { transform: translateY(0); opacity: .35; }
    50%      { transform: translateY(-4px); opacity: 1; }
}

@keyframes hearth-spark-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .3; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .hearth-main::before,
    .hearth-content,
    .hearth-hero-sheen::after,
    .hearth-livedot,
    .hearth-notif-dot,
    .hearth-typing span,
    .hearth-spark-dot { animation: none !important; }
}

/* ---------- Community branding ---------- */
/* The community's logo in place of the letter tile (sidebar). */
.hearth-brand-logo {
    background: var(--surface);
    object-fit: contain;
}

/* Accent picker swatch (top bar and its menu). */
.hearth-accent-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--border);
}

/* Sign-in page logo. */
.auth-brand-logo {
    max-width: 180px;
    max-height: 72px;
    object-fit: contain;
}

/* ---------- Impersonation banner ---------- */
.hearth-impersonation-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--danger-soft);
    color: var(--ink);
    border-bottom: 1px solid color-mix(in oklab, var(--danger), transparent 60%);
    font-size: 13.5px;
}
.hearth-impersonation-timer {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    color: var(--danger);
}
.hearth-impersonation-spacer { flex: 1; }
