/* =============================================================
   Shape Goal — shared stylesheet
   Consolidates styles that used to be duplicated inline across
   every template. Organised by section; page-specific rules are
   grouped near the bottom under a comment naming their page.
   ============================================================= */

:root {
    --primary:       #0ea5e9;
    --primary-dark:  #0284c7;
    --navy:          #0f172a;
    --navy-mid:      #1e293b;
    --success:       #10b981;
    --success-dark:  #059669;
    --danger:        #ef4444;
    --warning:       #f59e0b;
    --gray:          #64748b;
    --gray-dark:     #475569;
    --bg:            #f1f5f9;
    --card-bg:       #ffffff;
    --border:        #e2e8f0;
    --text:          #0f172a;
    --text-light:    #64748b;
    --radius:        12px;
    --radius-sm:     8px;
    --shadow:        0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.07);
    --shadow-hover:  0 4px 12px rgba(0,0,0,.1), 0 8px 24px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

h1, h2, h3 { color: var(--text); letter-spacing: -.01em; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 28px 20px;
}
.page-narrow {
    max-width: 460px;
    margin: 0 auto;
    padding: 28px 20px;
}

/* ── Navbar ───────────────────────────────────────────────── */
.navbar {
    background: var(--navy);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    height: 56px;
    flex-wrap: wrap;
    gap: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.navbar .brand {
    font-weight: 800;
    font-size: 1.1rem;
    color: white;
    text-decoration: none;
    letter-spacing: .02em;
    text-transform: uppercase;
}
.navbar .brand:hover { text-decoration: none; opacity: .85; }
.navbar-links { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.navbar-links a {
    color: rgba(255,255,255,.8);
    font-size: .85rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background .15s, color .15s;
}
.navbar-links a:hover {
    color: white;
    background: rgba(255,255,255,.1);
    text-decoration: none;
}

/* ── Flash / alert messages ──────────────────────────────── */
.flash-wrap { max-width: 1100px; margin: 14px auto 0; padding: 0 20px; }
.flash {
    border-radius: var(--radius-sm);
    padding: 11px 16px;
    margin-bottom: 10px;
    font-size: .92rem;
    font-weight: 500;
}
.flash-error, .flash-danger { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.flash-warning              { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.flash-success, .flash-info { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }

.bmi-warning-severe {
    background: #fef2f2; border: 1px solid #fecaca; border-radius: var(--radius-sm);
    padding: 14px 18px; margin-bottom: 18px; color: #991b1b;
}
.bmi-warning {
    background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius-sm);
    padding: 14px 18px; margin-bottom: 18px; color: #92400e;
}

/* ── Ad placeholder (monetization scaffolding — hidden for is_premium) ──── */
.ad-placeholder {
    background: #f8f9fa; border: 1px dashed #ced4da; border-radius: var(--radius-sm);
    padding: 14px 18px; margin: 18px 0; text-align: center; color: #6c757d;
    font-size: .85rem;
}
.ad-placeholder-label {
    display: block; font-size: .68rem; text-transform: uppercase;
    letter-spacing: .06em; color: #adb5bd; margin-bottom: 4px;
}
.ad-placeholder p { margin: 0; }

/* ── Buttons ──────────────────────────────────────────────── */
button, .btn {
    display: inline-block;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: .88rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    background: var(--primary);
    color: white;
    transition: background .15s, box-shadow .15s, transform .1s;
    letter-spacing: .01em;
}
button:hover, .btn:hover {
    background: var(--primary-dark);
    opacity: 1;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(14,165,233,.3);
}
button:active, .btn:active { transform: translateY(1px); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-dark); box-shadow: 0 2px 8px rgba(16,185,129,.3); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-secondary { background: var(--navy-mid); color: #fff; }
.btn-secondary:hover { background: var(--navy); box-shadow: 0 2px 8px rgba(15,23,42,.25); }
.btn-block     { display: block; width: 100%; text-align: center; }
.btn-row       { display: flex; gap: 10px; }
.btn-row .btn  { flex: 1; }

/* ── Forms ────────────────────────────────────────────────── */
form { display: flex; flex-direction: column; }
label { font-weight: 600; font-size: .85rem; color: var(--gray-dark); margin-bottom: 5px; display: block; text-transform: uppercase; letter-spacing: .04em; }
input, select, textarea {
    padding: 10px 12px;
    font-size: .95rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    width: 100%;
    font-family: inherit;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; margin: 0 6px 0 0; }
.consent-row {
    display: flex; align-items: flex-start; gap: 8px;
    font-weight: normal; font-size: .85rem; color: #555;
    margin-bottom: 16px; text-align: left; text-transform: none; letter-spacing: 0;
}
.consent-row input { margin-top: 3px; }
.form-card {
    max-width: 420px;
    margin: 20px auto;
    padding: 28px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.macro-row { display: flex; gap: 10px; }
.macro-row > div { flex: 1; }

/* ── Cards / sections ─────────────────────────────────────── */
.card, .section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
    transition: box-shadow .2s;
}
.card:hover, .section:hover { box-shadow: var(--shadow-hover); }
.section h2, .card h2 { margin-top: 0; font-size: 1.05rem; }

/* Section summary (collapsible headers) */
details.section > summary {
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    padding: 4px 0;
    user-select: none;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--navy);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
details.section > summary::before {
    content: "▶";
    font-size: .7rem;
    color: var(--primary);
    transition: transform .2s;
    display: inline-block;
}
details.section[open] > summary::before { transform: rotate(90deg); }
details.section > summary::-webkit-details-marker { display: none; }

.two-col { display: flex; gap: 20px; flex-wrap: wrap; }
.col-left  { flex: 1; min-width: 320px; }
.col-right { width: 340px; min-width: 280px; }
.left-column, .right-column { flex: 1; max-width: 50%; }
.container-row { display: flex; gap: 20px; }
@media (max-width: 700px) {
    .left-column, .right-column, .col-left, .col-right { max-width: 100%; width: 100%; }
    .container-row { flex-direction: column; }
}

/* ── Tables ───────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; margin-top: 10px; border-radius: var(--radius-sm); overflow: hidden; }
th, td { padding: 10px 12px; text-align: center; border-bottom: 1px solid var(--border); }
th { background: var(--navy); color: white; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ── Landing pages (welcome / home / index) ──────────────── */
.hero { text-align: center; }
.hero-header {
    background: var(--navy);
    color: white;
    padding: 60px 20px;
}
.hero-header h1 { margin: 0; font-size: 2.5em; color: white; letter-spacing: -.02em; }
.hero-body { padding: 32px 20px; }
.hero-body p { font-size: 1.1em; color: var(--text-light); margin-bottom: 20px; }
.hero-cta { text-decoration: none; }
.hero a.btn { margin: 6px; }
.hero footer { margin-top: 40px; color: #94a3b8; font-size: .9em; padding: 10px; }

/* ── Chat widgets (dashboard mini-chat + full AI page) ────── */
#chat-container {
    width: 100%; max-width: 640px; margin: 16px auto; padding: 16px;
    background: white; border-radius: var(--radius); border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
#chat-box, .chat-box {
    height: 300px; overflow-y: auto; padding: 12px;
    background: #f8fafc; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    display: flex; flex-direction: column; gap: 6px; font-size: .9rem; line-height: 1.6;
}
.msg, .cmsg { max-width: 88%; padding: 9px 13px; border-radius: 12px; font-size: .88rem; }
.msg-user, .cmsg-user { background: var(--navy); color: white; align-self: flex-end; border-bottom-right-radius: 3px; }
.msg-ai, .cmsg-ai     { background: white; border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 3px; white-space: pre-wrap; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.msg-log, .cmsg-log {
    align-self: flex-start; background: #ecfdf5; border: 1px solid #a7f3d0;
    color: #065f46; border-radius: 8px; font-size: .8rem; padding: 6px 10px;
}
.thinking, .cthinking { color: #94a3b8; font-style: italic; align-self: flex-start; font-size: .8rem; padding: 4px 0; }
.msg-img-preview { max-width: 200px; border-radius: 8px; margin: 4px 0; align-self: flex-end; }

#img-preview-wrap, #chat-img-preview-wrap {
    display: none; position: relative; margin: 6px 0; width: fit-content;
}
#img-preview-wrap img, #chat-img-preview-wrap img { height: 52px; border-radius: 6px; border: 1px solid #ccc; }
#img-preview-wrap button, #chat-img-preview-wrap button {
    position: absolute; top: -6px; right: -6px; background: var(--danger); color: white;
    border: none; border-radius: 50%; width: 18px; height: 18px; font-size: 10px;
    cursor: pointer; padding: 0; line-height: 18px;
}

.input-row, .chat-input-row { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
#chat-input {
    flex: 1; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    font-size: .88rem; resize: none; height: 40px; overflow-y: hidden; margin-bottom: 0;
    transition: border-color .15s;
}
#chat-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,233,.12); }
.icon-btn, .c-icon-btn {
    background: var(--navy-mid); color: white; border: none; border-radius: var(--radius-sm);
    width: 38px; height: 38px; cursor: pointer; font-size: 1rem;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: background .15s;
}
.icon-btn:hover, .c-icon-btn:hover { background: var(--navy); }
.send-btn { background: var(--primary); color: white; border: none; border-radius: var(--radius-sm);
    padding: 0 18px; height: 38px; cursor: pointer; font-size: .88rem; font-weight: 600;
    transition: background .15s; }
.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled, .icon-btn:disabled { opacity: .4; cursor: not-allowed; }
#file-input, #chat-file-input { display: none; }
.clear-link { font-size: .78rem; color: #94a3b8; cursor: pointer; text-decoration: underline; float: right; }
.clear-link:hover { color: var(--gray-dark); }

/* Camera capture modal (dashboard + ai_suggestions) */
#camera-modal {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.82);
    z-index: 900; align-items: center; justify-content: center;
}
#camera-modal .camera-panel {
    background: #fff; border-radius: var(--radius); padding: 24px;
    max-width: 460px; width: 95%; text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
#camera-video { width: 100%; border-radius: var(--radius-sm); background: #000; max-height: 320px; }
#camera-error { color: var(--danger); font-size: .85rem; display: none; margin: 8px 0 0; }

/* ── AI suggestions page ─────────────────────────────────── */
.api-warning {
    background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius-sm);
    padding: 11px 14px; margin-bottom: 18px; color: #92400e; font-size: .88rem;
}
.suggest-btns { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.suggest-btn { flex: 1; min-width: 120px; }
.suggest-btn.green { background: var(--success); }
.suggest-btn.green:hover { background: var(--success-dark); }
#result-box { white-space: pre-wrap; font-size: .88rem; line-height: 1.7; max-height: 380px; overflow-y: auto; }
.spinner { color: #94a3b8; font-style: italic; font-size: .88rem; }
.pref-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width:560px) { .pref-grid { grid-template-columns: 1fr; } }
.pref-grid label { font-size: .82rem; }
.save-msg { display: none; margin-top: 6px; color: var(--success); font-size: .8rem; }

/* ── Calendar ─────────────────────────────────────────────── */
.calendar-container {
    max-width: 1200px; margin: 20px auto; background: #fff; padding: 24px;
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.month-navigation { display: flex; justify-content: center; align-items: center; margin-bottom: 10px; gap: 10px; }
.calendar-container table { table-layout: fixed; }
.calendar-container th, .calendar-container td {
    width: 14.28%; padding: 12px; vertical-align: top; border-radius: 5px; word-wrap: break-word;
}
.calendar-container th { background: var(--navy); color: white; }
.cal-day { position: relative; background: #f0f9ff; cursor: pointer; transition: .2s; }
.cal-day:hover { background: #e0f2fe; }
.cal-inactive { background: #f8fafc; color: #cbd5e1; }
.cal-day a { font-weight: bold; display: block; padding: 5px; }
.activity-list, .food-list { list-style: none; padding: 0; margin: 5px 0 0; font-size: 14px; text-align: left; }
.tdee-info { font-size: 14px; font-weight: bold; color: var(--primary); margin-top: 5px; }
.edit-delete-links { display: flex; justify-content: space-between; margin-top: 5px; }
.edit-delete-links a { color: var(--danger); font-size: 12px; }
.edit-delete-links button.link-button {
    background: none; border: none; color: var(--danger); font-size: 12px; padding: 0; cursor: pointer;
}

/* ── Progress page ────────────────────────────────────────── */
.range-btns a {
    display: inline-block; padding: 7px 18px; border: 1.5px solid var(--primary);
    border-radius: 20px; font-size: .85rem; margin-right: 6px; color: var(--primary);
    background: white; font-weight: 600; transition: all .15s;
}
.range-btns a.active { background: var(--primary); color: white; box-shadow: 0 2px 8px rgba(14,165,233,.3); }
.range-btns a:not(.active):hover { background: #f0f9ff; text-decoration: none; }
.chart-wrap { position: relative; height: 240px; }
.summary-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px; margin-bottom: 24px;
}
.stat-card { text-align: center; background: var(--card-bg); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-card .val { font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.stat-card .lbl { font-size: .75rem; color: var(--text-light); margin-top: 3px; text-transform: uppercase; letter-spacing: .05em; }

/* ── Add food page ───────────────────────────────────────── */
.scan-section, .manual-form { text-align: center; }
.manual-form { text-align: left; }
.confirm-card { display: none; border: 2px solid var(--primary); }
.confirm-card .product-name { font-size: 1.2rem; font-weight: bold; color: #222; margin-bottom: 4px; }
.confirm-card .product-brand { font-size: .9rem; color: #777; margin-bottom: 16px; }
.confirm-card .question { font-size: 1rem; margin-bottom: 14px; }
.grams-section { display: none; border: 2px solid var(--success); }
.grams-section h3 { margin-top: 0; color: var(--success); }
.grams-input-row { display: flex; align-items: center; gap: 10px; }
.grams-input-row input { flex: 1; margin-bottom: 0; }
.grams-unit { font-size: 1.1rem; color: #555; white-space: nowrap; }
#preview { width: 100%; border-radius: var(--radius-sm); border: 1px solid #ccc; margin: 12px 0; display: none; }
.error-msg { color: var(--danger); margin-bottom: 14px; }

/* ── Add activity page (search autocomplete) ─────────────── */
#activityResults {
    display: none; border: 1px solid var(--border); border-top: none; max-height: 260px;
    overflow-y: auto; background: #fff; position: absolute; width: 100%; z-index: 100;
    box-shadow: 0 8px 20px rgba(0,0,0,.1); border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
#activityResults div { padding: 10px 14px; cursor: pointer; font-size: 15px; }
#activityResults div:hover { background: #f0f9ff; }
.selected-activity-badge {
    display: none; margin-top: 6px; padding: 7px 12px; background: #f0f9ff;
    border: 1px solid #bae6fd; border-radius: var(--radius-sm); font-size: 14px; color: #0369a1;
}

/* ── Small helpers ────────────────────────────────────────── */
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.ai-badge {
    font-size: .72rem; background: #f0f9ff; color: var(--primary-dark);
    border-radius: 4px; padding: 2px 6px; font-weight: 600;
}

/* ── Landing page ─────────────────────────────────────────── */
.landing-hero {
    min-height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}
.landing-title {
    font-size: clamp(2.4rem, 7vw, 4.2rem);
    font-weight: 800;
    letter-spacing: -.02em;
    margin: 0 0 14px;
    color: var(--navy);
}
.landing-subtitle {
    font-size: 1rem;
    color: var(--text-light);
    margin: 0;
}
.landing-subtitle a { font-weight: 600; }
.landing-sep { margin: 0 8px; color: var(--border); }

/* ── Floating corner controls (help tour + language switcher) ───────────── */
.fab-stack {
    position: fixed; right: 20px; bottom: 20px; z-index: 2000;
    display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
.fab {
    width: 46px; height: 46px; border-radius: 50%;
    background: var(--navy); color: white; border: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; font-weight: 700; cursor: pointer;
    box-shadow: var(--shadow-hover); transition: transform .12s, background .15s;
}
.fab:hover { transform: scale(1.06); background: var(--navy-mid); }
.fab-lang {
    background: white; color: var(--text); border: 1px solid var(--border);
    font-size: .72rem; gap: 2px; flex-direction: column; line-height: 1;
}
.fab-lang .fab-lang-flag { font-size: 1.05rem; }
.fab-lang .fab-lang-code { font-size: .58rem; font-weight: 800; letter-spacing: .03em; color: var(--text-light); }

.lang-menu {
    position: fixed; right: 20px; bottom: 76px; z-index: 2001;
    background: white; border-radius: var(--radius-sm); box-shadow: var(--shadow-hover);
    border: 1px solid var(--border); overflow: hidden; display: none; min-width: 150px;
}
.lang-menu.open { display: block; }
.lang-menu button {
    display: flex; align-items: center; gap: 8px; width: 100%;
    background: none; border: none; color: var(--text); font-weight: 500;
    padding: 10px 14px; border-radius: 0; box-shadow: none; text-align: left; font-size: .85rem;
}
.lang-menu button:hover { background: #f0f9ff; }
.lang-menu button.active { background: #f0f9ff; color: var(--primary-dark); font-weight: 700; }

/* ── Guided tour overlay ──────────────────────────────────── */
#tour-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 3000; display: none;
}
#tour-backdrop.open { display: block; }
#tour-spotlight {
    position: fixed; z-index: 3001; border-radius: 10px;
    box-shadow: 0 0 0 6px rgba(14,165,233,.35), 0 0 0 9999px rgba(15,23,42,.55);
    transition: top .2s, left .2s, width .2s, height .2s;
    pointer-events: none;
}
#tour-tooltip {
    position: fixed; z-index: 3002; max-width: 320px; background: white;
    border-radius: var(--radius); box-shadow: var(--shadow-hover); padding: 16px 18px;
    transition: top .2s, left .2s;
}
#tour-tooltip h4 { margin: 0 0 6px; font-size: 1rem; }
#tour-tooltip p { margin: 0 0 14px; font-size: .85rem; color: var(--text-light); }
#tour-tooltip .tour-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#tour-tooltip .tour-step-count { font-size: .72rem; color: var(--text-light); }
#tour-tooltip .tour-btns { display: flex; gap: 6px; }
#tour-tooltip button { padding: 6px 12px; font-size: .78rem; }
#tour-tooltip .tour-skip { background: none; color: var(--text-light); box-shadow: none; padding: 6px 4px; }
#tour-tooltip .tour-skip:hover { text-decoration: underline; }
