/* Nutria v003 — reusable UI components (UI/UX doc v2 §7–§11).
   Lists instead of cards, thin separators, green only with meaning. */

/* ----- Sections (former cards, stripped: spacing + heading only) ----- */

.card {
    background: none;
    border: none;
    padding: 0;
    margin-bottom: var(--space-6);
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.section-head h2 {
    margin: 0;
}

.section-head .icon-button,
.section-head a {
    color: var(--faint);
    text-decoration: none;
}

/* ----- Category browse (drilldown card, search_design_001 §6) ----- */

.browse-head {
    justify-content: flex-start;
}

.browse-back {
    padding: 0 var(--space-2) 0 0;
}

.browse-back[hidden],
.browse-more[hidden] {
    display: none;
}

.browse-more {
    display: block;
    text-align: center;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
}

/* overview pages (#/foods-all, #/activities-all) */

a.list-row {
    text-decoration: none;
}

.overview-segment {
    margin-bottom: var(--space-4);
}

.overview-segment[hidden] {
    display: none;
}

.scroll-sentinel {
    height: 1px;
}

/* ----- Lists: open rows with 1px separators ----- */

.list {
    display: block;
}

.list-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-3);
    align-items: center;
    width: 100%;
    background: none;
    border: none;
    border-radius: 0;
    padding: var(--space-3) 0;
    min-height: 44px;
    text-align: left;
    font: inherit;
    color: var(--fg);
}

.list > * + * {
    border-top: 1px solid var(--border);
}

/* row with a leading icon badge */
.list-row.row-icon {
    grid-template-columns: auto 1fr auto;
}

.row-main {
    min-width: 0; /* allow text to wrap instead of overflowing the grid */
}

.row-title {
    display: block;
    overflow-wrap: anywhere;
}

/* "Kein Ziel" chip on nutrient rows (profile_energy_design_001 §6.1) */
.no-target-chip {
    display: inline-block;
    margin-left: var(--space-2);
    padding: 1px 8px;
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--warning);
    font-size: var(--font-xs);
    font-weight: 600;
    white-space: nowrap;
    vertical-align: middle;
}

.no-target-chip:empty {
    display: none;
}

.row-sub {
    display: block;
    font-size: var(--font-sm);
    color: var(--muted);
    overflow-wrap: anywhere;
}

/* exact BLS name under a friendly food title (implementation_plan_006) */
.row-note {
    display: block;
    font-size: var(--font-xs);
    color: var(--muted);
    overflow-wrap: anywhere;
}

.row-note:empty {
    display: none;
}

.row-side {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    justify-self: end;
    text-align: right;
    font-size: var(--font-sm);
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.row-side .fa-chevron-right {
    color: var(--faint);
    font-size: 0.75rem;
}

/* ----- Icon badge (category icon instead of food photos, doc §6.4) ----- */

.icon-badge {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* ----- Progress (flat, green fill) ----- */

.progress {
    display: block; /* also when the track is a <span> (nutrient rows) */
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 6px;
}

.progress > span {
    display: block;
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
}

/* state is carried by the fill color (former left-border scheme) */
[data-state="warning"] .progress > span { background: var(--warning); }
[data-state="bad"] .progress > span     { background: var(--danger); }

/* ----- Hero (daily kcal, doc §10.1) ----- */

.hero {
    margin-bottom: var(--space-6);
}

.hero-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.hero-value {
    font-size: var(--font-2xl);
    font-weight: 700;
    letter-spacing: -0.035em;
    line-height: 1.1;
}

.hero-value small {
    font-size: var(--font-lg);
    font-weight: 600;
}

.hero-target {
    color: var(--muted);
    font-size: var(--font-sm);
}

.hero-percent {
    text-align: right;
    color: var(--muted);
    font-size: var(--font-xs);
    margin-top: 4px;
}

/* ----- Insight card (one of the few allowed color surfaces, doc §10.4) ----- */

.insight {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-3);
    align-items: start;
    width: 100%;
    padding: var(--space-4);
    background: var(--accent-soft);
    border: none;
    border-radius: 14px;
    margin-bottom: var(--space-6);
    text-align: left;
    font: inherit;
    color: var(--fg);
    cursor: pointer;
}

.insight .fa-circle-info {
    color: var(--accent);
    margin-top: 3px;
}

.insight-title {
    display: block;
    font-weight: 600;
    margin-bottom: 2px;
}

.insight-text {
    display: block;
    font-size: var(--font-sm);
    color: var(--muted);
}

/* ----- Status panels ----- */

.loading-panel,
.error-panel,
.placeholder-panel {
    padding: calc(var(--spacing) * 2) var(--spacing);
    text-align: center;
    color: var(--muted);
}

.error-panel {
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
}

/* ----- Bottom sheets (doc §11) ----- */

.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    z-index: 100;
    opacity: 0;
    transition: opacity 220ms ease;
}

