:root {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --surface2: #f0ede8;
  --border: #e2ddd6;
  --text: #1a1816;
  --text2: #6b6560;
  --text3: #9b958e;
  --accent: #e8622a;
  --accent2: #f0843e;
  --green: #27ae60;
  --yellow: #f39c12;
  --red: #e74c3c;
  --blue: #3498db;
  --purple: #9b59b6;
  --teal: #1abc9c;
  --shadow: 0 2px 12px rgba(0,0,0,0.07);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Poppins', sans-serif;
}
[data-theme="dark"] {
  --bg: #141210;
  --surface: #1e1b18;
  --surface2: #2a2620;
  --border: #3a3530;
  --text: #f0ede8;
  --text2: #a09890;
  --text3: #706860;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{scroll-behavior:smooth}
body{
  font-family:var(--font);
  background:var(--bg);
  color:var(--text);
  min-height:100vh;
  transition:background .3s,color .3s;
  font-size:14px;
  line-height:1.6;
}
/* ── LAYOUT ── */
.app{display:flex;flex-direction:column;min-height:100vh}
/* ── TOPBAR ── */
.topbar{
  background:var(--surface);
  border-bottom:1px solid var(--border);
  padding:0 24px;
  height:64px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  position:sticky;top:0;z-index:100;
  box-shadow:var(--shadow);
}
.logo{display:flex;align-items:center;gap:10px}
.logo-icon{
  width:36px;height:36px;
  background:linear-gradient(135deg,var(--accent),var(--accent2));
  border-radius:10px;
  display:flex;align-items:center;justify-content:center;
  font-size:18px;
}
.logo-text{font-size:20px;font-weight:700;letter-spacing:-0.3px}
.logo-text span{color:var(--accent)}
.topbar-right{display:flex;align-items:center;gap:12px}
.month-selector{
  display:flex;align-items:center;gap:8px;
  background:var(--surface2);
  border:1px solid var(--border);
  border-radius:var(--radius-sm);
  padding:6px 12px;
  font-family:var(--font);
  font-size:13px;
  font-weight:500;
  color:var(--text);
  cursor:pointer;
  outline:none;
  appearance:none;
}
.btn{
  padding:7px 16px;
  border-radius:var(--radius-sm);
  border:none;
  cursor:pointer;
  font-family:var(--font);
  font-size:13px;
  font-weight:600;
  transition:all .2s;
}
.btn-accent{background:var(--accent);color:#fff}
.btn-accent:hover{background:var(--accent2);transform:translateY(-1px)}
.btn-ghost{background:var(--surface2);color:var(--text);border:1px solid var(--border)}
.btn-ghost:hover{background:var(--border)}
.dark-toggle{
  width:40px;height:40px;
  border-radius:10px;
  background:var(--surface2);
  border:1px solid var(--border);
  cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  font-size:18px;
  transition:all .2s;
}
.dark-toggle:hover{transform:rotate(20deg)}
/* ── TABS ── */
.tabs{
  background:var(--surface);
  border-bottom:1px solid var(--border);
  padding:0 24px;
  display:flex;gap:4px;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab{
  padding:12px 20px;
  border:none;background:none;
  font-family:var(--font);font-size:13px;font-weight:500;
  color:var(--text2);cursor:pointer;
  border-bottom:2px solid transparent;
  transition:all .2s;
}
.tab.active{color:var(--accent);border-bottom-color:var(--accent);font-weight:600}
.tab:hover:not(.active){color:var(--text)}
/* ── MAIN ── */
.main{padding:24px;flex:1}
.panel{display:none}
.panel.active{display:block}
/* ── MARQUEE ── */
.marquee-wrap{
  background:linear-gradient(135deg,var(--accent),var(--accent2));
  border-radius:var(--radius-sm);
  padding:10px 20px;
  margin-bottom:24px;
  overflow:hidden;
}
.marquee-inner{
  display:flex;
  animation:marquee 30s linear infinite;
  white-space:nowrap;
}
.marquee-inner span{
  color:#fff;font-size:13px;font-weight:500;
  padding-right:80px;
}
@keyframes marquee{from{transform:translateX(0)}to{transform:translateX(-50%)}}
/* ── STAT CARDS ── */
.stat-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:16px;margin-bottom:24px}
.stat-card{
  background:var(--surface);
  border-radius:var(--radius);
  padding:20px;
  box-shadow:var(--shadow);
  border:1px solid var(--border);
  position:relative;overflow:hidden;
  transition:transform .2s,box-shadow .2s;
}
.stat-card:hover{transform:translateY(-2px);box-shadow:var(--shadow-lg)}
.stat-card::before{
  content:'';position:absolute;top:0;left:0;right:0;height:3px;
  background:var(--card-color,var(--accent));
}
.stat-label{font-size:12px;font-weight:500;color:var(--text2);text-transform:uppercase;letter-spacing:.6px;margin-bottom:8px}
.stat-value{font-size:32px;font-weight:700;color:var(--text);line-height:1}
.stat-sub{font-size:12px;color:var(--text3);margin-top:6px}
.stat-bar{height:4px;background:var(--border);border-radius:2px;margin-top:12px;overflow:hidden}
.stat-bar-fill{height:100%;border-radius:2px;background:var(--card-color,var(--accent));transition:width .6s ease}
/* ── CHARTS ROW ── */
.charts-row{display:grid;grid-template-columns:1fr 320px;gap:16px;margin-bottom:24px}
.chart-card{
  background:var(--surface);
  border-radius:var(--radius);
  padding:20px;
  box-shadow:var(--shadow);
  border:1px solid var(--border);
}
.chart-title{font-size:14px;font-weight:600;color:var(--text);margin-bottom:16px;display:flex;align-items:center;justify-content:space-between}
.chart-title span{font-size:12px;font-weight:400;color:var(--text3)}
.donut-wrap{position:relative;width:200px;height:200px;margin:0 auto}
.donut-center{
  position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);
  text-align:center;pointer-events:none;
}
.donut-pct{font-size:28px;font-weight:700;color:var(--text)}
.donut-lbl{font-size:11px;color:var(--text3);font-weight:500}
/* ── WEEKLY BARS ── */
.weekly-grid{display:grid;grid-template-columns:repeat(5,1fr);gap:12px;margin-bottom:24px}
.week-card{
  background:var(--surface);
  border-radius:var(--radius-sm);
  padding:16px;
  box-shadow:var(--shadow);
  border:1px solid var(--border);
  text-align:center;
}
.week-label{font-size:11px;font-weight:600;color:var(--text2);text-transform:uppercase;letter-spacing:.5px;margin-bottom:10px}
.week-ring{position:relative;width:64px;height:64px;margin:0 auto 10px}
.week-ring svg{transform:rotate(-90deg)}
.week-ring-bg{fill:none;stroke:var(--border);stroke-width:6}
.week-ring-fill{fill:none;stroke-width:6;stroke-linecap:round;transition:stroke-dashoffset .6s ease}
.week-ring-text{
  position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);
  font-size:13px;font-weight:700;color:var(--text);
}
.week-dates{font-size:11px;color:var(--text3)}
/* ── MINI HABITS ── */
.mini-habits{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-bottom:24px}
.mini-habit{
  background:var(--surface);
  border-radius:var(--radius-sm);
  padding:14px;
  box-shadow:var(--shadow);
  border:1px solid var(--border);
  display:flex;align-items:center;gap:12px;
  transition:transform .2s;
}
.mini-habit:hover{transform:translateY(-1px)}
.mini-habit-icon{
  width:40px;height:40px;border-radius:10px;
  display:flex;align-items:center;justify-content:center;
  font-size:18px;flex-shrink:0;
}
.mini-habit-info{flex:1;min-width:0}
.mini-habit-name{font-size:13px;font-weight:600;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.mini-habit-pct{font-size:11px;color:var(--text3);margin-top:2px}
.mini-habit-bar{height:3px;background:var(--border);border-radius:2px;margin-top:6px;overflow:hidden}
.mini-habit-fill{height:100%;border-radius:2px;transition:width .4s}
.streak-badge{
  background:var(--surface2);
  border:1px solid var(--border);
  border-radius:6px;
  padding:2px 6px;
  font-size:11px;font-weight:600;color:var(--accent);
  white-space:nowrap;
}
/* ── HABIT TABLE ── */
.table-header{
  display:flex;align-items:center;justify-content:space-between;
  margin-bottom:16px;
}
.table-title{font-size:16px;font-weight:700;color:var(--text)}
.table-actions{display:flex;gap:8px;align-items:center}
.table-wrap{
  background:var(--surface);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  border:1px solid var(--border);
  overflow:hidden;
}
.table-scroll{
  overflow-x:auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}
table{width:100%;border-collapse:collapse}
thead tr{background:var(--surface2)}
th{
  padding:10px 8px;
  font-size:11px;font-weight:600;color:var(--text2);
  text-transform:uppercase;letter-spacing:.5px;
  text-align:center;white-space:nowrap;
  border-bottom:2px solid var(--border);
  position:sticky;top:0;background:var(--surface2);z-index:2;
}
th.sticky-col{left:0;z-index:3;min-width:150px;text-align:left;padding-left:16px}
th.col-goal{min-width:60px}
th.col-meta{min-width:70px}
td{
  padding:8px;
  border-bottom:1px solid var(--border);
  text-align:center;vertical-align:middle;
}
td.sticky-col{
  position:sticky;left:0;
  background:var(--surface);z-index:1;
  text-align:left;padding-left:16px;
  box-shadow:4px 0 8px rgba(0,0,0,.05);
}
tr:last-child td{border-bottom:none}
tr:hover td{background:var(--surface2)}
tr:hover td.sticky-col{background:var(--surface2)}
.habit-name-cell{display:flex;align-items:center;gap:8px}
.habit-emoji{font-size:16px}
.habit-name{font-size:13px;font-weight:500;color:var(--text)}
.habit-cat{font-size:10px;font-weight:500;padding:2px 6px;border-radius:4px;margin-top:2px;display:inline-block}
.cat-health{background:#e8f8f0;color:#27ae60}
.cat-study{background:#e8f0fb;color:#3498db}
.cat-skill{background:#fef3e8;color:#e67e22}
.cat-mindset{background:#f5e8fb;color:#9b59b6}
.cat-fitness{background:#e8faf8;color:#1abc9c}
[data-theme="dark"] .cat-health{background:#1a3a28;color:#5dde8c}
[data-theme="dark"] .cat-study{background:#1a2a3a;color:#6ab4e8}
[data-theme="dark"] .cat-skill{background:#3a2a1a;color:#e8a06a}
[data-theme="dark"] .cat-mindset{background:#2a1a3a;color:#c87be0}
[data-theme="dark"] .cat-fitness{background:#1a3a36;color:#5dd8cc}
/* ── CHECKBOXES ── */
.day-cell{
  width:28px;height:28px;
  border-radius:6px;
  display:inline-flex;align-items:center;justify-content:center;
  cursor:pointer;
  font-size:13px;
  transition:all .15s;
  user-select:none;
  border:1.5px solid var(--border);
  background:transparent;
}
.day-cell.done{background:#e8f8f0;border-color:#27ae60;color:#27ae60}
.day-cell.missed{background:#fde8e8;border-color:#e74c3c;color:#e74c3c}
.day-cell.today-cell{border-color:var(--accent);font-weight:700}
.day-cell.future{opacity:.4;cursor:default}
.day-cell:hover:not(.future){transform:scale(1.1)}
[data-theme="dark"] .day-cell.done{background:#1a3a28;border-color:#27ae60;color:#5dde8c}
[data-theme="dark"] .day-cell.missed{background:#3a1a1a;border-color:#e74c3c;color:#e87070}
/* ── PROGRESS IN TABLE ── */
.pct-pill{
  display:inline-block;
  padding:3px 8px;
  border-radius:20px;
  font-size:11px;font-weight:700;
}
.pct-green{background:#e8f8f0;color:#27ae60}
.pct-yellow{background:#fef9e8;color:#f39c12}
.pct-red{background:#fde8e8;color:#e74c3c}
[data-theme="dark"] .pct-green{background:#1a3a28;color:#5dde8c}
[data-theme="dark"] .pct-yellow{background:#3a2e1a;color:#f8c56a}
[data-theme="dark"] .pct-red{background:#3a1a1a;color:#e87070}
.habit-progress-bar{width:60px;height:4px;background:var(--border);border-radius:2px;margin:4px auto 0;overflow:hidden}
.habit-progress-fill{height:100%;border-radius:2px;transition:width .4s}
/* ── ADD HABIT FORM ── */
.add-habit-form{
  background:var(--surface);
  border-radius:var(--radius);
  padding:20px;
  box-shadow:var(--shadow);
  border:1px solid var(--border);
  margin-top:16px;
  display:none;
}
.add-habit-form.open{display:block;animation:slideDown .2s ease}
@keyframes slideDown{from{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}
.form-grid{display:grid;grid-template-columns:2fr 1fr 1fr 1fr auto;gap:12px;align-items:end}
.form-group{display:flex;flex-direction:column;gap:4px}
.form-label{font-size:11px;font-weight:600;color:var(--text2);text-transform:uppercase;letter-spacing:.5px}
.form-input{
  padding:8px 12px;
  border-radius:var(--radius-sm);
  border:1.5px solid var(--border);
  background:var(--surface2);
  color:var(--text);
  font-family:var(--font);
  font-size:13px;
  outline:none;
  transition:border-color .2s;
}
.form-input:focus{border-color:var(--accent)}
.form-select{
  padding:8px 12px;
  border-radius:var(--radius-sm);
  border:1.5px solid var(--border);
  background:var(--surface2);
  color:var(--text);
  font-family:var(--font);
  font-size:13px;
  outline:none;
  cursor:pointer;
}
/* ── NOTES ── */
.notes-overlay{
  position:fixed;top:0;left:0;right:0;bottom:0;
  background:rgba(0,0,0,.5);
  z-index:200;
  display:flex;align-items:center;justify-content:center;
  opacity:0;pointer-events:none;transition:opacity .2s;
}
.notes-overlay.open{opacity:1;pointer-events:all}
.notes-modal{
  background:var(--surface);
  border-radius:var(--radius);
  padding:24px;
  width:400px;
  max-width:90vw;
  box-shadow:var(--shadow-lg);
  transform:scale(.95);
  transition:transform .2s;
}
.notes-overlay.open .notes-modal{transform:scale(1)}
.notes-title{font-size:16px;font-weight:700;margin-bottom:16px;display:flex;justify-content:space-between;align-items:center}
.notes-close{cursor:pointer;color:var(--text3);font-size:20px}
.notes-textarea{
  width:100%;
  height:120px;
  padding:10px 12px;
  border-radius:var(--radius-sm);
  border:1.5px solid var(--border);
  background:var(--surface2);
  color:var(--text);
  font-family:var(--font);
  font-size:13px;
  resize:vertical;
  outline:none;
  transition:border-color .2s;
}
.notes-textarea:focus{border-color:var(--accent)}
/* ── ANALYTICS ── */
.analytics-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:24px}
.analytics-card{
  background:var(--surface);
  border-radius:var(--radius);
  padding:20px;
  box-shadow:var(--shadow);
  border:1px solid var(--border);
}
.cat-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-bottom:24px}
.cat-card{
  background:var(--surface);
  border-radius:var(--radius-sm);
  padding:16px;
  box-shadow:var(--shadow);
  border:1px solid var(--border);
  text-align:center;
}
.cat-emoji{font-size:28px;margin-bottom:8px}
.cat-name{font-size:13px;font-weight:600;color:var(--text);margin-bottom:4px}
.cat-count{font-size:12px;color:var(--text3);margin-bottom:10px}
.cat-bar{height:6px;background:var(--border);border-radius:3px;overflow:hidden}
.cat-bar-fill{height:100%;border-radius:3px;transition:width .6s}
/* ── RANKINGS ── */
.podium{display:flex;align-items:flex-end;justify-content:center;gap:16px;margin-bottom:24px;padding:20px}
.podium-item{text-align:center;flex:1;max-width:140px}
.podium-card{
  background:var(--surface);
  border-radius:var(--radius-sm);
  padding:16px 12px;
  box-shadow:var(--shadow);
  border:1px solid var(--border);
  position:relative;
}
.podium-medal{font-size:28px;margin-bottom:8px}
.podium-name{font-size:13px;font-weight:700;color:var(--text)}
.podium-pct{font-size:20px;font-weight:800;margin-top:4px}
.podium-1 .podium-card{background:linear-gradient(135deg,#fffbe8,#fef3c7);border-color:#f8d44a}
.podium-2 .podium-card{background:linear-gradient(135deg,#f0f0f0,#e8e8e8);border-color:#c0c0c0}
.podium-3 .podium-card{background:linear-gradient(135deg,#fef0e8,#fde0c8);border-color:#cd7f32}
[data-theme="dark"] .podium-1 .podium-card{background:linear-gradient(135deg,#3a3010,#4a3e18);border-color:#f8d44a}
[data-theme="dark"] .podium-2 .podium-card{background:linear-gradient(135deg,#282828,#303030);border-color:#888}
[data-theme="dark"] .podium-3 .podium-card{background:linear-gradient(135deg,#3a2010,#4a2c18);border-color:#cd7f32}
.podium-base{height:12px;background:var(--border);border-radius:0 0 var(--radius-sm) var(--radius-sm)}
.podium-1 .podium-base{background:#f8d44a;height:80px}
.podium-2 .podium-base{background:#c0c0c0;height:60px}
.podium-3 .podium-base{background:#cd7f32;height:40px}
.rank-list{
  background:var(--surface);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  border:1px solid var(--border);
  overflow:hidden;
}
.rank-item{
  display:flex;align-items:center;gap:12px;
  padding:14px 20px;
  border-bottom:1px solid var(--border);
  transition:background .15s;
}
.rank-item:last-child{border-bottom:none}
.rank-item:hover{background:var(--surface2)}
.rank-num{
  width:28px;height:28px;
  border-radius:8px;
  background:var(--surface2);
  border:1px solid var(--border);
  display:flex;align-items:center;justify-content:center;
  font-size:12px;font-weight:700;color:var(--text2);
  flex-shrink:0;
}
.rank-info{flex:1;min-width:0}
.rank-name{font-size:13px;font-weight:600;color:var(--text)}
.rank-meta{font-size:11px;color:var(--text3);margin-top:2px}
.rank-bar-wrap{width:120px}
.rank-bar{height:6px;background:var(--border);border-radius:3px;overflow:hidden}
.rank-bar-fill{height:100%;border-radius:3px;transition:width .6s}
/* ── MATRIX TABLE ── */
.matrix-table th,.matrix-table td{padding:10px 14px;font-size:12px}
.matrix-table th{background:var(--surface2)}
/* ── FOOTER ── */
footer{
  text-align:center;
  padding:20px;
  font-size:12px;
  color:var(--text3);
  border-top:1px solid var(--border);
  background:var(--surface);
}

/* name  */
.user-box{
  display:flex;
  align-items:center;
  gap:6px;
  font-size:14px;
  color:var(--text2);
}
.user-name{
  font-weight:700;
  font-size:15px;
  padding:4px 10px;
  border-radius:20px;
  background:linear-gradient(135deg,#ff7e5f,#feb47b);
  color:#fff;
  letter-spacing:0.5px;
  box-shadow:0 2px 6px rgba(0,0,0,0.2);
}
/* Logout button */
.logout-btn{
  padding:6px 14px;
  border-radius:20px;
  border:none;
  font-size:13px;
  font-weight:600;
  cursor:pointer;
  background:linear-gradient(135deg,#ff4b2b,#ff416c);
  color:#fff;
  transition:all 0.25s ease;
  box-shadow:0 3px 10px rgba(0,0,0,0.2);
}
.logout-btn:hover{
  transform:translateY(-2px) scale(1.05);
  box-shadow:0 6px 15px rgba(0,0,0,0.3);
  background:linear-gradient(135deg,#ff416c,#ff4b2b);
}
.logout-btn:active{
  transform:scale(0.95);
}
[data-theme="dark"] .logout-btn{
  background:linear-gradient(135deg,#e74c3c,#c0392b);
}

/* ── TOOLTIP ── */
[data-tip]{position:relative}
[data-tip]::after{
  content:attr(data-tip);
  position:absolute;bottom:110%;left:50%;transform:translateX(-50%);
  background:var(--text);color:var(--surface);
  font-size:11px;font-weight:500;
  padding:4px 8px;border-radius:6px;
  white-space:nowrap;pointer-events:none;
  opacity:0;transition:opacity .2s;z-index:10;
}
[data-tip]:hover::after{opacity:1}

/* ── RESPONSIVE ── */
@media(max-width:1024px){
  .stat-grid{grid-template-columns:repeat(2,1fr)}
  .charts-row{grid-template-columns:1fr}
  .form-grid{grid-template-columns:1fr 1fr auto}
}

@media(max-width:768px){
  .topbar { height: auto; padding: 12px 16px; flex-wrap: wrap; gap: 12px; }
  .topbar-right { flex-wrap: wrap; width: 100%; justify-content: flex-start; }
  .weekly-grid{grid-template-columns:repeat(3,1fr)}
  .mini-habits{grid-template-columns:repeat(2,1fr)}
  .analytics-grid{grid-template-columns:1fr}
  .cat-grid{grid-template-columns:repeat(2,1fr)}
  .form-grid{grid-template-columns:1fr 1fr}
  .podium{gap:8px}
  .main{padding:16px}
  
  .form-input, .form-select, .btn { padding: 10px 16px; font-size: 14px; }
  .day-cell { width: 32px; height: 32px; }
}

@media(max-width:480px){
  .stat-grid{grid-template-columns:1fr}
  .weekly-grid{grid-template-columns:repeat(2,1fr)}
  .mini-habits{grid-template-columns:1fr}
  .cat-grid{grid-template-columns:1fr}
  .form-grid{grid-template-columns:1fr}
  .topbar{padding:12px}
  .tabs{padding:0 12px}
  .tab{padding:10px 12px;font-size:13px}
  
  .podium { flex-direction: column; align-items: center; }
  .podium-item { max-width: 100%; width: 100%; margin-bottom: 12px; }
  .podium-base { display: none; } 
  .podium-card { border-bottom-width: 4px; } 
  
  .chart-title { flex-direction: column; align-items: flex-start; gap: 4px; }
  .table-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}
