/* ── REFLECT PANEL ───────────────────────────────────────────────────────────
   Draggable floating panel — same pattern as .color-pick-panel.
   Fixed bottom-right by default; draggable anywhere via .reflect-panel-header.
   No dark overlay — user can see the day grid behind it.
   ─────────────────────────────────────────────────────────────────────────── */

.reflect-panel {
    position: fixed;
    bottom: 60px;
    right: 20px;
    width: 320px;
    background: var(--bg-panel);
    border: 1px solid var(--box-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    z-index: 500;
    overflow: hidden;
    animation: cp-fade-in 0.15s ease;
}

.reflect-panel-hidden {
    display: none !important;
}

/* ── Header / drag handle ── */
.reflect-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--box-border);
    cursor: grab;
    user-select: none;
    position: relative;
    min-height: 52px;
}

.reflect-panel-header:active {
    cursor: grabbing;
}

.reflect-panel.reflect-is-dragging .reflect-panel-header {
    cursor: grabbing;
}

/* Expand + close buttons sit together on the right */
.reflect-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* ── Expanded state — mirrors .stage-panel-expanded in stage.css ─────────── */
.reflect-panel-expanded {
    width: 600px !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    top: 0 !important;
    left: 50% !important;
    transform: translateX(-50%);
    right: auto !important;
    bottom: auto !important;
    border-radius: 0;
    box-shadow: 0 0 0 100vw rgba(0, 0, 0, 0.85);
    z-index: 1000;
}

.reflect-panel-expanded .reflect-panel-body {
    max-height: calc(100dvh - 80px);
    padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}

/* Cally row — expanded view: breathing room matching food/mood panels */
.reflect-panel-expanded .reflect-cally-row {
    padding-left: 100px;
    padding-right: 100px;
}

.reflect-panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.reflect-panel-title-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reflect-panel-date {
    font-size: 0.78rem;
    color: var(--accent-color);
    font-weight: 500;
    letter-spacing: 0.2px;
}

/* ── Cally row: bubble left, sprite right ── */
.reflect-cally-row {
    display: flex;
    align-items: center;
    margin: 10px 12px 0 12px;
    gap: 0;
}

.reflect-cally-bubble {
    position: relative;
    flex: 1;
    margin-right: 8px;
    background: var(--bg-panel);
    border: 1px solid var(--accent-color);
    border-radius: 8px;
    padding: 8px 10px;
    min-height: 40px;
    display: flex;
    align-items: center;
}

.reflect-cally-bubble::after {
    content: '';
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 7px 0 7px 8px;
    border-style: solid;
    border-color: transparent transparent transparent var(--accent-color);
}

.reflect-cally-bubble::before {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px 0 6px 7px;
    border-style: solid;
    border-color: transparent transparent transparent var(--bg-panel);
    z-index: 1;
}

.reflect-cally-bubble-text {
    font-size: 0.78rem;
    color: var(--accent-color);
    margin: 0;
    line-height: 1.4;
}

.reflect-cally-sprite {
    width: 48px;
    height: 48px;
    image-rendering: pixelated;
    object-fit: contain;
    flex-shrink: 0;
    padding-left: 10px;
    filter: var(--icon-accent-filter);
}

/* ── Panel body ── */
.reflect-panel-body {
    padding: 12px 16px 16px;
    max-height: 60vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--box-border) var(--bg-main);
}

.reflect-panel-body::-webkit-scrollbar { width: 4px; }
.reflect-panel-body::-webkit-scrollbar-track { background: var(--bg-main); }
.reflect-panel-body::-webkit-scrollbar-thumb { background-color: var(--box-border); border-radius: 2px; }

/* ── Section: label + input ── */
.reflect-section {
    margin-bottom: 14px;
}

.reflect-section-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: color-mix(in srgb, var(--text-main) 50%, transparent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

/* ── Star row ── */
.reflect-stars-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 4px 0;
}

.reflect-star {
    image-rendering: pixelated;
    cursor: pointer;
    filter: var(--icon-accent-filter);
    opacity: 0.2;
    transition: opacity 0.1s, transform 0.1s;
}

.reflect-star:hover {
    transform: scale(1.15);
    opacity: 0.7;
}

/* ── Textareas ── */
.reflect-textarea {
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-input);
    border: 1px solid var(--box-border);
    border-radius: 6px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.88rem;
    padding: 8px 10px;
    resize: vertical;
    outline: none;
    line-height: 1.5;
}

.reflect-textarea:focus {
    border-color: var(--accent-color);
}

.reflect-textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

/* ── Save button ── */
.reflect-save-btn {
    width: 100%;
    margin-top: 4px;
}

/* ── RITUAL REFLECT ROW: INHERITED GRID ALIGNMENT ── */

