/* Baby Bonneau — Design system (mobile-first) */
@import url("tokens.css");

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--color-background);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { font-family: var(--font-heading); line-height: var(--leading-tight); margin: 0; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--color-caramel-dark); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + var(--space-4));
}
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: calc(var(--space-3) + env(safe-area-inset-top)) var(--space-5) var(--space-3);
    background: color-mix(in srgb, var(--color-ivoire) 92%, transparent);
    backdrop-filter: saturate(140%) blur(8px);
    border-bottom: 1px solid var(--color-border);
}
.app-topbar h1 { font-size: var(--text-lg); font-weight: 700; }
.app-main {
    flex: 1;
    width: 100%;
    max-width: var(--max-content-width);
    margin: 0 auto;
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}
.container-narrow { max-width: 420px; margin: 0 auto; width: 100%; }

/* ---------- Bottom navigation ---------- */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -6px 20px rgba(138, 95, 59, 0.06);
}
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--tap-min);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: 600;
    transition: color var(--transition-fast);
}
.bottom-nav-item.is-active { color: var(--color-caramel-dark); }
.bottom-nav-item svg { width: 22px; height: 22px; }
.bottom-nav-fab {
    position: relative;
    flex: 0 0 64px;
}
.bottom-nav-fab button {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    border: none;
    background: linear-gradient(160deg, var(--color-caramel), var(--color-caramel-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-fast);
}
.bottom-nav-fab button:active { transform: translateX(-50%) scale(0.94); }
.bottom-nav-fab svg { width: 26px; height: 26px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--tap-min);
    padding: 0 var(--space-5);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: var(--text-base);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
    text-align: center;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--color-caramel-dark); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--color-caramel); }
.btn-secondary { background: var(--color-surface-secondary); color: var(--color-text); border-color: var(--color-border); }
.btn-ghost { background: transparent; color: var(--color-caramel-dark); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tap-min);
    height: var(--tap-min);
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Cards ---------- */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
}
.card-title { font-size: var(--text-sm); font-weight: 700; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

.stat-card { display: flex; flex-direction: column; gap: var(--space-1); }
.stat-card .stat-value { font-size: var(--text-2xl); font-weight: 800; font-family: var(--font-heading); }
.stat-card .stat-label { font-size: var(--text-sm); color: var(--color-text-muted); }

.progress-card .progress-value { font-size: var(--text-3xl); font-weight: 800; color: var(--color-caramel-dark); }
.progress-card .progress-caption { color: var(--color-text-muted); font-size: var(--text-sm); margin-top: var(--space-1); }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Progress bar ---------- */
.progress-bar { height: 8px; border-radius: var(--radius-full); background: var(--color-surface-secondary); overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--color-caramel), var(--color-caramel-dark)); border-radius: inherit; transition: width var(--transition-base); }

/* ---------- Badge / Chip ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 700; }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-neutral { background: var(--color-surface-secondary); color: var(--color-text-muted); }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: var(--radius-full); border: 1px solid var(--color-border); background: var(--color-surface); font-size: var(--text-sm); font-weight: 600; color: var(--color-text-muted); cursor: pointer; white-space: nowrap; }
.chip.is-active { background: var(--color-caramel-dark); border-color: var(--color-caramel-dark); color: #fff; }
.chip-row { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: var(--text-sm); font-weight: 600; color: var(--color-text-muted); }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="number"], .field input[type="date"], .field input[type="time"],
.field select, .field textarea {
    min-height: var(--tap-min);
    padding: 0 var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    font-size: var(--text-base);
}
.field textarea { padding: var(--space-3) var(--space-4); min-height: 88px; resize: vertical; }
.field-check { display: flex; align-items: center; gap: var(--space-2); min-height: var(--tap-min); }
.field-check input { width: 22px; height: 22px; accent-color: var(--color-caramel-dark); }
.field-hint { font-size: var(--text-xs); color: var(--color-text-muted); }
.field-error { font-size: var(--text-xs); color: var(--color-danger); }
.form-section { display: flex; flex-direction: column; gap: var(--space-4); }
.form-section-title { font-size: var(--text-sm); font-weight: 700; color: var(--color-caramel-dark); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: var(--space-1); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-4); }
@media (min-width: 560px) { .form-grid-2 { grid-template-columns: 1fr 1fr; } }

.search-field { position: relative; }
.search-field input { width: 100%; padding-left: 40px; }
.search-field svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--color-text-muted); }

/* ---------- Counter (+ / -) ---------- */
.counter { display: inline-flex; align-items: center; gap: var(--space-3); background: var(--color-surface-secondary); border-radius: var(--radius-full); padding: 4px; }
.counter button {
    width: 36px; height: 36px; border-radius: var(--radius-full); border: none;
    background: var(--color-surface); box-shadow: var(--shadow-sm); font-size: 18px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--color-caramel-dark);
}
.counter button:active { transform: scale(0.92); }
.counter button:disabled { opacity: 0.4; cursor: default; }
.counter .counter-value { min-width: 28px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- List item ---------- */
.list-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); }
.list-item:last-child { border-bottom: none; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 700; }
.list-item-subtitle { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: 2px; }
.list-item-icon { width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--color-surface-secondary); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }

