/* =========================================================
   HabitFlow — Design System
   Mobile-first, cards, bordas arredondadas, sombras suaves
   ========================================================= */

:root {
    --primary: #6C5CE7;
    --primary-dark: #5A4BD1;
    --primary-light: #EDE9FE;
    --success: #00B894;
    --warning: #FDCB6E;
    --danger: #E17055;
    --info: #0984E3;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-pill: 999px;

    --shadow-sm: 0 2px 8px rgba(20, 20, 43, 0.06);
    --shadow-md: 0 8px 24px rgba(20, 20, 43, 0.08);
    --shadow-lg: 0 16px 40px rgba(20, 20, 43, 0.12);

    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;

    --nav-height: 68px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

[data-theme="light"] {
    --bg: #F7F7FB;
    --surface: #FFFFFF;
    --surface-alt: #F1F0FA;
    --text: #1E1B2E;
    --text-muted: #6B6880;
    --border: #ECEAF6;
}

[data-theme="dark"] {
    --bg: #121018;
    --surface: #1C1926;
    --surface-alt: #262233;
    --text: #F2F1F8;
    --text-muted: #9C98B0;
    --border: #2E2A3D;
    --primary-light: #2A2540;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.35);
    --shadow-lg: 0 16px 40px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
    transition: background .2s ease, color .2s ease;
}

body.no-bottom-padding { padding-bottom: 0; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }

::selection { background: var(--primary-light); color: var(--primary-dark); }

/* ---------------- Layout containers ---------------- */
.app-shell { max-width: 640px; margin: 0 auto; padding: 20px 16px calc(16px + var(--safe-bottom)); }
.app-shell.wide { max-width: 960px; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(8px + var(--safe-top)) 4px 12px;
}
.topbar h1 { font-size: 1.4rem; margin: 0; }
.topbar .greeting { font-size: 1.35rem; font-weight: 700; margin: 0 0 2px; }
.topbar .date { color: var(--text-muted); font-size: .9rem; margin: 0; }

.avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .95rem; overflow: hidden; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------------- Cards ---------------- */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 18px;
    margin-bottom: 14px;
}
.card-title { font-size: 1rem; font-weight: 700; margin: 0 0 12px; }

/* ---------------- Summary / streak ---------------- */
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.summary-item {
    background: var(--surface); border-radius: var(--radius-md); padding: 14px 10px; text-align: center;
    box-shadow: var(--shadow-sm);
}
.summary-item .value { font-size: 1.4rem; font-weight: 800; display: block; }
.summary-item .label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }

.streak-banner {
    background: linear-gradient(135deg, #FF7675, #FDCB6E);
    color: #fff; border-radius: var(--radius-md); padding: 18px; margin-bottom: 14px;
    display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow-md);
}
.streak-banner .streak-emoji { font-size: 2rem; }
.streak-banner strong { font-size: 1.3rem; display: block; }
.streak-banner span { opacity: .95; font-size: .88rem; }

.progress-ring-wrap { display: flex; align-items: center; gap: 16px; }
.progress-ring-wrap .stats-text strong { font-size: 1.6rem; }
.progress-ring-wrap .stats-text p { margin: 2px 0 0; color: var(--text-muted); font-size: .85rem; }

