@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── Reset ── */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

:root {
    --bg:        #f5f7fa;
    --surface:   #ffffff;
    --surface2:  #f0f4f8;
    --blue:      #5a8fc4;
    --blue-soft: #d4e4f7;
    --green:     #5ac49e;
    --green-soft:#d4f5e4;
    --pink:      #e47ba8;
    --pink-soft: #f5d4e4;
    --amber:     #e8a857;
    --amber-soft:#f9e5c8;
    --purple:    #9b8fc4;
    --purple-soft:#e4d4f7;
    --text:      #1a1a2e;
    --text-muted:#6b7280;
    --border:    #e5e7eb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.05);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.10), 0 4px 16px rgba(0,0,0,0.06);
    --radius:    16px;
    --radius-sm: 10px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse at 0% 0%, rgba(90,143,196,0.08) 0%, transparent 55%),
        radial-gradient(ellipse at 100% 100%, rgba(92,196,154,0.08) 0%, transparent 55%);
    padding: 24px 20px;
    min-height: 100vh;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.container { max-width: 1600px; margin: 0 auto; }

/* ── Header ── */
.header { text-align: center; margin-bottom: 32px; }

.main-title {
    font-size: 42px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    line-height: 1.15;
}

.header-info { margin-bottom: 16px; }
.month-display { font-size: 32px; font-weight: 300; color: var(--text); letter-spacing: -0.5px; }
.subtitle { font-size: 11px; letter-spacing: 3px; color: var(--text-muted); margin: 6px 0; text-transform: uppercase; font-weight: 600; }
.current-date { font-size: 14px; color: var(--text-muted); font-weight: 500; margin-top: 4px; }

/* ── Controls Bar ── */
.controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 20px 0;
    flex-wrap: wrap;
    padding: 0 10px;
}

.select-box {
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: var(--shadow-sm);
}

.add-btn {
    background: linear-gradient(135deg, var(--blue) 0%, #4a7ab5 100%);
    color: white !important;
    border: none;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(90,143,196,0.3);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.add-btn img { filter: brightness(0) invert(1); }
.add-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(90,143,196,0.45); }
.add-btn:active { transform: translateY(0); }

/* ── Week Navigation ── */
.week-navigation { display: none; gap: 10px; justify-content: center; margin: 16px 0; }
.week-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white; border: none;
    padding: 11px 24px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 700;
    cursor: pointer; font-family: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 14px rgba(102,126,234,0.3);
}
.week-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(102,126,234,0.4); }

/* ── Download Buttons ── */
.download-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.download-btn {
    background: white;
    color: var(--blue);
    border: 1.5px solid var(--blue-soft);
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 700;
    cursor: pointer; font-family: inherit;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}
.download-btn:hover { background: var(--blue); color: white; border-color: var(--blue); transform: translateY(-1px); }

/* ── Dashboard Grid ── */
.dashboard { display: grid; grid-template-columns: 260px 1fr 360px; gap: 20px; }
.left-section, .right-section { display: flex; flex-direction: column; gap: 16px; }

