/* ============================================================
   Clinical Calm: app components (dashboard, its popups and the
   public calculator). Primitives are in ui.css, tokens in
   tailwind-input.css. Restyle hooks here; do not rename them.
   ============================================================ */

/* ---------- Type in the app ----------
   Page and popup titles use the display face; card and row titles are
   Figtree. :where() keeps these at zero specificity so any component
   class (e.g. .upcoming-card-title on an h3) wins. */

:where(.dashboard-app-shell, .journal-app, .calculator-page) :where(h1, h2) {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: var(--foreground);
}

:where(.dashboard-app-shell, .journal-app, .calculator-page) :where(h3, h4, h5) {
    font-family: var(--font-sans);
    font-weight: 600;
    line-height: 1.3;
    color: var(--foreground);
}

.dashboard-app-shell h1 { font-size: 1.875rem; }
.dashboard-app-shell h2 { font-size: 1.25rem; }
.dashboard-app-shell h3 { font-size: 1rem; }

/* Tailwind preflight resets headings to font-size: inherit, so popups,
   toasts and banners get their own small ladder. */
.journal-app :is(.modal-backdrop, #update-banner, #install-banner, #feedback-widget) h1 { font-size: 1.375rem; }
.journal-app :is(.modal-backdrop, #update-banner, #install-banner, #feedback-widget) h2 { font-size: 1.25rem; }
.journal-app :is(.modal-backdrop, #update-banner, #install-banner, #feedback-widget) h3 { font-size: 1rem; }
.journal-app :is(.modal-backdrop, #update-banner, #install-banner, #feedback-widget) h4 { font-size: 0.9375rem; }

:where(.dashboard-app-shell, .journal-app) :where(label) {
    font-size: 0.875rem;
    font-weight: 500;
}

:where(.dashboard-app-shell, .journal-app) .font-mono {
    font-family: var(--font-mono);
}

/* ---------- Page headers ---------- */

.lg-head {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding-top: 1.25rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 1024px) {
    .lg-head {
        padding-top: 2rem;
    }
}

.lg-head__title {
    display: inline-block;
}

.lg-head__sub {
    margin-top: 0.125rem;
    font-size: 0.8125rem;
    line-height: 1.35;
    color: var(--muted-foreground);
}

@media (max-width: 639px) {
    .dashboard-app-shell h1 { font-size: 1.625rem; }
}

/* ---------- Small marks ---------- */

/* Peptide colour as a small swatch beside the name. */
.lg-dot {
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    flex: 0 0 auto;
    border-radius: 999px;
    box-shadow: inset 0 0 0 1px rgba(2, 6, 23, 0.12);
}

.lg-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    flex: 0 0 auto;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-size: 1.1rem;
    line-height: 1;
}

.lg-avatar--lg {
    width: 3rem;
    height: 3rem;
    font-size: 1.45rem;
}

/* Streak: a small flame beside the count. Still, unless it just landed. */
.lg-streak {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
    margin-top: 0.1rem;
    white-space: nowrap;
}

.lg-streak__flame {
    width: 0.95rem;
    height: 1.25rem;
    flex: 0 0 auto;
    align-self: center;
    overflow: visible;
}

.lg-streak__outline {
    fill: none;
    stroke: #ea580c;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.lg-streak__core {
    fill: #fb923c;
}

.lg-streak[data-streak="0"] .lg-streak__core {
    fill: var(--muted);
}

.lg-streak[data-streak="0"] .lg-streak__outline {
    stroke: var(--border-strong);
}

.lg-streak__count {
    font-weight: 700;
    font-size: 1.125rem;
    line-height: 1;
    color: var(--foreground);
    font-variant-numeric: tabular-nums;
}

.lg-streak__count.is-landed {
    animation: lgTallyLand 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes lgTallyLand {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.lg-streak__unit {
    font-size: 0.8125rem;
    line-height: 1;
    color: var(--muted-foreground);
}

/* ---------- Calendar ---------- */

.calendar-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.125rem;
    line-height: 1.2;
    letter-spacing: -0.015em;
    color: var(--foreground);
}

.calendar-dow {
    padding-block: 0.25rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: center;
    color: var(--muted-foreground);
}

.calendar-day {
    position: relative;
    border-radius: 0.5rem;
    background: transparent;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    transition: background-color 120ms ease;
}

.calendar-day:hover {
    background: var(--muted);
}

.calendar-day:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 1px;
}

.calendar-week-row {
    position: relative;
    border-bottom: 1px solid var(--border);
}

.calendar-week-row:hover {
    background: var(--secondary);
}

.calendar-week-row--today {
    background: var(--accent-tint);
}

.calendar-week-date {
    width: 3.25rem;
    flex: 0 0 auto;
    text-align: center;
    line-height: 1;
}

.calendar-week-dow {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted-foreground);
}

.calendar-week-num {
    font-weight: 700;
    font-size: 1.25rem;
    line-height: 1.2;
    color: var(--foreground);
    font-variant-numeric: tabular-nums;
}

.calendar-week-row--today .calendar-week-num,
.calendar-week-row--today .calendar-week-dow {
    color: var(--accent-ink);
}

/* ---------- Popups ---------- */

/* One width for every popup; prompt and confirm dialogs (role="document")
   stay small. */
.modal-backdrop .lg-panel:not([role="document"]),
.modal-backdrop .modal-sheet:not([role="document"]) {
    max-width: 44rem;
}

/* Centre popups on the content column, not the viewport, beside the
   260px sidebar. */
@media (min-width: 1024px) {
    .journal-app .modal-backdrop {
        padding-left: 260px;
    }
}

/* Two surfaces inside a popup: the sheet, and slate-50 for sections and
   rows. Rows inside a section go back to the sheet colour. */
.modal-backdrop .modal-section-card,
.modal-backdrop .modal-section-card-muted {
    background: var(--surface);
    border-color: var(--border);
}

/* `[class*=...]` also matches `hover:bg-secondary`, so a selected chip that
   carries bg-primary is excluded, or its fill turns to surface/card under
   its own primary-foreground text (white on white, slate on slate). */
.modal-backdrop [class*="bg-secondary"]:not(input):not(select):not(textarea):not(.bg-primary) {
    background: var(--surface) !important;
}

.modal-backdrop .modal-section-card [class*="bg-secondary"]:not(input):not(select):not(textarea):not(.bg-primary),
.modal-backdrop .modal-section-card [class*="bg-card"]:not(input):not(select):not(textarea):not(.bg-primary) {
    background: var(--card) !important;
}

/* One button height inside popups; ghost icon buttons are exempt. */
.modal-backdrop .lg-btn:not(.lg-btn--ghost) {
    min-height: 2.5rem;
    padding-block: 0.4rem;
    font-size: 0.875rem;
}

.modal-backdrop [data-log-date-shortcut],
.journal-app [data-log-date-shortcut] {
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.8125rem;
}

/* Weight change reads as gain or loss without a second green. */
.stat-change--good,
.stat-change--bad {
    color: inherit;
}

/* ---------- Segmented toggles ----------
   calculator.js toggles bg-green-500/bg-accent/text-white at runtime,
   so the selected look is keyed off those classes. */

.calc-mode-btn,
.dose-unit-btn {
    border: 1px solid var(--border-strong);
    border-radius: 0.5rem;
    background: var(--card);
    color: var(--muted-foreground);
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.calc-mode-btn:hover,
.dose-unit-btn:hover {
    color: var(--foreground);
}

.calc-mode-btn.bg-green-500,
.calc-mode-btn.bg-accent,
.dose-unit-btn.bg-green-500,
.dose-unit-btn.bg-accent {
    border-color: var(--primary);
    background: var(--primary) !important;
    color: var(--primary-foreground);
}

/* ---------- Colour swatches ----------
   selectColor() marks the active swatch with .border-white; that hook
   draws a ring. The usage count only shows for colours in use. */

.lg-swatch,
.onboarding-color-option {
    position: relative;
    width: 2.25rem;
    height: 2.25rem;
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    border-radius: 999px;
    box-shadow: inset 0 0 0 1px rgba(2, 6, 23, 0.12);
    cursor: pointer;
    overflow: visible;
    transition: box-shadow 150ms ease;
}

.lg-swatch.border-white,
.onboarding-color-option.border-white {
    box-shadow:
        0 0 0 2px var(--card),
        0 0 0 4px var(--foreground);
}

.lg-swatch:focus-visible,
.onboarding-color-option:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 4px;
}

.lg-swatch .color-usage-count,
.onboarding-color-option .color-usage-count {
    right: -0.3rem;
    bottom: -0.3rem;
    min-width: 1.05rem;
    height: 1.05rem;
    font-size: 0.625rem;
    font-weight: 700;
}

.lg-swatch .color-usage-count.is-empty {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    .lg-streak__count.is-landed {
        animation: none;
    }

    .calendar-day,
    .lg-swatch,
    .onboarding-color-option {
        transition: none;
    }
}