.sheet-backdrop.open {
    opacity: 1;
}

.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
    box-shadow: var(--sheet-shadow);
    z-index: 101;
    transform: translateY(100%);
    transition: transform 220ms ease;
    touch-action: none;
}

.bottom-sheet.open {
    transform: translateY(0);
}

.bottom-sheet.dragging {
    transition: none;
}

.bottom-sheet__handle {
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: var(--border-strong);
    margin: 10px auto 2px;
    flex-shrink: 0;
    cursor: grab;
}

.bottom-sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) 20px 0;
    flex-shrink: 0;
}

.bottom-sheet__header h2 {
    margin: 0;
    font-size: var(--font-xl);
    letter-spacing: -0.02em;
    overflow-wrap: anywhere;
    min-width: 0;
}

.bottom-sheet__header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-shrink: 0;
}

.bottom-sheet__content {
    padding: var(--space-3) 20px calc(20px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    min-height: 0;
}

@media (min-width: 768px) {
    .bottom-sheet {
        left: calc(50% - 260px);
        right: auto;
        width: 520px;
    }
}

/* key/value rows inside sheets (Menge / Mahlzeit / Zeit, doc §12.2) */

.field-row {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
}

.field-row > .field-label,
.field-block > .field-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--fg);
}

.field-row .field-label i,
.field-block .field-label i {
    color: var(--muted);
    width: 20px;
    text-align: center;
}

.field-row input,
.field-row select {
    justify-self: end;
    max-width: 180px;
    text-align: right;
}

/* stacked variant: label above a full-width control (e.g. meal segment) */
.field-block {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
}

/* ----- food detail sheet extras (doc §12.2) ----- */

.food-category {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0 0 var(--space-2);
}

.food-category .icon-badge {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
}

.food-basics {
    margin: 0 0 var(--space-3);
    font-size: var(--font-sm);
}

/* exact BLS name + variant chooser above the basics (implementation_plan_006) */
.food-bls-name {
    margin: 0 0 var(--space-2);
    font-size: var(--font-xs);
    overflow-wrap: anywhere;
}

.field-block + .food-basics {
    margin-top: var(--space-3);
}

.sheet-subhead {
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: var(--space-4) 0 var(--space-1);
}

.icon-button.is-favorite {
    color: var(--accent);
}

/* segmented control (meal picker) */

.segment {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    overflow: hidden;
}

.segment button {
    border: none;
    border-radius: 0;
    background: none;
    min-height: 40px;
    padding: 6px 4px;
    font-size: var(--font-sm);
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.segment button + button {
    border-left: 1px solid var(--border-strong);
}

.segment button[aria-pressed="true"] {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

/* sheet action area */

.sheet-actions {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.sheet-actions button.primary {
    min-height: 48px;
}

/* ----- Simple key/value lines (targets, averages) ----- */

.kv-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
    font-size: var(--font-sm);
}

.kv-row .kv-value {
    font-variant-numeric: tabular-nums;
    color: var(--fg);
}

.kv-row .kv-label {
    color: var(--muted);
}

/* ----- 7-day chart (inline SVG, doc §11.2) ----- */

.chart {
    width: 100%;
    height: auto;
    color: var(--accent);
    margin: var(--space-3) 0 var(--space-2);
    display: block;
}

.chart .chart-axis {
    stroke: var(--border-strong);
}

.chart-labels {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    font-size: var(--font-xs);
    color: var(--faint);
    text-align: center;
}

/* ----- Toast ----- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tab-bar-height) + 16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--fg);
    color: var(--bg);
    padding: 10px 16px;
    border-radius: var(--radius);
    z-index: 110;
    max-width: calc(100vw - 32px);
}

.toast i {
    color: var(--accent);
}

.toast.toast-error i {
    color: var(--danger);
}

/* ----- Forms ----- */

.form {
    display: grid;
    gap: 12px;
}

.form label {
    display: grid;
    gap: 6px;
    font-size: var(--font-sm);
}

.form-error {
    color: var(--danger);
    font-size: var(--font-sm);
    min-height: 1.2em;
}
