/* ================================================================
   HabitOS v3.0 — Styles
   ================================================================ */

:root {
  --bg:     #07070f;
  --panel:  #0c0c18;
  --card:   #111120;
  --card2:  #15152a;
  --border: #1e1e38;
  --border2:#2a2a48;
  --text:   #d8daf0;
  --muted:  #3a3a5a;
  --muted2: #5a5a80;
  --lime:   #c8f135;
  --teal:   #2de8b0;
  --pink:   #f03672;
  --orange: #f09836;
  --blue:   #36a8f0;
  --purple: #a036f0;
  --yellow: #f0d836;
  --red:    #f03636;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* scanlines overlay */
body::before {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,0,0,0.05) 2px, rgba(0,0,0,0.05) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* dot grid bg */
body::after {
  content: '';
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(200,241,53,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200,241,53,0.02) 1px, transparent 1px);
  background-size: 52px 52px;
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 14px 80px;
}

/* ── HEADER ───────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  animation: fadeUp .5s both;
}

.logo {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2rem;
  letter-spacing: .14em;
  color: var(--lime);
  line-height: 1;
}
.logo span {
  color: var(--text);
  font-size: .9rem;
  letter-spacing: .2em;
  vertical-align: middle;
  margin-left: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── BUTTONS ──────────────────────────────────────────────────── */
.btn-primary {
  background: var(--lime);
  border: none;
  color: #000;
  padding: 8px 16px;
  border-radius: 10px;
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: .78rem;
  letter-spacing: .05em;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.btn-primary:hover { background: #d8ff44; transform: scale(1.03); }

.btn-ghost {
  background: var(--card);
  border: 1px solid;
  padding: 7px 13px;
  border-radius: 10px;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: .72rem;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.btn-ghost.teal  { color: var(--teal);   border-color: var(--teal); }
.btn-ghost.orange{ color: var(--orange); border-color: var(--orange); }
.btn-ghost:hover { opacity: .8; }

/* ── TABS ─────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 3px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  width: fit-content;
  margin-bottom: 18px;
  animation: fadeUp .5s .05s both;
}
.tab {
  padding: 6px 16px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted2);
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: .72rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all .2s;
}
.tab.active             { background: var(--lime); color: #000; }
.tab:not(.active):hover { color: var(--text); }

.view         { display: none; }
.view.active  { display: block; }

/* ── MONTH NAV ────────────────────────────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 12px;
}
.month-nav-btn {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text);
  width: 28px; height: 28px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.month-nav-btn:hover { background: var(--lime); color: #000; border-color: var(--lime); }
.month-name {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.3rem;
  letter-spacing: .1em;
  min-width: 130px;
  text-align: center;
}
.year-tag {
  font-family: 'Space Mono', monospace;
  font-size: .68rem;
  color: var(--muted2);
}

/* ── STATS ────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 14px;
  animation: fadeUp .5s .08s both;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 12px 14px;
  position: relative;
  overflow: hidden;
  transition: transform .2s;
}
.stat:hover { transform: translateY(-2px); }
.stat::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}
.stat:nth-child(1)::before { background: var(--lime); }
.stat:nth-child(2)::before { background: var(--teal); }
.stat:nth-child(3)::before { background: var(--orange); }
.stat:nth-child(4)::before { background: var(--pink); }
.stat:nth-child(5)::before { background: var(--blue); }

.stat-lbl {
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted2);
  font-weight: 700;
  margin-bottom: 5px;
}
.stat-val {
  font-family: 'Space Mono', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
}
.stat-val--sm { font-size: .9rem; padding-top: 6px; }
.stat:nth-child(1) .stat-val { color: var(--lime); }
.stat:nth-child(2) .stat-val { color: var(--teal); }
.stat:nth-child(3) .stat-val { color: var(--orange); }
.stat:nth-child(4) .stat-val { color: var(--pink); }
.stat:nth-child(5) .stat-val { color: var(--blue); }
.stat-sub { font-size: .62rem; color: var(--muted); margin-top: 3px; }

/* ── GLOBAL PROGRESS BAR ──────────────────────────────────────── */
.gbar-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 12px 16px;
  margin-bottom: 14px;
  animation: fadeUp .5s .1s both;
}
.gbar-header  { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.gbar-lbl     { font-size: .6rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted2); font-weight: 700; }
.gbar-pct     { font-family: 'Space Mono', monospace; font-size: 1.1rem; font-weight: 700; color: var(--lime); }
.gbar-track   { height: 7px; background: rgba(255,255,255,.04); border-radius: 999px; overflow: hidden; }
.gbar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--lime));
  transition: width .9s cubic-bezier(.16,1,.3,1);
  position: relative;
}
.gbar-fill::after {
  content: '';
  position: absolute; right: 0; top: 0; bottom: 0;
  width: 20px;
  background: rgba(255,255,255,.3);
  border-radius: 999px;
  animation: shimmer 1.8s ease-in-out infinite;
}

