*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand: #2563eb;
  --brand-dark: #2563eb;
  --brand-light: #EDE9FE;
  --text: #1E1B4B;
  --text-muted: #64748b;
  --border: #0f172a;
  --bg: #F9FAFB;
  --white: #FFFFFF;
  --green: #059669;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.07);
  --shadow-md: 0 4px 16px rgba(0,0,0,.09);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ===== HEADER ===== */
.site-header {
  background: var(--white); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 1100px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.logo {
  display: flex; align-items: center; gap: 9px;
  font-size: 18px; font-weight: 800; color: var(--brand);
}
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  background: var(--brand-light); color: var(--brand-dark);
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px;
}
.btn-icon {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--white); color: var(--text-muted); font-size: 12px;
  cursor: pointer; font-family: inherit; font-weight: 500;
  transition: all .12s;
}
.btn-icon:hover { border-color: var(--brand); color: var(--brand); }
.btn-icon-danger:hover { border-color: #EF4444; color: #EF4444; }

/* ===== MAIN LAYOUT ===== */
.app-main {
  max-width: 1100px; margin: 24px auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 800px) {
  .app-main { grid-template-columns: 1fr; padding: 0 14px; }
}

/* ===== TODAY PANEL ===== */
.today-panel {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  overflow: hidden;
}
.today-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 12px;
}
.today-date { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.today-label { font-size: 20px; font-weight: 800; }

.btn-add {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--brand); color: white; border: none;
  border-radius: 8px; padding: 9px 16px; font-size: 13px;
  font-weight: 600; cursor: pointer; font-family: inherit;
  transition: background .12s, transform .1s;
}
.btn-add:hover { background: var(--brand-dark); }
.btn-add:active { transform: scale(.97); }

/* Progress bar */
.progress-bar-wrap {
  padding: 0 20px 14px;
  display: flex; align-items: center; gap: 10px;
}
.progress-bar-track {
  flex: 1; height: 8px; background: var(--brand-light);
  border-radius: 4px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: var(--brand);
  border-radius: 4px; transition: width .4s ease;
}
.progress-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* Add form */
.add-form {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  background: #FAFAFA;
}
.add-input {
  flex: 1; min-width: 160px;
  padding: 9px 12px; border: 1.5px solid var(--brand);
  border-radius: 8px; font-size: 14px; font-family: inherit;
  outline: none; color: var(--text);
}
.add-input:focus { box-shadow: 0 0 0 3px rgba(139,92,246,.15); }
.add-select {
  padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; cursor: pointer;
  background: var(--white); font-family: inherit;
}
.btn-save {
  background: var(--brand); color: white; border: none;
  border-radius: 8px; padding: 9px 16px; font-size: 13px;
  font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-cancel {
  background: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 14px; font-size: 13px;
  color: var(--text-muted); cursor: pointer; font-family: inherit;
}

/* Habits list */
.habits-list { padding: 6px 0; }
.no-habits {
  padding: 40px 20px; text-align: center; color: var(--text-muted);
}

.habit-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.habit-row:last-child { border-bottom: none; }
.habit-row:hover { background: #FAFAFA; }

.habit-check {
  width: 26px; height: 26px; flex-shrink: 0;
  border: 2.5px solid var(--border); border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all .15s; background: var(--white);
}
.habit-check.done {
  background: var(--brand); border-color: var(--brand);
}
.habit-check.done::after {
  content: '✓'; color: white; font-size: 13px; font-weight: 700;
}

.habit-emoji { font-size: 20px; flex-shrink: 0; }

.habit-info { flex: 1; min-width: 0; }
.habit-name { font-size: 15px; font-weight: 600; truncate: ellipsis; }
.habit-name.done-text { text-decoration: line-through; color: var(--text-muted); }
.habit-meta { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.streak-fire { color: #b45309; }

.habit-del {
  background: none; border: none; color: #334155;
  cursor: pointer; font-size: 18px; padding: 4px; border-radius: 4px;
  transition: color .12s;
  display: none;
}
.habit-row:hover .habit-del { display: block; }
.habit-del:hover { color: #EF4444; }

/* ===== STATS PANEL ===== */
.stats-panel { display: flex; flex-direction: column; gap: 14px; }

.stats-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}

.stats-overview {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.stat-item { text-align: center; }
.stat-num { font-size: 28px; font-weight: 800; color: var(--brand); line-height: 1; }
.stat-lbl { font-size: 11px; color: var(--text-muted); margin-top: 2px; font-weight: 500; }

/* Streaks */
.streaks-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted); margin-bottom: 12px;
}
.streak-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.streak-item:last-child { border-bottom: none; }
.streak-name { display: flex; align-items: center; gap: 7px; font-weight: 500; }
.streak-val {
  font-size: 16px; font-weight: 800; color: var(--brand);
  display: flex; align-items: center; gap: 3px;
}

/* Heatmap */
.heatmap-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted); margin-bottom: 8px;
}
.heatmap-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.btn-icon-sm {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  width: 26px; height: 26px; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: all .12s;
}
.btn-icon-sm:hover { border-color: var(--brand); color: var(--brand); }
#heatmapMonthNav { font-size: 13px; font-weight: 600; color: var(--text); }

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin-bottom: 8px;
}
.heat-cell {
  aspect-ratio: 1; border-radius: 3px;
  cursor: default; position: relative;
}
.heat-cell:hover::after {
  content: attr(title);
  position: absolute; bottom: 110%; left: 50%; transform: translateX(-50%);
  background: #1E1B4B; color: white; padding: 3px 7px;
  border-radius: 5px; font-size: 11px; white-space: nowrap; z-index: 10;
  pointer-events: none;
}
.heat-0 { background: #F3F4F6; }
.heat-1 { background: #DDD6FE; }
.heat-2 { background: #2563eb; }
.heat-3 { background: #2563eb; }
.heat-4 { background: #4C1D95; }

.heatmap-legend {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-muted);
}
.legend-dots { display: flex; gap: 3px; }
.heat-dot { width: 12px; height: 12px; border-radius: 2px; }
.heatmap-day-labels {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 3px; margin-bottom: 4px;
}
.heatmap-day-label {
  text-align: center; font-size: 9px; color: var(--text-muted); font-weight: 600;
}

/* ===== FOOTER ===== */
.site-footer {
  border-top: 1px solid var(--border); text-align: center;
  padding: 20px; color: var(--text-muted); font-size: 13px;
  line-height: 1.8; margin-top: 20px; background: var(--white);
}
.footer-small { font-size: 11px; color: #5b6878; }