/* ---------- Size breakdown ---------- */
.size-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); }
.size-row:last-child { border-bottom: none; }
.size-row-label { font-weight: 700; }
.size-row-progress { display: flex; align-items: center; gap: var(--space-2); flex: 1; max-width: 160px; }
.size-row-fraction { font-variant-numeric: tabular-nums; color: var(--color-text-muted); font-size: var(--text-sm); white-space: nowrap; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: var(--space-8) var(--space-5); color: var(--color-text-muted); }
.empty-state .empty-emoji { font-size: 32px; margin-bottom: var(--space-2); }
.empty-state h3 { font-size: var(--text-base); color: var(--color-text); margin-bottom: var(--space-1); }

/* ---------- Skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--color-surface-secondary) 25%, var(--color-beige) 37%, var(--color-surface-secondary) 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Toast ---------- */
.toast-stack { position: fixed; left: 0; right: 0; bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + var(--space-3)); display: flex; flex-direction: column; align-items: center; gap: var(--space-2); z-index: 60; pointer-events: none; padding: 0 var(--space-4); }
.toast { pointer-events: auto; background: var(--color-encre); color: #fff; padding: var(--space-3) var(--space-5); border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: 600; box-shadow: var(--shadow-lg); max-width: 100%; opacity: 0; transform: translateY(8px); transition: opacity var(--transition-base), transform var(--transition-base); }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: var(--color-danger); }

/* ---------- Bottom sheet ---------- */
.sheet-overlay { position: fixed; inset: 0; background: rgba(53, 44, 34, 0.42); opacity: 0; pointer-events: none; transition: opacity var(--transition-base); z-index: 70; }
.sheet-overlay.is-open { opacity: 1; pointer-events: auto; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 71;
    background: var(--color-surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-3) var(--space-5) calc(var(--space-6) + env(safe-area-inset-bottom));
    transform: translateY(100%); transition: transform var(--transition-base);
    max-height: 80vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.sheet-overlay.is-open .sheet { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; border-radius: var(--radius-full); background: var(--color-border); margin: var(--space-2) auto var(--space-4); }
.sheet-title { font-size: var(--text-lg); font-weight: 700; margin-bottom: var(--space-4); }
.sheet-action { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: var(--space-3) var(--space-2); border-radius: var(--radius-md); background: none; border: none; text-align: left; cursor: pointer; min-height: var(--tap-min); }
.sheet-action:hover, .sheet-action:active { background: var(--color-surface-secondary); }
.sheet-action-icon { width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--color-primary-soft); color: var(--color-caramel-dark); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.sheet-action[disabled] { opacity: 0.45; pointer-events: none; }

/* ---------- Tabs / segmented control ---------- */
.segmented { display: flex; background: var(--color-surface-secondary); border-radius: var(--radius-md); padding: 3px; gap: 2px; }
.segmented button { flex: 1; min-height: 36px; border: none; background: transparent; border-radius: var(--radius-sm); font-size: var(--text-sm); font-weight: 600; color: var(--color-text-muted); cursor: pointer; }
.segmented button.is-active { background: var(--color-surface); color: var(--color-caramel-dark); box-shadow: var(--shadow-sm); }

/* ---------- Auth layout ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: max(var(--space-6), env(safe-area-inset-top)) var(--space-5) max(var(--space-6), env(safe-area-inset-bottom)); background: linear-gradient(180deg, var(--color-ivoire), var(--color-beige)); }
.auth-card { width: 100%; max-width: 400px; background: var(--color-surface); border-radius: var(--radius-lg); padding: var(--space-8) var(--space-6); box-shadow: var(--shadow-md); border: 1px solid var(--color-border); }
.auth-logo { text-align: center; margin-bottom: var(--space-6); }
.auth-logo .mark { font-size: 36px; }
.auth-logo h1 { font-size: var(--text-xl); margin-top: var(--space-2); }
.auth-logo p { color: var(--color-text-muted); font-size: var(--text-sm); margin-top: 4px; }
.auth-form { display: flex; flex-direction: column; gap: var(--space-4); }
.auth-links { display: flex; justify-content: center; margin-top: var(--space-5); font-size: var(--text-sm); }
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); margin-bottom: var(--space-4); }
.alert-error { background: var(--color-danger-soft); color: var(--color-danger); }
.alert-success { background: var(--color-success-soft); color: var(--color-success); }

/* ---------- Utilities ---------- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.font-bold { font-weight: 700; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.w-full { width: 100%; }
.text-center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* ---------- Responsive ---------- */
@media (min-width: 1024px) {
    .bottom-nav { display: none; }
    .app-shell { padding-bottom: 0; }
    .app-main { max-width: 760px; }
}
