/* ============================================================================
   components.css — reusable UI primitives shared across every view.
   ============================================================================ */

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease), transform var(--dur-1) var(--ease),
              border-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: rgb(var(--primary)); color: rgb(var(--on-primary)); box-shadow: var(--shadow-sm); }
.btn--primary:hover { background: rgb(var(--primary-strong)); }
.btn--soft { background: rgb(var(--primary) / 0.12); color: rgb(var(--primary-strong)); }
.btn--soft:hover { background: rgb(var(--primary) / 0.18); }
.btn--ghost { color: rgb(var(--text-2)); border: 1px solid rgb(var(--border-strong)); }
.btn--ghost:hover { background: rgb(var(--surface-hover)); color: rgb(var(--text)); }
.btn--danger { color: rgb(var(--family)); border-color: rgb(var(--family) / 0.4); }
.btn--danger:hover { background: rgb(var(--family) / 0.1); color: rgb(var(--family)); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  color: rgb(var(--text-2));
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.icon-btn:hover { background: rgb(var(--surface-hover)); color: rgb(var(--text)); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn--solid { background: rgb(var(--primary)); color: rgb(var(--on-primary)); box-shadow: var(--shadow-sm); }
.icon-btn--solid:hover { background: rgb(var(--primary-strong)); color: rgb(var(--on-primary)); }
.icon-btn--mini { width: 28px; height: 28px; color: rgb(var(--text-3)); }
.icon-btn--mini:hover { color: rgb(var(--text)); background: rgb(var(--surface-hover)); }

/* ---- Card + section ----------------------------------------------------- */
.card {
  background: rgb(var(--surface));
  border: 1px solid rgb(var(--border));
  border-radius: var(--r-lg);
  padding: var(--pad-card);
  box-shadow: var(--shadow);
}
.card--flush { padding: 0; }

.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.section-title { font-size: 15.5px; font-weight: 650; }
.section-sub { font-size: 13px; color: rgb(var(--text-2)); margin-top: 2px; }
.section-action { flex: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-title { font-size: clamp(22px, 3vw, 28px); font-weight: 700; letter-spacing: -0.025em; }
.page-sub { color: rgb(var(--text-2)); font-size: 14px; margin-top: 4px; }
.page-head__aside { flex: none; }

/* ---- Chip / dot / status ------------------------------------------------ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 12.5px;
  font-weight: 600;
  background: rgb(var(--area, var(--primary)) / 0.13);
  color: rgb(var(--area, var(--primary)));
}

.area-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: var(--r-full);
  background: rgb(var(--area, var(--primary)));
  box-shadow: 0 0 0 3px rgb(var(--area, var(--primary)) / 0.15);
  flex: none;
}

.status { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: var(--r-full); font-size: 12.5px; font-weight: 600; }
.status--live { background: rgb(var(--health) / 0.14); color: rgb(var(--health)); }
.status--calm { background: rgb(var(--surface-2)); color: rgb(var(--text-2)); border: 1px solid rgb(var(--border)); }

/* ---- Progress bar ------------------------------------------------------- */
.bar { position: relative; height: var(--bar-h, 8px); border-radius: var(--r-full); background: rgb(var(--ring-track)); overflow: hidden; }
.bar__fill {
  height: 100%;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, rgb(var(--area, var(--primary))), rgb(var(--area, var(--primary)) / 0.72));
  transition: width var(--dur-3) var(--ease-out);
}

/* ---- Progress ring ------------------------------------------------------ */
.ring { position: relative; display: inline-grid; place-items: center; width: var(--ring-size); height: var(--ring-size); flex: none; }
.ring svg { display: block; }
.ring__track { fill: none; stroke: rgb(var(--ring-track)); }
.ring__fill { fill: none; stroke: rgb(var(--area, var(--primary))); stroke-linecap: round; transition: stroke-dashoffset var(--dur-3) var(--ease-out); }
.ring__center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.05; }
.ring__value { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; }
.ring__value span { font-size: 0.78rem; color: rgb(var(--text-2)); font-weight: 600; }
.ring__label { font-size: 11px; color: rgb(var(--text-3)); margin-top: 3px; letter-spacing: 0.02em; }

/* ---- Segmented control -------------------------------------------------- */
.seg { display: inline-flex; gap: 2px; padding: 3px; background: rgb(var(--surface-2)); border: 1px solid rgb(var(--border)); border-radius: var(--r-sm); }
.seg__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: calc(var(--r-sm) - 3px);
  color: rgb(var(--text-2));
  font-size: 13.5px;
  font-weight: 600;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.seg__item .icon { color: rgb(var(--text-3)); transition: color var(--dur-1) var(--ease); }
.seg__item:hover { color: rgb(var(--text)); }
.seg__item.is-active { background: rgb(var(--surface)); color: rgb(var(--text)); box-shadow: var(--shadow-sm); }
.seg__item.is-active .icon { color: rgb(var(--primary)); }
.seg--sm .seg__item { padding: 5px 11px; font-size: 12.5px; }

/* ---- Round check toggle ------------------------------------------------- */
.check {
  width: 26px;
  height: 26px;
  border-radius: var(--r-full);
  border: 2px solid rgb(var(--border-strong));
  display: grid;
  place-items: center;
  color: rgb(var(--on-primary));
  flex: none;
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), transform var(--dur-1) var(--ease);
}
.check .icon { opacity: 0; transform: scale(0.5); transition: opacity var(--dur-1) var(--ease), transform var(--dur-2) var(--ease-spring); }
.check:hover { border-color: rgb(var(--area, var(--primary))); }
.check:active { transform: scale(0.9); }
.check.is-done { background: rgb(var(--area, var(--primary))); border-color: transparent; animation: pop var(--dur-3) var(--ease-spring); }
.check.is-done .icon { opacity: 1; transform: scale(1); }
.check--lg { width: 32px; height: 32px; }