/* ── ADD HABIT ROW ────────────────────────────────────────────── */
.add-row {
  display: flex;
  gap: 7px;
  margin-bottom: 14px;
  animation: fadeUp .5s .11s both;
  flex-wrap: wrap;
}
.add-input {
  flex: 1;
  min-width: 160px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 13px;
  border-radius: 10px;
  font-family: 'Syne', sans-serif;
  font-size: .85rem;
  outline: none;
  transition: border-color .2s;
}
.add-input:focus       { border-color: var(--lime); }
.add-input::placeholder{ color: var(--muted); }

.emoji-in {
  width: 42px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px;
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
}
.color-row {
  display: flex;
  gap: 5px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 10px;
}
.cdot {
  width: 13px; height: 13px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .15s;
  flex-shrink: 0;
}
.cdot:hover { transform: scale(1.35); }
.cdot.sel   { border-color: #fff; }

/* ── TRACKER TABLE ────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: 13px;
  border: 1px solid var(--border);
  animation: fadeUp .5s .14s both;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  min-width: 900px;
}

/* week header row */
.wk-row th {
  background: var(--panel);
  padding: 4px 3px;
  font-size: .55rem;
  text-transform: uppercase;
  letter-spacing: .15em;
  font-weight: 700;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.wk-lbl-th   { text-align: left; padding-left: 16px; color: var(--muted2); }
.wk-num      { color: var(--teal); }
.wk-sep-th   { border-left: 1px solid rgba(45,232,176,.25); }

/* day header row */
.day-row th {
  padding: 7px 3px;
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  border-bottom: 1px solid var(--border2);
  white-space: nowrap;
}
.day-row th:first-child { text-align: left; padding-left: 16px; min-width: 190px; color: var(--text); }
.th-today               { color: var(--lime) !important; }
.th-streak-h            { min-width: 60px; }
.th-prog-h              { min-width: 90px; }

/* category separator rows */
.cat-row td {
  padding: 5px 16px;
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  font-weight: 700;
  background: var(--panel);
  border-top: 1px solid var(--border2);
  border-bottom: 1px solid var(--border);
  color: var(--muted2);
}

/* data rows */
tbody tr                  { border-bottom: 1px solid var(--border); transition: background .15s; }
tbody tr:last-child       { border-bottom: none; }
tbody tr:hover            { background: rgba(255,255,255,.015); }

.hname-cell {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.h-dot   { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.h-emoji { font-size: .9rem; width: 18px; text-align: center; }
.h-name {
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
  outline: none;
}
.h-name:hover { border-color: var(--border2); }
.h-name:focus { border-color: var(--lime); color: var(--lime); }

.del-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .68rem;
  opacity: 0;
  transition: opacity .2s, color .2s;
  padding: 2px 4px;
}
tbody tr:hover .del-btn { opacity: 1; }
.del-btn:hover          { color: var(--pink); }

/* check cells */
.check-cell { text-align: center; padding: 6px 3px; vertical-align: middle; }
.cb {
  width: 20px; height: 20px;
  border-radius: 5px;
  border: 1.5px solid var(--border2);
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  font-size: 0;
}
.cb.done               { border-color: transparent; animation: pop .2s cubic-bezier(.16,1,.3,1); }
.cb.done::after        { content: '✓'; font-size: 10px; font-weight: 700; color: #000; line-height: 1; }
.cb:not(.done):hover   { background: rgba(255,255,255,.05); }
.cb.is-today           { box-shadow: 0 0 0 2px rgba(200,241,53,.2); }
.cb.is-future          { opacity: .18; pointer-events: none; }
.wk-sep-col            { border-left: 1px solid rgba(45,232,176,.15); }

/* streak & progress cells */
.streak-cell { text-align: center; padding: 7px 6px; }
.s-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: .62rem;
  font-weight: 700;
  font-family: 'Space Mono', monospace;
}
.rprog-cell  { padding: 7px 10px; min-width: 90px; }
.rb-track    { height: 5px; background: rgba(255,255,255,.04); border-radius: 999px; overflow: hidden; margin-bottom: 3px; }
.rb-fill     { height: 100%; border-radius: 999px; transition: width .6s cubic-bezier(.16,1,.3,1); }
.rb-pct      { font-family: 'Space Mono', monospace; font-size: .6rem; color: var(--muted); }

/* footer rows */
tfoot tr          { border-top: 2px solid var(--border2); }
tfoot td          { padding: 6px 3px; text-align: center; font-family: 'Space Mono', monospace; font-size: .62rem; color: var(--muted); }
tfoot td:first-child {
  text-align: left;
  padding-left: 16px;
  font-family: 'Syne', sans-serif;
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 700;
  color: var(--muted2);
}
.pct-pill { display: inline-block; padding: 1px 5px; border-radius: 5px; font-size: .58rem; font-weight: 700; }

/* ── DASHBOARD ────────────────────────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  animation: fadeUp .4s both;
}
.dash-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.dash-card.full { grid-column: span 2; }
.dash-title {
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--muted2);
  font-weight: 700;
  margin-bottom: 14px;
}
.chart-wrap { position: relative; height: 200px; }
canvas      { width: 100% !important; }

/* habit analysis bars */
.ha-row {
  display: grid;
  grid-template-columns: 22px 1fr 40px 50px;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}
.ha-emoji  { font-size: .85rem; text-align: center; }
.ha-track  { height: 6px; background: rgba(255,255,255,.04); border-radius: 999px; overflow: hidden; }
.ha-fill   { height: 100%; border-radius: 999px; transition: width .8s cubic-bezier(.16,1,.3,1); }
.ha-pct    { font-family: 'Space Mono', monospace; font-size: .62rem; color: var(--muted); text-align: right; }
.ha-streak { font-family: 'Space Mono', monospace; font-size: .6rem; color: var(--orange); }

/* heatmap */
.hm-days { display: grid; grid-template-columns: repeat(7,1fr); gap: 3px; margin-bottom: 4px; }
.hm-dl   { font-size: .56rem; color: var(--muted); text-align: center; font-weight: 700; text-transform: uppercase; }
.hm-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 3px; }
.hm-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: rgba(255,255,255,.03);
  transition: transform .15s;
  cursor: default;
  position: relative;
}
.hm-cell:hover { transform: scale(1.3); z-index: 2; }
.hm-cell:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  color: var(--text);
  font-size: .56rem;
  padding: 3px 7px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 10;
  border: 1px solid var(--border);
}

