/* ============================================================
   Streak Tracker — mobile-first styles
   ============================================================ */

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #273449;
  --border:    #334155;
  --text:      #f1f5f9;
  --text-muted:#94a3b8;
  --primary:   #3B82F6;
  --primary-dk:#2563eb;
  --success:   #22c55e;
  --success-dk:#16a34a;
  --danger:    #ef4444;
  --danger-dk: #dc2626;
  --radius:    10px;
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Utility ---- */
.hidden { display: none !important; }
.required { color: var(--danger); }

/* ---- Splash ---- */
.splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 1.1rem;
}
.splash__icon { font-size: 3rem; }

.loading {
  padding: 3rem;
  text-align: center;
  color: var(--text-muted);
}

.error {
  padding: 1.5rem;
  color: var(--danger);
  text-align: center;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__title {
  font-weight: 600;
  font-size: 1rem;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__nav {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

.topbar__user {
  font-size: .85rem;
  color: var(--text-muted);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.1rem;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary  { background: var(--primary);   color: #fff; }
.btn--primary:hover  { background: var(--primary-dk); }
.btn--success  { background: var(--success);   color: #fff; }
.btn--success:hover  { background: var(--success-dk); }
.btn--danger   { background: var(--danger);    color: #fff; }
.btn--danger:hover   { background: var(--danger-dk); }
.btn--ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn--ghost:hover  { background: var(--surface2); color: var(--text); }

.btn--sm  { padding: .4rem .75rem; font-size: .8rem; }
.btn--full { width: 100%; }

/* ---- Auth ---- */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.auth-title {
  text-align: center;
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1rem;
  font-size: .9rem;
  color: var(--text-muted);
}

/* ---- Forms ---- */
.form { display: flex; flex-direction: column; gap: 1rem; }

.form-field { display: flex; flex-direction: column; gap: .35rem; }
.form-field label { font-size: .85rem; color: var(--text-muted); font-weight: 500; }

input[type=text],
input[type=email],
input[type=password],
input[type=number],
select,
textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: .95rem;
  padding: .6rem .75rem;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

textarea { resize: vertical; }

input[type=color] {
  height: 2.5rem;
  padding: .2rem .3rem;
  cursor: pointer;
}

.form-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}
.form-group legend {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 500;
  padding: 0 .4rem;
}

.radio, .checkbox {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  font-size: .9rem;
  cursor: pointer;
  padding: .3rem 0;
}
.radio input, .checkbox input { margin-top: .2rem; flex-shrink: 0; }
.radio__hint { color: var(--text-muted); font-size: .8rem; }

.form-hint { font-size: .8rem; color: var(--text-muted); }

.form-row { display: flex; gap: .75rem; }
.form-row .form-field { flex: 1; min-width: 0; }

.form-field--inline { flex-direction: row; align-items: center; }

.form-error {
  color: var(--danger);
  font-size: .875rem;
  padding: .5rem .75rem;
  background: rgba(239,68,68,.1);
  border-radius: var(--radius);
}

.form-actions {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  padding-top: .5rem;
}

/* ---- Form page ---- */
.form-page {
  max-width: 560px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

/* ---- Dashboard ---- */
.dashboard {
  padding: 1rem;
  max-width: 900px;
  margin: 0 auto;
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .75rem;
}

@media (min-width: 540px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 800px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---- Tracker card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--tracker-color, var(--primary));
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card__body {
  flex: 1;
  padding: .9rem 1rem .5rem;
}

.card__name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  display: block;
  margin-bottom: .25rem;
}
.card__name:hover { color: var(--primary); text-decoration: none; }

.card__desc {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .5rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card__stats { display: flex; flex-direction: column; gap: .2rem; }
.card__stat  { font-size: .85rem; color: var(--text-muted); }
.card__stat--muted { color: var(--text-muted); font-style: italic; }
.card__stat-sub { font-size: .75rem; opacity: .75; }
.card__streak { font-size: .9rem; font-weight: 600; color: var(--primary); }
.card__today  { font-size: .78rem; font-weight: 600; color: var(--success); letter-spacing: .02em; }

.card__actions {
  padding: .6rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: .5rem;
}

/* ---- Disabled card ---- */
.card--disabled {
  opacity: .55;
  filter: grayscale(.4);
}

.card__name-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .25rem;
}
.card__name-row .card__name { margin-bottom: 0; }

.card__disabled-badge {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1rem .4rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex-shrink: 0;
}

.btn--ghost--active {
  background: var(--surface2);
  color: var(--text);
}

/* ---- Detail page ---- */
.detail {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 0 3rem;
}

.detail__log {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.log-actions { display: flex; gap: .75rem; flex-wrap: wrap; }

.detail__stats,
.detail__heatmap,
.detail__history {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .75rem;
}

/* ---- Stat boxes ---- */
.stat-row {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}
.stat-row--sm .stat-box { padding: .5rem .75rem; }

.stat-box {
  flex: 1;
  min-width: 80px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.stat-box--highlight { border-color: var(--primary); }
.stat-box--success   { border-color: var(--success); }
.stat-box--failure   { border-color: var(--danger); }

.stat-box__val {
  font-size: 1.4rem;
  font-weight: 700;
}
.stat-box__lbl {
  font-size: .75rem;
  color: var(--text-muted);
}

/* ---- Frequency goal card ---- */
.goal-card {
  margin-top: .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
}
.goal-card__header {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: .6rem;
}
.goal-card__progress {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .75rem;
}
.goal-card__count { font-size: .85rem; white-space: nowrap; }

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar__fill {
  height: 100%;
  background: var(--text-muted);
  border-radius: 4px;
  transition: width .3s;
}
.progress-bar__fill--ok { background: var(--success); }

/* ---- Year select ---- */
.year-select {
  width: auto;
  padding: .35rem .6rem;
  font-size: .85rem;
}

/* ---- Heatmap ---- */
.heatmap-wrap {
  overflow-x: auto;
  padding-bottom: .25rem;
}

.heatmap {
  display: block;
  height: 120px;
  min-width: 100%;
}

.hm-label {
  fill: var(--text-muted);
  font-size: 9px;
  font-family: var(--font);
}

.hm-cell        { fill: var(--surface2); }
.hm-cell--empty { fill: transparent; }
.hm-cell--none  { fill: var(--surface2); }
.hm-cell--l1    { fill: #1d4ed8; }
.hm-cell--l2    { fill: #2563eb; }
.hm-cell--l3    { fill: #3b82f6; }
.hm-cell--l4    { fill: #93c5fd; }
.hm-cell--success { fill: var(--success); }
.hm-cell--failure { fill: var(--danger); }
.hm-cell--mixed   { fill: #f59e0b; }

/* ---- Detail tabs ---- */
.detail-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 500;
  padding: .65rem 1rem;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn--active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover:not(.tab-btn--active) { color: var(--text); }

.tab-panel--hidden { display: none; }

/* ---- History entries ---- */
.entry {
  display: flex;
  gap: .75rem;
  align-items: flex-start;
  padding: .65rem 0;
  border-bottom: 1px solid var(--border);
}
.entry:last-child { border-bottom: none; }

.entry__icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  flex-shrink: 0;
}
.entry--success .entry__icon { background: rgba(34,197,94,.2); color: var(--success); }
.entry--failure .entry__icon { background: rgba(239,68,68,.2); color: var(--danger); }

.entry__date  { font-size: .8rem; color: var(--text-muted); }
.entry__qty   { font-size: .8rem; color: var(--text-muted); margin-left: .4rem; }
.entry__note  { font-size: .9rem; margin-top: .2rem; }

.entry__edit-btn { flex-shrink: 0; margin-left: auto; align-self: center; }

.entry--editing {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: .75rem;
  margin: .25rem 0;
  display: block;
}

.entry__edit-form { display: flex; flex-direction: column; gap: .5rem; }

.entry__edit-row { display: flex; gap: .5rem; }
.entry__edit-row select,
.entry__edit-row input[type=date] { flex: 1; }

.entry__edit-qty { display: flex; align-items: center; gap: .5rem; }
.entry__edit-qty-label { font-size: .85rem; color: var(--text-muted); white-space: nowrap; }
.entry__edit-qty .entry__qty-input { flex: 1; }

.entry__note-input { width: 100%; }

.entry__edit-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .25rem; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal__title { font-size: 1.1rem; font-weight: 600; }
.modal__note  { min-height: 80px; }
.modal__actions { display: flex; gap: .75rem; justify-content: flex-end; }

/* ---- Empty state ---- */
.empty {
  color: var(--text-muted);
  font-size: .95rem;
  padding: 1.5rem 0;
  text-align: center;
}

/* ---- Safe area for notched phones ---- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
}