/* ---- Checklist ---------------------------------------------------------- */
.checklist { display: flex; flex-direction: column; gap: 1px; }
.checklist__item { display: flex; align-items: center; gap: 12px; padding: 9px 8px; border-radius: var(--r-sm); transition: background var(--dur-1) var(--ease); }
.checklist__item:hover { background: rgb(var(--surface-2)); }
.checklist__icon { color: rgb(var(--area, var(--primary))); flex: none; }
.checklist__name { flex: 1; font-size: 14.5px; font-weight: 500; }
.checklist__item.is-done .checklist__name { color: rgb(var(--text-3)); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.checklist__meta { font-size: 12px; color: rgb(var(--text-3)); }
.checklist__right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.checklist__count { font-size: 13px; font-weight: 600; color: rgb(var(--text-2)); }
.checklist__count.is-done { color: rgb(var(--area, var(--primary))); }

/* ---- Drag to reorder ---------------------------------------------------- */
.drag-handle { display: grid; place-items: center; width: 22px; height: 30px; color: rgb(var(--text-3)); cursor: grab; touch-action: none; flex: none; opacity: 0.28; transition: opacity var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
.drag-handle:hover { color: rgb(var(--text-2)); }
.task:hover .drag-handle, .checklist__item:hover .drag-handle { opacity: 0.7; }
.is-dragging { cursor: grabbing; background: rgb(var(--surface)); box-shadow: var(--shadow-lg); border-radius: var(--r-sm); position: relative; z-index: 5; }
@media (hover: none) { .drag-handle { opacity: 0.45; } }

/* ---- Counter (steppers) ------------------------------------------------- */
.counter { display: inline-flex; align-items: center; gap: 8px; padding: 5px; background: rgb(var(--surface-2)); border: 1px solid rgb(var(--border)); border-radius: var(--r-full); }
.counter__btn { width: 34px; height: 34px; border-radius: var(--r-full); display: grid; place-items: center; color: rgb(var(--text-2)); background: rgb(var(--surface)); border: 1px solid rgb(var(--border)); transition: color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease); }
.counter__btn:hover { color: rgb(var(--area, var(--primary))); border-color: rgb(var(--area, var(--primary))); }
.counter__btn--sm { width: 26px; height: 26px; }
.counter__read { min-width: 96px; text-align: center; line-height: 1.05; }
.counter__value { font-size: 16px; font-weight: 700; }
.counter__target { display: block; font-size: 11px; color: rgb(var(--text-3)); }
.counter__read.is-done .counter__value { color: rgb(var(--area, var(--primary))); }

.check-control { display: flex; align-items: center; gap: 12px; }
.check-control__label { font-size: 13.5px; color: rgb(var(--text-2)); font-weight: 550; }

/* ---- 7-day trail -------------------------------------------------------- */
.trail { display: inline-flex; gap: 4px; }
.trail__dot { width: 9px; height: 9px; border-radius: 3px; background: rgb(var(--text-3) / 0.25); }
.trail__dot.is-done { background: rgb(var(--area, var(--primary))); }

/* ---- Inputs ------------------------------------------------------------- */
.input {
  width: 100%;
  padding: 9px 12px;
  background: rgb(var(--surface-2));
  border: 1px solid rgb(var(--border));
  border-radius: var(--r-sm);
  font-size: 14px;
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.input::placeholder { color: rgb(var(--text-3)); }
.input:focus { outline: none; border-color: rgb(var(--primary)); background: rgb(var(--surface)); box-shadow: 0 0 0 3px rgb(var(--primary) / 0.14); }
.input--select { width: auto; cursor: pointer; padding-right: 8px; }
.input--time { width: auto; }
.input--number, input[type='number'].input { width: auto; min-width: 120px; }

.add-row { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.add-row .input { flex: 1; }

/* ---- Switch ------------------------------------------------------------- */
.switch { appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: var(--r-full); background: rgb(var(--border-strong)); position: relative; cursor: pointer; flex: none; transition: background var(--dur-2) var(--ease); }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: var(--r-full); background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur-2) var(--ease); }
.switch:checked { background: rgb(var(--primary)); }
.switch:checked::after { transform: translateX(18px); }

/* ---- Stat tile ---------------------------------------------------------- */
.stat { display: flex; align-items: center; gap: 12px; }
.stat__icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: var(--r-sm); background: rgb(var(--area, var(--primary)) / 0.13); color: rgb(var(--area, var(--primary))); flex: none; }
.stat__value { font-size: 18px; font-weight: 700; line-height: 1.1; }
.stat__label { font-size: 13px; color: rgb(var(--text-2)); }
.stat__sub { font-size: 12px; color: rgb(var(--text-3)); }

/* ---- Empty state -------------------------------------------------------- */
.empty { text-align: center; padding: 30px 16px; }
.empty__icon { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 12px; border-radius: var(--r-lg); background: rgb(var(--surface-2)); color: rgb(var(--text-3)); }
.empty__title { font-size: 15.5px; font-weight: 600; }
.empty__text { font-size: 13.5px; color: rgb(var(--text-2)); max-width: 36ch; margin: 5px auto 0; }
.empty__action { margin-top: 16px; }

/* ---- Toast -------------------------------------------------------------- */
.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  padding: 11px 18px;
  background: rgb(var(--text));
  color: rgb(var(--bg));
  border-radius: var(--r-full);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease-out);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 900px) { .toast { bottom: 84px; } }