/* best/worst items */
.bw-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--card2);
  border-radius: 9px;
  border: 1px solid var(--border);
  margin-bottom: 6px;
}
.bw-rank { font-family: 'Space Mono', monospace; font-size: .58rem; color: var(--muted); width: 16px; text-align: center; }
.bw-name { font-size: .75rem; font-weight: 600; flex: 1; }
.bw-pct  { font-family: 'Space Mono', monospace; font-size: .7rem; font-weight: 700; }

/* ── TOAST ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 22px; right: 22px;
  background: var(--card);
  border: 1px solid var(--lime);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 11px;
  font-size: .8rem;
  font-weight: 600;
  transform: translateY(60px);
  opacity: 0;
  transition: all .4s cubic-bezier(.16,1,.3,1);
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 7px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.t-dot      { width: 6px; height: 6px; border-radius: 50%; background: var(--lime); flex-shrink: 0; }

/* ── MODAL ────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.8);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: 18px;
  padding: 28px;
  width: min(540px, 94vw);
  position: relative;
  box-shadow: 0 0 60px rgba(240,152,54,.1);
  animation: fadeUp .3s both;
}
.modal-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none;
  color: var(--muted2);
  font-size: 1.2rem; cursor: pointer; line-height: 1;
}
.modal-title { font-family: 'Bebas Neue', sans-serif; font-size: 1.5rem; letter-spacing: .1em; color: var(--orange); margin-bottom: 4px; }
.modal-sub   { font-size: .73rem; color: var(--muted2); line-height: 1.5; margin-bottom: 20px; }

/* drop zone */
.drop-zone {
  border: 2px dashed var(--border2);
  border-radius: 12px;
  padding: 30px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 16px;
}
.drop-zone.drag-over { border-color: var(--orange); background: rgba(240,152,54,.05); }
.drop-icon  { font-size: 2.2rem; margin-bottom: 8px; }
.drop-title { font-size: .85rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.drop-sub   { font-size: .68rem; color: var(--muted2); }

/* import preview */
.preview-box { background: var(--card2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; max-height: 220px; overflow-y: auto; }
.preview-lbl { font-size: .58rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted2); font-weight: 700; margin-bottom: 10px; }
.import-warning { background: rgba(240,152,54,.07); border: 1px solid rgba(240,152,54,.2); border-radius: 10px; padding: 12px; margin-bottom: 14px; }
.import-warning-title { font-size: .7rem; color: var(--orange); font-weight: 700; margin-bottom: 5px; }
#importWarning        { font-size: .68rem; color: var(--muted2); line-height: 1.6; }
.import-actions { display: flex; gap: 8px; }
.btn-merge   { flex: 1; background: var(--card2); border: 1px solid var(--teal); color: var(--teal); padding: 10px; border-radius: 10px; font-family: 'Syne', sans-serif; font-weight: 700; font-size: .76rem; cursor: pointer; transition: background .2s; }
.btn-merge:hover   { background: rgba(45,232,176,.1); }
.btn-replace { flex: 1; background: var(--orange); border: none; color: #000; padding: 10px; border-radius: 10px; font-family: 'Syne', sans-serif; font-weight: 700; font-size: .76rem; cursor: pointer; transition: opacity .2s; }
.btn-replace:hover { opacity: .85; }
.import-empty { font-size: .73rem; color: var(--muted2); text-align: center; padding: 6px 0; }

/* ── ANIMATIONS ───────────────────────────────────────────────── */
@keyframes fadeUp  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shimmer { 0%,100% { opacity: .2; } 50% { opacity: .5; } }
@keyframes pop     { 0% { transform: scale(.5); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes rowFlash{ from { background: rgba(200,241,53,.06); } to { background: transparent; } }
.row-flash { animation: rowFlash .5s ease-out; }

/* ── SCROLLBAR ────────────────────────────────────────────────── */
::-webkit-scrollbar        { width: 5px; height: 5px; }
::-webkit-scrollbar-track  { background: var(--bg); }
::-webkit-scrollbar-thumb  { background: var(--border2); border-radius: 3px; }

/* ── RESPONSIVE ───────────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .stat:nth-child(4), .stat:nth-child(5) { display: none; }
  .dash-grid { grid-template-columns: 1fr; }
  .dash-card.full { grid-column: span 1; }
}
@media (max-width: 560px) {
  .stats-row { grid-template-columns: 1fr 1fr; }
  header     { flex-wrap: wrap; gap: 8px; }
}