/* ---------------- Habit list / item ---------------- */
.habit-list { display: flex; flex-direction: column; gap: 10px; }
.habit-item {
    background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
    padding: 14px; display: flex; align-items: center; gap: 12px; position: relative;
    transition: transform .15s ease, box-shadow .15s ease;
}
.habit-item.completed { opacity: .68; }
.habit-item .habit-icon {
    width: 46px; height: 46px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; flex-shrink: 0;
}
.habit-item .habit-info { flex: 1; min-width: 0; }
.habit-item .habit-name { font-weight: 700; font-size: .98rem; margin: 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit-item.completed .habit-name { text-decoration: line-through; }
.habit-item .habit-meta { font-size: .78rem; color: var(--text-muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.check-btn {
    width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border);
    background: var(--surface); display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0; transition: all .15s ease; font-size: 1.1rem; color: transparent;
}
.check-btn.checked { background: var(--success); border-color: var(--success); color: #fff; }
.check-btn:active { transform: scale(0.9); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .emoji { font-size: 2.6rem; display: block; margin-bottom: 10px; }
.empty-state h3 { color: var(--text); margin: 0 0 6px; }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: none; border-radius: var(--radius-pill); padding: 13px 22px; font-weight: 700; font-size: .95rem;
    cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(108,92,231,.35); }
.btn-secondary { background: var(--surface-alt); color: var(--text); }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-google { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); width: 100%; }
.btn-sm { padding: 8px 14px; font-size: .82rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.fab-link {
    position: fixed; right: 20px; bottom: calc(var(--nav-height) + var(--safe-bottom) + 14px);
    width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 1.8rem; box-shadow: var(--shadow-lg);
    z-index: 40;
}

/* ---------------- Forms ---------------- */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input, .field select, .field textarea {
    width: 100%; padding: 13px 14px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 1rem; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field-inline { display: flex; justify-content: flex-end; margin: -6px 0 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle-row .toggle-label { font-weight: 600; font-size: .92rem; }
.toggle-row .toggle-desc { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; inset: 0; background: var(--border); border-radius: var(--radius-pill); cursor: pointer; transition: .2s;
}
.switch .slider::before {
    content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.icon-picker, .color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-picker button, .color-picker button {
    width: 40px; height: 40px; border-radius: var(--radius-sm); border: 2px solid transparent; background: var(--surface-alt);
    font-size: 1.1rem; cursor: pointer;
}
.icon-picker button.selected { border-color: var(--primary); }
.color-picker button.selected { border-color: var(--text); }

/* ---------------- Alerts / toast ---------------- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .88rem; }
.alert p { margin: 2px 0; }
.alert-error { background: #FDEDEA; color: #C0392B; }
[data-theme="dark"] .alert-error { background: #3A2222; color: #FF8A75; }
.alert-success { background: #E8F8F3; color: #04795B; }
[data-theme="dark"] .alert-success { background: #17332B; color: #6EE7C4; }
.alert-info { background: #EAF4FD; color: #0B5EA8; }

.toast-container { position: fixed; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast {
    background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: var(--radius-sm); font-size: .88rem;
    box-shadow: var(--shadow-lg); animation: toast-in .25s ease; text-align: center;
}
.toast.toast-error { background: var(--danger); color: #fff; }
.toast.toast-success { background: var(--success); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------- Bottom nav ---------------- */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-height) + var(--safe-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-around; padding-bottom: var(--safe-bottom);
    z-index: 50; box-shadow: 0 -2px 12px rgba(0,0,0,0.04);
}
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--text-muted); font-size: .68rem; padding: 6px 8px; flex: 1; }
.nav-item .nav-icon { font-size: 1.25rem; }
.nav-item.active { color: var(--primary); font-weight: 700; }
.nav-fab {
    width: 50px; height: 50px; border-radius: 50%; background: var(--primary); color: #fff; border: none;
    font-size: 1.6rem; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(108,92,231,.4);
    margin-top: -26px; cursor: pointer; flex-shrink: 0;
}

/* ---------------- Auth screens ---------------- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-logo { font-size: 1.3rem; font-weight: 800; display: block; margin-bottom: 24px; }
.auth-card h1 { font-size: 1.6rem; margin: 0 0 4px; }
.auth-subtitle { color: var(--text-muted); margin: 0 0 22px; font-size: .92rem; }
.auth-form { margin-top: 4px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: .9rem; color: var(--text-muted); }
.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--text-muted); font-size: .82rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.link-muted { color: var(--text-muted); font-size: .85rem; }

/* ---------------- Calendar ---------------- */
.calendar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.calendar-header button { background: var(--surface); border: 1px solid var(--border); border-radius: 50%; width: 36px; height: 36px; font-size: 1rem; cursor: pointer; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.calendar-grid .weekday { font-size: .7rem; color: var(--text-muted); font-weight: 700; padding-bottom: 6px; }
.day-cell {
    aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); font-size: .85rem; cursor: pointer; position: relative; background: var(--surface-alt);
}
.day-cell.muted { opacity: .3; pointer-events: none; }
.day-cell.today { border: 2px solid var(--primary); }
.day-cell .dot { width: 6px; height: 6px; border-radius: 50%; margin-top: 3px; }
.day-cell.status-full { background: rgba(0,184,148,.18); }
.day-cell.status-full .dot { background: var(--success); }
.day-cell.status-partial { background: rgba(253,203,110,.2); }
.day-cell.status-partial .dot { background: var(--warning); }
.day-cell.status-none .dot { background: var(--border); }

/* ---------------- Stats ---------------- */
.chart-card canvas { width: 100% !important; height: 180px !important; }
.stat-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.stat-row:last-child { border-bottom: none; }
.stat-row .name { font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: 8px; }
.stat-row .rate { font-weight: 800; }

/* ---------------- Filters (history) ---------------- */
.filter-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tabs button {
    flex-shrink: 0; padding: 9px 16px; border-radius: var(--radius-pill); border: 1.5px solid var(--border);
    background: var(--surface); color: var(--text-muted); font-size: .85rem; font-weight: 600; cursor: pointer;
}
.filter-tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.history-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.history-item:last-child { border-bottom: none; }
.history-item .status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.history-item .status-dot.done { background: var(--success); }
.history-item .status-dot.missed { background: var(--danger); }
.history-item .date-label { font-size: .74rem; color: var(--text-muted); min-width: 78px; }

/* ---------------- Modal (create/edit habit) ---------------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(10, 8, 20, .5); z-index: 200; display: none;
    align-items: flex-end; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
    background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
    border-radius: 24px 24px 0 0; padding: 20px 18px calc(24px + var(--safe-bottom));
    animation: sheet-up .25s ease;
}
@media (min-width: 680px) {
    .modal-overlay { align-items: center; }
    .modal-sheet { border-radius: var(--radius-lg); max-height: 88vh; }
}
@keyframes sheet-up { from { transform: translateY(30px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-handle { width: 40px; height: 4px; background: var(--border); border-radius: var(--radius-pill); margin: 0 auto 16px; }
.modal-title { font-size: 1.2rem; font-weight: 800; margin: 0 0 18px; }

/* ---------------- Ads ---------------- */
.ad-container { margin: 14px 0; }
.ad-banner {
    background: var(--surface-alt); border: 1px dashed var(--border); border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: .78rem;
    min-height: 90px; text-align: center; padding: 10px;
}

/* ---------------- Loading / skeleton ---------------- */
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-alt) 25%, var(--border) 50%, var(--surface-alt) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------------- Onboarding ---------------- */
.onboarding-screen { min-height: 100vh; display: flex; flex-direction: column; padding: 24px 20px calc(24px + var(--safe-bottom)); }
.onboarding-slides { flex: 1; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; }
.onboarding-slide { flex: 0 0 100%; scroll-snap-align: start; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; }
.onboarding-slide .emoji { font-size: 4rem; margin-bottom: 20px; }
.onboarding-slide h2 { font-size: 1.5rem; margin: 0 0 10px; }
.onboarding-slide p { color: var(--text-muted); }
.onboarding-dots { display: flex; justify-content: center; gap: 6px; margin: 16px 0; }
.onboarding-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.onboarding-dots span.active { background: var(--primary); width: 22px; border-radius: var(--radius-pill); }

/* ---------------- Landing page ---------------- */
.landing-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; max-width: 1100px; margin: 0 auto; }
.landing-header .logo { font-weight: 800; font-size: 1.3rem; }
.landing-header nav { display: flex; gap: 10px; }
.hero { text-align: center; padding: 50px 20px 30px; max-width: 780px; margin: 0 auto; }
.hero h1 { font-size: clamp(1.8rem, 5vw, 2.8rem); line-height: 1.15; margin: 0 0 16px; font-weight: 800; }
.hero p { color: var(--text-muted); font-size: 1.05rem; max-width: 560px; margin: 0 auto 26px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hero-mock { max-width: 320px; margin: 40px auto 0; }

.section { padding: 50px 20px; max-width: 1100px; margin: 0 auto; }
.section-title { text-align: center; font-size: clamp(1.4rem, 4vw, 2rem); font-weight: 800; margin: 0 0 8px; }
.section-subtitle { text-align: center; color: var(--text-muted); max-width: 520px; margin: 0 auto 34px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.feature-card { background: var(--surface); border-radius: var(--radius-md); padding: 22px; box-shadow: var(--shadow-sm); }
.feature-card .icon { font-size: 1.8rem; margin-bottom: 10px; }
.feature-card h3 { margin: 0 0 6px; font-size: 1rem; }
.feature-card p { margin: 0; color: var(--text-muted); font-size: .88rem; }

.steps-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; counter-reset: step; }
.step-card { text-align: center; }
.step-card .step-num { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; margin: 0 auto 10px; }

.faq-item { background: var(--surface); border-radius: var(--radius-md); margin-bottom: 10px; box-shadow: var(--shadow-sm); overflow: hidden; }
.faq-item summary { padding: 16px 18px; cursor: pointer; font-weight: 700; font-size: .95rem; list-style: none; display: flex; justify-content: space-between; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: '+'; color: var(--primary); font-size: 1.2rem; }
.faq-item[open] summary::after { content: '−'; }
.faq-item p { padding: 0 18px 16px; margin: 0; color: var(--text-muted); font-size: .9rem; }

.cta-section { text-align: center; background: linear-gradient(135deg, var(--primary), #A29BFE); color: #fff; border-radius: var(--radius-lg); padding: 50px 24px; max-width: 1000px; margin: 0 auto 60px; }
.cta-section h2 { font-size: clamp(1.4rem, 4vw, 2.1rem); margin: 0 0 10px; }
.cta-section .btn-primary { background: #fff; color: var(--primary); box-shadow: none; }

.landing-footer { text-align: center; padding: 26px; color: var(--text-muted); font-size: .82rem; }

/* ---------------- iOS install banner ---------------- */
.ios-banner {
    background: var(--surface-alt); border-radius: var(--radius-md); padding: 14px; margin-bottom: 14px;
    display: flex; gap: 10px; align-items: flex-start; font-size: .85rem;
}
.ios-banner .close-banner { margin-left: auto; background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; }

/* ---------------- Responsive tweaks ---------------- */
@media (min-width: 768px) {
    .summary-grid { grid-template-columns: repeat(4, 1fr); }
    .bottom-nav { max-width: 640px; left: 50%; transform: translateX(-50%); border-radius: var(--radius-lg) var(--radius-lg) 0 0; border: 1px solid var(--border); border-bottom: none; }
}
@media (min-width: 1024px) {
    body:not(.landing-body) { padding-bottom: 24px; }
    .app-shell { padding-top: 32px; }
}