/* ── Cards ── */
.trust-card {
    background: linear-gradient(135deg, var(--green-soft) 0%, #c8f0e0 100%);
    padding: 42px 20px;
    border-radius: var(--radius);
    text-align: center;
    border: 1px solid rgba(92,196,154,0.25);
    box-shadow: var(--shadow-sm);
}
.trust-card h2 { font-size: 28px; font-weight: 800; color: #2d8659; line-height: 1.2; letter-spacing: -0.3px; }

.affirmation-card {
    background: linear-gradient(135deg, var(--amber-soft) 0%, #fce8c5 100%);
    padding: 20px; border-radius: var(--radius);
    border: 1px solid rgba(232,168,87,0.2);
    box-shadow: var(--shadow-sm);
}
.affirmation-card p { font-size: 13.5px; font-style: italic; color: #7a5c30; line-height: 1.5; }
.affirmation-text { margin-top: 8px; font-size: 12.5px; color: #8a6840; }

.daily-habits-card {
    background: linear-gradient(135deg, var(--blue-soft) 0%, #c8d8f0 100%);
    padding: 20px; border-radius: var(--radius);
    border: 1px solid rgba(90,143,196,0.2);
    box-shadow: var(--shadow-sm);
    flex: 1;
}
.daily-habits-card h3 { font-size: 10.5px; letter-spacing: 2.5px; margin-bottom: 16px; color: var(--blue); text-transform: uppercase; font-weight: 800; }

/* ── Habit List ── */
.habit-list { display: flex; flex-direction: column; gap: 8px; }
.habit-item {
    display: flex; align-items: center; gap: 10px;
    font-size: 13px; position: relative;
    padding: 6px 8px; border-radius: 8px;
    transition: background 0.2s;
}
.habit-item:hover { background: rgba(255,255,255,0.5); }
.habit-item:hover .habit-actions { opacity: 1; }
.habit-actions { margin-left: auto; display: flex; gap: 6px; opacity: 0; transition: opacity 0.2s; }
.habit-edit-btn, .habit-delete-btn {
    background: none; border: none; cursor: pointer;
    padding: 2px 6px; border-radius: 6px;
    transition: all 0.2s; width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
}
.habit-edit-btn img, .habit-delete-btn img { width: 14px; height: 14px; opacity: 0.5; }
.habit-edit-btn:hover { background: rgba(255,255,255,0.7); }
.habit-edit-btn:hover img, .habit-delete-btn:hover img { opacity: 0.9; }
.habit-delete-btn:hover { background: rgba(255,100,100,0.2); }
.habit-number {
    background: white; width: 26px; height: 26px;
    border-radius: 7px; display: flex; align-items: center;
    justify-content: center; font-size: 11px; font-weight: 800;
    color: var(--blue); box-shadow: var(--shadow-sm);
}
.habit-name { flex: 1; font-weight: 500; }

/* ── Charts ── */
.center-section { display: flex; flex-direction: column; gap: 20px; }
.area-chart-card {
    background: var(--surface); padding: 20px;
    border-radius: var(--radius); height: 190px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}
#areaChart { width: 100%; height: 100%; }

/* ── Week Bars ── */
.weekly-bars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.week-bar { padding: 16px 14px; border-radius: var(--radius); text-align: center; box-shadow: var(--shadow-sm); }
.week-1 { background: linear-gradient(160deg, var(--blue-soft), #c8d8f0); border: 1px solid rgba(90,143,196,0.2); }
.week-2 { background: linear-gradient(160deg, var(--pink-soft), #f0c8d8); border: 1px solid rgba(228,123,168,0.2); }
.week-3 { background: linear-gradient(160deg, var(--green-soft), #c8f0e0); border: 1px solid rgba(92,196,154,0.2); }
.week-4 { background: linear-gradient(160deg, var(--amber-soft), #fce8c5); border: 1px solid rgba(232,168,87,0.2); }
.week-5 { background: linear-gradient(160deg, var(--purple-soft), #d8c8f0); border: 1px solid rgba(155,143,196,0.2); }
.week-label { font-size: 11px; font-style: italic; color: var(--text-muted); margin-bottom: 8px; font-weight: 500; }
.week-canvas { width: 100%; height: 80px; margin: 10px 0; }
.week-circles { display: flex; justify-content: center; margin-top: 10px; }
.circle-stat {
    width: 62px; height: 62px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 800; border: 3px solid; background: white;
    box-shadow: var(--shadow-sm);
}
.circle-stat.blue   { border-color: var(--blue);   color: var(--blue); }
.circle-stat.pink   { border-color: var(--pink);   color: var(--pink); }
.circle-stat.green  { border-color: var(--green);  color: var(--green); }
.circle-stat.orange { border-color: var(--amber);  color: var(--amber); }
.circle-stat.purple { border-color: var(--purple); color: var(--purple); }

/* ── Habit Grid ── */
.habit-grid-section {
    background: var(--surface); padding: 22px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    overflow-x: auto;
}
.week-headers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; text-align: center; }
.week-header {
    font-size: 11px; font-style: italic; color: var(--text-muted);
    padding: 8px; background: var(--surface2);
    border-radius: 8px; font-weight: 600;
}
.habit-grid {
    display: grid;
    grid-template-columns: repeat(31, 1fr);
    gap: 5px;
    min-width: 400px;
    -webkit-overflow-scrolling: touch; /* Momentum scroll */
}
.grid-cell {
    aspect-ratio: 1;
    min-height: 22px;
    border: 1.5px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}
.grid-cell:hover { transform: scale(1.2); box-shadow: 0 3px 10px rgba(0,0,0,0.14); }
.grid-cell.checked { border-color: transparent; box-shadow: var(--shadow-sm); }
.grid-cell.week-1.checked { background: var(--blue); }
.grid-cell.week-2.checked { background: var(--pink); }
.grid-cell.week-3.checked { background: var(--green); }
.grid-cell.week-4.checked { background: var(--amber); }
.grid-cell.week-5.checked { background: var(--purple); }

/* ── Right Section Cards ── */
.progress-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.progress-card {
    padding: 20px; border-radius: var(--radius);
    text-align: center; box-shadow: var(--shadow-sm);
}
.pink-card {
    background: linear-gradient(160deg, var(--pink-soft), #f0c8d8);
    border: 1px solid rgba(228,123,168,0.2);
}
.progress-label { font-size: 10px; letter-spacing: 2px; color: #a06080; margin-bottom: 14px; text-transform: uppercase; font-weight: 700; }
.progress-value { font-size: 30px; font-weight: 800; color: var(--pink); letter-spacing: -0.5px; }
#habitCircle { width: 100px; height: 100px; margin: 10px auto; }
.progress-fraction { font-size: 17px; font-weight: 700; color: var(--text); margin-top: 10px; }

.top-habits-card {
    background: linear-gradient(160deg, var(--blue-soft), #c8d8f0);
    padding: 20px; border-radius: var(--radius);
    border: 1px solid rgba(90,143,196,0.2); box-shadow: var(--shadow-sm);
}
.top-habits-card h3 { font-size: 10.5px; letter-spacing: 2.5px; margin-bottom: 16px; text-align: center; color: var(--blue); text-transform: uppercase; font-weight: 800; }
.top-habits-header {
    display: flex; justify-content: space-between;
    font-size: 11px; font-style: italic; color: var(--text-muted);
    padding: 10px 12px; background: rgba(255,255,255,0.7);
    border-radius: 8px; margin-bottom: 10px; font-weight: 500;
}
.top-habits-list { display: flex; flex-direction: column; gap: 8px; }
.top-habit-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 12px; background: rgba(255,255,255,0.8);
    border-radius: 8px; font-size: 12.5px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s;
}
.top-habit-item:hover { transform: translateX(2px); }
.habit-rank {
    background: var(--blue); color: white;
    width: 26px; height: 26px; border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 800; margin-right: 10px;
}
.habit-title { flex: 1; font-weight: 500; color: var(--text); }
.habit-percentage { font-weight: 800; color: var(--blue); }

.weekly-progress-card {
    background: linear-gradient(160deg, var(--blue-soft), #c8d8f0);
    padding: 20px; border-radius: var(--radius);
    border: 1px solid rgba(90,143,196,0.2); box-shadow: var(--shadow-sm);
}
.weekly-progress-card h3 { font-size: 10.5px; letter-spacing: 2.5px; margin-bottom: 16px; text-align: center; color: var(--blue); text-transform: uppercase; font-weight: 800; }
.weekly-progress-list { display: flex; flex-direction: column; gap: 8px; }
.weekly-progress-item {
    display: flex; justify-content: space-between;
    padding: 10px 12px; background: rgba(255,255,255,0.8);
    border-radius: 8px; font-size: 12.5px; font-weight: 500;
    box-shadow: var(--shadow-sm);
}

/* ── Responsive ── */
@media (max-width: 1200px) {
    .dashboard { grid-template-columns: 1fr; }
    .weekly-bars { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}
@media (max-width: 768px) {
    * { -webkit-tap-highlight-color: transparent; }
    body { padding: 12px; }
    .main-title { font-size: 28px; line-height: 1.2; }
    .month-display { font-size: 22px; }
    .controls { gap: 10px; padding: 0; }
    .select-box, .add-btn, .download-btn { 
        min-height: 48px; 
        font-size: 14px; 
        padding: 12px 18px; 
        flex: 1; /* Make them grow on mobile */
        justify-content: center;
    }
    .week-navigation { display: flex; width: 100%; gap: 8px; }
    .week-btn { min-height: 48px; flex: 1; }
    .download-buttons { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 8px; }
    .weekly-bars { grid-template-columns: 1fr; gap: 12px; }
    .habit-grid { 
        grid-template-columns: repeat(7, 1fr) !important; 
        gap: 8px; 
        min-width: auto; /* No more horizontal scroll here, let's stack or slice */
    }
    .grid-cell { border-width: 2px; border-radius: 10px; min-height: 44px; }
    .habit-actions { opacity: 1; margin-top: 8px; justify-content: flex-end; width: 100%; }
    .habit-edit-btn, .habit-delete-btn { min-width: 48px; min-height: 48px; background: var(--surface2); }
    .progress-cards { grid-template-columns: 1fr; }
    .area-chart-card { height: 220px; }
    .trust-card { padding: 32px 16px; }
    .habit-item { flex-wrap: wrap; padding: 12px; background: var(--surface2); border-radius: 12px; margin-bottom: 4px; }
}
@media (max-width: 480px) {
    .main-title { font-size: clamp(20px, 5vw, 22px); }
    .habit-grid { grid-template-columns: repeat(7, 1fr); gap: 3px; }
    .grid-cell { min-height: 28px; }
    .week-headers { display: none; }
}
