:root {
    --bg: #f7f5ef;
    --surface: #ffffff;
    --text: #2b2b28;
    --text-muted: #7a7a72;
    --accent: #4caf7d;
    --accent-dark: #2e7d52;
    --ring-track: #e7e2d3;
    --danger: #d97a6c;
    --danger-dark: #b85a4d;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-full: 999px;
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
}

.app-shell {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: 96px;
    position: relative;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 28px 20px 8px;
}

.page-header h1 {
    font-size: 1.5rem;
    margin: 0;
}

.logout-link {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: var(--surface);
}

.page-content {
    padding: 12px 20px 20px;
}

/* Date strip */

.date-strip-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 20px;
}

.date-strip-arrow {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 1.1rem;
}

.date-strip {
    flex: 1;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 4px 0;
}

.date-strip::-webkit-scrollbar {
    display: none;
}

.date-pill {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 48px;
    padding: 8px 6px;
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.75rem;
}

.date-pill-day {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.date-pill-active {
    background: var(--accent);
    color: #ffffff;
}

.date-pill-active .date-pill-day {
    color: #ffffff;
}

/* Progress summary */

.progress-summary {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 20px;
}

.progress-ring {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-ring-inner {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-pct {
    font-weight: 700;
    font-size: 0.95rem;
}

.progress-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.progress-heading {
    font-weight: 600;
}

.progress-detail {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Habit cards */

.habit-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.habit-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-radius: var(--radius-lg);
    transition: opacity 0.15s ease, box-shadow 0.3s ease;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.habit-card:active {
    opacity: 0.8;
}

.habit-card-pending {
    pointer-events: none;
    opacity: 0.6;
}

.habit-card-error {
    box-shadow: 0 0 0 2px var(--danger);
}

.habit-card-name {
    font-weight: 600;
    font-size: 1rem;
}

.habit-check {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.habit-check-mark {
    opacity: 0;
    color: #ffffff;
    font-weight: 700;
    transition: opacity 0.15s ease;
}

.habit-card-checked .habit-check {
    background: var(--accent);
}

.habit-card-checked .habit-check-mark {
    opacity: 1;
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 0;
}

/* Manage habits */

.add-habit-form {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.add-habit-form input[type="text"] {
    flex: 1;
    padding: 12px 16px;
    border-radius: var(--radius-full);
    border: 1px solid #e3e0d5;
    background: var(--surface);
    font-size: 0.95rem;
}

.btn {
    border-radius: var(--radius-full);
    padding: 10px 18px;
    font-size: 0.9rem;
    font-weight: 600;
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
    width: 100%;
    padding: 12px;
}

.btn-add {
    background: var(--accent);
    color: #ffffff;
    width: 44px;
    height: 44px;
    padding: 0;
    font-size: 1.3rem;
    border-radius: 50%;
    flex: 0 0 auto;
}

.habit-section {
    margin-bottom: 24px;
}

.habit-section h2 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.export-link {
    display: inline-block;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: var(--radius-full);
    background: var(--surface);
    text-decoration: none;
}

.manage-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.manage-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-radius: var(--radius-md);
}

.manage-item-archived {
    background: var(--surface);
    opacity: 0.75;
}

.manage-item-name {
    font-weight: 600;
}

.btn-small {
    padding: 6px 14px;
    font-size: 0.8rem;
}

.btn-remove {
    background: #ffffff;
    color: var(--danger-dark);
}

.btn-restore {
    background: var(--accent);
    color: #ffffff;
}

.form-error {
    color: var(--danger-dark);
    background: #fbe9e6;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

/* Heat map */

.period-toggle {
    display: inline-flex;
    background: var(--surface);
    border-radius: var(--radius-full);
    padding: 4px;
    margin-bottom: 20px;
}

.toggle-pill {
    padding: 8px 18px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.toggle-pill-active {
    background: var(--accent);
    color: #ffffff;
}

.stat-block {
    display: flex;
    flex-direction: column;
    margin-bottom: 24px;
}

.stat-number {
    font-size: 2.75rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.heatmap-wrap {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    overflow-x: auto;
}

.heatmap-bands {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.heatmap-grid {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(7, 1fr);
    gap: 3px;
    width: 100%;
}

.heatmap-cell {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 3px;
    background: var(--ring-track);
    display: block;
}

.heatmap-cell-future {
    background: transparent;
    border: 1px dashed var(--ring-track);
    box-sizing: border-box;
}

.heatmap-level-0 { background: var(--ring-track); }
.heatmap-level-1 { background: #bfe3cf; }
.heatmap-level-2 { background: #8fd0ac; }
.heatmap-level-3 { background: #55b380; }
.heatmap-level-4 { background: var(--accent-dark); }

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.legend-cell {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: block;
    flex: 0 0 auto;
}

/* Bottom nav */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    background: var(--surface);
    border-top: 1px solid #ece8dc;
    padding: 10px 0 max(10px, env(safe-area-inset-bottom));
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.nav-icon {
    font-size: 1.2rem;
}

.nav-item.active {
    color: var(--accent-dark);
    font-weight: 600;
}

/* Auth pages */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.auth-title {
    margin: 0 0 4px;
}

.auth-subtitle {
    color: var(--text-muted);
    margin: 0 0 20px;
    font-size: 0.9rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}

.auth-form label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 8px;
}

.auth-form input {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid #e3e0d5;
    font-size: 0.95rem;
}

.auth-form .btn {
    margin-top: 16px;
}

.auth-error {
    color: var(--danger-dark);
    background: #fbe9e6;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    margin-bottom: 12px;
}