.ritual-reflect-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    /* Mirroring .allocation-grid centering and width logic */
    width: 100%;
    max-width: 1000px; 
    margin: 0 auto 12px auto;
    
    /* Edge-to-edge: remove all padding so elements hit the grid's outer boundary */
    padding: 0;
    box-sizing: border-box;
}

#ritual {
    flex: 1;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-color);
    letter-spacing: 0.6px;
    text-transform: uppercase;
    opacity: 0.8;
    text-align: left; /* Aligns Ritual name to the absolute left edge of the grid */
}

.ritual-reflect-teaser {
    flex: 2; /* Larger weight ensures the middle stays centered */
    text-align: center;
    font-size: 0.7rem;
    color: var(--accent-color);
    opacity: 0.6;
    cursor: pointer;
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ritual-reflect-teaser:hover {
    opacity: 1;
}

#cally {
    flex: 1;
    display: flex;
    justify-content: flex-end; /* Aligns stars/button to the absolute right edge */
    align-items: center;
}

.ritual-reflect-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ritual-reflect-stars {
    display: flex;
    align-items: center;
    gap: 3px;
}

.ritual-reflect-star {
    image-rendering: pixelated;
    cursor: pointer;
    filter: var(--icon-accent-filter);
    transition: opacity 0.1s, transform 0.1s;
}

.ritual-reflect-star:hover {
    transform: scale(1.2);
}

/* ── Mobile ── */
@media (max-width: 600px) {
    .ritual-reflect-row {
        /* Matches mobile 4-box view constraints */
        max-width: 400px;
        padding: 0 4px;
    }

    /* Top-anchor the panel on mobile so the header is always visible.
       Mirrors the stage.css rule for .stage-panel — reflect uses its own
       class so needs its own override. The !important beats the inline
       bottom:60px set by openReflectPanel(). */
    .reflect-panel:not(.reflect-panel-expanded) {
        top: 8px !important;
        bottom: auto !important;
        max-height: calc(100dvh - 80px);
    }

    .reflect-panel:not(.reflect-panel-expanded) .reflect-panel-body {
        max-height: calc(100dvh - 150px - env(safe-area-inset-bottom, 0px));
        padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
    }
}

/* ── Weekly view ─────────────────────────────────────────────────────────────
   Tab bar reuses .report-tab-bar / .report-tab from report-food.css.
   Weekly-specific styles live here.
   ─────────────────────────────────────────────────────────────────────────── */

.reflect-weekly-wrap {
    padding: 4px 0 16px;
}

.reflect-streak-wrap {
    display: flex;
    justify-content: center;
    padding: 8px 0 4px;
}

.reflect-streak-badge {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-color);
}

.reflect-sparkline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
}

.reflect-weekly-section-title {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.reflect-net {
    font-size: 0.7rem;
    font-weight: 700;
}
.reflect-net--up   { color: var(--accent-color); }
.reflect-net--down { color: var(--color-report-warning, #c9913d); }

.reflect-weekly-empty {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
    margin: 8px 0 4px;
}

/* ── Sparkline SVG ── */
.reflect-sparkline {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
    margin-bottom: 12px;
}

.reflect-sparkline-line {
    stroke: var(--accent-color);
    stroke-width: 1.5;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.reflect-sparkline-dot         { fill: var(--accent-color); opacity: 0.65; }
.reflect-sparkline-dot--today  { opacity: 1; }

.reflect-sparkline-day-label {
    fill: var(--text-muted, rgba(255,255,255,0.5));
    font-size: 7px;
    text-anchor: middle;
    font-family: inherit;
}
.reflect-sparkline-day-label--today {
    fill: var(--accent-color);
    font-weight: 700;
}
.reflect-sparkline-val-label {
    fill: var(--text-main, #fff);
    font-size: 7.5px;
    font-weight: 600;
    text-anchor: middle;
    font-family: inherit;
}

/* ── Entry list ── */
.reflect-entry-list {
    display: flex;
    flex-direction: column;
    border-top: 1px solid rgba(255,255,255,0.07);
}

.reflect-entry {
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,0.07);
}

.reflect-entry--today .reflect-entry-date {
    color: var(--accent-color);
    font-weight: 700;
}

.reflect-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    gap: 8px;
}

.reflect-entry-date {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
}

.reflect-entry-stars {
    font-size: 0.72rem;
    letter-spacing: 1px;
    flex-shrink: 0;
}

.reflect-entry-star         { color: rgba(255,255,255,0.15); }
.reflect-entry-star--filled { color: var(--accent-color); }

.reflect-entry-field {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin-top: 3px;
    overflow-wrap: break-word;
}

.reflect-entry-field-label {
    font-weight: 700;
    color: color-mix(in srgb, var(--text-muted) 80%, var(--text-main));
}

/* Expanded view — cally row padding (tab bar now inside body) */
.reflect-panel-expanded .reflect-cally-row {
    padding-left: 100px;
    padding-right: 100px;
}
